|
|
// modules are defined as an array
|
|
|
// [ module function, map of requires ]
|
|
|
//
|
|
|
// map of requires is short require name -> numeric require
|
|
|
//
|
|
|
// anything defined in a previous bundle is accessed via the
|
|
|
// orig method which is the require for previous bundles
|
|
|
|
|
|
(function (modules, entry, mainEntry, parcelRequireName, globalName) {
|
|
|
/* eslint-disable no-undef */
|
|
|
var globalObject =
|
|
|
typeof globalThis !== 'undefined'
|
|
|
? globalThis
|
|
|
: typeof self !== 'undefined'
|
|
|
? self
|
|
|
: typeof window !== 'undefined'
|
|
|
? window
|
|
|
: typeof global !== 'undefined'
|
|
|
? global
|
|
|
: {};
|
|
|
/* eslint-enable no-undef */
|
|
|
|
|
|
// Save the require from previous bundle to this closure if any
|
|
|
var previousRequire =
|
|
|
typeof globalObject[parcelRequireName] === 'function' &&
|
|
|
globalObject[parcelRequireName];
|
|
|
|
|
|
var cache = previousRequire.cache || {};
|
|
|
// Do not use `require` to prevent Webpack from trying to bundle this call
|
|
|
var nodeRequire =
|
|
|
typeof module !== 'undefined' &&
|
|
|
typeof module.require === 'function' &&
|
|
|
module.require.bind(module);
|
|
|
|
|
|
function newRequire(name, jumped) {
|
|
|
if (!cache[name]) {
|
|
|
if (!modules[name]) {
|
|
|
// if we cannot find the module within our internal map or
|
|
|
// cache jump to the current global require ie. the last bundle
|
|
|
// that was added to the page.
|
|
|
var currentRequire =
|
|
|
typeof globalObject[parcelRequireName] === 'function' &&
|
|
|
globalObject[parcelRequireName];
|
|
|
if (!jumped && currentRequire) {
|
|
|
return currentRequire(name, true);
|
|
|
}
|
|
|
|
|
|
// If there are other bundles on this page the require from the
|
|
|
// previous one is saved to 'previousRequire'. Repeat this as
|
|
|
// many times as there are bundles until the module is found or
|
|
|
// we exhaust the require chain.
|
|
|
if (previousRequire) {
|
|
|
return previousRequire(name, true);
|
|
|
}
|
|
|
|
|
|
// Try the node require function if it exists.
|
|
|
if (nodeRequire && typeof name === 'string') {
|
|
|
return nodeRequire(name);
|
|
|
}
|
|
|
|
|
|
var err = new Error("Cannot find module '" + name + "'");
|
|
|
err.code = 'MODULE_NOT_FOUND';
|
|
|
throw err;
|
|
|
}
|
|
|
|
|
|
localRequire.resolve = resolve;
|
|
|
localRequire.cache = {};
|
|
|
|
|
|
var module = (cache[name] = new newRequire.Module(name));
|
|
|
|
|
|
modules[name][0].call(
|
|
|
module.exports,
|
|
|
localRequire,
|
|
|
module,
|
|
|
module.exports,
|
|
|
this
|
|
|
);
|
|
|
}
|
|
|
|
|
|
return cache[name].exports;
|
|
|
|
|
|
function localRequire(x) {
|
|
|
var res = localRequire.resolve(x);
|
|
|
return res === false ? {} : newRequire(res);
|
|
|
}
|
|
|
|
|
|
function resolve(x) {
|
|
|
var id = modules[name][1][x];
|
|
|
return id != null ? id : x;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function Module(moduleName) {
|
|
|
this.id = moduleName;
|
|
|
this.bundle = newRequire;
|
|
|
this.exports = {};
|
|
|
}
|
|
|
|
|
|
newRequire.isParcelRequire = true;
|
|
|
newRequire.Module = Module;
|
|
|
newRequire.modules = modules;
|
|
|
newRequire.cache = cache;
|
|
|
newRequire.parent = previousRequire;
|
|
|
newRequire.register = function (id, exports) {
|
|
|
modules[id] = [
|
|
|
function (require, module) {
|
|
|
module.exports = exports;
|
|
|
},
|
|
|
{},
|
|
|
];
|
|
|
};
|
|
|
|
|
|
Object.defineProperty(newRequire, 'root', {
|
|
|
get: function () {
|
|
|
return globalObject[parcelRequireName];
|
|
|
},
|
|
|
});
|
|
|
|
|
|
globalObject[parcelRequireName] = newRequire;
|
|
|
|
|
|
for (var i = 0; i < entry.length; i++) {
|
|
|
newRequire(entry[i]);
|
|
|
}
|
|
|
|
|
|
if (mainEntry) {
|
|
|
// Expose entry point to Node, AMD or browser globals
|
|
|
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
|
|
|
var mainExports = newRequire(mainEntry);
|
|
|
|
|
|
// CommonJS
|
|
|
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
|
module.exports = mainExports;
|
|
|
|
|
|
// RequireJS
|
|
|
} else if (typeof define === 'function' && define.amd) {
|
|
|
define(function () {
|
|
|
return mainExports;
|
|
|
});
|
|
|
|
|
|
// <script>
|
|
|
} else if (globalName) {
|
|
|
this[globalName] = mainExports;
|
|
|
}
|
|
|
}
|
|
|
})({"hHepG":[function(require,module,exports) {
|
|
|
"use strict";
|
|
|
var global = arguments[3];
|
|
|
var HMR_HOST = null;
|
|
|
var HMR_PORT = 1234;
|
|
|
var HMR_SECURE = false;
|
|
|
var HMR_ENV_HASH = "d6ea1d42532a7575";
|
|
|
module.bundle.HMR_BUNDLE_ID = "57183d3b35a81405";
|
|
|
/* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, chrome, browser, importScripts */ /*::
|
|
|
import type {
|
|
|
HMRAsset,
|
|
|
HMRMessage,
|
|
|
} from '@parcel/reporter-dev-server/src/HMRServer.js';
|
|
|
interface ParcelRequire {
|
|
|
(string): mixed;
|
|
|
cache: {|[string]: ParcelModule|};
|
|
|
hotData: mixed;
|
|
|
Module: any;
|
|
|
parent: ?ParcelRequire;
|
|
|
isParcelRequire: true;
|
|
|
modules: {|[string]: [Function, {|[string]: string|}]|};
|
|
|
HMR_BUNDLE_ID: string;
|
|
|
root: ParcelRequire;
|
|
|
}
|
|
|
interface ParcelModule {
|
|
|
hot: {|
|
|
|
data: mixed,
|
|
|
accept(cb: (Function) => void): void,
|
|
|
dispose(cb: (mixed) => void): void,
|
|
|
// accept(deps: Array<string> | string, cb: (Function) => void): void,
|
|
|
// decline(): void,
|
|
|
_acceptCallbacks: Array<(Function) => void>,
|
|
|
_disposeCallbacks: Array<(mixed) => void>,
|
|
|
|};
|
|
|
}
|
|
|
interface ExtensionContext {
|
|
|
runtime: {|
|
|
|
reload(): void,
|
|
|
|};
|
|
|
}
|
|
|
declare var module: {bundle: ParcelRequire, ...};
|
|
|
declare var HMR_HOST: string;
|
|
|
declare var HMR_PORT: string;
|
|
|
declare var HMR_ENV_HASH: string;
|
|
|
declare var HMR_SECURE: boolean;
|
|
|
declare var chrome: ExtensionContext;
|
|
|
declare var browser: ExtensionContext;
|
|
|
*/ var OVERLAY_ID = "__parcel__error__overlay__";
|
|
|
var OldModule = module.bundle.Module;
|
|
|
function Module(moduleName) {
|
|
|
OldModule.call(this, moduleName);
|
|
|
this.hot = {
|
|
|
data: module.bundle.hotData,
|
|
|
_acceptCallbacks: [],
|
|
|
_disposeCallbacks: [],
|
|
|
accept: function(fn) {
|
|
|
this._acceptCallbacks.push(fn || function() {});
|
|
|
},
|
|
|
dispose: function(fn) {
|
|
|
this._disposeCallbacks.push(fn);
|
|
|
}
|
|
|
};
|
|
|
module.bundle.hotData = undefined;
|
|
|
}
|
|
|
module.bundle.Module = Module;
|
|
|
var checkedAssets, acceptedAssets, assetsToAccept /*: Array<[ParcelRequire, string]> */ ;
|
|
|
function getHostname() {
|
|
|
return HMR_HOST || (location.protocol.indexOf("http") === 0 ? location.hostname : "localhost");
|
|
|
}
|
|
|
function getPort() {
|
|
|
return HMR_PORT || location.port;
|
|
|
} // eslint-disable-next-line no-redeclare
|
|
|
var parent = module.bundle.parent;
|
|
|
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== "undefined") {
|
|
|
var hostname = getHostname();
|
|
|
var port = getPort();
|
|
|
var protocol = HMR_SECURE || location.protocol == "https:" && !/localhost|127.0.0.1|0.0.0.0/.test(hostname) ? "wss" : "ws";
|
|
|
var ws = new WebSocket(protocol + "://" + hostname + (port ? ":" + port : "") + "/"); // Safari doesn't support sourceURL in error stacks.
|
|
|
// eval may also be disabled via CSP, so do a quick check.
|
|
|
var supportsSourceURL = false;
|
|
|
try {
|
|
|
(0, eval)('throw new Error("test"); //# sourceURL=test.js');
|
|
|
} catch (err) {
|
|
|
supportsSourceURL = err.stack.includes("test.js");
|
|
|
} // $FlowFixMe
|
|
|
ws.onmessage = async function(event) {
|
|
|
checkedAssets = {} /*: {|[string]: boolean|} */ ;
|
|
|
acceptedAssets = {} /*: {|[string]: boolean|} */ ;
|
|
|
assetsToAccept = [];
|
|
|
var data = JSON.parse(event.data);
|
|
|
if (data.type === "update") {
|
|
|
// Remove error overlay if there is one
|
|
|
if (typeof document !== "undefined") removeErrorOverlay();
|
|
|
let assets = data.assets.filter((asset)=>asset.envHash === HMR_ENV_HASH); // Handle HMR Update
|
|
|
let handled = assets.every((asset)=>{
|
|
|
return asset.type === "css" || asset.type === "js" && hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle);
|
|
|
});
|
|
|
if (handled) {
|
|
|
console.clear(); // Dispatch custom event so other runtimes (e.g React Refresh) are aware.
|
|
|
if (typeof window !== "undefined" && typeof CustomEvent !== "undefined") window.dispatchEvent(new CustomEvent("parcelhmraccept"));
|
|
|
await hmrApplyUpdates(assets);
|
|
|
for(var i = 0; i < assetsToAccept.length; i++){
|
|
|
var id = assetsToAccept[i][1];
|
|
|
if (!acceptedAssets[id]) hmrAcceptRun(assetsToAccept[i][0], id);
|
|
|
}
|
|
|
} else if ("reload" in location) location.reload();
|
|
|
else {
|
|
|
// Web extension context
|
|
|
var ext = typeof chrome === "undefined" ? typeof browser === "undefined" ? null : browser : chrome;
|
|
|
if (ext && ext.runtime && ext.runtime.reload) ext.runtime.reload();
|
|
|
}
|
|
|
}
|
|
|
if (data.type === "error") {
|
|
|
// Log parcel errors to console
|
|
|
for (let ansiDiagnostic of data.diagnostics.ansi){
|
|
|
let stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack;
|
|
|
console.error("\uD83D\uDEA8 [parcel]: " + ansiDiagnostic.message + "\n" + stack + "\n\n" + ansiDiagnostic.hints.join("\n"));
|
|
|
}
|
|
|
if (typeof document !== "undefined") {
|
|
|
// Render the fancy html overlay
|
|
|
removeErrorOverlay();
|
|
|
var overlay = createErrorOverlay(data.diagnostics.html); // $FlowFixMe
|
|
|
document.body.appendChild(overlay);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
ws.onerror = function(e) {
|
|
|
console.error(e.message);
|
|
|
};
|
|
|
ws.onclose = function() {
|
|
|
console.warn("[parcel] \uD83D\uDEA8 Connection to the HMR server was lost");
|
|
|
};
|
|
|
}
|
|
|
function removeErrorOverlay() {
|
|
|
var overlay = document.getElementById(OVERLAY_ID);
|
|
|
if (overlay) {
|
|
|
overlay.remove();
|
|
|
console.log("[parcel] \u2728 Error resolved");
|
|
|
}
|
|
|
}
|
|
|
function createErrorOverlay(diagnostics) {
|
|
|
var overlay = document.createElement("div");
|
|
|
overlay.id = OVERLAY_ID;
|
|
|
let errorHTML = '<div style="background: black; opacity: 0.85; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; font-family: Menlo, Consolas, monospace; z-index: 9999;">';
|
|
|
for (let diagnostic of diagnostics){
|
|
|
let stack = diagnostic.frames.length ? diagnostic.frames.reduce((p, frame)=>{
|
|
|
return `${p}
|
|
|
<a href="/__parcel_launch_editor?file=${encodeURIComponent(frame.location)}" style="text-decoration: underline; color: #888" onclick="fetch(this.href); return false">${frame.location}</a>
|
|
|
${frame.code}`;
|
|
|
}, "") : diagnostic.stack;
|
|
|
errorHTML += `
|
|
|
<div>
|
|
|
<div style="font-size: 18px; font-weight: bold; margin-top: 20px;">
|
|
|
🚨 ${diagnostic.message}
|
|
|
</div>
|
|
|
<pre>${stack}</pre>
|
|
|
<div>
|
|
|
${diagnostic.hints.map((hint)=>"<div>\uD83D\uDCA1 " + hint + "</div>").join("")}
|
|
|
</div>
|
|
|
${diagnostic.documentation ? `<div>📝 <a style="color: violet" href="${diagnostic.documentation}" target="_blank">Learn more</a></div>` : ""}
|
|
|
</div>
|
|
|
`;
|
|
|
}
|
|
|
errorHTML += "</div>";
|
|
|
overlay.innerHTML = errorHTML;
|
|
|
return overlay;
|
|
|
}
|
|
|
function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */ {
|
|
|
var modules = bundle.modules;
|
|
|
if (!modules) return [];
|
|
|
var parents = [];
|
|
|
var k, d, dep;
|
|
|
for(k in modules)for(d in modules[k][1]){
|
|
|
dep = modules[k][1][d];
|
|
|
if (dep === id || Array.isArray(dep) && dep[dep.length - 1] === id) parents.push([
|
|
|
bundle,
|
|
|
k
|
|
|
]);
|
|
|
}
|
|
|
if (bundle.parent) parents = parents.concat(getParents(bundle.parent, id));
|
|
|
return parents;
|
|
|
}
|
|
|
function updateLink(link) {
|
|
|
var newLink = link.cloneNode();
|
|
|
newLink.onload = function() {
|
|
|
if (link.parentNode !== null) // $FlowFixMe
|
|
|
link.parentNode.removeChild(link);
|
|
|
};
|
|
|
newLink.setAttribute("href", link.getAttribute("href").split("?")[0] + "?" + Date.now()); // $FlowFixMe
|
|
|
link.parentNode.insertBefore(newLink, link.nextSibling);
|
|
|
}
|
|
|
var cssTimeout = null;
|
|
|
function reloadCSS() {
|
|
|
if (cssTimeout) return;
|
|
|
cssTimeout = setTimeout(function() {
|
|
|
var links = document.querySelectorAll('link[rel="stylesheet"]');
|
|
|
for(var i = 0; i < links.length; i++){
|
|
|
// $FlowFixMe[incompatible-type]
|
|
|
var href = links[i].getAttribute("href");
|
|
|
var hostname = getHostname();
|
|
|
var servedFromHMRServer = hostname === "localhost" ? new RegExp("^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):" + getPort()).test(href) : href.indexOf(hostname + ":" + getPort());
|
|
|
var absolute = /^https?:\/\//i.test(href) && href.indexOf(location.origin) !== 0 && !servedFromHMRServer;
|
|
|
if (!absolute) updateLink(links[i]);
|
|
|
}
|
|
|
cssTimeout = null;
|
|
|
}, 50);
|
|
|
}
|
|
|
async function hmrApplyUpdates(assets) {
|
|
|
global.parcelHotUpdate = Object.create(null);
|
|
|
let scriptsToRemove;
|
|
|
try {
|
|
|
// If sourceURL comments aren't supported in eval, we need to load
|
|
|
// the update from the dev server over HTTP so that stack traces
|
|
|
// are correct in errors/logs. This is much slower than eval, so
|
|
|
// we only do it if needed (currently just Safari).
|
|
|
// https://bugs.webkit.org/show_bug.cgi?id=137297
|
|
|
// This path is also taken if a CSP disallows eval.
|
|
|
if (!supportsSourceURL) {
|
|
|
let promises = assets.map((asset)=>{
|
|
|
if (asset.type === "js") {
|
|
|
if (typeof document !== "undefined") {
|
|
|
let script = document.createElement("script");
|
|
|
script.src = asset.url;
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
var _document$head;
|
|
|
script.onload = ()=>resolve(script);
|
|
|
script.onerror = reject;
|
|
|
(_document$head = document.head) === null || _document$head === void 0 || _document$head.appendChild(script);
|
|
|
});
|
|
|
} else if (typeof importScripts === "function") return new Promise((resolve, reject)=>{
|
|
|
try {
|
|
|
importScripts(asset.url);
|
|
|
} catch (err) {
|
|
|
reject(err);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
scriptsToRemove = await Promise.all(promises);
|
|
|
}
|
|
|
assets.forEach(function(asset) {
|
|
|
hmrApply(module.bundle.root, asset);
|
|
|
});
|
|
|
} finally{
|
|
|
delete global.parcelHotUpdate;
|
|
|
if (scriptsToRemove) scriptsToRemove.forEach((script)=>{
|
|
|
if (script) {
|
|
|
var _document$head2;
|
|
|
(_document$head2 = document.head) === null || _document$head2 === void 0 || _document$head2.removeChild(script);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
function hmrApply(bundle, asset) {
|
|
|
var modules = bundle.modules;
|
|
|
if (!modules) return;
|
|
|
if (asset.type === "css") reloadCSS();
|
|
|
else if (asset.type === "js") {
|
|
|
let deps = asset.depsByBundle[bundle.HMR_BUNDLE_ID];
|
|
|
if (deps) {
|
|
|
if (modules[asset.id]) {
|
|
|
// Remove dependencies that are removed and will become orphaned.
|
|
|
// This is necessary so that if the asset is added back again, the cache is gone, and we prevent a full page reload.
|
|
|
let oldDeps = modules[asset.id][1];
|
|
|
for(let dep in oldDeps)if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
|
|
|
let id = oldDeps[dep];
|
|
|
let parents = getParents(module.bundle.root, id);
|
|
|
if (parents.length === 1) hmrDelete(module.bundle.root, id);
|
|
|
}
|
|
|
}
|
|
|
if (supportsSourceURL) // Global eval. We would use `new Function` here but browser
|
|
|
// support for source maps is better with eval.
|
|
|
(0, eval)(asset.output);
|
|
|
let fn = global.parcelHotUpdate[asset.id];
|
|
|
modules[asset.id] = [
|
|
|
fn,
|
|
|
deps
|
|
|
];
|
|
|
} else if (bundle.parent) hmrApply(bundle.parent, asset);
|
|
|
}
|
|
|
}
|
|
|
function hmrDelete(bundle, id1) {
|
|
|
let modules = bundle.modules;
|
|
|
if (!modules) return;
|
|
|
if (modules[id1]) {
|
|
|
// Collect dependencies that will become orphaned when this module is deleted.
|
|
|
let deps = modules[id1][1];
|
|
|
let orphans = [];
|
|
|
for(let dep in deps){
|
|
|
let parents = getParents(module.bundle.root, deps[dep]);
|
|
|
if (parents.length === 1) orphans.push(deps[dep]);
|
|
|
} // Delete the module. This must be done before deleting dependencies in case of circular dependencies.
|
|
|
delete modules[id1];
|
|
|
delete bundle.cache[id1]; // Now delete the orphans.
|
|
|
orphans.forEach((id)=>{
|
|
|
hmrDelete(module.bundle.root, id);
|
|
|
});
|
|
|
} else if (bundle.parent) hmrDelete(bundle.parent, id1);
|
|
|
}
|
|
|
function hmrAcceptCheck(bundle, id, depsByBundle) {
|
|
|
if (hmrAcceptCheckOne(bundle, id, depsByBundle)) return true;
|
|
|
// Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
|
|
|
let parents = getParents(module.bundle.root, id);
|
|
|
let accepted = false;
|
|
|
while(parents.length > 0){
|
|
|
let v = parents.shift();
|
|
|
let a = hmrAcceptCheckOne(v[0], v[1], null);
|
|
|
if (a) // If this parent accepts, stop traversing upward, but still consider siblings.
|
|
|
accepted = true;
|
|
|
else {
|
|
|
// Otherwise, queue the parents in the next level upward.
|
|
|
let p = getParents(module.bundle.root, v[1]);
|
|
|
if (p.length === 0) {
|
|
|
// If there are no parents, then we've reached an entry without accepting. Reload.
|
|
|
accepted = false;
|
|
|
break;
|
|
|
}
|
|
|
parents.push(...p);
|
|
|
}
|
|
|
}
|
|
|
return accepted;
|
|
|
}
|
|
|
function hmrAcceptCheckOne(bundle, id, depsByBundle) {
|
|
|
var modules = bundle.modules;
|
|
|
if (!modules) return;
|
|
|
if (depsByBundle && !depsByBundle[bundle.HMR_BUNDLE_ID]) {
|
|
|
// If we reached the root bundle without finding where the asset should go,
|
|
|
// there's nothing to do. Mark as "accepted" so we don't reload the page.
|
|
|
if (!bundle.parent) return true;
|
|
|
return hmrAcceptCheck(bundle.parent, id, depsByBundle);
|
|
|
}
|
|
|
if (checkedAssets[id]) return true;
|
|
|
checkedAssets[id] = true;
|
|
|
var cached = bundle.cache[id];
|
|
|
assetsToAccept.push([
|
|
|
bundle,
|
|
|
id
|
|
|
]);
|
|
|
if (!cached || cached.hot && cached.hot._acceptCallbacks.length) return true;
|
|
|
}
|
|
|
function hmrAcceptRun(bundle, id) {
|
|
|
var cached = bundle.cache[id];
|
|
|
bundle.hotData = {};
|
|
|
if (cached && cached.hot) cached.hot.data = bundle.hotData;
|
|
|
if (cached && cached.hot && cached.hot._disposeCallbacks.length) cached.hot._disposeCallbacks.forEach(function(cb) {
|
|
|
cb(bundle.hotData);
|
|
|
});
|
|
|
delete bundle.cache[id];
|
|
|
bundle(id);
|
|
|
cached = bundle.cache[id];
|
|
|
if (cached && cached.hot && cached.hot._acceptCallbacks.length) cached.hot._acceptCallbacks.forEach(function(cb) {
|
|
|
var assetsToAlsoAccept = cb(function() {
|
|
|
return getParents(module.bundle.root, id);
|
|
|
});
|
|
|
if (assetsToAlsoAccept && assetsToAccept.length) // $FlowFixMe[method-unbinding]
|
|
|
assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
|
|
|
});
|
|
|
acceptedAssets[id] = true;
|
|
|
}
|
|
|
|
|
|
},{}],"7bZzU":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
var _base = require("./Base");
|
|
|
var _baseDefault = parcelHelpers.interopDefault(_base);
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
new (0, _baseDefault.default)();
|
|
|
}, false);
|
|
|
|
|
|
},{"./Base":"cqs8R","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"cqs8R":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
var _fipamoAdminAPI = require("../libraries/FipamoAdminAPI");
|
|
|
var _fipamoAdminAPIDefault = parcelHelpers.interopDefault(_fipamoAdminAPI);
|
|
|
var _maintenanceManager = require("./controllers/MaintenanceManager");
|
|
|
var _maintenanceManagerDefault = parcelHelpers.interopDefault(_maintenanceManager);
|
|
|
var _dataUtils = require("./utils/DataUtils");
|
|
|
var _dataUtilsDefault = parcelHelpers.interopDefault(_dataUtils);
|
|
|
var _dataEvent = require("./events/DataEvent");
|
|
|
var _dashManager = require("./controllers/DashManager");
|
|
|
var _dashManagerDefault = parcelHelpers.interopDefault(_dashManager);
|
|
|
var _notifications = require("./ui/Notifications");
|
|
|
var _notificationsDefault = parcelHelpers.interopDefault(_notifications);
|
|
|
const data = new (0, _dataUtilsDefault.default)();
|
|
|
const notify = new (0, _notificationsDefault.default)();
|
|
|
class Base {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){
|
|
|
this.processing = false;
|
|
|
this.start();
|
|
|
}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
start() {
|
|
|
if (document.getElementById("dash-form") || document.getElementById("dash-init")) {
|
|
|
var options = document.getElementsByClassName("init-option");
|
|
|
for(let index = 0; index < options.length; index++)options[index].addEventListener("click", (e)=>this.handleOptions(e));
|
|
|
if (document.getElementById("dash-form")) document.getElementById("login-btn").addEventListener("click", (e)=>this.handleLogin(e));
|
|
|
else {
|
|
|
document.getElementById("init-blog").addEventListener("click", (e)=>this.handleSetup(e));
|
|
|
document.getElementById("blog-restore").addEventListener("click", (e)=>this.handleRestore(e));
|
|
|
}
|
|
|
} else if (document.getElementById("dash-reset")) {
|
|
|
document.getElementById("get-secret-btn").addEventListener("click", (e)=>this.handleReset(e));
|
|
|
document.getElementById("reset-btn").addEventListener("click", (e)=>this.handleReset(e));
|
|
|
} else new (0, _dashManagerDefault.default)();
|
|
|
}
|
|
|
// event handlers
|
|
|
//--------------------------
|
|
|
handleLogin(e) {
|
|
|
if (this.processing) return;
|
|
|
let self = this;
|
|
|
e.preventDefault();
|
|
|
let authForm = data.formDataToJSON(document.getElementById("login"));
|
|
|
notify.alert("Looking, hold up", null);
|
|
|
let api = new (0, _fipamoAdminAPIDefault.default)();
|
|
|
this.processing = true;
|
|
|
api.login(authForm).then((response)=>{
|
|
|
self.processing = false;
|
|
|
if (response.type === _dataEvent.REQUEST_LAME) notify.alert(response.message, false);
|
|
|
else {
|
|
|
notify.alert(response.message, true);
|
|
|
e.target.innerHTML = response.message;
|
|
|
setTimeout(()=>{
|
|
|
window.location = "/dashboard";
|
|
|
}, 500);
|
|
|
}
|
|
|
}).catch((err)=>{
|
|
|
self.processing = false;
|
|
|
notify.alert(err, false);
|
|
|
});
|
|
|
}
|
|
|
handleSetup(e) {
|
|
|
if (this.processing) return;
|
|
|
let self = this;
|
|
|
e.stopPropagation();
|
|
|
e.preventDefault();
|
|
|
let setUpForm = data.formDataToJSON(document.getElementById("init-form"));
|
|
|
let mm = new (0, _maintenanceManagerDefault.default)();
|
|
|
this.processing = true;
|
|
|
mm.create(setUpForm).then((response)=>{
|
|
|
if (response.type === _dataEvent.API_INIT_LAME) {
|
|
|
self.processing = false;
|
|
|
notify.alert(response.message, false);
|
|
|
} else {
|
|
|
self.processing = false;
|
|
|
notify.alert(response.message, true);
|
|
|
setTimeout(()=>{
|
|
|
window.location = "/dashboard";
|
|
|
}, 700);
|
|
|
}
|
|
|
}).catch((err)=>{
|
|
|
self.processing = false;
|
|
|
notify.alert(err, false);
|
|
|
});
|
|
|
}
|
|
|
handleRestore(e) {
|
|
|
if (this.processing) return;
|
|
|
let self = this;
|
|
|
e.stopPropagation();
|
|
|
e.preventDefault();
|
|
|
let mm = new (0, _maintenanceManagerDefault.default)();
|
|
|
var form = document.getElementById("init-restore");
|
|
|
this.processing = true;
|
|
|
mm.restore(form).then((response)=>{
|
|
|
if (response.type === _dataEvent.REQUEST_LAME) {
|
|
|
self.processing = false;
|
|
|
notify.alert(response.message, false);
|
|
|
} else {
|
|
|
self.processing = false;
|
|
|
notify.alert(response.message, true);
|
|
|
setTimeout(()=>{
|
|
|
window.location = "/dashboard";
|
|
|
}, 1500);
|
|
|
}
|
|
|
}).catch((err)=>{
|
|
|
self.processing = false;
|
|
|
notify.alert(err, false);
|
|
|
});
|
|
|
}
|
|
|
handleReset(e) {
|
|
|
e.stopPropagation();
|
|
|
e.preventDefault();
|
|
|
let self = this;
|
|
|
let mm = new (0, _maintenanceManagerDefault.default)();
|
|
|
if (e.target.id == "get-secret-btn") {
|
|
|
let data1 = {
|
|
|
email: document.getElementById("email").value,
|
|
|
task: "retrieveSecret"
|
|
|
};
|
|
|
this.processing = true;
|
|
|
mm.secret(data1).then((response)=>{
|
|
|
self.processing = false;
|
|
|
if (response.secret) {
|
|
|
document.getElementById("secret").value = response.secret;
|
|
|
notify.alert(response.message, true);
|
|
|
} else if (response.type == "mailSent") notify.alert(response.message, true);
|
|
|
else notify.alert(response.message, false);
|
|
|
}).catch((err)=>{
|
|
|
self.processing = false;
|
|
|
notify.alert(err, false);
|
|
|
});
|
|
|
} else {
|
|
|
let data2 = {
|
|
|
newPass: document.getElementById("new_password").value,
|
|
|
newPassConfirm: document.getElementById("new_password2").value,
|
|
|
secret: document.getElementById("secret").value
|
|
|
};
|
|
|
mm.newPass(data2).then((response)=>{
|
|
|
self.processing = false;
|
|
|
if (response.type == "passNotCreated") notify.alert(response.message, false);
|
|
|
else {
|
|
|
notify.alert(response.message, true);
|
|
|
setTimeout(()=>{
|
|
|
window.location = "/dashboard";
|
|
|
}, 1000);
|
|
|
}
|
|
|
}).catch((err)=>{
|
|
|
self.processing = false;
|
|
|
notify.alert(err, false);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
handleOptions(e) {
|
|
|
e.stopPropagation();
|
|
|
e.preventDefault();
|
|
|
let init = document.getElementById("dash-init");
|
|
|
let restore = document.getElementById("dash-restore");
|
|
|
if (e.target.id === "init-switch-restore") {
|
|
|
init.style.display = "none";
|
|
|
init.style.visibility = "hidden";
|
|
|
restore.style.display = "flex";
|
|
|
restore.style.visibility = "visible";
|
|
|
} else {
|
|
|
init.style.display = "flex";
|
|
|
init.style.visibility = "visible";
|
|
|
restore.style.display = "none";
|
|
|
restore.style.visibility = "hidden";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
exports.default = Base;
|
|
|
|
|
|
},{"../libraries/FipamoAdminAPI":"3dcvg","./controllers/MaintenanceManager":"cYXLM","./utils/DataUtils":"eM6UW","./events/DataEvent":"hCRFh","./controllers/DashManager":"9gCOB","./ui/Notifications":"9GRdG","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"3dcvg":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
parcelHelpers.export(exports, "REQUEST_TYPE_POST", ()=>REQUEST_TYPE_POST);
|
|
|
parcelHelpers.export(exports, "REQUEST_TYPE_GET", ()=>REQUEST_TYPE_GET);
|
|
|
parcelHelpers.export(exports, "REQUEST_TYPE_PUT", ()=>REQUEST_TYPE_PUT);
|
|
|
parcelHelpers.export(exports, "REQUEST_TYPE_DELETE", ()=>REQUEST_TYPE_DELETE);
|
|
|
parcelHelpers.export(exports, "CONTENT_TYPE_JSON", ()=>CONTENT_TYPE_JSON);
|
|
|
parcelHelpers.export(exports, "CONTENT_TYPE_FORM", ()=>CONTENT_TYPE_FORM);
|
|
|
parcelHelpers.export(exports, "API_STATUS", ()=>API_STATUS);
|
|
|
parcelHelpers.export(exports, "API_GET_SETTINGS", ()=>API_GET_SETTINGS);
|
|
|
parcelHelpers.export(exports, "API_GET_MEMBER_INFO", ()=>API_GET_MEMBER_INFO);
|
|
|
parcelHelpers.export(exports, "API_NEW_PAGE", ()=>API_NEW_PAGE);
|
|
|
parcelHelpers.export(exports, "API_EDIT_PAGE", ()=>API_EDIT_PAGE);
|
|
|
parcelHelpers.export(exports, "API_DELETE_PAGE", ()=>API_DELETE_PAGE);
|
|
|
parcelHelpers.export(exports, "API_SETTINGS_SYNC", ()=>API_SETTINGS_SYNC);
|
|
|
parcelHelpers.export(exports, "API_PUBLISH_PAGES", ()=>API_PUBLISH_PAGES);
|
|
|
parcelHelpers.export(exports, "API_NAV_SYNC", ()=>API_NAV_SYNC);
|
|
|
parcelHelpers.export(exports, "API_REINDEX_PAGES", ()=>API_REINDEX_PAGES);
|
|
|
parcelHelpers.export(exports, "API_SEND_MAIL", ()=>API_SEND_MAIL);
|
|
|
parcelHelpers.export(exports, "API_LOGIN", ()=>API_LOGIN);
|
|
|
parcelHelpers.export(exports, "AUTH_STATUS", ()=>AUTH_STATUS);
|
|
|
parcelHelpers.export(exports, "TASK_SETTINGS_WRITE", ()=>TASK_SETTINGS_WRITE);
|
|
|
parcelHelpers.export(exports, "TASK_PUBLISH_SITE", ()=>TASK_PUBLISH_SITE);
|
|
|
parcelHelpers.export(exports, "TASK_PAGE_CREATE", ()=>TASK_PAGE_CREATE);
|
|
|
parcelHelpers.export(exports, "TASK_PAGE_EDIT", ()=>TASK_PAGE_EDIT);
|
|
|
parcelHelpers.export(exports, "TASK_PAGE_DELETE", ()=>TASK_PAGE_DELETE);
|
|
|
parcelHelpers.export(exports, "TASK_SEND_MAIL", ()=>TASK_SEND_MAIL);
|
|
|
parcelHelpers.export(exports, "TASK_REINDEX_PAGE", ()=>TASK_REINDEX_PAGE);
|
|
|
parcelHelpers.export(exports, "TASK_SYNC_SETTNIGS", ()=>TASK_SYNC_SETTNIGS);
|
|
|
parcelHelpers.export(exports, "TASK_SYNC_NAV", ()=>TASK_SYNC_NAV);
|
|
|
parcelHelpers.export(exports, "TASK_GET_SETTINGS", ()=>TASK_GET_SETTINGS);
|
|
|
parcelHelpers.export(exports, "TASK_GET_MEMBER_INFO", ()=>TASK_GET_MEMBER_INFO);
|
|
|
parcelHelpers.export(exports, "API_ACCESS_GOOD", ()=>API_ACCESS_GOOD);
|
|
|
parcelHelpers.export(exports, "API_ACCESS_BAD", ()=>API_ACCESS_BAD);
|
|
|
parcelHelpers.export(exports, "default", ()=>FipamoAdminAPI);
|
|
|
const REQUEST_TYPE_POST = "POST";
|
|
|
const REQUEST_TYPE_GET = "GET";
|
|
|
const REQUEST_TYPE_PUT = "PUT";
|
|
|
const REQUEST_TYPE_DELETE = "DELETE"; //** POST CONTENT TYPES **//
|
|
|
const CONTENT_TYPE_JSON = "json";
|
|
|
const CONTENT_TYPE_FORM = "x-www-form-urlencoded"; //** API URLS **//
|
|
|
const API_STATUS = "/api/v1/status";
|
|
|
const API_GET_SETTINGS = "/api/v1/settings/site";
|
|
|
const API_GET_MEMBER_INFO = "/api/v1/settings/member";
|
|
|
const API_NEW_PAGE = "/api/v1/page/create";
|
|
|
const API_EDIT_PAGE = "/api/v1/page/write";
|
|
|
const API_DELETE_PAGE = "/api/v1/page/delete";
|
|
|
const API_SETTINGS_SYNC = "/api/v1/settings/sync";
|
|
|
const API_PUBLISH_PAGES = "/api/v1/settings/publish";
|
|
|
const API_NAV_SYNC = "/api/v1/settings/nav-sync";
|
|
|
const API_REINDEX_PAGES = "/api/v1/settings/reindex";
|
|
|
const API_SEND_MAIL = "/api/v1/mailer";
|
|
|
const API_LOGIN = "/api/v1/login"; //** API TASKS **//
|
|
|
const AUTH_STATUS = "getAuthStatus";
|
|
|
const TASK_SETTINGS_WRITE = "writeSettings";
|
|
|
const TASK_PUBLISH_SITE = "publishSite";
|
|
|
const TASK_PAGE_CREATE = "createNewPage";
|
|
|
const TASK_PAGE_EDIT = "editPage";
|
|
|
const TASK_PAGE_DELETE = "deletePage";
|
|
|
const TASK_SEND_MAIL = "sendMail";
|
|
|
const TASK_REINDEX_PAGE = "reIndexPages";
|
|
|
const TASK_SYNC_SETTNIGS = "syncSite";
|
|
|
const TASK_SYNC_NAV = "syncNav";
|
|
|
const TASK_GET_SETTINGS = "getSiteSettings";
|
|
|
const TASK_GET_MEMBER_INFO = "getMemberInfo"; //** API STATUS **//
|
|
|
const API_ACCESS_GOOD = "apiUseAuthorized";
|
|
|
const API_ACCESS_BAD = "apiUseNotAuthorized";
|
|
|
/**
|
|
|
* A can of methods used to edit install settings, navigation pages and content pages
|
|
|
*/ class FipamoAdminAPI {
|
|
|
/**
|
|
|
* @constructor
|
|
|
* @param {string} baseURL - url of site; uses local when empty
|
|
|
* @param {object} progressBar - element to be used to display upload progress
|
|
|
*/ constructor(baseURL = null, progressBar = null){
|
|
|
this.percentComplete = 0; //for later
|
|
|
this.baseURL = null;
|
|
|
this.progressBar = progressBar;
|
|
|
this.status = false;
|
|
|
if (baseURL) this.baseURL = baseURL; //asks server if a session is active
|
|
|
this._request(this.baseURL ? this.baseURL + API_STATUS : API_STATUS).then((response)=>{
|
|
|
if (response.type === API_ACCESS_GOOD) this.token = response.token;
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Promise method for authenticating and starting a session\
|
|
|
* **POST**`/api/v1/login`
|
|
|
* @param {Object[]} data - json object that contains data for set up
|
|
|
* @param {string} data[].handle - handle for site user
|
|
|
* @param {string} data[].password - password for site user
|
|
|
* @example
|
|
|
* api.login(data).then(response=>{
|
|
|
* console.log("RESPONSE", response);
|
|
|
* })
|
|
|
* @returns {object} json object that contains type and status of login request
|
|
|
```
|
|
|
{
|
|
|
"message":"Example Message of Affirmation or what you're missing!",
|
|
|
"type":"exampleType",
|
|
|
}
|
|
|
```
|
|
|
*/ login(data) {
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
this.baseURL ? data.remote = true : data.remote = false;
|
|
|
this.key ? data.key = this.key : data.key = null;
|
|
|
this._request(this.baseURL ? this.baseURL + API_LOGIN : API_LOGIN, AUTH_STATUS, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data).then((result)=>{
|
|
|
resolve(result);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Method for saving site and navigation settings\
|
|
|
* **POST**`/api/v1/settings/:task`
|
|
|
* @param {string} task - settings being synced `config | navigation`
|
|
|
* @param {object[]} data - json object that contains settings data for [site] or [nav]
|
|
|
* @param {string} data[].global.base_url - base url for site [site]
|
|
|
* @param {string} data[].global.title - site title [site]
|
|
|
* @param {string} data[].global.descriptions - brief site summary [site]
|
|
|
* @param {string} data[].global.background - url for site feature image for header [site]
|
|
|
* @param {boolean} data[].global.private - privacy state for site [disabled] [site]
|
|
|
* @param {boolean} data[].global.renderOnSave - property for publishing site when page saved [disabled] [site]
|
|
|
* @param {string} data[].global.theme - current theme for site [site]
|
|
|
* @param {boolean} data[].global.externalAPI - toggle for external API access [site]
|
|
|
* @param {string} data[].member.handle - current member handle [site]
|
|
|
* @param {string} data[].member.email - current member email [site]
|
|
|
* @param {string} data[].email.active - current email protocol being used [site]
|
|
|
* @param {string} data[].email.smtp.domain - url of smtp service being [site]
|
|
|
* @param {string} data[].email.smtp.email - email account of smtp service [site]
|
|
|
* @param {string} data[].email.smtp.password - password for email of smtp service [site]
|
|
|
* @param {string} data[].email.mailgun.domain - mailgun domain url [site]
|
|
|
* @param {string} data[].email.mailgun.key - mailgun key [site]
|
|
|
*
|
|
|
* @param {string} data[].item.title - page title [nav]
|
|
|
* @param {string} data[].item.slug - url safe title [nav]
|
|
|
* @param {string} data[].item.uuid - unique identifier [nav]
|
|
|
* @param {string} data[].item.path - directory path to associated markdown file [nav]
|
|
|
* @example
|
|
|
* api.sync(TASK, data).then(response=>{
|
|
|
* console.log("RESPONSE", response);
|
|
|
* })
|
|
|
* @returns {object} json object that contains type and status of sync request
|
|
|
```
|
|
|
*
|
|
|
{
|
|
|
"message":"Example Message of Affirmation!",
|
|
|
"type":"exampleType",
|
|
|
}
|
|
|
```
|
|
|
*/ sync(task, data) {
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
let url = "";
|
|
|
switch(task){
|
|
|
case "syncSite":
|
|
|
url = API_SETTINGS_SYNC;
|
|
|
break;
|
|
|
case "syncNav":
|
|
|
url = API_NAV_SYNC;
|
|
|
break;
|
|
|
}
|
|
|
this._request(this.baseURL ? this.baseURL + url : url, TASK_SETTINGS_WRITE, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data).then((result)=>{
|
|
|
resolve(result);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Method for retrieving user authorizing user login
|
|
|
* @param {object[]} data - json object that contains task
|
|
|
* @param {string} data[].task - publishing task
|
|
|
* @example
|
|
|
* api.publish(TASK).then(response=>{
|
|
|
* console.log("RESPONSE", response);
|
|
|
* })
|
|
|
* @returns {object} json object that contains type and status of publis request
|
|
|
* ```
|
|
|
{
|
|
|
"message":"Example Message of Affirmation!",
|
|
|
"type":"exampleType",
|
|
|
}
|
|
|
* ```
|
|
|
*/ publish(data) {
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
this._request(this.baseURL ? this.baseURL + API_PUBLISH_PAGES : API_PUBLISH_PAGES, TASK_PUBLISH_SITE, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data).then((result)=>{
|
|
|
resolve(result);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Method for handling page creating and editing\
|
|
|
* **POST**`/api/v1/page/:task`
|
|
|
* @param {string} task - current page action
|
|
|
* @param {object[]} form - form object that contains info for current page being edited/created
|
|
|
* @param {string} form[].id - sequence id for page, leave empty for new page
|
|
|
* @param {string} form[].uuid - unique identifier for page, leave empty for new page
|
|
|
* @param {string} form[].layout - current page layout
|
|
|
* @param {string} form[].current_title - saved url save title for persistence when changing title, leave empty for new page
|
|
|
* @param {string} form[].content - markdown body of page
|
|
|
* @param {string} form[].title - current title of page
|
|
|
* @param {string} form[].created - date page was created, leave empty for new page
|
|
|
* @param {string} form[].slug - url safe string of page title
|
|
|
* @param {string} form[].tags - comma separated list of tags
|
|
|
* @param {boolean} form[].menu - property that indicates page is included in site menu
|
|
|
* @param {boolean} form[].featured - property that indicates page is featured
|
|
|
* @param {boolean} form[].published - property that indicates page is public
|
|
|
* @param {string} form[].form_token - hidden property to authenticate form submission
|
|
|
* @param {input} form[].feature_image - main image for page
|
|
|
* @example
|
|
|
* api.pageActions(TASK, data).then(response=>{
|
|
|
* console.log("RESPONSE", response);
|
|
|
* })
|
|
|
* @returns {object} json object that contains type and status of page edit request
|
|
|
```
|
|
|
{
|
|
|
"message":"Example Message of Affirmation!",
|
|
|
"type":"exampleType",
|
|
|
}
|
|
|
```
|
|
|
*/ pageActions(task, data) {
|
|
|
let url, event, content;
|
|
|
switch(task){
|
|
|
case TASK_PAGE_CREATE:
|
|
|
url = API_NEW_PAGE;
|
|
|
event = TASK_PAGE_CREATE;
|
|
|
content = CONTENT_TYPE_FORM;
|
|
|
break;
|
|
|
case TASK_PAGE_EDIT:
|
|
|
url = API_EDIT_PAGE;
|
|
|
event = TASK_PAGE_EDIT;
|
|
|
content = CONTENT_TYPE_FORM;
|
|
|
break;
|
|
|
case TASK_PAGE_DELETE:
|
|
|
url = API_DELETE_PAGE;
|
|
|
event = TASK_PAGE_DELETE;
|
|
|
content = CONTENT_TYPE_FORM;
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
if (this.baseURL) //data.key = this.key;
|
|
|
data.remote = true;
|
|
|
else data.remote = false;
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
this._request(this.baseURL ? this.baseURL + url : url, event, REQUEST_TYPE_POST, content, data).then((result)=>{
|
|
|
resolve(result);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Method for sending mail (if completed in settings)\
|
|
|
* **POST**`/api/v1/mailer`
|
|
|
* @param {object[]} message - json object that contains items to be included in main site navigation
|
|
|
* @param {string} message[].content - message to send
|
|
|
* @example
|
|
|
* api.sendMail(message).then(response=>{
|
|
|
* console.log("RESPONSE", response);
|
|
|
* })
|
|
|
* @returns {object} json object that contains type and status of page edit request
|
|
|
```
|
|
|
{
|
|
|
"message":"Example Message of Affirmation!",
|
|
|
"type":"exampleType"
|
|
|
}
|
|
|
```
|
|
|
*/ sendMail(message) {
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
this._request(this.baseURL ? this.baseURL + API_SEND_MAIL : API_SEND_MAIL, TASK_SEND_MAIL, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, message).then((result)=>{
|
|
|
resolve(result);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* *Promise method for retrieving site and member info*\
|
|
|
* **GET** `/api/v1/settings/:type`
|
|
|
* @param {string} type - type of info requested ['site'|'member'];
|
|
|
* @example
|
|
|
* api.getInfo("type").then(data=>{
|
|
|
console.log("Info Object", data);
|
|
|
* })
|
|
|
* @returns {object} json object that contains data for requested information
|
|
|
*
|
|
|
* *info object example*
|
|
|
* ```
|
|
|
{
|
|
|
"message":"message of affirmation!",
|
|
|
"task":"type of info request",
|
|
|
"data":json-data-object,
|
|
|
}
|
|
|
* ```
|
|
|
*/ getInfo(type) {
|
|
|
let url, task;
|
|
|
if (type == "site") {
|
|
|
url = API_GET_SETTINGS;
|
|
|
task = TASK_GET_SETTINGS;
|
|
|
} else {
|
|
|
url = API_GET_MEMBER_INFO;
|
|
|
task = TASK_GET_MEMBER_INFO;
|
|
|
}
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
this._request(this.baseURL ? this.baseURL + url : url, task).then((result)=>{
|
|
|
resolve(result);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
// private
|
|
|
//--------------------------
|
|
|
_request(requestURL, eventType, requestType = REQUEST_TYPE_GET, contentType = CONTENT_TYPE_JSON, requestData = null) {
|
|
|
var self = this;
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
var request = new XMLHttpRequest();
|
|
|
request.upload.addEventListener("progress", (e)=>self.handleLoadProgress(e, self.progressBar));
|
|
|
request.open(requestType, requestURL, true);
|
|
|
request.onload = ()=>{
|
|
|
if (request.status == 200) {
|
|
|
let response = JSON.parse(request["response"]);
|
|
|
resolve(response);
|
|
|
} else {
|
|
|
let error = JSON.parse(request["response"]);
|
|
|
reject(error);
|
|
|
}
|
|
|
};
|
|
|
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
|
|
if (eventType === TASK_SETTINGS_WRITE || eventType === TASK_PAGE_EDIT || eventType === TASK_PAGE_CREATE || eventType === TASK_PAGE_DELETE || eventType === TASK_PUBLISH_SITE || eventType === TASK_REINDEX_PAGE) request.setRequestHeader("fipamo-access-token", self.token);
|
|
|
switch(contentType){
|
|
|
case CONTENT_TYPE_JSON:
|
|
|
request.setRequestHeader("Content-type", "application/" + contentType);
|
|
|
request.send(JSON.stringify(requestData));
|
|
|
break;
|
|
|
case CONTENT_TYPE_FORM:
|
|
|
request.send(requestData);
|
|
|
break;
|
|
|
}
|
|
|
} else {
|
|
|
if (eventType === TASK_GET_SETTINGS || eventType === TASK_GET_MEMBER_INFO) request.setRequestHeader("fipamo-access-token", self.token);
|
|
|
request.send();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
// event handlers
|
|
|
//--------------------------
|
|
|
handleLoadProgress(e, progressBar) {
|
|
|
let percent = Math.ceil(e.loaded / e.total * 100); //if a progress bar element is present, talk to it
|
|
|
if (progressBar != null) progressBar.style.width = percent + "%";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"gkKU3":[function(require,module,exports) {
|
|
|
exports.interopDefault = function(a) {
|
|
|
return a && a.__esModule ? a : {
|
|
|
default: a
|
|
|
};
|
|
|
};
|
|
|
exports.defineInteropFlag = function(a) {
|
|
|
Object.defineProperty(a, "__esModule", {
|
|
|
value: true
|
|
|
});
|
|
|
};
|
|
|
exports.exportAll = function(source, dest) {
|
|
|
Object.keys(source).forEach(function(key) {
|
|
|
if (key === "default" || key === "__esModule" || dest.hasOwnProperty(key)) return;
|
|
|
Object.defineProperty(dest, key, {
|
|
|
enumerable: true,
|
|
|
get: function() {
|
|
|
return source[key];
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
return dest;
|
|
|
};
|
|
|
exports.export = function(dest, destName, get) {
|
|
|
Object.defineProperty(dest, destName, {
|
|
|
enumerable: true,
|
|
|
get: get
|
|
|
});
|
|
|
};
|
|
|
|
|
|
},{}],"cYXLM":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
parcelHelpers.export(exports, "REQUEST_TYPE_POST", ()=>REQUEST_TYPE_POST);
|
|
|
parcelHelpers.export(exports, "REQUEST_TYPE_GET", ()=>REQUEST_TYPE_GET);
|
|
|
parcelHelpers.export(exports, "REQUEST_TYPE_PUT", ()=>REQUEST_TYPE_PUT);
|
|
|
parcelHelpers.export(exports, "REQUEST_TYPE_DELETE", ()=>REQUEST_TYPE_DELETE);
|
|
|
parcelHelpers.export(exports, "CONTENT_TYPE_JSON", ()=>CONTENT_TYPE_JSON);
|
|
|
parcelHelpers.export(exports, "CONTENT_TYPE_FORM", ()=>CONTENT_TYPE_FORM);
|
|
|
parcelHelpers.export(exports, "API_STATUS", ()=>API_STATUS);
|
|
|
parcelHelpers.export(exports, "API_INIT", ()=>API_INIT);
|
|
|
parcelHelpers.export(exports, "API_RESTORE", ()=>API_RESTORE);
|
|
|
parcelHelpers.export(exports, "API_GET_SECRET", ()=>API_GET_SECRET);
|
|
|
parcelHelpers.export(exports, "API_RESET_PASS", ()=>API_RESET_PASS);
|
|
|
parcelHelpers.export(exports, "API_CREATE_BACKUP", ()=>API_CREATE_BACKUP);
|
|
|
parcelHelpers.export(exports, "API_DOWNLOAD_BACKUP", ()=>API_DOWNLOAD_BACKUP);
|
|
|
parcelHelpers.export(exports, "API_RESTORE_BACKUP", ()=>API_RESTORE_BACKUP);
|
|
|
parcelHelpers.export(exports, "API_UPLOAD_AVATAR", ()=>API_UPLOAD_AVATAR);
|
|
|
parcelHelpers.export(exports, "API_UPLOAD_BACKGROUND", ()=>API_UPLOAD_BACKGROUND);
|
|
|
parcelHelpers.export(exports, "API_IMAGE_UPLOAD", ()=>API_IMAGE_UPLOAD);
|
|
|
parcelHelpers.export(exports, "TASK_SITE_INIT", ()=>TASK_SITE_INIT);
|
|
|
parcelHelpers.export(exports, "TASK_BACKUP_RESTORE", ()=>TASK_BACKUP_RESTORE);
|
|
|
parcelHelpers.export(exports, "TASK_BACKUP_CREATE", ()=>TASK_BACKUP_CREATE);
|
|
|
parcelHelpers.export(exports, "TASK_GET_SECRET", ()=>TASK_GET_SECRET);
|
|
|
parcelHelpers.export(exports, "TASK_RESET_PASS", ()=>TASK_RESET_PASS);
|
|
|
parcelHelpers.export(exports, "TASK_UPLOAD_FILES", ()=>TASK_UPLOAD_FILES);
|
|
|
parcelHelpers.export(exports, "API_ACCESS_GOOD", ()=>API_ACCESS_GOOD);
|
|
|
parcelHelpers.export(exports, "API_ACCESS_BAD", ()=>API_ACCESS_BAD);
|
|
|
parcelHelpers.export(exports, "default", ()=>MaintenanceManager);
|
|
|
const REQUEST_TYPE_POST = "POST";
|
|
|
const REQUEST_TYPE_GET = "GET";
|
|
|
const REQUEST_TYPE_PUT = "PUT";
|
|
|
const REQUEST_TYPE_DELETE = "DELETE"; //** POST CONTENT TYPES **//
|
|
|
const CONTENT_TYPE_JSON = "json";
|
|
|
const CONTENT_TYPE_FORM = "x-www-form-urlencoded"; //** API URLS **//
|
|
|
const API_STATUS = "/api/v1/status";
|
|
|
const API_INIT = "/api/v1/init";
|
|
|
const API_RESTORE = "/api/v1/restore";
|
|
|
const API_GET_SECRET = "/api/v1/get-secret";
|
|
|
const API_RESET_PASS = "/api/v1/reset-password";
|
|
|
const API_CREATE_BACKUP = "/api/v1/backup";
|
|
|
const API_DOWNLOAD_BACKUP = "/api/v1/backup/download";
|
|
|
const API_RESTORE_BACKUP = "/api/v1/backup/restore";
|
|
|
const API_UPLOAD_AVATAR = "/api/v1/settings/add-avatar";
|
|
|
const API_UPLOAD_BACKGROUND = "/api/v1/settings/add-feature-background";
|
|
|
const API_IMAGE_UPLOAD = "/api/v1/page/add-entry-image"; //** API TASKS **//
|
|
|
const TASK_SITE_INIT = "blogInit";
|
|
|
const TASK_BACKUP_RESTORE = "restoreBackup";
|
|
|
const TASK_BACKUP_CREATE = "createBackup";
|
|
|
const TASK_GET_SECRET = "retrieveSecret";
|
|
|
const TASK_RESET_PASS = "resetPassword";
|
|
|
const TASK_UPLOAD_FILES = "uploadFiles"; //** API STATUS **//
|
|
|
const API_ACCESS_GOOD = "apiUseAuthorized";
|
|
|
const API_ACCESS_BAD = "apiUseNotAuthorized";
|
|
|
/**
|
|
|
* A tub of methods for creating/restoring installs, resetting passwords and uploading images.
|
|
|
*/ class MaintenanceManager {
|
|
|
/**
|
|
|
* @constructor
|
|
|
* @param {string} baseURL - url of site; uses local when empty
|
|
|
* @param {string} key - user api key
|
|
|
*/ constructor(baseURL = null, key = null, progressBar = null){
|
|
|
this.percentComplete = 0; //for later
|
|
|
this.token = null;
|
|
|
this.baseURL = null;
|
|
|
this.progressBar = progressBar;
|
|
|
this.key = null;
|
|
|
if (key) this.key = key;
|
|
|
if (baseURL) this.baseURL = baseURL; //if key is valid, checks to see if a session is active and returns
|
|
|
this._request(this.baseURL ? this.baseURL + API_STATUS + "?key=" + this.key : API_STATUS + "?key=" + this.key).then((response)=>{
|
|
|
if (response.type === API_ACCESS_GOOD) this.token = response.token;
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Promise method used create new site from scratch. For local use only.
|
|
|
* @param {object} data - json object that contains data for set up
|
|
|
* @property {string} new_member_handle - handle for new user
|
|
|
* @property {string} new_member_email - email for new user
|
|
|
* @property {string} new_member_pass - password for new user
|
|
|
* @property {string} new_member_title - title for new user
|
|
|
*/ create(data) {
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
this._request(API_INIT, TASK_SITE_INIT, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data).then((result)=>{
|
|
|
resolve(result);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Promise method for restoring site from a previous back up. For local use only.
|
|
|
* @param {object} form - form object that contains restore data and files
|
|
|
* @property {string} restore_member_handle - handle for site user
|
|
|
* @property {string} restore_member_pass - password for site user
|
|
|
* @property {file} backup-upload - backup zip file
|
|
|
*/ restore(form) {
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
var url, event, method, type, data;
|
|
|
url = API_RESTORE;
|
|
|
event = TASK_BACKUP_RESTORE;
|
|
|
method = REQUEST_TYPE_POST;
|
|
|
type = CONTENT_TYPE_FORM;
|
|
|
data = new FormData(form);
|
|
|
this._request(url, event, method, type, data).then((result)=>{
|
|
|
resolve(result);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Promise method for creating a zip back up of current site. For local use only.
|
|
|
*/ backup() {
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
var url, event, method, type, data;
|
|
|
url = API_CREATE_BACKUP;
|
|
|
event = TASK_BACKUP_CREATE;
|
|
|
method = REQUEST_TYPE_POST;
|
|
|
type = CONTENT_TYPE_JSON;
|
|
|
data = {
|
|
|
task: "create_backup"
|
|
|
};
|
|
|
this._request(url, event, method, type, data).then((result)=>{
|
|
|
resolve(result);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Promise method for retrieving user secret key. For local use only.
|
|
|
* @param {object} data - json object that contains data for set up
|
|
|
* @property {string} email - email for site user
|
|
|
*/ secret(data) {
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
this._request(API_GET_SECRET, TASK_GET_SECRET, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data).then((result)=>{
|
|
|
resolve(result);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Promise method for resetting password for user. For local use only.
|
|
|
* @param {object} data - json object that contains data for set up
|
|
|
* @property {string} new_password - password for user
|
|
|
* @property {string} new_password2 - confirm password for user
|
|
|
* @property {string} secret - secret key for user
|
|
|
*/ newPass(data) {
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
this._request(API_RESET_PASS, TASK_RESET_PASS, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data).then((result)=>{
|
|
|
resolve(result);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Promise method for uploading images [todo: change to uploading files]
|
|
|
* @param {string} type - type of upload
|
|
|
* @param {input} files - form input containing files
|
|
|
*/ imageUpload(type, files) {
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
let url = "";
|
|
|
switch(type){
|
|
|
case "avatar-upload":
|
|
|
url = API_UPLOAD_AVATAR;
|
|
|
break;
|
|
|
case "background-upload":
|
|
|
url = API_UPLOAD_BACKGROUND;
|
|
|
break;
|
|
|
default:
|
|
|
url = API_IMAGE_UPLOAD;
|
|
|
break;
|
|
|
}
|
|
|
var imageData = new FormData();
|
|
|
if (this.baseURL) {
|
|
|
imageData.append("key", this.key);
|
|
|
imageData.append("remote", true);
|
|
|
} else imageData.append("remote", false);
|
|
|
for(var i = 0; i < files.length; i++){
|
|
|
var file = files[i]; // Check the file type.
|
|
|
if (!file.type.match("image.*")) continue;
|
|
|
if (type === "avatar-upload") imageData.append("avatar_upload", file, file.name);
|
|
|
else if (type === "background-upload") imageData.append("background_upload", file, file.name);
|
|
|
else imageData.append("post_image", file, file.name);
|
|
|
}
|
|
|
this._request(url, TASK_UPLOAD_FILES, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData).then((r)=>{
|
|
|
resolve(r);
|
|
|
}).catch((err)=>{
|
|
|
reject(err);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
// private
|
|
|
//--------------------------
|
|
|
_request(requestURL, eventType, requestType = REQUEST_TYPE_GET, contentType = CONTENT_TYPE_JSON, requestData = null) {
|
|
|
var self = this;
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
var request = new XMLHttpRequest();
|
|
|
request.upload.addEventListener("progress", (e)=>self.handleLoadProgress(e, self.progressBar));
|
|
|
request.open(requestType, requestURL, true);
|
|
|
request.onload = ()=>{
|
|
|
if (request.status == 200) {
|
|
|
let response = JSON.parse(request["response"]);
|
|
|
resolve(response);
|
|
|
} else {
|
|
|
let error = JSON.parse(request["response"]);
|
|
|
reject(error);
|
|
|
}
|
|
|
};
|
|
|
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
|
|
if (eventType === TASK_UPLOAD_FILES) request.setRequestHeader("fipamo-access-token", self.token);
|
|
|
switch(contentType){
|
|
|
case CONTENT_TYPE_JSON:
|
|
|
request.setRequestHeader("Content-type", "application/" + contentType);
|
|
|
request.send(JSON.stringify(requestData));
|
|
|
break;
|
|
|
case CONTENT_TYPE_FORM:
|
|
|
request.send(requestData);
|
|
|
break;
|
|
|
}
|
|
|
} else request.send();
|
|
|
});
|
|
|
}
|
|
|
// event handlers
|
|
|
//--------------------------
|
|
|
handleLoadProgress(e, progressBar) {
|
|
|
let percent = Math.ceil(e.loaded / e.total * 100); //if a progress bar element is present, talk to it
|
|
|
if (progressBar != null) progressBar.style.width = percent + "%";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"eM6UW":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
class DataUtils {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
imgLoad(url) {
|
|
|
"use strict"; // Create new promise with the Promise() constructor;
|
|
|
// This has as its argument a function with two parameters, resolve and reject
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
// Standard XHR to load an image
|
|
|
var request = new XMLHttpRequest();
|
|
|
request.open("GET", url);
|
|
|
request.responseType = "blob"; // When the request loads, check whether it was successful
|
|
|
request.onload = function() {
|
|
|
if (request.status === 200) // If successful, resolve the promise by passing back the request response
|
|
|
resolve(request.response);
|
|
|
else // If it fails, reject the promise with a error message
|
|
|
reject(new Error("Image didn't load successfully; error code:" + request.statusText));
|
|
|
};
|
|
|
request.onerror = function() {
|
|
|
// Also deal with the case when the entire request fails to begin with
|
|
|
// This is probably a network error, so reject the promise with an appropriate message
|
|
|
reject(new Error("There was a network error."));
|
|
|
}; // Send the request
|
|
|
request.send();
|
|
|
});
|
|
|
}
|
|
|
loadImage(src) {
|
|
|
"use strict";
|
|
|
let self = this;
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
// Get a reference to the body element, and create a new image object
|
|
|
var myImage = new Image();
|
|
|
myImage.crossOrigin = ""; // or "anonymous"
|
|
|
// Call the function with the URL we want to load, but then chain the
|
|
|
// promise then() method on to the end of it. This contains two callbacks
|
|
|
self.imgLoad(src).then(function(response) {
|
|
|
// The first runs when the promise resolves, with the request.reponse specified within the resolve() method.
|
|
|
var imageURL = window.URL.createObjectURL(response);
|
|
|
resolve(imageURL); //$('background-content').setStyle('background-image', 'url('+imageURL+')') //myImage.src = imageURL;
|
|
|
//console.log(imageURL);
|
|
|
//body.appendChild(myImage);
|
|
|
// The second runs when the promise is rejected, and logs the Error specified with the reject() method.
|
|
|
}, function(Error) {
|
|
|
reject(Error);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Create a function to convert the serialize and convert the form data to JSON
|
|
|
* @param : $('#form_example');
|
|
|
* @return a JSON Stringify
|
|
|
*/ formDataToJSON(form) {
|
|
|
let object = {};
|
|
|
let formData = new FormData(form);
|
|
|
formData.forEach((value, key)=>{
|
|
|
if (!object.hasOwnProperty(key)) {
|
|
|
object[key] = value;
|
|
|
return;
|
|
|
}
|
|
|
if (!Array.isArray(object[key])) object[key] = [
|
|
|
object[key]
|
|
|
];
|
|
|
object[key].push(value);
|
|
|
}); //let json = JSON.stringify(object);
|
|
|
return object;
|
|
|
}
|
|
|
}
|
|
|
exports.default = DataUtils;
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"hCRFh":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
parcelHelpers.export(exports, "AUTH_STATUS", ()=>AUTH_STATUS);
|
|
|
parcelHelpers.export(exports, "REQUEST_GOOD", ()=>REQUEST_GOOD);
|
|
|
parcelHelpers.export(exports, "REQUEST_LAME", ()=>REQUEST_LAME);
|
|
|
parcelHelpers.export(exports, "API_REQUEST_GOOD", ()=>API_REQUEST_GOOD);
|
|
|
parcelHelpers.export(exports, "API_REQUEST_LAME", ()=>API_REQUEST_LAME);
|
|
|
parcelHelpers.export(exports, "IMG_REQUEST_GOOD", ()=>IMG_REQUEST_GOOD);
|
|
|
parcelHelpers.export(exports, "IMG_REQUEST_LAME", ()=>IMG_REQUEST_LAME);
|
|
|
parcelHelpers.export(exports, "SETTINGS_LOADED", ()=>SETTINGS_LOADED);
|
|
|
parcelHelpers.export(exports, "POST_IMAGE_ADDED", ()=>POST_IMAGE_ADDED);
|
|
|
parcelHelpers.export(exports, "FEATURE_IMAGE_ADDED", ()=>FEATURE_IMAGE_ADDED);
|
|
|
parcelHelpers.export(exports, "PAGE_ERROR", ()=>PAGE_ERROR);
|
|
|
parcelHelpers.export(exports, "PAGE_ADDED", ()=>PAGE_ADDED);
|
|
|
parcelHelpers.export(exports, "PAGE_UPDATED", ()=>PAGE_UPDATED);
|
|
|
parcelHelpers.export(exports, "PAGE_DELETED", ()=>PAGE_DELETED);
|
|
|
parcelHelpers.export(exports, "PAGES_RENDERED", ()=>PAGES_RENDERED);
|
|
|
parcelHelpers.export(exports, "PAGES_NOT_RENDERED", ()=>PAGES_NOT_RENDERED);
|
|
|
parcelHelpers.export(exports, "TAG_PAGES_RENDERED", ()=>TAG_PAGES_RENDERED);
|
|
|
parcelHelpers.export(exports, "TAG_PAGES_NOT_RENDERED", ()=>TAG_PAGES_NOT_RENDERED);
|
|
|
parcelHelpers.export(exports, "SETTINGS_UPDATED", ()=>SETTINGS_UPDATED);
|
|
|
parcelHelpers.export(exports, "SETTINGS_NOT_UPDATED", ()=>SETTINGS_NOT_UPDATED);
|
|
|
parcelHelpers.export(exports, "MENU_ADD_ITEM", ()=>MENU_ADD_ITEM);
|
|
|
parcelHelpers.export(exports, "MENU_DELETE_ITEM", ()=>MENU_DELETE_ITEM);
|
|
|
parcelHelpers.export(exports, "MENU_UPDATED", ()=>MENU_UPDATED);
|
|
|
parcelHelpers.export(exports, "AVATAR_UPLOADED", ()=>AVATAR_UPLOADED);
|
|
|
parcelHelpers.export(exports, "SITE_BACKGROUND_UPLOADED", ()=>SITE_BACKGROUND_UPLOADED);
|
|
|
parcelHelpers.export(exports, "UPLOAD_PROGRESS", ()=>UPLOAD_PROGRESS);
|
|
|
parcelHelpers.export(exports, "API_PAGE_WRITE", ()=>API_PAGE_WRITE);
|
|
|
parcelHelpers.export(exports, "API_PAGE_CREATE", ()=>API_PAGE_CREATE);
|
|
|
parcelHelpers.export(exports, "API_PAGE_DELETE", ()=>API_PAGE_DELETE);
|
|
|
parcelHelpers.export(exports, "API_SETTINGS_WRITE", ()=>API_SETTINGS_WRITE);
|
|
|
parcelHelpers.export(exports, "API_BACKUP_CREATE", ()=>API_BACKUP_CREATE);
|
|
|
parcelHelpers.export(exports, "API_BACKUP_DOWNLOAD", ()=>API_BACKUP_DOWNLOAD);
|
|
|
parcelHelpers.export(exports, "API_BACKUP_RESTORE", ()=>API_BACKUP_RESTORE);
|
|
|
parcelHelpers.export(exports, "API_IMAGES_UPLOAD", ()=>API_IMAGES_UPLOAD);
|
|
|
parcelHelpers.export(exports, "API_RENDER_PAGES", ()=>API_RENDER_PAGES);
|
|
|
parcelHelpers.export(exports, "API_REINDEX_PAGES", ()=>API_REINDEX_PAGES);
|
|
|
parcelHelpers.export(exports, "API_INIT", ()=>API_INIT);
|
|
|
parcelHelpers.export(exports, "API_INIT_GOOD", ()=>API_INIT_GOOD);
|
|
|
parcelHelpers.export(exports, "API_INIT_LAME", ()=>API_INIT_LAME);
|
|
|
parcelHelpers.export(exports, "API_GET_SECRET", ()=>API_GET_SECRET);
|
|
|
parcelHelpers.export(exports, "API_RESET_PASS", ()=>API_RESET_PASS);
|
|
|
parcelHelpers.export(exports, "SEND_MAIL", ()=>SEND_MAIL);
|
|
|
const AUTH_STATUS = "getAuthStatus";
|
|
|
const REQUEST_GOOD = "requestGood";
|
|
|
const REQUEST_LAME = "requestLame";
|
|
|
const API_REQUEST_GOOD = "apiUseAuthorized";
|
|
|
const API_REQUEST_LAME = "apiUseNotAuthorized";
|
|
|
const IMG_REQUEST_GOOD = "imgRequestGood";
|
|
|
const IMG_REQUEST_LAME = "imgRequestLame";
|
|
|
const SETTINGS_LOADED = "settingsLoaded";
|
|
|
const POST_IMAGE_ADDED = "postImageAdded";
|
|
|
const FEATURE_IMAGE_ADDED = "featureImageAdded";
|
|
|
const PAGE_ERROR = "postError";
|
|
|
const PAGE_ADDED = "postAdded";
|
|
|
const PAGE_UPDATED = "postUpdated";
|
|
|
const PAGE_DELETED = "postImageAdded";
|
|
|
const PAGES_RENDERED = "pagesRendered";
|
|
|
const PAGES_NOT_RENDERED = "pagesNotRendered";
|
|
|
const TAG_PAGES_RENDERED = "tagPagesRendered";
|
|
|
const TAG_PAGES_NOT_RENDERED = "tagPagesNotRendered";
|
|
|
const SETTINGS_UPDATED = "settingsUpdated";
|
|
|
const SETTINGS_NOT_UPDATED = "settingsNotUpdated";
|
|
|
const MENU_ADD_ITEM = "menuAddItem";
|
|
|
const MENU_DELETE_ITEM = "menuDeleteItem";
|
|
|
const MENU_UPDATED = "menuUpdated";
|
|
|
const AVATAR_UPLOADED = "avatarUploaded";
|
|
|
const SITE_BACKGROUND_UPLOADED = "siteBackgroundUploaded";
|
|
|
const UPLOAD_PROGRESS = "uploadProgress";
|
|
|
const API_PAGE_WRITE = "writingItDown";
|
|
|
const API_PAGE_CREATE = "writingNewEntry";
|
|
|
const API_PAGE_DELETE = "erasingPage";
|
|
|
const API_SETTINGS_WRITE = "savingSettings";
|
|
|
const API_BACKUP_CREATE = "createBackup";
|
|
|
const API_BACKUP_DOWNLOAD = "downloadBackup";
|
|
|
const API_BACKUP_RESTORE = "downloadBackup";
|
|
|
const API_IMAGES_UPLOAD = "uploadProfileImages";
|
|
|
const API_RENDER_PAGES = "renderPages";
|
|
|
const API_REINDEX_PAGES = "reindexPages";
|
|
|
const API_INIT = "blogInit";
|
|
|
const API_INIT_GOOD = "blogInitGood";
|
|
|
const API_INIT_LAME = "blogInitLame";
|
|
|
const API_GET_SECRET = "retrieveSecret";
|
|
|
const API_RESET_PASS = "resetPassword";
|
|
|
const SEND_MAIL = "sendMail";
|
|
|
class DataEvent {
|
|
|
}
|
|
|
exports.default = new DataEvent();
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"9gCOB":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
var _postIndex = require("./PostIndex");
|
|
|
var _postIndexDefault = parcelHelpers.interopDefault(_postIndex);
|
|
|
var _settingsIndex = require("./SettingsIndex");
|
|
|
var _settingsIndexDefault = parcelHelpers.interopDefault(_settingsIndex);
|
|
|
var _navIndex = require("./NavIndex");
|
|
|
var _navIndexDefault = parcelHelpers.interopDefault(_navIndex);
|
|
|
class DashManager {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){
|
|
|
this.currentDisplay = "";
|
|
|
this.urlPieces = document.URL.split("/");
|
|
|
this.chooseDisplay(this.urlPieces[4], this.urlPieces[5]);
|
|
|
}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
start() {}
|
|
|
chooseDisplay(section, page) {
|
|
|
this.currentDisplay = "";
|
|
|
switch(section){
|
|
|
case "page":
|
|
|
this.currentDisplay = new (0, _postIndexDefault.default)(page);
|
|
|
break;
|
|
|
case "settings":
|
|
|
this.currentDisplay = new (0, _settingsIndexDefault.default)();
|
|
|
break;
|
|
|
case "navigation":
|
|
|
this.currentDisplay = new (0, _navIndexDefault.default)();
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
this.start();
|
|
|
}
|
|
|
}
|
|
|
exports.default = DashManager;
|
|
|
|
|
|
},{"./PostIndex":"gp1bn","./SettingsIndex":"4SQpj","./NavIndex":"6S99f","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"gp1bn":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
var _pageEditor = require("./PageEditor");
|
|
|
var _pageEditorDefault = parcelHelpers.interopDefault(_pageEditor);
|
|
|
class PostIndex {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(page){
|
|
|
this.currentPage = null;
|
|
|
this.choosePage(page);
|
|
|
this.start();
|
|
|
}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
start() {}
|
|
|
choosePage(page) {
|
|
|
this.currentPage = "";
|
|
|
switch(page){
|
|
|
case "edit":
|
|
|
case "add":
|
|
|
this.currentPage = new (0, _pageEditorDefault.default)();
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
exports.default = PostIndex;
|
|
|
|
|
|
},{"./PageEditor":"jaapu","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"jaapu":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
//TOOLS
|
|
|
var _fipamoAdminAPI = require("../../libraries/FipamoAdminAPI");
|
|
|
var _fipamoAdminAPIDefault = parcelHelpers.interopDefault(_fipamoAdminAPI);
|
|
|
var _maintenanceManager = require("./MaintenanceManager");
|
|
|
var _maintenanceManagerDefault = parcelHelpers.interopDefault(_maintenanceManager);
|
|
|
var _dataEvent = require("../events/DataEvent");
|
|
|
var _pageActions = require("../actions/PageActions");
|
|
|
var _pageActionsDefault = parcelHelpers.interopDefault(_pageActions);
|
|
|
var _editorEvent = require("../events/EditorEvent"); //import TinyDatePicker from 'tiny-date-picker'; TODO: Reactivate for scheduled publishing
|
|
|
var _textEditor = require("../ui/TextEditor");
|
|
|
var _textEditorDefault = parcelHelpers.interopDefault(_textEditor);
|
|
|
var _notifications = require("../ui/Notifications");
|
|
|
var _notificationsDefault = parcelHelpers.interopDefault(_notifications);
|
|
|
var _fileManager = require("../ui/FileManager");
|
|
|
var _fileManagerDefault = parcelHelpers.interopDefault(_fileManager);
|
|
|
const notify = new (0, _notificationsDefault.default)();
|
|
|
class PostEditor {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){
|
|
|
this.processing = false;
|
|
|
let self = "this";
|
|
|
this.admin = new (0, _fipamoAdminAPIDefault.default)(null, document.getElementById("notify-progress"));
|
|
|
this.mm = new (0, _maintenanceManagerDefault.default)(null, null, document.getElementById("notify-progress"));
|
|
|
this.urlPieces = document.URL.split("/");
|
|
|
this.post = [];
|
|
|
this.postID = null;
|
|
|
this.postUUID = null;
|
|
|
this.postLayout = null;
|
|
|
this.fm = null;
|
|
|
if (document.getElementById("post-edit-index").getAttribute("data-index")) {
|
|
|
this.postID = document.getElementById("post-edit-index").getAttribute("data-index");
|
|
|
this.postUUID = document.getElementById("post-edit-index").getAttribute("data-uuid");
|
|
|
this.postLayout = document.getElementById("post-edit-index").getAttribute("data-layout");
|
|
|
}
|
|
|
if (document.getElementById("edit")) {
|
|
|
this.editor = new (0, _textEditorDefault.default)(document.getElementById("edit"), document.getElementById("header").offsetHeight + document.getElementById("post-header").offsetHeight + document.getElementById("post-feature").offsetHeight);
|
|
|
this.editor.addListener(_editorEvent.EDITOR_DELETE, ()=>this.handleEditorOptions(_editorEvent.EDITOR_DELETE), false);
|
|
|
this.editor.addListener(_editorEvent.EDITOR_UPLOAD_POST_IMAGE, ()=>this.handleEditorOptions(_editorEvent.EDITOR_UPLOAD_POST_IMAGE), false);
|
|
|
this.editor.addListener(_editorEvent.EDITOR_UPDATE, ()=>this.handleEditorOptions(_editorEvent.EDITOR_UPDATE), false);
|
|
|
this.editor.addListener(_editorEvent.EDITOR_SAVE, ()=>this.handleEditorOptions(_editorEvent.EDITOR_SAVE), false);
|
|
|
document.getElementById("post-image-upload").addEventListener("change", (e)=>{
|
|
|
this.handleImageUpload(e.target.id, e.target.files);
|
|
|
}, false);
|
|
|
/*
|
|
|
TinyDatePicker(document.getElementById('post-date'), {
|
|
|
mode: 'dp-below',
|
|
|
format() {
|
|
|
//return self.dateUtils.getDate('origin', date);
|
|
|
}
|
|
|
});
|
|
|
*/ this.start();
|
|
|
}
|
|
|
}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
start() {
|
|
|
if (document.getElementById("page-file-drop")) {
|
|
|
//insert fileManager here
|
|
|
this.fm = new (0, _fileManagerDefault.default)(document.getElementById("page-file-drop"), document.getElementById("page-files-upload"), document.getElementById("page-images-list"), document.getElementById("page-files-list"));
|
|
|
var optionButtons = document.querySelectorAll(".post-option-btn");
|
|
|
for(var i = 0, length = optionButtons.length; i < length; i++)optionButtons[i].addEventListener("click", (e)=>this.handlePostOptions(e), false);
|
|
|
}
|
|
|
}
|
|
|
// event handlers
|
|
|
//--------------------------
|
|
|
handlePostOptions(e) {
|
|
|
let currentOption = null;
|
|
|
switch(e.target.id){
|
|
|
case "option-page-icon":
|
|
|
case "option-menu-pin":
|
|
|
currentOption = document.getElementById("option-menu-pin");
|
|
|
break;
|
|
|
case "option-feature-icon":
|
|
|
case "option-feature":
|
|
|
currentOption = document.getElementById("option-feature");
|
|
|
break;
|
|
|
case "option-published-icon":
|
|
|
case "option-published":
|
|
|
currentOption = document.getElementById("option-published");
|
|
|
break;
|
|
|
}
|
|
|
if (currentOption != null) {
|
|
|
let active = currentOption.getAttribute("data-active");
|
|
|
active == "false" ? currentOption.setAttribute("data-active", "true") : currentOption.setAttribute("data-active", "false");
|
|
|
}
|
|
|
}
|
|
|
handleEditorOptions(e) {
|
|
|
if (this.processing) return;
|
|
|
let self = this;
|
|
|
switch(e){
|
|
|
case _editorEvent.EDITOR_SAVE:
|
|
|
case _editorEvent.EDITOR_UPDATE:
|
|
|
var task = "";
|
|
|
e === _editorEvent.EDITOR_SAVE ? task = (0, _fipamoAdminAPI.TASK_PAGE_CREATE) : task = (0, _fipamoAdminAPI.TASK_PAGE_EDIT);
|
|
|
new (0, _pageActionsDefault.default)().collectInfo(this.fm.getFiles()).then((page)=>{
|
|
|
self.processing = true;
|
|
|
notify.alert("Writing down changes", null);
|
|
|
self.admin.pageActions(task, page).then((r)=>{
|
|
|
self.processing = false;
|
|
|
if (r.type === _dataEvent.PAGE_ERROR || r.type === _dataEvent.API_REQUEST_LAME) notify.alert(r.message, false);
|
|
|
else if (r.type === _dataEvent.PAGE_UPDATED) notify.alert(r.message, true);
|
|
|
else {
|
|
|
notify.alert(r.message, true);
|
|
|
window.location = "/dashboard/page/edit/" + r.id;
|
|
|
}
|
|
|
}).catch((err)=>{
|
|
|
self.processing = false;
|
|
|
notify.alert(err, false);
|
|
|
});
|
|
|
});
|
|
|
break;
|
|
|
case _editorEvent.EDITOR_DELETE:
|
|
|
if (this.postLayout === "index") {
|
|
|
notify.alert("Index cannot be deleted", false);
|
|
|
return;
|
|
|
}
|
|
|
if (confirm("AYE! You know you're deleting this post, right?")) new (0, _pageActionsDefault.default)().collectInfo(document.getElementById("featured-image-upload").files[0]).then((page)=>{
|
|
|
self.processing = true;
|
|
|
this.admin.pageActions((0, _fipamoAdminAPI.TASK_PAGE_DELETE), page).then(()=>{
|
|
|
self.processing = false;
|
|
|
window.location = "/dashboard/pages";
|
|
|
}).catch((err)=>{
|
|
|
self.processing = false;
|
|
|
notify.alert(err, false);
|
|
|
});
|
|
|
}).catch(()=>{});
|
|
|
break;
|
|
|
case _editorEvent.EDITOR_UPLOAD_POST_IMAGE:
|
|
|
document.getElementById("post-image-upload").click();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
handleImageUpload(type, files) {
|
|
|
let self = this;
|
|
|
notify.alert("Uploading Image", null);
|
|
|
self.mm.imageUpload(type, files).then((r)=>{
|
|
|
if (r.type == _dataEvent.POST_IMAGE_ADDED) {
|
|
|
self.editor.notify(_editorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url);
|
|
|
notify.alert("Image Added to Entry", true);
|
|
|
} else notify.alert("Uh oh. Image not added", false);
|
|
|
}).catch(()=>{
|
|
|
notify.alert("Uh oh. Image not added", false); //console.log('ERROR', err);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
exports.default = PostEditor;
|
|
|
PostEditor.uploadFiles = [];
|
|
|
|
|
|
},{"../../libraries/FipamoAdminAPI":"3dcvg","./MaintenanceManager":"cYXLM","../events/DataEvent":"hCRFh","../actions/PageActions":"aIgBQ","../events/EditorEvent":"lqMYV","../ui/TextEditor":"hpLqF","../ui/Notifications":"9GRdG","../ui/FileManager":"6B20o","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"aIgBQ":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
var _stringUtils = require("../utils/StringUtils");
|
|
|
var _stringUtilsDefault = parcelHelpers.interopDefault(_stringUtils);
|
|
|
class PostActions {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
collectInfo(files) {
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
let pageInfo = new FormData();
|
|
|
pageInfo.enctype = "multipart/form-data";
|
|
|
let txt = document.createElement("textarea");
|
|
|
txt.innerHTML = document.getElementById("highlight-content").innerHTML;
|
|
|
let html = txt.value;
|
|
|
html = html.replace(/<\/?span[^>]*>/g, ""); //removes prism styling
|
|
|
html = html.replace(/<\/?br[^>]*>/g, "\n"); //convert back to encoded line break for storage
|
|
|
pageInfo.append("id", document.getElementById("post-edit-index").getAttribute("data-index"));
|
|
|
pageInfo.append("uuid", document.getElementById("post-edit-index").getAttribute("data-uuid"));
|
|
|
pageInfo.append("layout", document.getElementById("post-edit-index").getAttribute("data-layout"));
|
|
|
pageInfo.append("current_title", document.getElementById("post-edit-index").getAttribute("data-slug"));
|
|
|
pageInfo.append("content", html);
|
|
|
pageInfo.append("title", document.getElementById("post-title-text").value);
|
|
|
pageInfo.append("created", document.getElementById("post-date").getAttribute("data-raw"));
|
|
|
pageInfo.append("slug", new (0, _stringUtilsDefault.default)().cleanString(document.getElementById("post-title-text").value));
|
|
|
pageInfo.append("tags", document.getElementById("post-tags").value);
|
|
|
pageInfo.append("menu", document.getElementById("option-menu-pin").getAttribute("data-active"));
|
|
|
pageInfo.append("featured", document.getElementById("option-feature").getAttribute("data-active"));
|
|
|
pageInfo.append("published", document.getElementById("option-published").getAttribute("data-active"));
|
|
|
pageInfo.append("layout", document.getElementById("page-templates").value);
|
|
|
pageInfo.append("form_token", document.getElementById("form_token").value);
|
|
|
if (files.length > 0 && files != null) for(var i = 0; i < files.length; i++){
|
|
|
var file = files[i];
|
|
|
if (file.type.match("image.*") || file.type.match("video.mp4") || file.type.match("audio.mpeg") || file.type.match("application.pdf") || file.type.match("text.plain") || file.type.match("text.rtf")) pageInfo.append("page_files[]", file, file.name);
|
|
|
else reject("Not an image file: " + file.type);
|
|
|
}
|
|
|
else //check to see if image exists
|
|
|
if (document.getElementById("featured-image")) {
|
|
|
var imageURL = document.getElementById("featured-image").src;
|
|
|
imageURL != null || imageURL != undefined ? pageInfo.append("feature_image", imageURL) : pageInfo.append("feature_image", null);
|
|
|
}
|
|
|
//console.log("FILES", files);
|
|
|
resolve(pageInfo);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
exports.default = PostActions;
|
|
|
|
|
|
},{"../utils/StringUtils":"3SgRC","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"3SgRC":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
class StringUtils {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
cleanString(string) {
|
|
|
var clean = string.replace(/(^\-+|[^a-zA-Z0-9\/_| -]+|\-+$)/g, "").toLowerCase().replace(/[\/_| -]+/g, "-");
|
|
|
return clean;
|
|
|
}
|
|
|
decodeHTML(string, quote_style) {
|
|
|
var optTemp = 0, i = 0, noquotes = false;
|
|
|
if (typeof quote_style === "undefined") quote_style = 2;
|
|
|
string = string.toString().replace(/</g, "<").replace(/>/g, ">");
|
|
|
var OPTS = {
|
|
|
ENT_NOQUOTES: 0,
|
|
|
ENT_HTML_QUOTE_SINGLE: 1,
|
|
|
ENT_HTML_QUOTE_DOUBLE: 2,
|
|
|
ENT_COMPAT: 2,
|
|
|
ENT_QUOTES: 3,
|
|
|
ENT_IGNORE: 4
|
|
|
};
|
|
|
if (quote_style === 0) noquotes = true;
|
|
|
if (typeof quote_style !== "number") {
|
|
|
// Allow for a single string or an array of string flags
|
|
|
quote_style = [].concat(quote_style);
|
|
|
for(i = 0; i < quote_style.length; i++){
|
|
|
// Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
|
|
|
if (OPTS[quote_style[i]] === 0) noquotes = true;
|
|
|
else if (OPTS[quote_style[i]]) optTemp = optTemp | OPTS[quote_style[i]];
|
|
|
}
|
|
|
quote_style = optTemp;
|
|
|
}
|
|
|
if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) string = string.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
|
|
|
if (!noquotes) string = string.replace(/"/g, '"');
|
|
|
// Put this in last place to avoid escape being double-decoded
|
|
|
string = string.replace(/&/g, "&");
|
|
|
return string;
|
|
|
}
|
|
|
}
|
|
|
exports.default = StringUtils;
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"lqMYV":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
parcelHelpers.export(exports, "EDITOR_DELETE", ()=>EDITOR_DELETE);
|
|
|
parcelHelpers.export(exports, "EDITOR_UPLOAD_POST_IMAGE", ()=>EDITOR_UPLOAD_POST_IMAGE);
|
|
|
parcelHelpers.export(exports, "EDITOR_SAVE", ()=>EDITOR_SAVE);
|
|
|
parcelHelpers.export(exports, "EDITOR_UPDATE", ()=>EDITOR_UPDATE);
|
|
|
const EDITOR_DELETE = "editorDelete";
|
|
|
const EDITOR_UPLOAD_POST_IMAGE = "editorUploadImage";
|
|
|
const EDITOR_SAVE = "editorSave";
|
|
|
const EDITOR_UPDATE = "editorUpdate";
|
|
|
class EditorEvent {
|
|
|
}
|
|
|
exports.default = new EditorEvent();
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"hpLqF":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
var _dataEvent = require("../events/DataEvent");
|
|
|
var _caretPos = require("caret-pos");
|
|
|
var _eventEmitter = require("../events/EventEmitter");
|
|
|
var _eventEmitterDefault = parcelHelpers.interopDefault(_eventEmitter);
|
|
|
var _editorEvent = require("../events/EditorEvent");
|
|
|
var _prismCore = require("prismjs/components/prism-core");
|
|
|
var _prismCoreDefault = parcelHelpers.interopDefault(_prismCore);
|
|
|
var _prismMarkup = require("prismjs/components/prism-markup");
|
|
|
var _prismMarkdown = require("prismjs/components/prism-markdown");
|
|
|
class TextEditor extends (0, _eventEmitterDefault.default) {
|
|
|
/**
|
|
|
* Text Editor UI Component
|
|
|
* @constructor
|
|
|
* @param {object} textEditor - Text area that will edit text
|
|
|
* @param {number} scrollLimit - YPos where editor position will become fixed
|
|
|
*/ //--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(textEditor, scrollLimit){
|
|
|
super();
|
|
|
document.getElementById("edit").addEventListener("input", (e)=>{
|
|
|
let result_element = document.querySelector("#highlight-content");
|
|
|
this.textEditor = textEditor; // Update code
|
|
|
let text = e.target.value;
|
|
|
result_element.innerHTML = text.replace(new RegExp("&", "g"), "&").replace(new RegExp("<", "g"), "<");
|
|
|
let editorHeight = document.getElementById("highlight").offsetHeight;
|
|
|
document.getElementById("edit-post-wrapper").style.height = editorHeight + "px";
|
|
|
e.target.style.height = editorHeight + 30 + "px"; //TODO: yeah, it's ugly but it works for now, fix soon
|
|
|
// Syntax Highlight
|
|
|
(0, _prismCoreDefault.default).highlightElement(result_element);
|
|
|
});
|
|
|
document.getElementById("edit").addEventListener("scroll", (e)=>{
|
|
|
/* Scroll result to scroll coords of event - sync with textarea */ let result_element = document.querySelector("#highlight"); // Get and set x and y
|
|
|
result_element.scrollTop = e.scrollTop;
|
|
|
result_element.scrollLeft = e.scrollLeft;
|
|
|
});
|
|
|
document.getElementById("edit").dispatchEvent(new Event("input"));
|
|
|
this.setInputs(); //freeze editor formatting so it doesn't scroll off screen
|
|
|
window.addEventListener("scroll", ()=>{
|
|
|
var fixLimit = scrollLimit;
|
|
|
if (window.pageYOffset + 5 >= fixLimit) document.getElementById("edit-control").style.position = "fixed";
|
|
|
else document.getElementById("edit-control").style.position = "relative";
|
|
|
});
|
|
|
}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
setInputs() {
|
|
|
var editorButtons = document.querySelectorAll(".editor-button");
|
|
|
for(var i = 0, length = editorButtons.length; i < length; i++)editorButtons[i].addEventListener("click", (e)=>this.handleEditorOption(e), false);
|
|
|
}
|
|
|
notify(type, data) {
|
|
|
switch(type){
|
|
|
case _dataEvent.PAGE_UPDATED:
|
|
|
document.getElementById("submit-update").classList.add("icon-hide");
|
|
|
document.getElementById("submit-good").classList.remove("icon-hide");
|
|
|
document.getElementById("edit-update").classList.remove("submit-start");
|
|
|
document.getElementById("edit-update").classList.add("submit-cool");
|
|
|
setTimeout(()=>{
|
|
|
document.getElementById("submit-update").classList.remove("icon-hide");
|
|
|
document.getElementById("submit-good").classList.add("icon-hide");
|
|
|
document.getElementById("edit-update").classList.add("submit-start");
|
|
|
document.getElementById("edit-update").classList.remove("submit-cool");
|
|
|
}, 2000);
|
|
|
break;
|
|
|
case _dataEvent.PAGE_ADDED:
|
|
|
break;
|
|
|
case _editorEvent.EDITOR_UPLOAD_POST_IMAGE:
|
|
|
{
|
|
|
let len = this.textEditor.value.length;
|
|
|
let start = this.textEditor.selectionStart;
|
|
|
let end = this.textEditor.selectionEnd;
|
|
|
let insert = "![image alt text](" + data + ")";
|
|
|
this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len);
|
|
|
document.getElementById("edit").dispatchEvent(new Event("input"));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// event handlers
|
|
|
//--------------------------
|
|
|
handleEditorOption(e) {
|
|
|
e.preventDefault();
|
|
|
let len = this.textEditor.value.length;
|
|
|
let start = this.textEditor.selectionStart;
|
|
|
let end = this.textEditor.selectionEnd;
|
|
|
let selectedText = this.textEditor.value.substring(start, end);
|
|
|
let insert = "";
|
|
|
switch(e.target.id){
|
|
|
case "edit-bold":
|
|
|
insert = "**" + selectedText + "**";
|
|
|
this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len);
|
|
|
break;
|
|
|
case "edit-italic":
|
|
|
insert = "*" + selectedText + "*"; //console.log(this.textEditor);
|
|
|
this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len);
|
|
|
break;
|
|
|
case "edit-strikethrough":
|
|
|
insert = "~~" + selectedText + "~~";
|
|
|
this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len);
|
|
|
break;
|
|
|
case "edit-header1":
|
|
|
insert = "# " + selectedText + "\n";
|
|
|
this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len);
|
|
|
break;
|
|
|
case "edit-header2":
|
|
|
insert = "## " + selectedText + "\n";
|
|
|
this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len);
|
|
|
break;
|
|
|
case "edit-header3":
|
|
|
insert = "### " + selectedText + "\n";
|
|
|
this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len);
|
|
|
break;
|
|
|
case "edit-link":
|
|
|
{
|
|
|
let url = prompt("Let's get that url, boss");
|
|
|
let link = url.toLowerCase();
|
|
|
insert = "[" + selectedText + "](" + link + ")";
|
|
|
this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len);
|
|
|
}
|
|
|
break;
|
|
|
case "edit-image":
|
|
|
this.caretPos = (0, _caretPos.position)(this.textEditor).pos;
|
|
|
this.emitEvent(_editorEvent.EDITOR_UPLOAD_POST_IMAGE);
|
|
|
break;
|
|
|
case "submit-save":
|
|
|
case "edit-save":
|
|
|
this.emitEvent(_editorEvent.EDITOR_SAVE);
|
|
|
break;
|
|
|
case "submit-update":
|
|
|
case "edit-update":
|
|
|
this.emitEvent(_editorEvent.EDITOR_UPDATE);
|
|
|
break;
|
|
|
case "edit-delete":
|
|
|
this.emitEvent(_editorEvent.EDITOR_DELETE);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
document.getElementById("edit").dispatchEvent(new Event("input"));
|
|
|
}
|
|
|
}
|
|
|
exports.default = TextEditor;
|
|
|
|
|
|
},{"../events/DataEvent":"hCRFh","caret-pos":"eNzYQ","../events/EventEmitter":"7LyKC","../events/EditorEvent":"lqMYV","prismjs/components/prism-core":"dRApq","prismjs/components/prism-markup":"lzIPu","prismjs/components/prism-markdown":"15tfx","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"eNzYQ":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
parcelHelpers.export(exports, "getOffset", ()=>getOffset);
|
|
|
parcelHelpers.export(exports, "offset", ()=>offset);
|
|
|
parcelHelpers.export(exports, "position", ()=>position);
|
|
|
var attributes = [
|
|
|
"borderBottomWidth",
|
|
|
"borderLeftWidth",
|
|
|
"borderRightWidth",
|
|
|
"borderTopStyle",
|
|
|
"borderRightStyle",
|
|
|
"borderBottomStyle",
|
|
|
"borderLeftStyle",
|
|
|
"borderTopWidth",
|
|
|
"boxSizing",
|
|
|
"fontFamily",
|
|
|
"fontSize",
|
|
|
"fontWeight",
|
|
|
"height",
|
|
|
"letterSpacing",
|
|
|
"lineHeight",
|
|
|
"marginBottom",
|
|
|
"marginLeft",
|
|
|
"marginRight",
|
|
|
"marginTop",
|
|
|
"outlineWidth",
|
|
|
"overflow",
|
|
|
"overflowX",
|
|
|
"overflowY",
|
|
|
"paddingBottom",
|
|
|
"paddingLeft",
|
|
|
"paddingRight",
|
|
|
"paddingTop",
|
|
|
"textAlign",
|
|
|
"textOverflow",
|
|
|
"textTransform",
|
|
|
"whiteSpace",
|
|
|
"wordBreak",
|
|
|
"wordWrap"
|
|
|
];
|
|
|
/**
|
|
|
* Create a mirror
|
|
|
*
|
|
|
* @param {Element} element The element
|
|
|
* @param {string} html The html
|
|
|
*
|
|
|
* @return {object} The mirror object
|
|
|
*/ var createMirror = function createMirror(element, html1) {
|
|
|
/**
|
|
|
* The mirror element
|
|
|
*/ var mirror = document.createElement("div");
|
|
|
/**
|
|
|
* Create the CSS for the mirror object
|
|
|
*
|
|
|
* @return {object} The style object
|
|
|
*/ var mirrorCss = function mirrorCss() {
|
|
|
var css = {
|
|
|
position: "absolute",
|
|
|
left: -9999,
|
|
|
top: 0,
|
|
|
zIndex: -2000
|
|
|
};
|
|
|
if (element.tagName === "TEXTAREA") attributes.push("width");
|
|
|
attributes.forEach(function(attr) {
|
|
|
css[attr] = getComputedStyle(element)[attr];
|
|
|
});
|
|
|
return css;
|
|
|
};
|
|
|
/**
|
|
|
* Initialize the mirror
|
|
|
*
|
|
|
* @param {string} html The html
|
|
|
*
|
|
|
* @return {void}
|
|
|
*/ var initialize = function initialize(html) {
|
|
|
var styles = mirrorCss();
|
|
|
Object.keys(styles).forEach(function(key) {
|
|
|
mirror.style[key] = styles[key];
|
|
|
});
|
|
|
mirror.innerHTML = html;
|
|
|
element.parentNode.insertBefore(mirror, element.nextSibling);
|
|
|
};
|
|
|
/**
|
|
|
* Get the rect
|
|
|
*
|
|
|
* @return {Rect} The bounding rect
|
|
|
*/ var rect = function rect() {
|
|
|
var marker = mirror.ownerDocument.getElementById("caret-position-marker");
|
|
|
var boundingRect = {
|
|
|
left: marker.offsetLeft,
|
|
|
top: marker.offsetTop,
|
|
|
height: marker.offsetHeight
|
|
|
};
|
|
|
mirror.parentNode.removeChild(mirror);
|
|
|
return boundingRect;
|
|
|
};
|
|
|
initialize(html1);
|
|
|
return {
|
|
|
rect: rect
|
|
|
};
|
|
|
};
|
|
|
function _typeof(obj1) {
|
|
|
"@babel/helpers - typeof";
|
|
|
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") _typeof = function(obj) {
|
|
|
return typeof obj;
|
|
|
};
|
|
|
else _typeof = function(obj) {
|
|
|
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
|
};
|
|
|
return _typeof(obj1);
|
|
|
}
|
|
|
/**
|
|
|
* Check if a DOM Element is content editable
|
|
|
*
|
|
|
* @param {Element} element The DOM element
|
|
|
*
|
|
|
* @return {bool} If it is content editable
|
|
|
*/ var isContentEditable = function isContentEditable(element) {
|
|
|
return !!(element.contentEditable ? element.contentEditable === "true" : element.getAttribute("contenteditable") === "true");
|
|
|
};
|
|
|
/**
|
|
|
* Get the context from settings passed in
|
|
|
*
|
|
|
* @param {object} settings The settings object
|
|
|
*
|
|
|
* @return {object} window and document
|
|
|
*/ var getContext = function getContext() {
|
|
|
var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
|
var customPos = settings.customPos, iframe = settings.iframe, noShadowCaret = settings.noShadowCaret;
|
|
|
if (iframe) return {
|
|
|
iframe: iframe,
|
|
|
window: iframe.contentWindow,
|
|
|
document: iframe.contentDocument || iframe.contentWindow.document,
|
|
|
noShadowCaret: noShadowCaret,
|
|
|
customPos: customPos
|
|
|
};
|
|
|
return {
|
|
|
window: window,
|
|
|
document: document,
|
|
|
noShadowCaret: noShadowCaret,
|
|
|
customPos: customPos
|
|
|
};
|
|
|
};
|
|
|
/**
|
|
|
* Get the offset of an element
|
|
|
*
|
|
|
* @param {Element} element The DOM element
|
|
|
* @param {object} ctx The context
|
|
|
*
|
|
|
* @return {object} top and left
|
|
|
*/ var getOffset = function getOffset(element, ctx) {
|
|
|
var win = ctx && ctx.window || window;
|
|
|
var doc = ctx && ctx.document || document;
|
|
|
var rect = element.getBoundingClientRect();
|
|
|
var docEl = doc.documentElement;
|
|
|
var scrollLeft = win.pageXOffset || docEl.scrollLeft;
|
|
|
var scrollTop = win.pageYOffset || docEl.scrollTop;
|
|
|
return {
|
|
|
top: rect.top + scrollTop,
|
|
|
left: rect.left + scrollLeft
|
|
|
};
|
|
|
};
|
|
|
/**
|
|
|
* Check if a value is an object
|
|
|
*
|
|
|
* @param {any} value The value to check
|
|
|
*
|
|
|
* @return {bool} If it is an object
|
|
|
*/ var isObject = function isObject(value) {
|
|
|
return _typeof(value) === "object" && value !== null;
|
|
|
};
|
|
|
/**
|
|
|
* Create a Input caret object.
|
|
|
*
|
|
|
* @param {Element} element The element
|
|
|
* @param {Object} ctx The context
|
|
|
*/ var createInputCaret = function createInputCaret(element, ctx) {
|
|
|
/**
|
|
|
* Get the current position
|
|
|
*
|
|
|
* @returns {int} The caret position
|
|
|
*/ var getPos = function getPos() {
|
|
|
return element.selectionStart;
|
|
|
};
|
|
|
/**
|
|
|
* Set the position
|
|
|
*
|
|
|
* @param {int} pos The position
|
|
|
*
|
|
|
* @return {Element} The element
|
|
|
*/ var setPos = function setPos(pos) {
|
|
|
element.setSelectionRange(pos, pos);
|
|
|
return element;
|
|
|
};
|
|
|
/**
|
|
|
* The offset
|
|
|
*
|
|
|
* @param {int} pos The position
|
|
|
*
|
|
|
* @return {object} The offset
|
|
|
*/ var getOffset$1 = function getOffset$1(pos) {
|
|
|
var rect = getOffset(element);
|
|
|
var position1 = getPosition(pos);
|
|
|
return {
|
|
|
top: rect.top + position1.top + ctx.document.body.scrollTop,
|
|
|
left: rect.left + position1.left + ctx.document.body.scrollLeft,
|
|
|
height: position1.height
|
|
|
};
|
|
|
};
|
|
|
/**
|
|
|
* Get the current position
|
|
|
*
|
|
|
* @param {int} pos The position
|
|
|
*
|
|
|
* @return {object} The position
|
|
|
*/ var getPosition = function getPosition(pos) {
|
|
|
var format = function format(val) {
|
|
|
var value = val.replace(/<|>|`|"|&/g, "?").replace(/\r\n|\r|\n/g, "<br/>");
|
|
|
return value;
|
|
|
};
|
|
|
if (ctx.customPos || ctx.customPos === 0) pos = ctx.customPos;
|
|
|
var position2 = pos === undefined ? getPos() : pos;
|
|
|
var startRange = element.value.slice(0, position2);
|
|
|
var endRange = element.value.slice(position2);
|
|
|
var html = '<span style="position: relative; display: inline;">'.concat(format(startRange), "</span>");
|
|
|
html += '<span id="caret-position-marker" style="position: relative; display: inline;">|</span>';
|
|
|
html += '<span style="position: relative; display: inline;">'.concat(format(endRange), "</span>");
|
|
|
var mirror = createMirror(element, html);
|
|
|
var rect = mirror.rect();
|
|
|
rect.pos = getPos();
|
|
|
return rect;
|
|
|
};
|
|
|
return {
|
|
|
getPos: getPos,
|
|
|
setPos: setPos,
|
|
|
getOffset: getOffset$1,
|
|
|
getPosition: getPosition
|
|
|
};
|
|
|
};
|
|
|
/**
|
|
|
* Create an Editable Caret
|
|
|
* @param {Element} element The editable element
|
|
|
* @param {object|null} ctx The context
|
|
|
*
|
|
|
* @return {EditableCaret}
|
|
|
*/ var createEditableCaret = function createEditableCaret(element, ctx) {
|
|
|
/**
|
|
|
* Set the caret position
|
|
|
*
|
|
|
* @param {int} pos The position to se
|
|
|
*
|
|
|
* @return {Element} The element
|
|
|
*/ var setPos = function setPos(pos) {
|
|
|
var sel = ctx.window.getSelection();
|
|
|
if (sel) {
|
|
|
var offset1 = 0;
|
|
|
var found = false;
|
|
|
var find1 = function find(position3, parent) {
|
|
|
for(var i = 0; i < parent.childNodes.length; i++){
|
|
|
var node = parent.childNodes[i];
|
|
|
if (found) break;
|
|
|
if (node.nodeType === 3) {
|
|
|
if (offset1 + node.length >= position3) {
|
|
|
found = true;
|
|
|
var range = ctx.document.createRange();
|
|
|
range.setStart(node, position3 - offset1);
|
|
|
sel.removeAllRanges();
|
|
|
sel.addRange(range);
|
|
|
break;
|
|
|
} else offset1 += node.length;
|
|
|
} else find(pos, node);
|
|
|
}
|
|
|
};
|
|
|
find1(pos, element);
|
|
|
}
|
|
|
return element;
|
|
|
};
|
|
|
/**
|
|
|
* Get the offset
|
|
|
*
|
|
|
* @return {object} The offset
|
|
|
*/ var getOffset1 = function getOffset() {
|
|
|
var range = getRange();
|
|
|
var offset2 = {
|
|
|
height: 0,
|
|
|
left: 0,
|
|
|
right: 0
|
|
|
};
|
|
|
if (!range) return offset2;
|
|
|
var hasCustomPos = ctx.customPos || ctx.customPos === 0; // endContainer in Firefox would be the element at the start of
|
|
|
// the line
|
|
|
if (range.endOffset - 1 > 0 && range.endContainer !== element || hasCustomPos) {
|
|
|
var clonedRange = range.cloneRange();
|
|
|
var fixedPosition = hasCustomPos ? ctx.customPos : range.endOffset;
|
|
|
clonedRange.setStart(range.endContainer, fixedPosition - 1 < 0 ? 0 : fixedPosition - 1);
|
|
|
clonedRange.setEnd(range.endContainer, fixedPosition);
|
|
|
var rect = clonedRange.getBoundingClientRect();
|
|
|
offset2 = {
|
|
|
height: rect.height,
|
|
|
left: rect.left + rect.width,
|
|
|
top: rect.top
|
|
|
};
|
|
|
clonedRange.detach();
|
|
|
}
|
|
|
if ((!offset2 || offset2 && offset2.height === 0) && !ctx.noShadowCaret) {
|
|
|
var _clonedRange = range.cloneRange();
|
|
|
var shadowCaret = ctx.document.createTextNode("|");
|
|
|
_clonedRange.insertNode(shadowCaret);
|
|
|
_clonedRange.selectNode(shadowCaret);
|
|
|
var _rect = _clonedRange.getBoundingClientRect();
|
|
|
offset2 = {
|
|
|
height: _rect.height,
|
|
|
left: _rect.left,
|
|
|
top: _rect.top
|
|
|
};
|
|
|
shadowCaret.parentNode.removeChild(shadowCaret);
|
|
|
_clonedRange.detach();
|
|
|
}
|
|
|
if (offset2) {
|
|
|
var doc = ctx.document.documentElement;
|
|
|
offset2.top += ctx.window.pageYOffset - (doc.clientTop || 0);
|
|
|
offset2.left += ctx.window.pageXOffset - (doc.clientLeft || 0);
|
|
|
}
|
|
|
return offset2;
|
|
|
};
|
|
|
/**
|
|
|
* Get the position
|
|
|
*
|
|
|
* @return {object} The position
|
|
|
*/ var getPosition = function getPosition() {
|
|
|
var offset3 = getOffset1();
|
|
|
var pos = getPos();
|
|
|
var rect = element.getBoundingClientRect();
|
|
|
var inputOffset = {
|
|
|
top: rect.top + ctx.document.body.scrollTop,
|
|
|
left: rect.left + ctx.document.body.scrollLeft
|
|
|
};
|
|
|
offset3.left -= inputOffset.left;
|
|
|
offset3.top -= inputOffset.top;
|
|
|
offset3.pos = pos;
|
|
|
return offset3;
|
|
|
};
|
|
|
/**
|
|
|
* Get the range
|
|
|
*
|
|
|
* @return {Range|null}
|
|
|
*/ var getRange = function getRange() {
|
|
|
if (!ctx.window.getSelection) return;
|
|
|
var sel = ctx.window.getSelection();
|
|
|
return sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
|
|
|
};
|
|
|
/**
|
|
|
* Get the caret position
|
|
|
*
|
|
|
* @return {int} The position
|
|
|
*/ var getPos = function getPos() {
|
|
|
var range = getRange();
|
|
|
var clonedRange = range.cloneRange();
|
|
|
clonedRange.selectNodeContents(element);
|
|
|
clonedRange.setEnd(range.endContainer, range.endOffset);
|
|
|
var pos = clonedRange.toString().length;
|
|
|
clonedRange.detach();
|
|
|
return pos;
|
|
|
};
|
|
|
return {
|
|
|
getPos: getPos,
|
|
|
setPos: setPos,
|
|
|
getPosition: getPosition,
|
|
|
getOffset: getOffset1,
|
|
|
getRange: getRange
|
|
|
};
|
|
|
};
|
|
|
var createCaret = function createCaret(element, ctx) {
|
|
|
if (isContentEditable(element)) return createEditableCaret(element, ctx);
|
|
|
return createInputCaret(element, ctx);
|
|
|
};
|
|
|
var position = function position(element, value) {
|
|
|
var settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
|
var options = settings;
|
|
|
if (isObject(value)) {
|
|
|
options = value;
|
|
|
value = null;
|
|
|
}
|
|
|
var ctx = getContext(options);
|
|
|
var caret = createCaret(element, ctx);
|
|
|
if (value || value === 0) return caret.setPos(value);
|
|
|
return caret.getPosition();
|
|
|
};
|
|
|
/**
|
|
|
*
|
|
|
* @param {Element} element The DOM element
|
|
|
* @param {number|undefined} value The value to set
|
|
|
* @param {object} settings Any settings for context
|
|
|
*/ var offset = function offset(element, value) {
|
|
|
var settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
|
var options = settings;
|
|
|
if (isObject(value)) {
|
|
|
options = value;
|
|
|
value = null;
|
|
|
}
|
|
|
var ctx = getContext(options);
|
|
|
var caret = createCaret(element, ctx);
|
|
|
return caret.getOffset(value);
|
|
|
};
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"7LyKC":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
class EventEmitter {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){
|
|
|
this.listeners = new Map();
|
|
|
}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
addListener(label, callback) {
|
|
|
this.listeners.has(label) || this.listeners.set(label, []);
|
|
|
this.listeners.get(label).push(callback);
|
|
|
}
|
|
|
removeListener(label, callback) {
|
|
|
var isFunction = function(obj) {
|
|
|
return typeof obj == "function" || false;
|
|
|
};
|
|
|
var listeners = this.listeners.get(label), index1;
|
|
|
if (listeners && listeners.length) {
|
|
|
index1 = listeners.reduce((i, listener, index)=>{
|
|
|
return isFunction(listener) && listener === callback ? i = index : i;
|
|
|
}, -1);
|
|
|
if (index1 > -1) {
|
|
|
listeners.splice(index1, 1);
|
|
|
this.listeners.set(label, listeners);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
emitEvent(label, ...args) {
|
|
|
var listeners = this.listeners.get(label);
|
|
|
if (listeners && listeners.length) {
|
|
|
listeners.forEach((listener)=>{
|
|
|
listener(...args);
|
|
|
});
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
exports.default = EventEmitter;
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"dRApq":[function(require,module,exports) {
|
|
|
var global = arguments[3];
|
|
|
/// <reference lib="WebWorker"/>
|
|
|
var _self = typeof window !== "undefined" ? window // if in browser
|
|
|
: typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope ? self // if in worker
|
|
|
: {} // if in node js
|
|
|
;
|
|
|
/**
|
|
|
* Prism: Lightweight, robust, elegant syntax highlighting
|
|
|
*
|
|
|
* @license MIT <https://opensource.org/licenses/MIT>
|
|
|
* @author Lea Verou <https://lea.verou.me>
|
|
|
* @namespace
|
|
|
* @public
|
|
|
*/ var Prism = function(_self1) {
|
|
|
// Private helper vars
|
|
|
var lang1 = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
|
|
|
var uniqueId = 0;
|
|
|
// The grammar object for plaintext
|
|
|
var plainTextGrammar = {};
|
|
|
var _ = {
|
|
|
/**
|
|
|
* By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
|
|
|
* current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
|
|
|
* additional languages or plugins yourself.
|
|
|
*
|
|
|
* By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
|
|
|
*
|
|
|
* You obviously have to change this value before the automatic highlighting started. To do this, you can add an
|
|
|
* empty Prism object into the global scope before loading the Prism script like this:
|
|
|
*
|
|
|
* ```js
|
|
|
* window.Prism = window.Prism || {};
|
|
|
* Prism.manual = true;
|
|
|
* // add a new <script> to load Prism's script
|
|
|
* ```
|
|
|
*
|
|
|
* @default false
|
|
|
* @type {boolean}
|
|
|
* @memberof Prism
|
|
|
* @public
|
|
|
*/ manual: _self1.Prism && _self1.Prism.manual,
|
|
|
/**
|
|
|
* By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
|
|
|
* `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
|
|
|
* own worker, you don't want it to do this.
|
|
|
*
|
|
|
* By setting this value to `true`, Prism will not add its own listeners to the worker.
|
|
|
*
|
|
|
* You obviously have to change this value before Prism executes. To do this, you can add an
|
|
|
* empty Prism object into the global scope before loading the Prism script like this:
|
|
|
*
|
|
|
* ```js
|
|
|
* window.Prism = window.Prism || {};
|
|
|
* Prism.disableWorkerMessageHandler = true;
|
|
|
* // Load Prism's script
|
|
|
* ```
|
|
|
*
|
|
|
* @default false
|
|
|
* @type {boolean}
|
|
|
* @memberof Prism
|
|
|
* @public
|
|
|
*/ disableWorkerMessageHandler: _self1.Prism && _self1.Prism.disableWorkerMessageHandler,
|
|
|
/**
|
|
|
* A namespace for utility methods.
|
|
|
*
|
|
|
* All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
|
|
|
* change or disappear at any time.
|
|
|
*
|
|
|
* @namespace
|
|
|
* @memberof Prism
|
|
|
*/ util: {
|
|
|
encode: function encode(tokens) {
|
|
|
if (tokens instanceof Token) return new Token(tokens.type, encode(tokens.content), tokens.alias);
|
|
|
else if (Array.isArray(tokens)) return tokens.map(encode);
|
|
|
else return tokens.replace(/&/g, "&").replace(/</g, "<").replace(/\u00a0/g, " ");
|
|
|
},
|
|
|
/**
|
|
|
* Returns the name of the type of the given value.
|
|
|
*
|
|
|
* @param {any} o
|
|
|
* @returns {string}
|
|
|
* @example
|
|
|
* type(null) === 'Null'
|
|
|
* type(undefined) === 'Undefined'
|
|
|
* type(123) === 'Number'
|
|
|
* type('foo') === 'String'
|
|
|
* type(true) === 'Boolean'
|
|
|
* type([1, 2]) === 'Array'
|
|
|
* type({}) === 'Object'
|
|
|
* type(String) === 'Function'
|
|
|
* type(/abc+/) === 'RegExp'
|
|
|
*/ type: function(o) {
|
|
|
return Object.prototype.toString.call(o).slice(8, -1);
|
|
|
},
|
|
|
/**
|
|
|
* Returns a unique number for the given object. Later calls will still return the same number.
|
|
|
*
|
|
|
* @param {Object} obj
|
|
|
* @returns {number}
|
|
|
*/ objId: function(obj) {
|
|
|
if (!obj["__id"]) Object.defineProperty(obj, "__id", {
|
|
|
value: ++uniqueId
|
|
|
});
|
|
|
return obj["__id"];
|
|
|
},
|
|
|
/**
|
|
|
* Creates a deep clone of the given object.
|
|
|
*
|
|
|
* The main intended use of this function is to clone language definitions.
|
|
|
*
|
|
|
* @param {T} o
|
|
|
* @param {Record<number, any>} [visited]
|
|
|
* @returns {T}
|
|
|
* @template T
|
|
|
*/ clone: function deepClone(o, visited) {
|
|
|
visited = visited || {};
|
|
|
var clone;
|
|
|
var id;
|
|
|
switch(_.util.type(o)){
|
|
|
case "Object":
|
|
|
id = _.util.objId(o);
|
|
|
if (visited[id]) return visited[id];
|
|
|
clone = {};
|
|
|
visited[id] = clone;
|
|
|
for(var key in o)if (o.hasOwnProperty(key)) clone[key] = deepClone(o[key], visited);
|
|
|
return clone;
|
|
|
case "Array":
|
|
|
id = _.util.objId(o);
|
|
|
if (visited[id]) return visited[id];
|
|
|
clone = [];
|
|
|
visited[id] = clone;
|
|
|
o.forEach(function(v, i) {
|
|
|
clone[i] = deepClone(v, visited);
|
|
|
});
|
|
|
return clone;
|
|
|
default:
|
|
|
return o;
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
* Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
|
|
|
*
|
|
|
* If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
|
|
|
*
|
|
|
* @param {Element} element
|
|
|
* @returns {string}
|
|
|
*/ getLanguage: function(element) {
|
|
|
while(element){
|
|
|
var m = lang1.exec(element.className);
|
|
|
if (m) return m[1].toLowerCase();
|
|
|
element = element.parentElement;
|
|
|
}
|
|
|
return "none";
|
|
|
},
|
|
|
/**
|
|
|
* Sets the Prism `language-xxxx` class of the given element.
|
|
|
*
|
|
|
* @param {Element} element
|
|
|
* @param {string} language
|
|
|
* @returns {void}
|
|
|
*/ setLanguage: function(element, language) {
|
|
|
// remove all `language-xxxx` classes
|
|
|
// (this might leave behind a leading space)
|
|
|
element.className = element.className.replace(RegExp(lang1, "gi"), "");
|
|
|
// add the new `language-xxxx` class
|
|
|
// (using `classList` will automatically clean up spaces for us)
|
|
|
element.classList.add("language-" + language);
|
|
|
},
|
|
|
/**
|
|
|
* Returns the script element that is currently executing.
|
|
|
*
|
|
|
* This does __not__ work for line script element.
|
|
|
*
|
|
|
* @returns {HTMLScriptElement | null}
|
|
|
*/ currentScript: function() {
|
|
|
if (typeof document === "undefined") return null;
|
|
|
if ("currentScript" in document && true /* hack to trip TS' flow analysis */ ) return document.currentScript;
|
|
|
// IE11 workaround
|
|
|
// we'll get the src of the current script by parsing IE11's error stack trace
|
|
|
// this will not work for inline scripts
|
|
|
try {
|
|
|
throw new Error();
|
|
|
} catch (err) {
|
|
|
// Get file src url from stack. Specifically works with the format of stack traces in IE.
|
|
|
// A stack will look like this:
|
|
|
//
|
|
|
// Error
|
|
|
// at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
|
|
|
// at Global code (http://localhost/components/prism-core.js:606:1)
|
|
|
var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
|
|
|
if (src) {
|
|
|
var scripts = document.getElementsByTagName("script");
|
|
|
for(var i in scripts){
|
|
|
if (scripts[i].src == src) return scripts[i];
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
* Returns whether a given class is active for `element`.
|
|
|
*
|
|
|
* The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
|
|
|
* if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
|
|
|
* given class is just the given class with a `no-` prefix.
|
|
|
*
|
|
|
* Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
|
|
|
* closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
|
|
|
* ancestors have the given class or the negated version of it, then the default activation will be returned.
|
|
|
*
|
|
|
* In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
|
|
|
* version of it, the class is considered active.
|
|
|
*
|
|
|
* @param {Element} element
|
|
|
* @param {string} className
|
|
|
* @param {boolean} [defaultActivation=false]
|
|
|
* @returns {boolean}
|
|
|
*/ isActive: function(element, className, defaultActivation) {
|
|
|
var no = "no-" + className;
|
|
|
while(element){
|
|
|
var classList = element.classList;
|
|
|
if (classList.contains(className)) return true;
|
|
|
if (classList.contains(no)) return false;
|
|
|
element = element.parentElement;
|
|
|
}
|
|
|
return !!defaultActivation;
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
* This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
|
|
|
*
|
|
|
* @namespace
|
|
|
* @memberof Prism
|
|
|
* @public
|
|
|
*/ languages: {
|
|
|
/**
|
|
|
* The grammar for plain, unformatted text.
|
|
|
*/ plain: plainTextGrammar,
|
|
|
plaintext: plainTextGrammar,
|
|
|
text: plainTextGrammar,
|
|
|
txt: plainTextGrammar,
|
|
|
/**
|
|
|
* Creates a deep copy of the language with the given id and appends the given tokens.
|
|
|
*
|
|
|
* If a token in `redef` also appears in the copied language, then the existing token in the copied language
|
|
|
* will be overwritten at its original position.
|
|
|
*
|
|
|
* ## Best practices
|
|
|
*
|
|
|
* Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
|
|
|
* doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
|
|
|
* understand the language definition because, normally, the order of tokens matters in Prism grammars.
|
|
|
*
|
|
|
* Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
|
|
|
* Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
|
|
|
*
|
|
|
* @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
|
|
|
* @param {Grammar} redef The new tokens to append.
|
|
|
* @returns {Grammar} The new language created.
|
|
|
* @public
|
|
|
* @example
|
|
|
* Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
|
|
|
* // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
|
|
|
* // at its original position
|
|
|
* 'comment': { ... },
|
|
|
* // CSS doesn't have a 'color' token, so this token will be appended
|
|
|
* 'color': /\b(?:red|green|blue)\b/
|
|
|
* });
|
|
|
*/ extend: function(id, redef) {
|
|
|
var lang = _.util.clone(_.languages[id]);
|
|
|
for(var key in redef)lang[key] = redef[key];
|
|
|
return lang;
|
|
|
},
|
|
|
/**
|
|
|
* Inserts tokens _before_ another token in a language definition or any other grammar.
|
|
|
*
|
|
|
* ## Usage
|
|
|
*
|
|
|
* This helper method makes it easy to modify existing languages. For example, the CSS language definition
|
|
|
* not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
|
|
|
* in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
|
|
|
* appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
|
|
|
* this:
|
|
|
*
|
|
|
* ```js
|
|
|
* Prism.languages.markup.style = {
|
|
|
* // token
|
|
|
* };
|
|
|
* ```
|
|
|
*
|
|
|
* then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
|
|
|
* before existing tokens. For the CSS example above, you would use it like this:
|
|
|
*
|
|
|
* ```js
|
|
|
* Prism.languages.insertBefore('markup', 'cdata', {
|
|
|
* 'style': {
|
|
|
* // token
|
|
|
* }
|
|
|
* });
|
|
|
* ```
|
|
|
*
|
|
|
* ## Special cases
|
|
|
*
|
|
|
* If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
|
|
|
* will be ignored.
|
|
|
*
|
|
|
* This behavior can be used to insert tokens after `before`:
|
|
|
*
|
|
|
* ```js
|
|
|
* Prism.languages.insertBefore('markup', 'comment', {
|
|
|
* 'comment': Prism.languages.markup.comment,
|
|
|
* // tokens after 'comment'
|
|
|
* });
|
|
|
* ```
|
|
|
*
|
|
|
* ## Limitations
|
|
|
*
|
|
|
* The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
|
|
|
* properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
|
|
|
* differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
|
|
|
* deleting properties which is necessary to insert at arbitrary positions.
|
|
|
*
|
|
|
* To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
|
|
|
* Instead, it will create a new object and replace all references to the target object with the new one. This
|
|
|
* can be done without temporarily deleting properties, so the iteration order is well-defined.
|
|
|
*
|
|
|
* However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
|
|
|
* you hold the target object in a variable, then the value of the variable will not change.
|
|
|
*
|
|
|
* ```js
|
|
|
* var oldMarkup = Prism.languages.markup;
|
|
|
* var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
|
|
|
*
|
|
|
* assert(oldMarkup !== Prism.languages.markup);
|
|
|
* assert(newMarkup === Prism.languages.markup);
|
|
|
* ```
|
|
|
*
|
|
|
* @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
|
|
|
* object to be modified.
|
|
|
* @param {string} before The key to insert before.
|
|
|
* @param {Grammar} insert An object containing the key-value pairs to be inserted.
|
|
|
* @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
|
|
|
* object to be modified.
|
|
|
*
|
|
|
* Defaults to `Prism.languages`.
|
|
|
* @returns {Grammar} The new grammar object.
|
|
|
* @public
|
|
|
*/ insertBefore: function(inside, before, insert, root) {
|
|
|
root = root || _.languages;
|
|
|
var grammar = root[inside];
|
|
|
/** @type {Grammar} */ var ret = {};
|
|
|
for(var token in grammar)if (grammar.hasOwnProperty(token)) {
|
|
|
if (token == before) {
|
|
|
for(var newToken in insert)if (insert.hasOwnProperty(newToken)) ret[newToken] = insert[newToken];
|
|
|
}
|
|
|
// Do not insert token which also occur in insert. See #1525
|
|
|
if (!insert.hasOwnProperty(token)) ret[token] = grammar[token];
|
|
|
}
|
|
|
var old = root[inside];
|
|
|
root[inside] = ret;
|
|
|
// Update references in other language definitions
|
|
|
_.languages.DFS(_.languages, function(key, value) {
|
|
|
if (value === old && key != inside) this[key] = ret;
|
|
|
});
|
|
|
return ret;
|
|
|
},
|
|
|
// Traverse a language definition with Depth First Search
|
|
|
DFS: function DFS(o, callback, type, visited) {
|
|
|
visited = visited || {};
|
|
|
var objId = _.util.objId;
|
|
|
for(var i in o)if (o.hasOwnProperty(i)) {
|
|
|
callback.call(o, i, o[i], type || i);
|
|
|
var property = o[i];
|
|
|
var propertyType = _.util.type(property);
|
|
|
if (propertyType === "Object" && !visited[objId(property)]) {
|
|
|
visited[objId(property)] = true;
|
|
|
DFS(property, callback, null, visited);
|
|
|
} else if (propertyType === "Array" && !visited[objId(property)]) {
|
|
|
visited[objId(property)] = true;
|
|
|
DFS(property, callback, i, visited);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
plugins: {},
|
|
|
/**
|
|
|
* This is the most high-level function in Prism’s API.
|
|
|
* It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
|
|
|
* each one of them.
|
|
|
*
|
|
|
* This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
|
|
|
*
|
|
|
* @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
|
|
|
* @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
|
|
|
* @memberof Prism
|
|
|
* @public
|
|
|
*/ highlightAll: function(async, callback) {
|
|
|
_.highlightAllUnder(document, async, callback);
|
|
|
},
|
|
|
/**
|
|
|
* Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
|
|
|
* {@link Prism.highlightElement} on each one of them.
|
|
|
*
|
|
|
* The following hooks will be run:
|
|
|
* 1. `before-highlightall`
|
|
|
* 2. `before-all-elements-highlight`
|
|
|
* 3. All hooks of {@link Prism.highlightElement} for each element.
|
|
|
*
|
|
|
* @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
|
|
|
* @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
|
|
|
* @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
|
|
|
* @memberof Prism
|
|
|
* @public
|
|
|
*/ highlightAllUnder: function(container, async, callback) {
|
|
|
var env = {
|
|
|
callback: callback,
|
|
|
container: container,
|
|
|
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
|
|
|
};
|
|
|
_.hooks.run("before-highlightall", env);
|
|
|
env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
|
|
|
_.hooks.run("before-all-elements-highlight", env);
|
|
|
for(var i = 0, element; element = env.elements[i++];)_.highlightElement(element, async === true, env.callback);
|
|
|
},
|
|
|
/**
|
|
|
* Highlights the code inside a single element.
|
|
|
*
|
|
|
* The following hooks will be run:
|
|
|
* 1. `before-sanity-check`
|
|
|
* 2. `before-highlight`
|
|
|
* 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
|
|
|
* 4. `before-insert`
|
|
|
* 5. `after-highlight`
|
|
|
* 6. `complete`
|
|
|
*
|
|
|
* Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
|
|
|
* the element's language.
|
|
|
*
|
|
|
* @param {Element} element The element containing the code.
|
|
|
* It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
|
|
|
* @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
|
|
|
* to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
|
|
|
* [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
|
|
|
*
|
|
|
* Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
|
|
|
* asynchronous highlighting to work. You can build your own bundle on the
|
|
|
* [Download page](https://prismjs.com/download.html).
|
|
|
* @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
|
|
|
* Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
|
|
|
* @memberof Prism
|
|
|
* @public
|
|
|
*/ highlightElement: function(element, async, callback) {
|
|
|
// Find language
|
|
|
var language = _.util.getLanguage(element);
|
|
|
var grammar = _.languages[language];
|
|
|
// Set language on the element, if not present
|
|
|
_.util.setLanguage(element, language);
|
|
|
// Set language on the parent, for styling
|
|
|
var parent = element.parentElement;
|
|
|
if (parent && parent.nodeName.toLowerCase() === "pre") _.util.setLanguage(parent, language);
|
|
|
var code = element.textContent;
|
|
|
var env = {
|
|
|
element: element,
|
|
|
language: language,
|
|
|
grammar: grammar,
|
|
|
code: code
|
|
|
};
|
|
|
function insertHighlightedCode(highlightedCode) {
|
|
|
env.highlightedCode = highlightedCode;
|
|
|
_.hooks.run("before-insert", env);
|
|
|
env.element.innerHTML = env.highlightedCode;
|
|
|
_.hooks.run("after-highlight", env);
|
|
|
_.hooks.run("complete", env);
|
|
|
callback && callback.call(env.element);
|
|
|
}
|
|
|
_.hooks.run("before-sanity-check", env);
|
|
|
// plugins may change/add the parent/element
|
|
|
parent = env.element.parentElement;
|
|
|
if (parent && parent.nodeName.toLowerCase() === "pre" && !parent.hasAttribute("tabindex")) parent.setAttribute("tabindex", "0");
|
|
|
if (!env.code) {
|
|
|
_.hooks.run("complete", env);
|
|
|
callback && callback.call(env.element);
|
|
|
return;
|
|
|
}
|
|
|
_.hooks.run("before-highlight", env);
|
|
|
if (!env.grammar) {
|
|
|
insertHighlightedCode(_.util.encode(env.code));
|
|
|
return;
|
|
|
}
|
|
|
if (async && _self1.Worker) {
|
|
|
var worker = new Worker(_.filename);
|
|
|
worker.onmessage = function(evt) {
|
|
|
insertHighlightedCode(evt.data);
|
|
|
};
|
|
|
worker.postMessage(JSON.stringify({
|
|
|
language: env.language,
|
|
|
code: env.code,
|
|
|
immediateClose: true
|
|
|
}));
|
|
|
} else insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
|
|
|
},
|
|
|
/**
|
|
|
* Low-level function, only use if you know what you’re doing. It accepts a string of text as input
|
|
|
* and the language definitions to use, and returns a string with the HTML produced.
|
|
|
*
|
|
|
* The following hooks will be run:
|
|
|
* 1. `before-tokenize`
|
|
|
* 2. `after-tokenize`
|
|
|
* 3. `wrap`: On each {@link Token}.
|
|
|
*
|
|
|
* @param {string} text A string with the code to be highlighted.
|
|
|
* @param {Grammar} grammar An object containing the tokens to use.
|
|
|
*
|
|
|
* Usually a language definition like `Prism.languages.markup`.
|
|
|
* @param {string} language The name of the language definition passed to `grammar`.
|
|
|
* @returns {string} The highlighted HTML.
|
|
|
* @memberof Prism
|
|
|
* @public
|
|
|
* @example
|
|
|
* Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
|
|
|
*/ highlight: function(text, grammar, language) {
|
|
|
var env = {
|
|
|
code: text,
|
|
|
grammar: grammar,
|
|
|
language: language
|
|
|
};
|
|
|
_.hooks.run("before-tokenize", env);
|
|
|
if (!env.grammar) throw new Error('The language "' + env.language + '" has no grammar.');
|
|
|
env.tokens = _.tokenize(env.code, env.grammar);
|
|
|
_.hooks.run("after-tokenize", env);
|
|
|
return Token.stringify(_.util.encode(env.tokens), env.language);
|
|
|
},
|
|
|
/**
|
|
|
* This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
|
|
|
* and the language definitions to use, and returns an array with the tokenized code.
|
|
|
*
|
|
|
* When the language definition includes nested tokens, the function is called recursively on each of these tokens.
|
|
|
*
|
|
|
* This method could be useful in other contexts as well, as a very crude parser.
|
|
|
*
|
|
|
* @param {string} text A string with the code to be highlighted.
|
|
|
* @param {Grammar} grammar An object containing the tokens to use.
|
|
|
*
|
|
|
* Usually a language definition like `Prism.languages.markup`.
|
|
|
* @returns {TokenStream} An array of strings and tokens, a token stream.
|
|
|
* @memberof Prism
|
|
|
* @public
|
|
|
* @example
|
|
|
* let code = `var foo = 0;`;
|
|
|
* let tokens = Prism.tokenize(code, Prism.languages.javascript);
|
|
|
* tokens.forEach(token => {
|
|
|
* if (token instanceof Prism.Token && token.type === 'number') {
|
|
|
* console.log(`Found numeric literal: ${token.content}`);
|
|
|
* }
|
|
|
* });
|
|
|
*/ tokenize: function(text, grammar) {
|
|
|
var rest = grammar.rest;
|
|
|
if (rest) {
|
|
|
for(var token in rest)grammar[token] = rest[token];
|
|
|
delete grammar.rest;
|
|
|
}
|
|
|
var tokenList = new LinkedList();
|
|
|
addAfter(tokenList, tokenList.head, text);
|
|
|
matchGrammar(text, tokenList, grammar, tokenList.head, 0);
|
|
|
return toArray(tokenList);
|
|
|
},
|
|
|
/**
|
|
|
* @namespace
|
|
|
* @memberof Prism
|
|
|
* @public
|
|
|
*/ hooks: {
|
|
|
all: {},
|
|
|
/**
|
|
|
* Adds the given callback to the list of callbacks for the given hook.
|
|
|
*
|
|
|
* The callback will be invoked when the hook it is registered for is run.
|
|
|
* Hooks are usually directly run by a highlight function but you can also run hooks yourself.
|
|
|
*
|
|
|
* One callback function can be registered to multiple hooks and the same hook multiple times.
|
|
|
*
|
|
|
* @param {string} name The name of the hook.
|
|
|
* @param {HookCallback} callback The callback function which is given environment variables.
|
|
|
* @public
|
|
|
*/ add: function(name, callback) {
|
|
|
var hooks = _.hooks.all;
|
|
|
hooks[name] = hooks[name] || [];
|
|
|
hooks[name].push(callback);
|
|
|
},
|
|
|
/**
|
|
|
* Runs a hook invoking all registered callbacks with the given environment variables.
|
|
|
*
|
|
|
* Callbacks will be invoked synchronously and in the order in which they were registered.
|
|
|
*
|
|
|
* @param {string} name The name of the hook.
|
|
|
* @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
|
|
|
* @public
|
|
|
*/ run: function(name, env) {
|
|
|
var callbacks = _.hooks.all[name];
|
|
|
if (!callbacks || !callbacks.length) return;
|
|
|
for(var i = 0, callback; callback = callbacks[i++];)callback(env);
|
|
|
}
|
|
|
},
|
|
|
Token: Token
|
|
|
};
|
|
|
_self1.Prism = _;
|
|
|
// Typescript note:
|
|
|
// The following can be used to import the Token type in JSDoc:
|
|
|
//
|
|
|
// @typedef {InstanceType<import("./prism-core")["Token"]>} Token
|
|
|
/**
|
|
|
* Creates a new token.
|
|
|
*
|
|
|
* @param {string} type See {@link Token#type type}
|
|
|
* @param {string | TokenStream} content See {@link Token#content content}
|
|
|
* @param {string|string[]} [alias] The alias(es) of the token.
|
|
|
* @param {string} [matchedStr=""] A copy of the full string this token was created from.
|
|
|
* @class
|
|
|
* @global
|
|
|
* @public
|
|
|
*/ function Token(type, content, alias, matchedStr) {
|
|
|
/**
|
|
|
* The type of the token.
|
|
|
*
|
|
|
* This is usually the key of a pattern in a {@link Grammar}.
|
|
|
*
|
|
|
* @type {string}
|
|
|
* @see GrammarToken
|
|
|
* @public
|
|
|
*/ this.type = type;
|
|
|
/**
|
|
|
* The strings or tokens contained by this token.
|
|
|
*
|
|
|
* This will be a token stream if the pattern matched also defined an `inside` grammar.
|
|
|
*
|
|
|
* @type {string | TokenStream}
|
|
|
* @public
|
|
|
*/ this.content = content;
|
|
|
/**
|
|
|
* The alias(es) of the token.
|
|
|
*
|
|
|
* @type {string|string[]}
|
|
|
* @see GrammarToken
|
|
|
* @public
|
|
|
*/ this.alias = alias;
|
|
|
// Copy of the full string this token was created from
|
|
|
this.length = (matchedStr || "").length | 0;
|
|
|
}
|
|
|
/**
|
|
|
* A token stream is an array of strings and {@link Token Token} objects.
|
|
|
*
|
|
|
* Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
|
|
|
* them.
|
|
|
*
|
|
|
* 1. No adjacent strings.
|
|
|
* 2. No empty strings.
|
|
|
*
|
|
|
* The only exception here is the token stream that only contains the empty string and nothing else.
|
|
|
*
|
|
|
* @typedef {Array<string | Token>} TokenStream
|
|
|
* @global
|
|
|
* @public
|
|
|
*/ /**
|
|
|
* Converts the given token or token stream to an HTML representation.
|
|
|
*
|
|
|
* The following hooks will be run:
|
|
|
* 1. `wrap`: On each {@link Token}.
|
|
|
*
|
|
|
* @param {string | Token | TokenStream} o The token or token stream to be converted.
|
|
|
* @param {string} language The name of current language.
|
|
|
* @returns {string} The HTML representation of the token or token stream.
|
|
|
* @memberof Token
|
|
|
* @static
|
|
|
*/ Token.stringify = function stringify(o, language) {
|
|
|
if (typeof o == "string") return o;
|
|
|
if (Array.isArray(o)) {
|
|
|
var s = "";
|
|
|
o.forEach(function(e) {
|
|
|
s += stringify(e, language);
|
|
|
});
|
|
|
return s;
|
|
|
}
|
|
|
var env = {
|
|
|
type: o.type,
|
|
|
content: stringify(o.content, language),
|
|
|
tag: "span",
|
|
|
classes: [
|
|
|
"token",
|
|
|
o.type
|
|
|
],
|
|
|
attributes: {},
|
|
|
language: language
|
|
|
};
|
|
|
var aliases = o.alias;
|
|
|
if (aliases) {
|
|
|
if (Array.isArray(aliases)) Array.prototype.push.apply(env.classes, aliases);
|
|
|
else env.classes.push(aliases);
|
|
|
}
|
|
|
_.hooks.run("wrap", env);
|
|
|
var attributes = "";
|
|
|
for(var name in env.attributes)attributes += " " + name + '="' + (env.attributes[name] || "").replace(/"/g, """) + '"';
|
|
|
return "<" + env.tag + ' class="' + env.classes.join(" ") + '"' + attributes + ">" + env.content + "</" + env.tag + ">";
|
|
|
};
|
|
|
/**
|
|
|
* @param {RegExp} pattern
|
|
|
* @param {number} pos
|
|
|
* @param {string} text
|
|
|
* @param {boolean} lookbehind
|
|
|
* @returns {RegExpExecArray | null}
|
|
|
*/ function matchPattern(pattern, pos, text, lookbehind) {
|
|
|
pattern.lastIndex = pos;
|
|
|
var match = pattern.exec(text);
|
|
|
if (match && lookbehind && match[1]) {
|
|
|
// change the match to remove the text matched by the Prism lookbehind group
|
|
|
var lookbehindLength = match[1].length;
|
|
|
match.index += lookbehindLength;
|
|
|
match[0] = match[0].slice(lookbehindLength);
|
|
|
}
|
|
|
return match;
|
|
|
}
|
|
|
/**
|
|
|
* @param {string} text
|
|
|
* @param {LinkedList<string | Token>} tokenList
|
|
|
* @param {any} grammar
|
|
|
* @param {LinkedListNode<string | Token>} startNode
|
|
|
* @param {number} startPos
|
|
|
* @param {RematchOptions} [rematch]
|
|
|
* @returns {void}
|
|
|
* @private
|
|
|
*
|
|
|
* @typedef RematchOptions
|
|
|
* @property {string} cause
|
|
|
* @property {number} reach
|
|
|
*/ function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
|
|
|
for(var token in grammar){
|
|
|
if (!grammar.hasOwnProperty(token) || !grammar[token]) continue;
|
|
|
var patterns = grammar[token];
|
|
|
patterns = Array.isArray(patterns) ? patterns : [
|
|
|
patterns
|
|
|
];
|
|
|
for(var j = 0; j < patterns.length; ++j){
|
|
|
if (rematch && rematch.cause == token + "," + j) return;
|
|
|
var patternObj = patterns[j];
|
|
|
var inside = patternObj.inside;
|
|
|
var lookbehind = !!patternObj.lookbehind;
|
|
|
var greedy = !!patternObj.greedy;
|
|
|
var alias = patternObj.alias;
|
|
|
if (greedy && !patternObj.pattern.global) {
|
|
|
// Without the global flag, lastIndex won't work
|
|
|
var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
|
|
|
patternObj.pattern = RegExp(patternObj.pattern.source, flags + "g");
|
|
|
}
|
|
|
/** @type {RegExp} */ var pattern = patternObj.pattern || patternObj;
|
|
|
for(var currentNode = startNode.next, pos = startPos; currentNode !== tokenList.tail; pos += currentNode.value.length, currentNode = currentNode.next){
|
|
|
if (rematch && pos >= rematch.reach) break;
|
|
|
var str = currentNode.value;
|
|
|
if (tokenList.length > text.length) // Something went terribly wrong, ABORT, ABORT!
|
|
|
return;
|
|
|
if (str instanceof Token) continue;
|
|
|
var removeCount = 1; // this is the to parameter of removeBetween
|
|
|
var match;
|
|
|
if (greedy) {
|
|
|
match = matchPattern(pattern, pos, text, lookbehind);
|
|
|
if (!match || match.index >= text.length) break;
|
|
|
var from = match.index;
|
|
|
var to = match.index + match[0].length;
|
|
|
var p = pos;
|
|
|
// find the node that contains the match
|
|
|
p += currentNode.value.length;
|
|
|
while(from >= p){
|
|
|
currentNode = currentNode.next;
|
|
|
p += currentNode.value.length;
|
|
|
}
|
|
|
// adjust pos (and p)
|
|
|
p -= currentNode.value.length;
|
|
|
pos = p;
|
|
|
// the current node is a Token, then the match starts inside another Token, which is invalid
|
|
|
if (currentNode.value instanceof Token) continue;
|
|
|
// find the last node which is affected by this match
|
|
|
for(var k = currentNode; k !== tokenList.tail && (p < to || typeof k.value === "string"); k = k.next){
|
|
|
removeCount++;
|
|
|
p += k.value.length;
|
|
|
}
|
|
|
removeCount--;
|
|
|
// replace with the new match
|
|
|
str = text.slice(pos, p);
|
|
|
match.index -= pos;
|
|
|
} else {
|
|
|
match = matchPattern(pattern, 0, str, lookbehind);
|
|
|
if (!match) continue;
|
|
|
}
|
|
|
// eslint-disable-next-line no-redeclare
|
|
|
var from = match.index;
|
|
|
var matchStr = match[0];
|
|
|
var before = str.slice(0, from);
|
|
|
var after = str.slice(from + matchStr.length);
|
|
|
var reach = pos + str.length;
|
|
|
if (rematch && reach > rematch.reach) rematch.reach = reach;
|
|
|
var removeFrom = currentNode.prev;
|
|
|
if (before) {
|
|
|
removeFrom = addAfter(tokenList, removeFrom, before);
|
|
|
pos += before.length;
|
|
|
}
|
|
|
removeRange(tokenList, removeFrom, removeCount);
|
|
|
var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
|
|
|
currentNode = addAfter(tokenList, removeFrom, wrapped);
|
|
|
if (after) addAfter(tokenList, currentNode, after);
|
|
|
if (removeCount > 1) {
|
|
|
// at least one Token object was removed, so we have to do some rematching
|
|
|
// this can only happen if the current pattern is greedy
|
|
|
/** @type {RematchOptions} */ var nestedRematch = {
|
|
|
cause: token + "," + j,
|
|
|
reach: reach
|
|
|
};
|
|
|
matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
|
|
|
// the reach might have been extended because of the rematching
|
|
|
if (rematch && nestedRematch.reach > rematch.reach) rematch.reach = nestedRematch.reach;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* @typedef LinkedListNode
|
|
|
* @property {T} value
|
|
|
* @property {LinkedListNode<T> | null} prev The previous node.
|
|
|
* @property {LinkedListNode<T> | null} next The next node.
|
|
|
* @template T
|
|
|
* @private
|
|
|
*/ /**
|
|
|
* @template T
|
|
|
* @private
|
|
|
*/ function LinkedList() {
|
|
|
/** @type {LinkedListNode<T>} */ var head = {
|
|
|
value: null,
|
|
|
prev: null,
|
|
|
next: null
|
|
|
};
|
|
|
/** @type {LinkedListNode<T>} */ var tail = {
|
|
|
value: null,
|
|
|
prev: head,
|
|
|
next: null
|
|
|
};
|
|
|
head.next = tail;
|
|
|
/** @type {LinkedListNode<T>} */ this.head = head;
|
|
|
/** @type {LinkedListNode<T>} */ this.tail = tail;
|
|
|
this.length = 0;
|
|
|
}
|
|
|
/**
|
|
|
* Adds a new node with the given value to the list.
|
|
|
*
|
|
|
* @param {LinkedList<T>} list
|
|
|
* @param {LinkedListNode<T>} node
|
|
|
* @param {T} value
|
|
|
* @returns {LinkedListNode<T>} The added node.
|
|
|
* @template T
|
|
|
*/ function addAfter(list, node, value) {
|
|
|
// assumes that node != list.tail && values.length >= 0
|
|
|
var next = node.next;
|
|
|
var newNode = {
|
|
|
value: value,
|
|
|
prev: node,
|
|
|
next: next
|
|
|
};
|
|
|
node.next = newNode;
|
|
|
next.prev = newNode;
|
|
|
list.length++;
|
|
|
return newNode;
|
|
|
}
|
|
|
/**
|
|
|
* Removes `count` nodes after the given node. The given node will not be removed.
|
|
|
*
|
|
|
* @param {LinkedList<T>} list
|
|
|
* @param {LinkedListNode<T>} node
|
|
|
* @param {number} count
|
|
|
* @template T
|
|
|
*/ function removeRange(list, node, count) {
|
|
|
var next = node.next;
|
|
|
for(var i = 0; i < count && next !== list.tail; i++)next = next.next;
|
|
|
node.next = next;
|
|
|
next.prev = node;
|
|
|
list.length -= i;
|
|
|
}
|
|
|
/**
|
|
|
* @param {LinkedList<T>} list
|
|
|
* @returns {T[]}
|
|
|
* @template T
|
|
|
*/ function toArray(list) {
|
|
|
var array = [];
|
|
|
var node = list.head.next;
|
|
|
while(node !== list.tail){
|
|
|
array.push(node.value);
|
|
|
node = node.next;
|
|
|
}
|
|
|
return array;
|
|
|
}
|
|
|
if (!_self1.document) {
|
|
|
if (!_self1.addEventListener) // in Node.js
|
|
|
return _;
|
|
|
if (!_.disableWorkerMessageHandler) // In worker
|
|
|
_self1.addEventListener("message", function(evt) {
|
|
|
var message = JSON.parse(evt.data);
|
|
|
var lang = message.language;
|
|
|
var code = message.code;
|
|
|
var immediateClose = message.immediateClose;
|
|
|
_self1.postMessage(_.highlight(code, _.languages[lang], lang));
|
|
|
if (immediateClose) _self1.close();
|
|
|
}, false);
|
|
|
return _;
|
|
|
}
|
|
|
// Get current script and highlight
|
|
|
var script = _.util.currentScript();
|
|
|
if (script) {
|
|
|
_.filename = script.src;
|
|
|
if (script.hasAttribute("data-manual")) _.manual = true;
|
|
|
}
|
|
|
function highlightAutomaticallyCallback() {
|
|
|
if (!_.manual) _.highlightAll();
|
|
|
}
|
|
|
if (!_.manual) {
|
|
|
// If the document state is "loading", then we'll use DOMContentLoaded.
|
|
|
// If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
|
|
|
// DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
|
|
|
// might take longer one animation frame to execute which can create a race condition where only some plugins have
|
|
|
// been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
|
|
|
// See https://github.com/PrismJS/prism/issues/2102
|
|
|
var readyState = document.readyState;
|
|
|
if (readyState === "loading" || readyState === "interactive" && script && script.defer) document.addEventListener("DOMContentLoaded", highlightAutomaticallyCallback);
|
|
|
else if (window.requestAnimationFrame) window.requestAnimationFrame(highlightAutomaticallyCallback);
|
|
|
else window.setTimeout(highlightAutomaticallyCallback, 16);
|
|
|
}
|
|
|
return _;
|
|
|
}(_self);
|
|
|
if (module.exports) module.exports = Prism;
|
|
|
// hack for components to work correctly in node.js
|
|
|
if (typeof global !== "undefined") global.Prism = Prism;
|
|
|
// some additional documentation/types
|
|
|
/**
|
|
|
* The expansion of a simple `RegExp` literal to support additional properties.
|
|
|
*
|
|
|
* @typedef GrammarToken
|
|
|
* @property {RegExp} pattern The regular expression of the token.
|
|
|
* @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
|
|
|
* behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
|
|
|
* @property {boolean} [greedy=false] Whether the token is greedy.
|
|
|
* @property {string|string[]} [alias] An optional alias or list of aliases.
|
|
|
* @property {Grammar} [inside] The nested grammar of this token.
|
|
|
*
|
|
|
* The `inside` grammar will be used to tokenize the text value of each token of this kind.
|
|
|
*
|
|
|
* This can be used to make nested and even recursive language definitions.
|
|
|
*
|
|
|
* Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
|
|
|
* each another.
|
|
|
* @global
|
|
|
* @public
|
|
|
*/ /**
|
|
|
* @typedef Grammar
|
|
|
* @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
|
|
|
* @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
|
|
|
* @global
|
|
|
* @public
|
|
|
*/ /**
|
|
|
* A function which will invoked after an element was successfully highlighted.
|
|
|
*
|
|
|
* @callback HighlightCallback
|
|
|
* @param {Element} element The element successfully highlighted.
|
|
|
* @returns {void}
|
|
|
* @global
|
|
|
* @public
|
|
|
*/ /**
|
|
|
* @callback HookCallback
|
|
|
* @param {Object<string, any>} env The environment variables of the hook.
|
|
|
* @returns {void}
|
|
|
* @global
|
|
|
* @public
|
|
|
*/
|
|
|
|
|
|
},{}],"lzIPu":[function(require,module,exports) {
|
|
|
Prism.languages.markup = {
|
|
|
"comment": {
|
|
|
pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
|
|
|
greedy: true
|
|
|
},
|
|
|
"prolog": {
|
|
|
pattern: /<\?[\s\S]+?\?>/,
|
|
|
greedy: true
|
|
|
},
|
|
|
"doctype": {
|
|
|
// https://www.w3.org/TR/xml/#NT-doctypedecl
|
|
|
pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
|
|
|
greedy: true,
|
|
|
inside: {
|
|
|
"internal-subset": {
|
|
|
pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
|
|
|
lookbehind: true,
|
|
|
greedy: true,
|
|
|
inside: null // see below
|
|
|
},
|
|
|
"string": {
|
|
|
pattern: /"[^"]*"|'[^']*'/,
|
|
|
greedy: true
|
|
|
},
|
|
|
"punctuation": /^<!|>$|[[\]]/,
|
|
|
"doctype-tag": /^DOCTYPE/i,
|
|
|
"name": /[^\s<>'"]+/
|
|
|
}
|
|
|
},
|
|
|
"cdata": {
|
|
|
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
|
|
greedy: true
|
|
|
},
|
|
|
"tag": {
|
|
|
pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
|
|
|
greedy: true,
|
|
|
inside: {
|
|
|
"tag": {
|
|
|
pattern: /^<\/?[^\s>\/]+/,
|
|
|
inside: {
|
|
|
"punctuation": /^<\/?/,
|
|
|
"namespace": /^[^\s>\/:]+:/
|
|
|
}
|
|
|
},
|
|
|
"special-attr": [],
|
|
|
"attr-value": {
|
|
|
pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
|
|
|
inside: {
|
|
|
"punctuation": [
|
|
|
{
|
|
|
pattern: /^=/,
|
|
|
alias: "attr-equals"
|
|
|
},
|
|
|
/"|'/
|
|
|
]
|
|
|
}
|
|
|
},
|
|
|
"punctuation": /\/?>/,
|
|
|
"attr-name": {
|
|
|
pattern: /[^\s>\/]+/,
|
|
|
inside: {
|
|
|
"namespace": /^[^\s>\/:]+:/
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
"entity": [
|
|
|
{
|
|
|
pattern: /&[\da-z]{1,8};/i,
|
|
|
alias: "named-entity"
|
|
|
},
|
|
|
/&#x?[\da-f]{1,8};/i
|
|
|
]
|
|
|
};
|
|
|
Prism.languages.markup["tag"].inside["attr-value"].inside["entity"] = Prism.languages.markup["entity"];
|
|
|
Prism.languages.markup["doctype"].inside["internal-subset"].inside = Prism.languages.markup;
|
|
|
// Plugin to make entity title show the real entity, idea by Roman Komarov
|
|
|
Prism.hooks.add("wrap", function(env) {
|
|
|
if (env.type === "entity") env.attributes["title"] = env.content.replace(/&/, "&");
|
|
|
});
|
|
|
Object.defineProperty(Prism.languages.markup.tag, "addInlined", {
|
|
|
/**
|
|
|
* Adds an inlined language to markup.
|
|
|
*
|
|
|
* An example of an inlined language is CSS with `<style>` tags.
|
|
|
*
|
|
|
* @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
|
|
|
* case insensitive.
|
|
|
* @param {string} lang The language key.
|
|
|
* @example
|
|
|
* addInlined('style', 'css');
|
|
|
*/ value: function addInlined(tagName, lang) {
|
|
|
var includedCdataInside = {};
|
|
|
includedCdataInside["language-" + lang] = {
|
|
|
pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
|
|
|
lookbehind: true,
|
|
|
inside: Prism.languages[lang]
|
|
|
};
|
|
|
includedCdataInside["cdata"] = /^<!\[CDATA\[|\]\]>$/i;
|
|
|
var inside = {
|
|
|
"included-cdata": {
|
|
|
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
|
|
inside: includedCdataInside
|
|
|
}
|
|
|
};
|
|
|
inside["language-" + lang] = {
|
|
|
pattern: /[\s\S]+/,
|
|
|
inside: Prism.languages[lang]
|
|
|
};
|
|
|
var def = {};
|
|
|
def[tagName] = {
|
|
|
pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function() {
|
|
|
return tagName;
|
|
|
}), "i"),
|
|
|
lookbehind: true,
|
|
|
greedy: true,
|
|
|
inside: inside
|
|
|
};
|
|
|
Prism.languages.insertBefore("markup", "cdata", def);
|
|
|
}
|
|
|
});
|
|
|
Object.defineProperty(Prism.languages.markup.tag, "addAttribute", {
|
|
|
/**
|
|
|
* Adds an pattern to highlight languages embedded in HTML attributes.
|
|
|
*
|
|
|
* An example of an inlined language is CSS with `style` attributes.
|
|
|
*
|
|
|
* @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
|
|
|
* case insensitive.
|
|
|
* @param {string} lang The language key.
|
|
|
* @example
|
|
|
* addAttribute('style', 'css');
|
|
|
*/ value: function(attrName, lang) {
|
|
|
Prism.languages.markup.tag.inside["special-attr"].push({
|
|
|
pattern: RegExp(/(^|["'\s])/.source + "(?:" + attrName + ")" + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source, "i"),
|
|
|
lookbehind: true,
|
|
|
inside: {
|
|
|
"attr-name": /^[^\s=]+/,
|
|
|
"attr-value": {
|
|
|
pattern: /=[\s\S]+/,
|
|
|
inside: {
|
|
|
"value": {
|
|
|
pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
|
|
|
lookbehind: true,
|
|
|
alias: [
|
|
|
lang,
|
|
|
"language-" + lang
|
|
|
],
|
|
|
inside: Prism.languages[lang]
|
|
|
},
|
|
|
"punctuation": [
|
|
|
{
|
|
|
pattern: /^=/,
|
|
|
alias: "attr-equals"
|
|
|
},
|
|
|
/"|'/
|
|
|
]
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
Prism.languages.html = Prism.languages.markup;
|
|
|
Prism.languages.mathml = Prism.languages.markup;
|
|
|
Prism.languages.svg = Prism.languages.markup;
|
|
|
Prism.languages.xml = Prism.languages.extend("markup", {});
|
|
|
Prism.languages.ssml = Prism.languages.xml;
|
|
|
Prism.languages.atom = Prism.languages.xml;
|
|
|
Prism.languages.rss = Prism.languages.xml;
|
|
|
|
|
|
},{}],"15tfx":[function(require,module,exports) {
|
|
|
(function(Prism) {
|
|
|
// Allow only one line break
|
|
|
var inner = /(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?![\r\n]))/.source;
|
|
|
/**
|
|
|
* This function is intended for the creation of the bold or italic pattern.
|
|
|
*
|
|
|
* This also adds a lookbehind group to the given pattern to ensure that the pattern is not backslash-escaped.
|
|
|
*
|
|
|
* _Note:_ Keep in mind that this adds a capturing group.
|
|
|
*
|
|
|
* @param {string} pattern
|
|
|
* @returns {RegExp}
|
|
|
*/ function createInline(pattern) {
|
|
|
pattern = pattern.replace(/<inner>/g, function() {
|
|
|
return inner;
|
|
|
});
|
|
|
return RegExp(/((?:^|[^\\])(?:\\{2})*)/.source + "(?:" + pattern + ")");
|
|
|
}
|
|
|
var tableCell = /(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source;
|
|
|
var tableRow = /\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|(?![\s\S]))/.source.replace(/__/g, function() {
|
|
|
return tableCell;
|
|
|
});
|
|
|
var tableLine = /\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;
|
|
|
Prism.languages.markdown = Prism.languages.extend("markup", {});
|
|
|
Prism.languages.insertBefore("markdown", "prolog", {
|
|
|
"front-matter-block": {
|
|
|
pattern: /(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,
|
|
|
lookbehind: true,
|
|
|
greedy: true,
|
|
|
inside: {
|
|
|
"punctuation": /^---|---$/,
|
|
|
"front-matter": {
|
|
|
pattern: /\S+(?:\s+\S+)*/,
|
|
|
alias: [
|
|
|
"yaml",
|
|
|
"language-yaml"
|
|
|
],
|
|
|
inside: Prism.languages.yaml
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
"blockquote": {
|
|
|
// > ...
|
|
|
pattern: /^>(?:[\t ]*>)*/m,
|
|
|
alias: "punctuation"
|
|
|
},
|
|
|
"table": {
|
|
|
pattern: RegExp("^" + tableRow + tableLine + "(?:" + tableRow + ")*", "m"),
|
|
|
inside: {
|
|
|
"table-data-rows": {
|
|
|
pattern: RegExp("^(" + tableRow + tableLine + ")(?:" + tableRow + ")*$"),
|
|
|
lookbehind: true,
|
|
|
inside: {
|
|
|
"table-data": {
|
|
|
pattern: RegExp(tableCell),
|
|
|
inside: Prism.languages.markdown
|
|
|
},
|
|
|
"punctuation": /\|/
|
|
|
}
|
|
|
},
|
|
|
"table-line": {
|
|
|
pattern: RegExp("^(" + tableRow + ")" + tableLine + "$"),
|
|
|
lookbehind: true,
|
|
|
inside: {
|
|
|
"punctuation": /\||:?-{3,}:?/
|
|
|
}
|
|
|
},
|
|
|
"table-header-row": {
|
|
|
pattern: RegExp("^" + tableRow + "$"),
|
|
|
inside: {
|
|
|
"table-header": {
|
|
|
pattern: RegExp(tableCell),
|
|
|
alias: "important",
|
|
|
inside: Prism.languages.markdown
|
|
|
},
|
|
|
"punctuation": /\|/
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
"code": [
|
|
|
{
|
|
|
// Prefixed by 4 spaces or 1 tab and preceded by an empty line
|
|
|
pattern: /((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,
|
|
|
lookbehind: true,
|
|
|
alias: "keyword"
|
|
|
},
|
|
|
{
|
|
|
// ```optional language
|
|
|
// code block
|
|
|
// ```
|
|
|
pattern: /^```[\s\S]*?^```$/m,
|
|
|
greedy: true,
|
|
|
inside: {
|
|
|
"code-block": {
|
|
|
pattern: /^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,
|
|
|
lookbehind: true
|
|
|
},
|
|
|
"code-language": {
|
|
|
pattern: /^(```).+/,
|
|
|
lookbehind: true
|
|
|
},
|
|
|
"punctuation": /```/
|
|
|
}
|
|
|
}
|
|
|
],
|
|
|
"title": [
|
|
|
{
|
|
|
// title 1
|
|
|
// =======
|
|
|
// title 2
|
|
|
// -------
|
|
|
pattern: /\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,
|
|
|
alias: "important",
|
|
|
inside: {
|
|
|
punctuation: /==+$|--+$/
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
// # title 1
|
|
|
// ###### title 6
|
|
|
pattern: /(^\s*)#.+/m,
|
|
|
lookbehind: true,
|
|
|
alias: "important",
|
|
|
inside: {
|
|
|
punctuation: /^#+|#+$/
|
|
|
}
|
|
|
}
|
|
|
],
|
|
|
"hr": {
|
|
|
// ***
|
|
|
// ---
|
|
|
// * * *
|
|
|
// -----------
|
|
|
pattern: /(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,
|
|
|
lookbehind: true,
|
|
|
alias: "punctuation"
|
|
|
},
|
|
|
"list": {
|
|
|
// * item
|
|
|
// + item
|
|
|
// - item
|
|
|
// 1. item
|
|
|
pattern: /(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,
|
|
|
lookbehind: true,
|
|
|
alias: "punctuation"
|
|
|
},
|
|
|
"url-reference": {
|
|
|
// [id]: http://example.com "Optional title"
|
|
|
// [id]: http://example.com 'Optional title'
|
|
|
// [id]: http://example.com (Optional title)
|
|
|
// [id]: <http://example.com> "Optional title"
|
|
|
pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,
|
|
|
inside: {
|
|
|
"variable": {
|
|
|
pattern: /^(!?\[)[^\]]+/,
|
|
|
lookbehind: true
|
|
|
},
|
|
|
"string": /(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,
|
|
|
"punctuation": /^[\[\]!:]|[<>]/
|
|
|
},
|
|
|
alias: "url"
|
|
|
},
|
|
|
"bold": {
|
|
|
// **strong**
|
|
|
// __strong__
|
|
|
// allow one nested instance of italic text using the same delimiter
|
|
|
pattern: createInline(/\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\b|\*\*(?:(?!\*)<inner>|\*(?:(?!\*)<inner>)+\*)+\*\*/.source),
|
|
|
lookbehind: true,
|
|
|
greedy: true,
|
|
|
inside: {
|
|
|
"content": {
|
|
|
pattern: /(^..)[\s\S]+(?=..$)/,
|
|
|
lookbehind: true,
|
|
|
inside: {} // see below
|
|
|
},
|
|
|
"punctuation": /\*\*|__/
|
|
|
}
|
|
|
},
|
|
|
"italic": {
|
|
|
// *em*
|
|
|
// _em_
|
|
|
// allow one nested instance of bold text using the same delimiter
|
|
|
pattern: createInline(/\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\b|\*(?:(?!\*)<inner>|\*\*(?:(?!\*)<inner>)+\*\*)+\*/.source),
|
|
|
lookbehind: true,
|
|
|
greedy: true,
|
|
|
inside: {
|
|
|
"content": {
|
|
|
pattern: /(^.)[\s\S]+(?=.$)/,
|
|
|
lookbehind: true,
|
|
|
inside: {} // see below
|
|
|
},
|
|
|
"punctuation": /[*_]/
|
|
|
}
|
|
|
},
|
|
|
"strike": {
|
|
|
// ~~strike through~~
|
|
|
// ~strike~
|
|
|
// eslint-disable-next-line regexp/strict
|
|
|
pattern: createInline(/(~~?)(?:(?!~)<inner>)+\2/.source),
|
|
|
lookbehind: true,
|
|
|
greedy: true,
|
|
|
inside: {
|
|
|
"content": {
|
|
|
pattern: /(^~~?)[\s\S]+(?=\1$)/,
|
|
|
lookbehind: true,
|
|
|
inside: {} // see below
|
|
|
},
|
|
|
"punctuation": /~~?/
|
|
|
}
|
|
|
},
|
|
|
"code-snippet": {
|
|
|
// `code`
|
|
|
// ``code``
|
|
|
pattern: /(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,
|
|
|
lookbehind: true,
|
|
|
greedy: true,
|
|
|
alias: [
|
|
|
"code",
|
|
|
"keyword"
|
|
|
]
|
|
|
},
|
|
|
"url": {
|
|
|
// [example](http://example.com "Optional title")
|
|
|
// [example][id]
|
|
|
// [example] [id]
|
|
|
pattern: createInline(/!?\[(?:(?!\])<inner>)+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)|[ \t]?\[(?:(?!\])<inner>)+\])/.source),
|
|
|
lookbehind: true,
|
|
|
greedy: true,
|
|
|
inside: {
|
|
|
"operator": /^!/,
|
|
|
"content": {
|
|
|
pattern: /(^\[)[^\]]+(?=\])/,
|
|
|
lookbehind: true,
|
|
|
inside: {} // see below
|
|
|
},
|
|
|
"variable": {
|
|
|
pattern: /(^\][ \t]?\[)[^\]]+(?=\]$)/,
|
|
|
lookbehind: true
|
|
|
},
|
|
|
"url": {
|
|
|
pattern: /(^\]\()[^\s)]+/,
|
|
|
lookbehind: true
|
|
|
},
|
|
|
"string": {
|
|
|
pattern: /(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,
|
|
|
lookbehind: true
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
[
|
|
|
"url",
|
|
|
"bold",
|
|
|
"italic",
|
|
|
"strike"
|
|
|
].forEach(function(token) {
|
|
|
[
|
|
|
"url",
|
|
|
"bold",
|
|
|
"italic",
|
|
|
"strike",
|
|
|
"code-snippet"
|
|
|
].forEach(function(inside) {
|
|
|
if (token !== inside) Prism.languages.markdown[token].inside.content.inside[inside] = Prism.languages.markdown[inside];
|
|
|
});
|
|
|
});
|
|
|
Prism.hooks.add("after-tokenize", function(env) {
|
|
|
if (env.language !== "markdown" && env.language !== "md") return;
|
|
|
function walkTokens(tokens) {
|
|
|
if (!tokens || typeof tokens === "string") return;
|
|
|
for(var i = 0, l = tokens.length; i < l; i++){
|
|
|
var token = tokens[i];
|
|
|
if (token.type !== "code") {
|
|
|
walkTokens(token.content);
|
|
|
continue;
|
|
|
}
|
|
|
/*
|
|
|
* Add the correct `language-xxxx` class to this code block. Keep in mind that the `code-language` token
|
|
|
* is optional. But the grammar is defined so that there is only one case we have to handle:
|
|
|
*
|
|
|
* token.content = [
|
|
|
* <span class="punctuation">```</span>,
|
|
|
* <span class="code-language">xxxx</span>,
|
|
|
* '\n', // exactly one new lines (\r or \n or \r\n)
|
|
|
* <span class="code-block">...</span>,
|
|
|
* '\n', // exactly one new lines again
|
|
|
* <span class="punctuation">```</span>
|
|
|
* ];
|
|
|
*/ var codeLang = token.content[1];
|
|
|
var codeBlock = token.content[3];
|
|
|
if (codeLang && codeBlock && codeLang.type === "code-language" && codeBlock.type === "code-block" && typeof codeLang.content === "string") {
|
|
|
// this might be a language that Prism does not support
|
|
|
// do some replacements to support C++, C#, and F#
|
|
|
var lang = codeLang.content.replace(/\b#/g, "sharp").replace(/\b\+\+/g, "pp");
|
|
|
// only use the first word
|
|
|
lang = (/[a-z][\w-]*/i.exec(lang) || [
|
|
|
""
|
|
|
])[0].toLowerCase();
|
|
|
var alias = "language-" + lang;
|
|
|
// add alias
|
|
|
if (!codeBlock.alias) codeBlock.alias = [
|
|
|
alias
|
|
|
];
|
|
|
else if (typeof codeBlock.alias === "string") codeBlock.alias = [
|
|
|
codeBlock.alias,
|
|
|
alias
|
|
|
];
|
|
|
else codeBlock.alias.push(alias);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
walkTokens(env.tokens);
|
|
|
});
|
|
|
Prism.hooks.add("wrap", function(env) {
|
|
|
if (env.type !== "code-block") return;
|
|
|
var codeLang = "";
|
|
|
for(var i = 0, l = env.classes.length; i < l; i++){
|
|
|
var cls = env.classes[i];
|
|
|
var match = /language-(.+)/.exec(cls);
|
|
|
if (match) {
|
|
|
codeLang = match[1];
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
var grammar = Prism.languages[codeLang];
|
|
|
if (!grammar) {
|
|
|
if (codeLang && codeLang !== "none" && Prism.plugins.autoloader) {
|
|
|
var id = "md-" + new Date().valueOf() + "-" + Math.floor(Math.random() * 1e16);
|
|
|
env.attributes["id"] = id;
|
|
|
Prism.plugins.autoloader.loadLanguages(codeLang, function() {
|
|
|
var ele = document.getElementById(id);
|
|
|
if (ele) ele.innerHTML = Prism.highlight(ele.textContent, Prism.languages[codeLang], codeLang);
|
|
|
});
|
|
|
}
|
|
|
} else env.content = Prism.highlight(textContent(env.content), grammar, codeLang);
|
|
|
});
|
|
|
var tagPattern = RegExp(Prism.languages.markup.tag.pattern.source, "gi");
|
|
|
/**
|
|
|
* A list of known entity names.
|
|
|
*
|
|
|
* This will always be incomplete to save space. The current list is the one used by lowdash's unescape function.
|
|
|
*
|
|
|
* @see {@link https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/unescape.js#L2}
|
|
|
*/ var KNOWN_ENTITY_NAMES = {
|
|
|
"amp": "&",
|
|
|
"lt": "<",
|
|
|
"gt": ">",
|
|
|
"quot": '"'
|
|
|
};
|
|
|
// IE 11 doesn't support `String.fromCodePoint`
|
|
|
var fromCodePoint = String.fromCodePoint || String.fromCharCode;
|
|
|
/**
|
|
|
* Returns the text content of a given HTML source code string.
|
|
|
*
|
|
|
* @param {string} html
|
|
|
* @returns {string}
|
|
|
*/ function textContent(html) {
|
|
|
// remove all tags
|
|
|
var text = html.replace(tagPattern, "");
|
|
|
// decode known entities
|
|
|
text = text.replace(/&(\w{1,8}|#x?[\da-f]{1,8});/gi, function(m, code) {
|
|
|
code = code.toLowerCase();
|
|
|
if (code[0] === "#") {
|
|
|
var value;
|
|
|
if (code[1] === "x") value = parseInt(code.slice(2), 16);
|
|
|
else value = Number(code.slice(1));
|
|
|
return fromCodePoint(value);
|
|
|
} else {
|
|
|
var known = KNOWN_ENTITY_NAMES[code];
|
|
|
if (known) return known;
|
|
|
// unable to decode
|
|
|
return m;
|
|
|
}
|
|
|
});
|
|
|
return text;
|
|
|
}
|
|
|
Prism.languages.md = Prism.languages.markdown;
|
|
|
})(Prism);
|
|
|
|
|
|
},{}],"9GRdG":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
var _animeEsJs = require("animejs/lib/anime.es.js");
|
|
|
var _animeEsJsDefault = parcelHelpers.interopDefault(_animeEsJs);
|
|
|
const notifcation = document.getElementById("notifications");
|
|
|
const notify = document.getElementById("notify-message");
|
|
|
const messageText = document.getElementById("message-text");
|
|
|
const notifyText = document.getElementById("notify-text");
|
|
|
const notifyProgress = document.getElementById("notify-progress");
|
|
|
const iconGood = document.getElementById("notify-good");
|
|
|
const iconLame = document.getElementById("notify-lame");
|
|
|
const iconWorking = document.getElementById("notify-working");
|
|
|
class Notfications {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
alert(text, status) {
|
|
|
iconWorking.style.display = "none";
|
|
|
iconGood.style.display = "none";
|
|
|
iconLame.style.display = "none";
|
|
|
var color = "";
|
|
|
if (status !== null) {
|
|
|
(0, _animeEsJsDefault.default)({
|
|
|
targets: notifyProgress,
|
|
|
opacity: 0,
|
|
|
easing: "easeInOutQuint",
|
|
|
duration: 500
|
|
|
});
|
|
|
if (status) {
|
|
|
color = "#32cd32";
|
|
|
iconWorking.style.display = "none";
|
|
|
iconGood.style.display = "block";
|
|
|
} else {
|
|
|
color = "#F64747";
|
|
|
iconWorking.style.display = "none";
|
|
|
iconLame.style.display = "block";
|
|
|
}
|
|
|
} else {
|
|
|
color = "#200317";
|
|
|
iconWorking.style.display = "block";
|
|
|
(0, _animeEsJsDefault.default)({
|
|
|
targets: notifyProgress,
|
|
|
opacity: 1,
|
|
|
easing: "easeInOutQuint",
|
|
|
duration: 500
|
|
|
});
|
|
|
}
|
|
|
messageText.innerHTML = text;
|
|
|
(0, _animeEsJsDefault.default)({
|
|
|
targets: notifcation,
|
|
|
marginTop: "-10",
|
|
|
easing: "easeInOutQuint",
|
|
|
duration: 10,
|
|
|
complete: ()=>{
|
|
|
(0, _animeEsJsDefault.default)({
|
|
|
targets: notify,
|
|
|
rotateX: "0",
|
|
|
easing: "easeInOutQuint",
|
|
|
duration: 700
|
|
|
});
|
|
|
(0, _animeEsJsDefault.default)({
|
|
|
targets: notifyText,
|
|
|
backgroundColor: color,
|
|
|
easing: "easeInOutQuint",
|
|
|
duration: 700,
|
|
|
complete: ()=>{
|
|
|
setTimeout(()=>{
|
|
|
if (status !== null) (0, _animeEsJsDefault.default)({
|
|
|
targets: notify,
|
|
|
rotateX: "-120",
|
|
|
easing: "easeInOutQuint",
|
|
|
duration: 700,
|
|
|
complete: ()=>{
|
|
|
(0, _animeEsJsDefault.default)({
|
|
|
targets: notifcation,
|
|
|
marginTop: "-55",
|
|
|
easing: "easeInOutQuint",
|
|
|
delay: 700,
|
|
|
duration: 50
|
|
|
}); //notifcation.style.display = 'none';
|
|
|
}
|
|
|
});
|
|
|
}, 1000);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
exports.default = Notfications;
|
|
|
|
|
|
},{"animejs/lib/anime.es.js":"jokr5","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"jokr5":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
/*
|
|
|
* anime.js v3.2.1
|
|
|
* (c) 2020 Julian Garnier
|
|
|
* Released under the MIT license
|
|
|
* animejs.com
|
|
|
*/ // Defaults
|
|
|
var defaultInstanceSettings = {
|
|
|
update: null,
|
|
|
begin: null,
|
|
|
loopBegin: null,
|
|
|
changeBegin: null,
|
|
|
change: null,
|
|
|
changeComplete: null,
|
|
|
loopComplete: null,
|
|
|
complete: null,
|
|
|
loop: 1,
|
|
|
direction: "normal",
|
|
|
autoplay: true,
|
|
|
timelineOffset: 0
|
|
|
};
|
|
|
var defaultTweenSettings = {
|
|
|
duration: 1000,
|
|
|
delay: 0,
|
|
|
endDelay: 0,
|
|
|
easing: "easeOutElastic(1, .5)",
|
|
|
round: 0
|
|
|
};
|
|
|
var validTransforms = [
|
|
|
"translateX",
|
|
|
"translateY",
|
|
|
"translateZ",
|
|
|
"rotate",
|
|
|
"rotateX",
|
|
|
"rotateY",
|
|
|
"rotateZ",
|
|
|
"scale",
|
|
|
"scaleX",
|
|
|
"scaleY",
|
|
|
"scaleZ",
|
|
|
"skew",
|
|
|
"skewX",
|
|
|
"skewY",
|
|
|
"perspective",
|
|
|
"matrix",
|
|
|
"matrix3d"
|
|
|
];
|
|
|
// Caching
|
|
|
var cache = {
|
|
|
CSS: {},
|
|
|
springs: {}
|
|
|
};
|
|
|
// Utils
|
|
|
function minMax(val, min, max) {
|
|
|
return Math.min(Math.max(val, min), max);
|
|
|
}
|
|
|
function stringContains(str, text) {
|
|
|
return str.indexOf(text) > -1;
|
|
|
}
|
|
|
function applyArguments(func, args) {
|
|
|
return func.apply(null, args);
|
|
|
}
|
|
|
var is = {
|
|
|
arr: function(a) {
|
|
|
return Array.isArray(a);
|
|
|
},
|
|
|
obj: function(a) {
|
|
|
return stringContains(Object.prototype.toString.call(a), "Object");
|
|
|
},
|
|
|
pth: function(a) {
|
|
|
return is.obj(a) && a.hasOwnProperty("totalLength");
|
|
|
},
|
|
|
svg: function(a) {
|
|
|
return a instanceof SVGElement;
|
|
|
},
|
|
|
inp: function(a) {
|
|
|
return a instanceof HTMLInputElement;
|
|
|
},
|
|
|
dom: function(a) {
|
|
|
return a.nodeType || is.svg(a);
|
|
|
},
|
|
|
str: function(a) {
|
|
|
return typeof a === "string";
|
|
|
},
|
|
|
fnc: function(a) {
|
|
|
return typeof a === "function";
|
|
|
},
|
|
|
und: function(a) {
|
|
|
return typeof a === "undefined";
|
|
|
},
|
|
|
nil: function(a) {
|
|
|
return is.und(a) || a === null;
|
|
|
},
|
|
|
hex: function(a) {
|
|
|
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a);
|
|
|
},
|
|
|
rgb: function(a) {
|
|
|
return /^rgb/.test(a);
|
|
|
},
|
|
|
hsl: function(a) {
|
|
|
return /^hsl/.test(a);
|
|
|
},
|
|
|
col: function(a) {
|
|
|
return is.hex(a) || is.rgb(a) || is.hsl(a);
|
|
|
},
|
|
|
key: function(a) {
|
|
|
return !defaultInstanceSettings.hasOwnProperty(a) && !defaultTweenSettings.hasOwnProperty(a) && a !== "targets" && a !== "keyframes";
|
|
|
}
|
|
|
};
|
|
|
// Easings
|
|
|
function parseEasingParameters(string) {
|
|
|
var match = /\(([^)]+)\)/.exec(string);
|
|
|
return match ? match[1].split(",").map(function(p) {
|
|
|
return parseFloat(p);
|
|
|
}) : [];
|
|
|
}
|
|
|
// Spring solver inspired by Webkit Copyright © 2016 Apple Inc. All rights reserved. https://webkit.org/demos/spring/spring.js
|
|
|
function spring(string, duration1) {
|
|
|
var params = parseEasingParameters(string);
|
|
|
var mass = minMax(is.und(params[0]) ? 1 : params[0], .1, 100);
|
|
|
var stiffness = minMax(is.und(params[1]) ? 100 : params[1], .1, 100);
|
|
|
var damping = minMax(is.und(params[2]) ? 10 : params[2], .1, 100);
|
|
|
var velocity = minMax(is.und(params[3]) ? 0 : params[3], .1, 100);
|
|
|
var w0 = Math.sqrt(stiffness / mass);
|
|
|
var zeta = damping / (2 * Math.sqrt(stiffness * mass));
|
|
|
var wd = zeta < 1 ? w0 * Math.sqrt(1 - zeta * zeta) : 0;
|
|
|
var a = 1;
|
|
|
var b = zeta < 1 ? (zeta * w0 + -velocity) / wd : -velocity + w0;
|
|
|
function solver(t) {
|
|
|
var progress = duration1 ? duration1 * t / 1000 : t;
|
|
|
if (zeta < 1) progress = Math.exp(-progress * zeta * w0) * (a * Math.cos(wd * progress) + b * Math.sin(wd * progress));
|
|
|
else progress = (a + b * progress) * Math.exp(-progress * w0);
|
|
|
if (t === 0 || t === 1) return t;
|
|
|
return 1 - progress;
|
|
|
}
|
|
|
function getDuration() {
|
|
|
var cached = cache.springs[string];
|
|
|
if (cached) return cached;
|
|
|
var frame = 1 / 6;
|
|
|
var elapsed = 0;
|
|
|
var rest = 0;
|
|
|
while(true){
|
|
|
elapsed += frame;
|
|
|
if (solver(elapsed) === 1) {
|
|
|
rest++;
|
|
|
if (rest >= 16) break;
|
|
|
} else rest = 0;
|
|
|
}
|
|
|
var duration = elapsed * frame * 1000;
|
|
|
cache.springs[string] = duration;
|
|
|
return duration;
|
|
|
}
|
|
|
return duration1 ? solver : getDuration;
|
|
|
}
|
|
|
// Basic steps easing implementation https://developer.mozilla.org/fr/docs/Web/CSS/transition-timing-function
|
|
|
function steps(steps1) {
|
|
|
if (steps1 === void 0) steps1 = 10;
|
|
|
return function(t) {
|
|
|
return Math.ceil(minMax(t, 0.000001, 1) * steps1) * (1 / steps1);
|
|
|
};
|
|
|
}
|
|
|
// BezierEasing https://github.com/gre/bezier-easing
|
|
|
var bezier = function() {
|
|
|
var kSplineTableSize = 11;
|
|
|
var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
|
|
|
function A(aA1, aA2) {
|
|
|
return 1.0 - 3.0 * aA2 + 3.0 * aA1;
|
|
|
}
|
|
|
function B(aA1, aA2) {
|
|
|
return 3.0 * aA2 - 6.0 * aA1;
|
|
|
}
|
|
|
function C(aA1) {
|
|
|
return 3.0 * aA1;
|
|
|
}
|
|
|
function calcBezier(aT, aA1, aA2) {
|
|
|
return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
|
|
|
}
|
|
|
function getSlope(aT, aA1, aA2) {
|
|
|
return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
|
|
|
}
|
|
|
function binarySubdivide(aX, aA, aB, mX1, mX2) {
|
|
|
var currentX, currentT, i = 0;
|
|
|
do {
|
|
|
currentT = aA + (aB - aA) / 2.0;
|
|
|
currentX = calcBezier(currentT, mX1, mX2) - aX;
|
|
|
if (currentX > 0.0) aB = currentT;
|
|
|
else aA = currentT;
|
|
|
}while (Math.abs(currentX) > 0.0000001 && ++i < 10);
|
|
|
return currentT;
|
|
|
}
|
|
|
function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
|
|
|
for(var i = 0; i < 4; ++i){
|
|
|
var currentSlope = getSlope(aGuessT, mX1, mX2);
|
|
|
if (currentSlope === 0.0) return aGuessT;
|
|
|
var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
|
|
|
aGuessT -= currentX / currentSlope;
|
|
|
}
|
|
|
return aGuessT;
|
|
|
}
|
|
|
function bezier1(mX1, mY1, mX2, mY2) {
|
|
|
if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) return;
|
|
|
var sampleValues = new Float32Array(kSplineTableSize);
|
|
|
if (mX1 !== mY1 || mX2 !== mY2) for(var i = 0; i < kSplineTableSize; ++i)sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
|
|
|
function getTForX(aX) {
|
|
|
var intervalStart = 0;
|
|
|
var currentSample = 1;
|
|
|
var lastSample = kSplineTableSize - 1;
|
|
|
for(; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample)intervalStart += kSampleStepSize;
|
|
|
--currentSample;
|
|
|
var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
|
|
|
var guessForT = intervalStart + dist * kSampleStepSize;
|
|
|
var initialSlope = getSlope(guessForT, mX1, mX2);
|
|
|
if (initialSlope >= 0.001) return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
|
|
|
else if (initialSlope === 0.0) return guessForT;
|
|
|
else return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
|
|
|
}
|
|
|
return function(x) {
|
|
|
if (mX1 === mY1 && mX2 === mY2) return x;
|
|
|
if (x === 0 || x === 1) return x;
|
|
|
return calcBezier(getTForX(x), mY1, mY2);
|
|
|
};
|
|
|
}
|
|
|
return bezier1;
|
|
|
}();
|
|
|
var penner = function() {
|
|
|
// Based on jQuery UI's implemenation of easing equations from Robert Penner (http://www.robertpenner.com/easing)
|
|
|
var eases = {
|
|
|
linear: function() {
|
|
|
return function(t) {
|
|
|
return t;
|
|
|
};
|
|
|
}
|
|
|
};
|
|
|
var functionEasings = {
|
|
|
Sine: function() {
|
|
|
return function(t) {
|
|
|
return 1 - Math.cos(t * Math.PI / 2);
|
|
|
};
|
|
|
},
|
|
|
Circ: function() {
|
|
|
return function(t) {
|
|
|
return 1 - Math.sqrt(1 - t * t);
|
|
|
};
|
|
|
},
|
|
|
Back: function() {
|
|
|
return function(t) {
|
|
|
return t * t * (3 * t - 2);
|
|
|
};
|
|
|
},
|
|
|
Bounce: function() {
|
|
|
return function(t) {
|
|
|
var pow2, b = 4;
|
|
|
while(t < ((pow2 = Math.pow(2, --b)) - 1) / 11);
|
|
|
return 1 / Math.pow(4, 3 - b) - 7.5625 * Math.pow((pow2 * 3 - 2) / 22 - t, 2);
|
|
|
};
|
|
|
},
|
|
|
Elastic: function(amplitude, period) {
|
|
|
if (amplitude === void 0) amplitude = 1;
|
|
|
if (period === void 0) period = .5;
|
|
|
var a = minMax(amplitude, 1, 10);
|
|
|
var p = minMax(period, .1, 2);
|
|
|
return function(t) {
|
|
|
return t === 0 || t === 1 ? t : -a * Math.pow(2, 10 * (t - 1)) * Math.sin((t - 1 - p / (Math.PI * 2) * Math.asin(1 / a)) * (Math.PI * 2) / p);
|
|
|
};
|
|
|
}
|
|
|
};
|
|
|
var baseEasings = [
|
|
|
"Quad",
|
|
|
"Cubic",
|
|
|
"Quart",
|
|
|
"Quint",
|
|
|
"Expo"
|
|
|
];
|
|
|
baseEasings.forEach(function(name, i) {
|
|
|
functionEasings[name] = function() {
|
|
|
return function(t) {
|
|
|
return Math.pow(t, i + 2);
|
|
|
};
|
|
|
};
|
|
|
});
|
|
|
Object.keys(functionEasings).forEach(function(name) {
|
|
|
var easeIn = functionEasings[name];
|
|
|
eases["easeIn" + name] = easeIn;
|
|
|
eases["easeOut" + name] = function(a, b) {
|
|
|
return function(t) {
|
|
|
return 1 - easeIn(a, b)(1 - t);
|
|
|
};
|
|
|
};
|
|
|
eases["easeInOut" + name] = function(a, b) {
|
|
|
return function(t) {
|
|
|
return t < 0.5 ? easeIn(a, b)(t * 2) / 2 : 1 - easeIn(a, b)(t * -2 + 2) / 2;
|
|
|
};
|
|
|
};
|
|
|
eases["easeOutIn" + name] = function(a, b) {
|
|
|
return function(t) {
|
|
|
return t < 0.5 ? (1 - easeIn(a, b)(1 - t * 2)) / 2 : (easeIn(a, b)(t * 2 - 1) + 1) / 2;
|
|
|
};
|
|
|
};
|
|
|
});
|
|
|
return eases;
|
|
|
}();
|
|
|
function parseEasings(easing, duration) {
|
|
|
if (is.fnc(easing)) return easing;
|
|
|
var name = easing.split("(")[0];
|
|
|
var ease = penner[name];
|
|
|
var args = parseEasingParameters(easing);
|
|
|
switch(name){
|
|
|
case "spring":
|
|
|
return spring(easing, duration);
|
|
|
case "cubicBezier":
|
|
|
return applyArguments(bezier, args);
|
|
|
case "steps":
|
|
|
return applyArguments(steps, args);
|
|
|
default:
|
|
|
return applyArguments(ease, args);
|
|
|
}
|
|
|
}
|
|
|
// Strings
|
|
|
function selectString(str) {
|
|
|
try {
|
|
|
var nodes = document.querySelectorAll(str);
|
|
|
return nodes;
|
|
|
} catch (e) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
// Arrays
|
|
|
function filterArray(arr, callback) {
|
|
|
var len = arr.length;
|
|
|
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
|
|
|
var result = [];
|
|
|
for(var i = 0; i < len; i++)if (i in arr) {
|
|
|
var val = arr[i];
|
|
|
if (callback.call(thisArg, val, i, arr)) result.push(val);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
function flattenArray(arr) {
|
|
|
return arr.reduce(function(a, b) {
|
|
|
return a.concat(is.arr(b) ? flattenArray(b) : b);
|
|
|
}, []);
|
|
|
}
|
|
|
function toArray(o) {
|
|
|
if (is.arr(o)) return o;
|
|
|
if (is.str(o)) o = selectString(o) || o;
|
|
|
if (o instanceof NodeList || o instanceof HTMLCollection) return [].slice.call(o);
|
|
|
return [
|
|
|
o
|
|
|
];
|
|
|
}
|
|
|
function arrayContains(arr, val) {
|
|
|
return arr.some(function(a) {
|
|
|
return a === val;
|
|
|
});
|
|
|
}
|
|
|
// Objects
|
|
|
function cloneObject(o) {
|
|
|
var clone = {};
|
|
|
for(var p in o)clone[p] = o[p];
|
|
|
return clone;
|
|
|
}
|
|
|
function replaceObjectProps(o1, o2) {
|
|
|
var o = cloneObject(o1);
|
|
|
for(var p in o1)o[p] = o2.hasOwnProperty(p) ? o2[p] : o1[p];
|
|
|
return o;
|
|
|
}
|
|
|
function mergeObjects(o1, o2) {
|
|
|
var o = cloneObject(o1);
|
|
|
for(var p in o2)o[p] = is.und(o1[p]) ? o2[p] : o1[p];
|
|
|
return o;
|
|
|
}
|
|
|
// Colors
|
|
|
function rgbToRgba(rgbValue) {
|
|
|
var rgb = /rgb\((\d+,\s*[\d]+,\s*[\d]+)\)/g.exec(rgbValue);
|
|
|
return rgb ? "rgba(" + rgb[1] + ",1)" : rgbValue;
|
|
|
}
|
|
|
function hexToRgba(hexValue) {
|
|
|
var rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
|
var hex = hexValue.replace(rgx, function(m, r, g, b) {
|
|
|
return r + r + g + g + b + b;
|
|
|
});
|
|
|
var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
|
var r1 = parseInt(rgb[1], 16);
|
|
|
var g1 = parseInt(rgb[2], 16);
|
|
|
var b1 = parseInt(rgb[3], 16);
|
|
|
return "rgba(" + r1 + "," + g1 + "," + b1 + ",1)";
|
|
|
}
|
|
|
function hslToRgba(hslValue) {
|
|
|
var hsl = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(hslValue) || /hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)/g.exec(hslValue);
|
|
|
var h = parseInt(hsl[1], 10) / 360;
|
|
|
var s = parseInt(hsl[2], 10) / 100;
|
|
|
var l = parseInt(hsl[3], 10) / 100;
|
|
|
var a = hsl[4] || 1;
|
|
|
function hue2rgb(p, q, t) {
|
|
|
if (t < 0) t += 1;
|
|
|
if (t > 1) t -= 1;
|
|
|
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
|
if (t < 0.5) return q;
|
|
|
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
|
return p;
|
|
|
}
|
|
|
var r, g, b;
|
|
|
if (s == 0) r = g = b = l;
|
|
|
else {
|
|
|
var q1 = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
|
var p1 = 2 * l - q1;
|
|
|
r = hue2rgb(p1, q1, h + 1 / 3);
|
|
|
g = hue2rgb(p1, q1, h);
|
|
|
b = hue2rgb(p1, q1, h - 1 / 3);
|
|
|
}
|
|
|
return "rgba(" + r * 255 + "," + g * 255 + "," + b * 255 + "," + a + ")";
|
|
|
}
|
|
|
function colorToRgb(val) {
|
|
|
if (is.rgb(val)) return rgbToRgba(val);
|
|
|
if (is.hex(val)) return hexToRgba(val);
|
|
|
if (is.hsl(val)) return hslToRgba(val);
|
|
|
}
|
|
|
// Units
|
|
|
function getUnit(val) {
|
|
|
var split = /[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?(%|px|pt|em|rem|in|cm|mm|ex|ch|pc|vw|vh|vmin|vmax|deg|rad|turn)?$/.exec(val);
|
|
|
if (split) return split[1];
|
|
|
}
|
|
|
function getTransformUnit(propName) {
|
|
|
if (stringContains(propName, "translate") || propName === "perspective") return "px";
|
|
|
if (stringContains(propName, "rotate") || stringContains(propName, "skew")) return "deg";
|
|
|
}
|
|
|
// Values
|
|
|
function getFunctionValue(val, animatable) {
|
|
|
if (!is.fnc(val)) return val;
|
|
|
return val(animatable.target, animatable.id, animatable.total);
|
|
|
}
|
|
|
function getAttribute(el, prop) {
|
|
|
return el.getAttribute(prop);
|
|
|
}
|
|
|
function convertPxToUnit(el, value, unit) {
|
|
|
var valueUnit = getUnit(value);
|
|
|
if (arrayContains([
|
|
|
unit,
|
|
|
"deg",
|
|
|
"rad",
|
|
|
"turn"
|
|
|
], valueUnit)) return value;
|
|
|
var cached = cache.CSS[value + unit];
|
|
|
if (!is.und(cached)) return cached;
|
|
|
var baseline = 100;
|
|
|
var tempEl = document.createElement(el.tagName);
|
|
|
var parentEl = el.parentNode && el.parentNode !== document ? el.parentNode : document.body;
|
|
|
parentEl.appendChild(tempEl);
|
|
|
tempEl.style.position = "absolute";
|
|
|
tempEl.style.width = baseline + unit;
|
|
|
var factor = baseline / tempEl.offsetWidth;
|
|
|
parentEl.removeChild(tempEl);
|
|
|
var convertedUnit = factor * parseFloat(value);
|
|
|
cache.CSS[value + unit] = convertedUnit;
|
|
|
return convertedUnit;
|
|
|
}
|
|
|
function getCSSValue(el, prop, unit) {
|
|
|
if (prop in el.style) {
|
|
|
var uppercasePropName = prop.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
|
var value = el.style[prop] || getComputedStyle(el).getPropertyValue(uppercasePropName) || "0";
|
|
|
return unit ? convertPxToUnit(el, value, unit) : value;
|
|
|
}
|
|
|
}
|
|
|
function getAnimationType(el, prop) {
|
|
|
if (is.dom(el) && !is.inp(el) && (!is.nil(getAttribute(el, prop)) || is.svg(el) && el[prop])) return "attribute";
|
|
|
if (is.dom(el) && arrayContains(validTransforms, prop)) return "transform";
|
|
|
if (is.dom(el) && prop !== "transform" && getCSSValue(el, prop)) return "css";
|
|
|
if (el[prop] != null) return "object";
|
|
|
}
|
|
|
function getElementTransforms(el) {
|
|
|
if (!is.dom(el)) return;
|
|
|
var str = el.style.transform || "";
|
|
|
var reg = /(\w+)\(([^)]*)\)/g;
|
|
|
var transforms = new Map();
|
|
|
var m;
|
|
|
while(m = reg.exec(str))transforms.set(m[1], m[2]);
|
|
|
return transforms;
|
|
|
}
|
|
|
function getTransformValue(el, propName, animatable, unit) {
|
|
|
var defaultVal = stringContains(propName, "scale") ? 1 : 0 + getTransformUnit(propName);
|
|
|
var value = getElementTransforms(el).get(propName) || defaultVal;
|
|
|
if (animatable) {
|
|
|
animatable.transforms.list.set(propName, value);
|
|
|
animatable.transforms["last"] = propName;
|
|
|
}
|
|
|
return unit ? convertPxToUnit(el, value, unit) : value;
|
|
|
}
|
|
|
function getOriginalTargetValue(target, propName, unit, animatable) {
|
|
|
switch(getAnimationType(target, propName)){
|
|
|
case "transform":
|
|
|
return getTransformValue(target, propName, animatable, unit);
|
|
|
case "css":
|
|
|
return getCSSValue(target, propName, unit);
|
|
|
case "attribute":
|
|
|
return getAttribute(target, propName);
|
|
|
default:
|
|
|
return target[propName] || 0;
|
|
|
}
|
|
|
}
|
|
|
function getRelativeValue(to, from) {
|
|
|
var operator = /^(\*=|\+=|-=)/.exec(to);
|
|
|
if (!operator) return to;
|
|
|
var u = getUnit(to) || 0;
|
|
|
var x = parseFloat(from);
|
|
|
var y = parseFloat(to.replace(operator[0], ""));
|
|
|
switch(operator[0][0]){
|
|
|
case "+":
|
|
|
return x + y + u;
|
|
|
case "-":
|
|
|
return x - y + u;
|
|
|
case "*":
|
|
|
return x * y + u;
|
|
|
}
|
|
|
}
|
|
|
function validateValue(val, unit) {
|
|
|
if (is.col(val)) return colorToRgb(val);
|
|
|
if (/\s/g.test(val)) return val;
|
|
|
var originalUnit = getUnit(val);
|
|
|
var unitLess = originalUnit ? val.substr(0, val.length - originalUnit.length) : val;
|
|
|
if (unit) return unitLess + unit;
|
|
|
return unitLess;
|
|
|
}
|
|
|
// getTotalLength() equivalent for circle, rect, polyline, polygon and line shapes
|
|
|
// adapted from https://gist.github.com/SebLambla/3e0550c496c236709744
|
|
|
function getDistance(p1, p2) {
|
|
|
return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
|
|
|
}
|
|
|
function getCircleLength(el) {
|
|
|
return Math.PI * 2 * getAttribute(el, "r");
|
|
|
}
|
|
|
function getRectLength(el) {
|
|
|
return getAttribute(el, "width") * 2 + getAttribute(el, "height") * 2;
|
|
|
}
|
|
|
function getLineLength(el) {
|
|
|
return getDistance({
|
|
|
x: getAttribute(el, "x1"),
|
|
|
y: getAttribute(el, "y1")
|
|
|
}, {
|
|
|
x: getAttribute(el, "x2"),
|
|
|
y: getAttribute(el, "y2")
|
|
|
});
|
|
|
}
|
|
|
function getPolylineLength(el) {
|
|
|
var points = el.points;
|
|
|
var totalLength = 0;
|
|
|
var previousPos;
|
|
|
for(var i = 0; i < points.numberOfItems; i++){
|
|
|
var currentPos = points.getItem(i);
|
|
|
if (i > 0) totalLength += getDistance(previousPos, currentPos);
|
|
|
previousPos = currentPos;
|
|
|
}
|
|
|
return totalLength;
|
|
|
}
|
|
|
function getPolygonLength(el) {
|
|
|
var points = el.points;
|
|
|
return getPolylineLength(el) + getDistance(points.getItem(points.numberOfItems - 1), points.getItem(0));
|
|
|
}
|
|
|
// Path animation
|
|
|
function getTotalLength(el) {
|
|
|
if (el.getTotalLength) return el.getTotalLength();
|
|
|
switch(el.tagName.toLowerCase()){
|
|
|
case "circle":
|
|
|
return getCircleLength(el);
|
|
|
case "rect":
|
|
|
return getRectLength(el);
|
|
|
case "line":
|
|
|
return getLineLength(el);
|
|
|
case "polyline":
|
|
|
return getPolylineLength(el);
|
|
|
case "polygon":
|
|
|
return getPolygonLength(el);
|
|
|
}
|
|
|
}
|
|
|
function setDashoffset(el) {
|
|
|
var pathLength = getTotalLength(el);
|
|
|
el.setAttribute("stroke-dasharray", pathLength);
|
|
|
return pathLength;
|
|
|
}
|
|
|
// Motion path
|
|
|
function getParentSvgEl(el) {
|
|
|
var parentEl = el.parentNode;
|
|
|
while(is.svg(parentEl)){
|
|
|
if (!is.svg(parentEl.parentNode)) break;
|
|
|
parentEl = parentEl.parentNode;
|
|
|
}
|
|
|
return parentEl;
|
|
|
}
|
|
|
function getParentSvg(pathEl, svgData) {
|
|
|
var svg = svgData || {};
|
|
|
var parentSvgEl = svg.el || getParentSvgEl(pathEl);
|
|
|
var rect = parentSvgEl.getBoundingClientRect();
|
|
|
var viewBoxAttr = getAttribute(parentSvgEl, "viewBox");
|
|
|
var width = rect.width;
|
|
|
var height = rect.height;
|
|
|
var viewBox = svg.viewBox || (viewBoxAttr ? viewBoxAttr.split(" ") : [
|
|
|
0,
|
|
|
0,
|
|
|
width,
|
|
|
height
|
|
|
]);
|
|
|
return {
|
|
|
el: parentSvgEl,
|
|
|
viewBox: viewBox,
|
|
|
x: viewBox[0] / 1,
|
|
|
y: viewBox[1] / 1,
|
|
|
w: width,
|
|
|
h: height,
|
|
|
vW: viewBox[2],
|
|
|
vH: viewBox[3]
|
|
|
};
|
|
|
}
|
|
|
function getPath(path, percent) {
|
|
|
var pathEl = is.str(path) ? selectString(path)[0] : path;
|
|
|
var p = percent || 100;
|
|
|
return function(property) {
|
|
|
return {
|
|
|
property: property,
|
|
|
el: pathEl,
|
|
|
svg: getParentSvg(pathEl),
|
|
|
totalLength: getTotalLength(pathEl) * (p / 100)
|
|
|
};
|
|
|
};
|
|
|
}
|
|
|
function getPathProgress(path, progress, isPathTargetInsideSVG) {
|
|
|
function point(offset) {
|
|
|
if (offset === void 0) offset = 0;
|
|
|
var l = progress + offset >= 1 ? progress + offset : 0;
|
|
|
return path.el.getPointAtLength(l);
|
|
|
}
|
|
|
var svg = getParentSvg(path.el, path.svg);
|
|
|
var p = point();
|
|
|
var p0 = point(-1);
|
|
|
var p1 = point(1);
|
|
|
var scaleX = isPathTargetInsideSVG ? 1 : svg.w / svg.vW;
|
|
|
var scaleY = isPathTargetInsideSVG ? 1 : svg.h / svg.vH;
|
|
|
switch(path.property){
|
|
|
case "x":
|
|
|
return (p.x - svg.x) * scaleX;
|
|
|
case "y":
|
|
|
return (p.y - svg.y) * scaleY;
|
|
|
case "angle":
|
|
|
return Math.atan2(p1.y - p0.y, p1.x - p0.x) * 180 / Math.PI;
|
|
|
}
|
|
|
}
|
|
|
// Decompose value
|
|
|
function decomposeValue(val, unit) {
|
|
|
// const rgx = /-?\d*\.?\d+/g; // handles basic numbers
|
|
|
// const rgx = /[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g; // handles exponents notation
|
|
|
var rgx = /[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g; // handles exponents notation
|
|
|
var value = validateValue(is.pth(val) ? val.totalLength : val, unit) + "";
|
|
|
return {
|
|
|
original: value,
|
|
|
numbers: value.match(rgx) ? value.match(rgx).map(Number) : [
|
|
|
0
|
|
|
],
|
|
|
strings: is.str(val) || unit ? value.split(rgx) : []
|
|
|
};
|
|
|
}
|
|
|
// Animatables
|
|
|
function parseTargets(targets) {
|
|
|
var targetsArray = targets ? flattenArray(is.arr(targets) ? targets.map(toArray) : toArray(targets)) : [];
|
|
|
return filterArray(targetsArray, function(item, pos, self) {
|
|
|
return self.indexOf(item) === pos;
|
|
|
});
|
|
|
}
|
|
|
function getAnimatables(targets) {
|
|
|
var parsed = parseTargets(targets);
|
|
|
return parsed.map(function(t, i) {
|
|
|
return {
|
|
|
target: t,
|
|
|
id: i,
|
|
|
total: parsed.length,
|
|
|
transforms: {
|
|
|
list: getElementTransforms(t)
|
|
|
}
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
// Properties
|
|
|
function normalizePropertyTweens(prop, tweenSettings) {
|
|
|
var settings = cloneObject(tweenSettings);
|
|
|
// Override duration if easing is a spring
|
|
|
if (/^spring/.test(settings.easing)) settings.duration = spring(settings.easing);
|
|
|
if (is.arr(prop)) {
|
|
|
var l = prop.length;
|
|
|
var isFromTo = l === 2 && !is.obj(prop[0]);
|
|
|
if (!isFromTo) // Duration divided by the number of tweens
|
|
|
{
|
|
|
if (!is.fnc(tweenSettings.duration)) settings.duration = tweenSettings.duration / l;
|
|
|
} else // Transform [from, to] values shorthand to a valid tween value
|
|
|
prop = {
|
|
|
value: prop
|
|
|
};
|
|
|
}
|
|
|
var propArray = is.arr(prop) ? prop : [
|
|
|
prop
|
|
|
];
|
|
|
return propArray.map(function(v, i) {
|
|
|
var obj = is.obj(v) && !is.pth(v) ? v : {
|
|
|
value: v
|
|
|
};
|
|
|
// Default delay value should only be applied to the first tween
|
|
|
if (is.und(obj.delay)) obj.delay = !i ? tweenSettings.delay : 0;
|
|
|
// Default endDelay value should only be applied to the last tween
|
|
|
if (is.und(obj.endDelay)) obj.endDelay = i === propArray.length - 1 ? tweenSettings.endDelay : 0;
|
|
|
return obj;
|
|
|
}).map(function(k) {
|
|
|
return mergeObjects(k, settings);
|
|
|
});
|
|
|
}
|
|
|
function flattenKeyframes(keyframes) {
|
|
|
var propertyNames = filterArray(flattenArray(keyframes.map(function(key) {
|
|
|
return Object.keys(key);
|
|
|
})), function(p) {
|
|
|
return is.key(p);
|
|
|
}).reduce(function(a, b) {
|
|
|
if (a.indexOf(b) < 0) a.push(b);
|
|
|
return a;
|
|
|
}, []);
|
|
|
var properties = {};
|
|
|
var loop = function(i) {
|
|
|
var propName = propertyNames[i];
|
|
|
properties[propName] = keyframes.map(function(key) {
|
|
|
var newKey = {};
|
|
|
for(var p in key){
|
|
|
if (is.key(p)) {
|
|
|
if (p == propName) newKey.value = key[p];
|
|
|
} else newKey[p] = key[p];
|
|
|
}
|
|
|
return newKey;
|
|
|
});
|
|
|
};
|
|
|
for(var i1 = 0; i1 < propertyNames.length; i1++)loop(i1);
|
|
|
return properties;
|
|
|
}
|
|
|
function getProperties(tweenSettings, params) {
|
|
|
var properties = [];
|
|
|
var keyframes = params.keyframes;
|
|
|
if (keyframes) params = mergeObjects(flattenKeyframes(keyframes), params);
|
|
|
for(var p in params)if (is.key(p)) properties.push({
|
|
|
name: p,
|
|
|
tweens: normalizePropertyTweens(params[p], tweenSettings)
|
|
|
});
|
|
|
return properties;
|
|
|
}
|
|
|
// Tweens
|
|
|
function normalizeTweenValues(tween, animatable) {
|
|
|
var t = {};
|
|
|
for(var p in tween){
|
|
|
var value = getFunctionValue(tween[p], animatable);
|
|
|
if (is.arr(value)) {
|
|
|
value = value.map(function(v) {
|
|
|
return getFunctionValue(v, animatable);
|
|
|
});
|
|
|
if (value.length === 1) value = value[0];
|
|
|
}
|
|
|
t[p] = value;
|
|
|
}
|
|
|
t.duration = parseFloat(t.duration);
|
|
|
t.delay = parseFloat(t.delay);
|
|
|
return t;
|
|
|
}
|
|
|
function normalizeTweens(prop, animatable) {
|
|
|
var previousTween;
|
|
|
return prop.tweens.map(function(t) {
|
|
|
var tween = normalizeTweenValues(t, animatable);
|
|
|
var tweenValue = tween.value;
|
|
|
var to = is.arr(tweenValue) ? tweenValue[1] : tweenValue;
|
|
|
var toUnit = getUnit(to);
|
|
|
var originalValue = getOriginalTargetValue(animatable.target, prop.name, toUnit, animatable);
|
|
|
var previousValue = previousTween ? previousTween.to.original : originalValue;
|
|
|
var from = is.arr(tweenValue) ? tweenValue[0] : previousValue;
|
|
|
var fromUnit = getUnit(from) || getUnit(originalValue);
|
|
|
var unit = toUnit || fromUnit;
|
|
|
if (is.und(to)) to = previousValue;
|
|
|
tween.from = decomposeValue(from, unit);
|
|
|
tween.to = decomposeValue(getRelativeValue(to, from), unit);
|
|
|
tween.start = previousTween ? previousTween.end : 0;
|
|
|
tween.end = tween.start + tween.delay + tween.duration + tween.endDelay;
|
|
|
tween.easing = parseEasings(tween.easing, tween.duration);
|
|
|
tween.isPath = is.pth(tweenValue);
|
|
|
tween.isPathTargetInsideSVG = tween.isPath && is.svg(animatable.target);
|
|
|
tween.isColor = is.col(tween.from.original);
|
|
|
if (tween.isColor) tween.round = 1;
|
|
|
previousTween = tween;
|
|
|
return tween;
|
|
|
});
|
|
|
}
|
|
|
// Tween progress
|
|
|
var setProgressValue = {
|
|
|
css: function(t, p, v) {
|
|
|
return t.style[p] = v;
|
|
|
},
|
|
|
attribute: function(t, p, v) {
|
|
|
return t.setAttribute(p, v);
|
|
|
},
|
|
|
object: function(t, p, v) {
|
|
|
return t[p] = v;
|
|
|
},
|
|
|
transform: function(t, p, v, transforms, manual) {
|
|
|
transforms.list.set(p, v);
|
|
|
if (p === transforms.last || manual) {
|
|
|
var str = "";
|
|
|
transforms.list.forEach(function(value, prop) {
|
|
|
str += prop + "(" + value + ") ";
|
|
|
});
|
|
|
t.style.transform = str;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
// Set Value helper
|
|
|
function setTargetsValue(targets, properties) {
|
|
|
var animatables = getAnimatables(targets);
|
|
|
animatables.forEach(function(animatable) {
|
|
|
for(var property in properties){
|
|
|
var value = getFunctionValue(properties[property], animatable);
|
|
|
var target = animatable.target;
|
|
|
var valueUnit = getUnit(value);
|
|
|
var originalValue = getOriginalTargetValue(target, property, valueUnit, animatable);
|
|
|
var unit = valueUnit || getUnit(originalValue);
|
|
|
var to = getRelativeValue(validateValue(value, unit), originalValue);
|
|
|
var animType = getAnimationType(target, property);
|
|
|
setProgressValue[animType](target, property, to, animatable.transforms, true);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
// Animations
|
|
|
function createAnimation(animatable, prop) {
|
|
|
var animType = getAnimationType(animatable.target, prop.name);
|
|
|
if (animType) {
|
|
|
var tweens = normalizeTweens(prop, animatable);
|
|
|
var lastTween = tweens[tweens.length - 1];
|
|
|
return {
|
|
|
type: animType,
|
|
|
property: prop.name,
|
|
|
animatable: animatable,
|
|
|
tweens: tweens,
|
|
|
duration: lastTween.end,
|
|
|
delay: tweens[0].delay,
|
|
|
endDelay: lastTween.endDelay
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
function getAnimations(animatables, properties) {
|
|
|
return filterArray(flattenArray(animatables.map(function(animatable) {
|
|
|
return properties.map(function(prop) {
|
|
|
return createAnimation(animatable, prop);
|
|
|
});
|
|
|
})), function(a) {
|
|
|
return !is.und(a);
|
|
|
});
|
|
|
}
|
|
|
// Create Instance
|
|
|
function getInstanceTimings(animations, tweenSettings) {
|
|
|
var animLength = animations.length;
|
|
|
var getTlOffset = function(anim) {
|
|
|
return anim.timelineOffset ? anim.timelineOffset : 0;
|
|
|
};
|
|
|
var timings = {};
|
|
|
timings.duration = animLength ? Math.max.apply(Math, animations.map(function(anim) {
|
|
|
return getTlOffset(anim) + anim.duration;
|
|
|
})) : tweenSettings.duration;
|
|
|
timings.delay = animLength ? Math.min.apply(Math, animations.map(function(anim) {
|
|
|
return getTlOffset(anim) + anim.delay;
|
|
|
})) : tweenSettings.delay;
|
|
|
timings.endDelay = animLength ? timings.duration - Math.max.apply(Math, animations.map(function(anim) {
|
|
|
return getTlOffset(anim) + anim.duration - anim.endDelay;
|
|
|
})) : tweenSettings.endDelay;
|
|
|
return timings;
|
|
|
}
|
|
|
var instanceID = 0;
|
|
|
function createNewInstance(params) {
|
|
|
var instanceSettings = replaceObjectProps(defaultInstanceSettings, params);
|
|
|
var tweenSettings = replaceObjectProps(defaultTweenSettings, params);
|
|
|
var properties = getProperties(tweenSettings, params);
|
|
|
var animatables = getAnimatables(params.targets);
|
|
|
var animations = getAnimations(animatables, properties);
|
|
|
var timings = getInstanceTimings(animations, tweenSettings);
|
|
|
var id = instanceID;
|
|
|
instanceID++;
|
|
|
return mergeObjects(instanceSettings, {
|
|
|
id: id,
|
|
|
children: [],
|
|
|
animatables: animatables,
|
|
|
animations: animations,
|
|
|
duration: timings.duration,
|
|
|
delay: timings.delay,
|
|
|
endDelay: timings.endDelay
|
|
|
});
|
|
|
}
|
|
|
// Core
|
|
|
var activeInstances = [];
|
|
|
var engine = function() {
|
|
|
var raf;
|
|
|
function play() {
|
|
|
if (!raf && (!isDocumentHidden() || !anime.suspendWhenDocumentHidden) && activeInstances.length > 0) raf = requestAnimationFrame(step);
|
|
|
}
|
|
|
function step(t) {
|
|
|
// memo on algorithm issue:
|
|
|
// dangerous iteration over mutable `activeInstances`
|
|
|
// (that collection may be updated from within callbacks of `tick`-ed animation instances)
|
|
|
var activeInstancesLength = activeInstances.length;
|
|
|
var i = 0;
|
|
|
while(i < activeInstancesLength){
|
|
|
var activeInstance = activeInstances[i];
|
|
|
if (!activeInstance.paused) {
|
|
|
activeInstance.tick(t);
|
|
|
i++;
|
|
|
} else {
|
|
|
activeInstances.splice(i, 1);
|
|
|
activeInstancesLength--;
|
|
|
}
|
|
|
}
|
|
|
raf = i > 0 ? requestAnimationFrame(step) : undefined;
|
|
|
}
|
|
|
function handleVisibilityChange() {
|
|
|
if (!anime.suspendWhenDocumentHidden) return;
|
|
|
if (isDocumentHidden()) // suspend ticks
|
|
|
raf = cancelAnimationFrame(raf);
|
|
|
else {
|
|
|
// first adjust animations to consider the time that ticks were suspended
|
|
|
activeInstances.forEach(function(instance) {
|
|
|
return instance._onDocumentVisibility();
|
|
|
});
|
|
|
engine();
|
|
|
}
|
|
|
}
|
|
|
if (typeof document !== "undefined") document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
|
return play;
|
|
|
}();
|
|
|
function isDocumentHidden() {
|
|
|
return !!document && document.hidden;
|
|
|
}
|
|
|
// Public Instance
|
|
|
function anime(params) {
|
|
|
if (params === void 0) params = {};
|
|
|
var startTime = 0, lastTime = 0, now = 0;
|
|
|
var children, childrenLength = 0;
|
|
|
var resolve = null;
|
|
|
function makePromise(instance) {
|
|
|
var promise = window.Promise && new Promise(function(_resolve) {
|
|
|
return resolve = _resolve;
|
|
|
});
|
|
|
instance.finished = promise;
|
|
|
return promise;
|
|
|
}
|
|
|
var instance1 = createNewInstance(params);
|
|
|
var promise1 = makePromise(instance1);
|
|
|
function toggleInstanceDirection() {
|
|
|
var direction = instance1.direction;
|
|
|
if (direction !== "alternate") instance1.direction = direction !== "normal" ? "normal" : "reverse";
|
|
|
instance1.reversed = !instance1.reversed;
|
|
|
children.forEach(function(child) {
|
|
|
return child.reversed = instance1.reversed;
|
|
|
});
|
|
|
}
|
|
|
function adjustTime(time) {
|
|
|
return instance1.reversed ? instance1.duration - time : time;
|
|
|
}
|
|
|
function resetTime() {
|
|
|
startTime = 0;
|
|
|
lastTime = adjustTime(instance1.currentTime) * (1 / anime.speed);
|
|
|
}
|
|
|
function seekChild(time, child) {
|
|
|
if (child) child.seek(time - child.timelineOffset);
|
|
|
}
|
|
|
function syncInstanceChildren(time) {
|
|
|
if (!instance1.reversePlayback) for(var i = 0; i < childrenLength; i++)seekChild(time, children[i]);
|
|
|
else for(var i$1 = childrenLength; i$1--;)seekChild(time, children[i$1]);
|
|
|
}
|
|
|
function setAnimationsProgress(insTime) {
|
|
|
var i = 0;
|
|
|
var animations = instance1.animations;
|
|
|
var animationsLength = animations.length;
|
|
|
while(i < animationsLength){
|
|
|
var anim = animations[i];
|
|
|
var animatable = anim.animatable;
|
|
|
var tweens = anim.tweens;
|
|
|
var tweenLength = tweens.length - 1;
|
|
|
var tween = tweens[tweenLength];
|
|
|
// Only check for keyframes if there is more than one tween
|
|
|
if (tweenLength) tween = filterArray(tweens, function(t) {
|
|
|
return insTime < t.end;
|
|
|
})[0] || tween;
|
|
|
var elapsed = minMax(insTime - tween.start - tween.delay, 0, tween.duration) / tween.duration;
|
|
|
var eased = isNaN(elapsed) ? 1 : tween.easing(elapsed);
|
|
|
var strings = tween.to.strings;
|
|
|
var round = tween.round;
|
|
|
var numbers = [];
|
|
|
var toNumbersLength = tween.to.numbers.length;
|
|
|
var progress = void 0;
|
|
|
for(var n = 0; n < toNumbersLength; n++){
|
|
|
var value = void 0;
|
|
|
var toNumber = tween.to.numbers[n];
|
|
|
var fromNumber = tween.from.numbers[n] || 0;
|
|
|
if (!tween.isPath) value = fromNumber + eased * (toNumber - fromNumber);
|
|
|
else value = getPathProgress(tween.value, eased * toNumber, tween.isPathTargetInsideSVG);
|
|
|
if (round) {
|
|
|
if (!(tween.isColor && n > 2)) value = Math.round(value * round) / round;
|
|
|
}
|
|
|
numbers.push(value);
|
|
|
}
|
|
|
// Manual Array.reduce for better performances
|
|
|
var stringsLength = strings.length;
|
|
|
if (!stringsLength) progress = numbers[0];
|
|
|
else {
|
|
|
progress = strings[0];
|
|
|
for(var s = 0; s < stringsLength; s++){
|
|
|
var a = strings[s];
|
|
|
var b = strings[s + 1];
|
|
|
var n$1 = numbers[s];
|
|
|
if (!isNaN(n$1)) {
|
|
|
if (!b) progress += n$1 + " ";
|
|
|
else progress += n$1 + b;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
setProgressValue[anim.type](animatable.target, anim.property, progress, animatable.transforms);
|
|
|
anim.currentValue = progress;
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
function setCallback(cb) {
|
|
|
if (instance1[cb] && !instance1.passThrough) instance1[cb](instance1);
|
|
|
}
|
|
|
function countIteration() {
|
|
|
if (instance1.remaining && instance1.remaining !== true) instance1.remaining--;
|
|
|
}
|
|
|
function setInstanceProgress(engineTime) {
|
|
|
var insDuration = instance1.duration;
|
|
|
var insDelay = instance1.delay;
|
|
|
var insEndDelay = insDuration - instance1.endDelay;
|
|
|
var insTime = adjustTime(engineTime);
|
|
|
instance1.progress = minMax(insTime / insDuration * 100, 0, 100);
|
|
|
instance1.reversePlayback = insTime < instance1.currentTime;
|
|
|
if (children) syncInstanceChildren(insTime);
|
|
|
if (!instance1.began && instance1.currentTime > 0) {
|
|
|
instance1.began = true;
|
|
|
setCallback("begin");
|
|
|
}
|
|
|
if (!instance1.loopBegan && instance1.currentTime > 0) {
|
|
|
instance1.loopBegan = true;
|
|
|
setCallback("loopBegin");
|
|
|
}
|
|
|
if (insTime <= insDelay && instance1.currentTime !== 0) setAnimationsProgress(0);
|
|
|
if (insTime >= insEndDelay && instance1.currentTime !== insDuration || !insDuration) setAnimationsProgress(insDuration);
|
|
|
if (insTime > insDelay && insTime < insEndDelay) {
|
|
|
if (!instance1.changeBegan) {
|
|
|
instance1.changeBegan = true;
|
|
|
instance1.changeCompleted = false;
|
|
|
setCallback("changeBegin");
|
|
|
}
|
|
|
setCallback("change");
|
|
|
setAnimationsProgress(insTime);
|
|
|
} else if (instance1.changeBegan) {
|
|
|
instance1.changeCompleted = true;
|
|
|
instance1.changeBegan = false;
|
|
|
setCallback("changeComplete");
|
|
|
}
|
|
|
instance1.currentTime = minMax(insTime, 0, insDuration);
|
|
|
if (instance1.began) setCallback("update");
|
|
|
if (engineTime >= insDuration) {
|
|
|
lastTime = 0;
|
|
|
countIteration();
|
|
|
if (!instance1.remaining) {
|
|
|
instance1.paused = true;
|
|
|
if (!instance1.completed) {
|
|
|
instance1.completed = true;
|
|
|
setCallback("loopComplete");
|
|
|
setCallback("complete");
|
|
|
if (!instance1.passThrough && "Promise" in window) {
|
|
|
resolve();
|
|
|
promise1 = makePromise(instance1);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
startTime = now;
|
|
|
setCallback("loopComplete");
|
|
|
instance1.loopBegan = false;
|
|
|
if (instance1.direction === "alternate") toggleInstanceDirection();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
instance1.reset = function() {
|
|
|
var direction = instance1.direction;
|
|
|
instance1.passThrough = false;
|
|
|
instance1.currentTime = 0;
|
|
|
instance1.progress = 0;
|
|
|
instance1.paused = true;
|
|
|
instance1.began = false;
|
|
|
instance1.loopBegan = false;
|
|
|
instance1.changeBegan = false;
|
|
|
instance1.completed = false;
|
|
|
instance1.changeCompleted = false;
|
|
|
instance1.reversePlayback = false;
|
|
|
instance1.reversed = direction === "reverse";
|
|
|
instance1.remaining = instance1.loop;
|
|
|
children = instance1.children;
|
|
|
childrenLength = children.length;
|
|
|
for(var i = childrenLength; i--;)instance1.children[i].reset();
|
|
|
if (instance1.reversed && instance1.loop !== true || direction === "alternate" && instance1.loop === 1) instance1.remaining++;
|
|
|
setAnimationsProgress(instance1.reversed ? instance1.duration : 0);
|
|
|
};
|
|
|
// internal method (for engine) to adjust animation timings before restoring engine ticks (rAF)
|
|
|
instance1._onDocumentVisibility = resetTime;
|
|
|
// Set Value helper
|
|
|
instance1.set = function(targets, properties) {
|
|
|
setTargetsValue(targets, properties);
|
|
|
return instance1;
|
|
|
};
|
|
|
instance1.tick = function(t) {
|
|
|
now = t;
|
|
|
if (!startTime) startTime = now;
|
|
|
setInstanceProgress((now + (lastTime - startTime)) * anime.speed);
|
|
|
};
|
|
|
instance1.seek = function(time) {
|
|
|
setInstanceProgress(adjustTime(time));
|
|
|
};
|
|
|
instance1.pause = function() {
|
|
|
instance1.paused = true;
|
|
|
resetTime();
|
|
|
};
|
|
|
instance1.play = function() {
|
|
|
if (!instance1.paused) return;
|
|
|
if (instance1.completed) instance1.reset();
|
|
|
instance1.paused = false;
|
|
|
activeInstances.push(instance1);
|
|
|
resetTime();
|
|
|
engine();
|
|
|
};
|
|
|
instance1.reverse = function() {
|
|
|
toggleInstanceDirection();
|
|
|
instance1.completed = instance1.reversed ? false : true;
|
|
|
resetTime();
|
|
|
};
|
|
|
instance1.restart = function() {
|
|
|
instance1.reset();
|
|
|
instance1.play();
|
|
|
};
|
|
|
instance1.remove = function(targets) {
|
|
|
var targetsArray = parseTargets(targets);
|
|
|
removeTargetsFromInstance(targetsArray, instance1);
|
|
|
};
|
|
|
instance1.reset();
|
|
|
if (instance1.autoplay) instance1.play();
|
|
|
return instance1;
|
|
|
}
|
|
|
// Remove targets from animation
|
|
|
function removeTargetsFromAnimations(targetsArray, animations) {
|
|
|
for(var a = animations.length; a--;)if (arrayContains(targetsArray, animations[a].animatable.target)) animations.splice(a, 1);
|
|
|
}
|
|
|
function removeTargetsFromInstance(targetsArray, instance) {
|
|
|
var animations = instance.animations;
|
|
|
var children = instance.children;
|
|
|
removeTargetsFromAnimations(targetsArray, animations);
|
|
|
for(var c = children.length; c--;){
|
|
|
var child = children[c];
|
|
|
var childAnimations = child.animations;
|
|
|
removeTargetsFromAnimations(targetsArray, childAnimations);
|
|
|
if (!childAnimations.length && !child.children.length) children.splice(c, 1);
|
|
|
}
|
|
|
if (!animations.length && !children.length) instance.pause();
|
|
|
}
|
|
|
function removeTargetsFromActiveInstances(targets) {
|
|
|
var targetsArray = parseTargets(targets);
|
|
|
for(var i = activeInstances.length; i--;){
|
|
|
var instance = activeInstances[i];
|
|
|
removeTargetsFromInstance(targetsArray, instance);
|
|
|
}
|
|
|
}
|
|
|
// Stagger helpers
|
|
|
function stagger(val3, params) {
|
|
|
if (params === void 0) params = {};
|
|
|
var direction = params.direction || "normal";
|
|
|
var easing = params.easing ? parseEasings(params.easing) : null;
|
|
|
var grid = params.grid;
|
|
|
var axis = params.axis;
|
|
|
var fromIndex = params.from || 0;
|
|
|
var fromFirst = fromIndex === "first";
|
|
|
var fromCenter = fromIndex === "center";
|
|
|
var fromLast = fromIndex === "last";
|
|
|
var isRange = is.arr(val3);
|
|
|
var val1 = isRange ? parseFloat(val3[0]) : parseFloat(val3);
|
|
|
var val2 = isRange ? parseFloat(val3[1]) : 0;
|
|
|
var unit = getUnit(isRange ? val3[1] : val3) || 0;
|
|
|
var start = params.start || 0 + (isRange ? val1 : 0);
|
|
|
var values = [];
|
|
|
var maxValue = 0;
|
|
|
return function(el, i, t) {
|
|
|
if (fromFirst) fromIndex = 0;
|
|
|
if (fromCenter) fromIndex = (t - 1) / 2;
|
|
|
if (fromLast) fromIndex = t - 1;
|
|
|
if (!values.length) {
|
|
|
for(var index = 0; index < t; index++){
|
|
|
if (!grid) values.push(Math.abs(fromIndex - index));
|
|
|
else {
|
|
|
var fromX = !fromCenter ? fromIndex % grid[0] : (grid[0] - 1) / 2;
|
|
|
var fromY = !fromCenter ? Math.floor(fromIndex / grid[0]) : (grid[1] - 1) / 2;
|
|
|
var toX = index % grid[0];
|
|
|
var toY = Math.floor(index / grid[0]);
|
|
|
var distanceX = fromX - toX;
|
|
|
var distanceY = fromY - toY;
|
|
|
var value = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
|
|
|
if (axis === "x") value = -distanceX;
|
|
|
if (axis === "y") value = -distanceY;
|
|
|
values.push(value);
|
|
|
}
|
|
|
maxValue = Math.max.apply(Math, values);
|
|
|
}
|
|
|
if (easing) values = values.map(function(val) {
|
|
|
return easing(val / maxValue) * maxValue;
|
|
|
});
|
|
|
if (direction === "reverse") values = values.map(function(val) {
|
|
|
return axis ? val < 0 ? val * -1 : -val : Math.abs(maxValue - val);
|
|
|
});
|
|
|
}
|
|
|
var spacing = isRange ? (val2 - val1) / maxValue : val1;
|
|
|
return start + spacing * (Math.round(values[i] * 100) / 100) + unit;
|
|
|
};
|
|
|
}
|
|
|
// Timeline
|
|
|
function timeline(params) {
|
|
|
if (params === void 0) params = {};
|
|
|
var tl = anime(params);
|
|
|
tl.duration = 0;
|
|
|
tl.add = function(instanceParams, timelineOffset) {
|
|
|
var tlIndex = activeInstances.indexOf(tl);
|
|
|
var children = tl.children;
|
|
|
if (tlIndex > -1) activeInstances.splice(tlIndex, 1);
|
|
|
function passThrough(ins) {
|
|
|
ins.passThrough = true;
|
|
|
}
|
|
|
for(var i = 0; i < children.length; i++)passThrough(children[i]);
|
|
|
var insParams = mergeObjects(instanceParams, replaceObjectProps(defaultTweenSettings, params));
|
|
|
insParams.targets = insParams.targets || params.targets;
|
|
|
var tlDuration = tl.duration;
|
|
|
insParams.autoplay = false;
|
|
|
insParams.direction = tl.direction;
|
|
|
insParams.timelineOffset = is.und(timelineOffset) ? tlDuration : getRelativeValue(timelineOffset, tlDuration);
|
|
|
passThrough(tl);
|
|
|
tl.seek(insParams.timelineOffset);
|
|
|
var ins1 = anime(insParams);
|
|
|
passThrough(ins1);
|
|
|
children.push(ins1);
|
|
|
var timings = getInstanceTimings(children, params);
|
|
|
tl.delay = timings.delay;
|
|
|
tl.endDelay = timings.endDelay;
|
|
|
tl.duration = timings.duration;
|
|
|
tl.seek(0);
|
|
|
tl.reset();
|
|
|
if (tl.autoplay) tl.play();
|
|
|
return tl;
|
|
|
};
|
|
|
return tl;
|
|
|
}
|
|
|
anime.version = "3.2.1";
|
|
|
anime.speed = 1;
|
|
|
// TODO:#review: naming, documentation
|
|
|
anime.suspendWhenDocumentHidden = true;
|
|
|
anime.running = activeInstances;
|
|
|
anime.remove = removeTargetsFromActiveInstances;
|
|
|
anime.get = getOriginalTargetValue;
|
|
|
anime.set = setTargetsValue;
|
|
|
anime.convertPx = convertPxToUnit;
|
|
|
anime.path = getPath;
|
|
|
anime.setDashoffset = setDashoffset;
|
|
|
anime.stagger = stagger;
|
|
|
anime.timeline = timeline;
|
|
|
anime.easing = parseEasings;
|
|
|
anime.penner = penner;
|
|
|
anime.random = function(min, max) {
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
};
|
|
|
exports.default = anime;
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"6B20o":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
var _sortablejs = require("sortablejs");
|
|
|
var _sortablejsDefault = parcelHelpers.interopDefault(_sortablejs);
|
|
|
var _dataUtils = require("../utils/DataUtils");
|
|
|
var _dataUtilsDefault = parcelHelpers.interopDefault(_dataUtils);
|
|
|
var _notificationsJs = require("./Notifications.js");
|
|
|
var _notificationsJsDefault = parcelHelpers.interopDefault(_notificationsJs);
|
|
|
const notify = new (0, _notificationsJsDefault.default)();
|
|
|
class FileManager {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(upload, input, imageList, fileList){
|
|
|
this.upload = upload;
|
|
|
this.input = input;
|
|
|
this.imageList = imageList;
|
|
|
this.fileList = fileList;
|
|
|
this.accetableFiles = [
|
|
|
"image/jpeg",
|
|
|
"image/gif",
|
|
|
"image/png",
|
|
|
"image/svg",
|
|
|
"audio/mpeg",
|
|
|
"video/mp4",
|
|
|
"application/pdf",
|
|
|
"text/plain",
|
|
|
"text/rtf"
|
|
|
];
|
|
|
this.files = [];
|
|
|
this.sortedFiles = [];
|
|
|
this.storage = [];
|
|
|
this.mediaSort = (0, _sortablejsDefault.default).create(this.imageList, {
|
|
|
animation: 150,
|
|
|
onUpdate: ()=>{
|
|
|
notify.alert("REINDEXING MEDIA", null);
|
|
|
this.updateFiles();
|
|
|
}
|
|
|
});
|
|
|
this.fileSort = (0, _sortablejsDefault.default).create(this.fileList, {
|
|
|
animation: 150,
|
|
|
onUpdate: ()=>{
|
|
|
notify.alert("REINDEXING FILES", null);
|
|
|
this.updateFiles();
|
|
|
}
|
|
|
});
|
|
|
this.start();
|
|
|
}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
start() {
|
|
|
this.upload.addEventListener("dragover", (e)=>this.handleFileActions(e), false);
|
|
|
this.upload.addEventListener("drop", (e)=>this.handleFileActions(e), false);
|
|
|
this.input.addEventListener("change", (e)=>this.handleFileActions(e), false);
|
|
|
var removeMedia = document.querySelectorAll(".media-remove");
|
|
|
for(var i = 0, length = removeMedia.length; i < length; i++)removeMedia[i].addEventListener("click", (e)=>this.removeFile(e, "media"), false);
|
|
|
}
|
|
|
getFiles() {
|
|
|
return this.files;
|
|
|
}
|
|
|
reindexFiles(sortOrder, step) {
|
|
|
let count = sortOrder.length;
|
|
|
if (step == 0) this.files = [];
|
|
|
var utils = new (0, _dataUtilsDefault.default)();
|
|
|
utils.imgLoad(sortOrder[step].earl).then((blob)=>{
|
|
|
var fresh = new File([
|
|
|
blob
|
|
|
], sortOrder[step].fileName, {
|
|
|
type: blob.type
|
|
|
});
|
|
|
this.files.push(fresh);
|
|
|
var limit = count - 1;
|
|
|
if (this.files.length <= limit) {
|
|
|
step = step + 1;
|
|
|
this.reindexFiles(sortOrder, step);
|
|
|
} else notify.alert("FILES READY TO UPLOAD", true);
|
|
|
});
|
|
|
}
|
|
|
sortFiles(files) {
|
|
|
var self = this;
|
|
|
for(var i = 0, file1; file1 = files[i]; i++){
|
|
|
var reader = new FileReader(); // Closure to capture the file information
|
|
|
reader.onload = ((theFile)=>{
|
|
|
return function(f) {
|
|
|
//create remove button object
|
|
|
var remove = document.createElement("button");
|
|
|
remove.className = "media-remove";
|
|
|
remove.innerHTML = "X";
|
|
|
remove.addEventListener("click", (e)=>self.removeFile(e, "media"), false); //get counts for lists
|
|
|
var mediaCount = self.imageList.childNodes.length;
|
|
|
var fileCount = self.fileList.childNodes.length; // sort files
|
|
|
switch(theFile.type){
|
|
|
case "image/jpg":
|
|
|
case "image/jpeg":
|
|
|
case "image/gif":
|
|
|
case "image/svg":
|
|
|
case "image/png":
|
|
|
//create element and add to list
|
|
|
//var image = document.createElement('img');
|
|
|
//image.src = f.target.result;
|
|
|
//image.title = escape(theFile.name);
|
|
|
var span = document.createElement("div");
|
|
|
span.style.background = "url(" + f.target.result + ") no-repeat center center / cover";
|
|
|
span.className = "img-item"; //image.setAttribute('id', i);
|
|
|
self.storage.push([
|
|
|
{
|
|
|
id: "page_image" + i,
|
|
|
data: f.target.result,
|
|
|
type: theFile.type,
|
|
|
name: escape(theFile.name)
|
|
|
}
|
|
|
]);
|
|
|
if (mediaCount < 0) mediaCount = 0;
|
|
|
span.setAttribute("id", mediaCount);
|
|
|
remove.setAttribute("id", mediaCount);
|
|
|
span.setAttribute("data-file-name", theFile.name);
|
|
|
span.appendChild(remove);
|
|
|
self.imageList.appendChild(span);
|
|
|
break;
|
|
|
case "video/mp4":
|
|
|
var video = document.createElement("div");
|
|
|
video.className = "video-item";
|
|
|
video.setAttribute("data-source", f.target.result);
|
|
|
if (mediaCount < 0) mediaCount = 0;
|
|
|
video.setAttribute("id", mediaCount);
|
|
|
remove.setAttribute("id", mediaCount);
|
|
|
video.setAttribute("data-file-name", theFile.name);
|
|
|
video.appendChild(remove);
|
|
|
self.imageList.appendChild(video);
|
|
|
break;
|
|
|
case "audio/mpeg":
|
|
|
var sound = document.createElement("div");
|
|
|
sound.className = "audio-item";
|
|
|
sound.setAttribute("data-source", f.target.result);
|
|
|
sound.setAttribute("id", fileCount);
|
|
|
remove.setAttribute("id", fileCount);
|
|
|
sound.setAttribute("data-file-name", theFile.name);
|
|
|
sound.appendChild(remove);
|
|
|
self.fileList.appendChild(sound);
|
|
|
break;
|
|
|
case "application/pdf":
|
|
|
case "text/plain":
|
|
|
case "text/rtf":
|
|
|
var file = document.createElement("div");
|
|
|
file.className = "file-item";
|
|
|
file.setAttribute("data-source", f.target.result);
|
|
|
file.setAttribute("id", fileCount);
|
|
|
remove.setAttribute("id", fileCount);
|
|
|
file.setAttribute("data-file-name", theFile.name);
|
|
|
file.appendChild(remove);
|
|
|
self.fileList.appendChild(file);
|
|
|
break;
|
|
|
}
|
|
|
};
|
|
|
})(file1); // Read in the image file as a data URL.
|
|
|
reader.readAsDataURL(file1);
|
|
|
} //give the script a beat to add the child nodes, then update it all
|
|
|
setTimeout(()=>{
|
|
|
self.updateFiles();
|
|
|
}, 50);
|
|
|
}
|
|
|
// event handlers
|
|
|
//--------------------------
|
|
|
updateFiles() {
|
|
|
let currentFiles = []; //store current list
|
|
|
let items = []; //get files from media and files list
|
|
|
for(let index = 0; index < this.imageList.childNodes.length; index++)items.push(this.imageList.childNodes[index]);
|
|
|
for(let index1 = 0; index1 < this.fileList.childNodes.length; index1++)items.push(this.fileList.childNodes[index1]);
|
|
|
for(let index2 = 0; index2 < items.length; index2++){
|
|
|
var item = items[index2];
|
|
|
let url = "";
|
|
|
if (item.className == "img-item") url = item.style.backgroundImage.slice(4, -1).replace(/"/g, "");
|
|
|
else url = item.getAttribute("data-source");
|
|
|
currentFiles.push({
|
|
|
earl: url,
|
|
|
fileName: item.getAttribute("data-file-name")
|
|
|
});
|
|
|
}
|
|
|
this.reindexFiles(currentFiles, 0);
|
|
|
}
|
|
|
removeFile(e) {
|
|
|
var list = [];
|
|
|
switch(e.target.parentNode.className){
|
|
|
case "img-item":
|
|
|
case "video-item":
|
|
|
list = this.imageList;
|
|
|
break;
|
|
|
case "audio-item":
|
|
|
case "file-item":
|
|
|
list = this.fileList;
|
|
|
break;
|
|
|
}
|
|
|
for(let index = 0; index < list.childNodes.length; index++){
|
|
|
let media = list.childNodes[index];
|
|
|
if (media.id == e.target.id) {
|
|
|
list.removeChild(media);
|
|
|
notify.alert("REINDEXING MEDIA", null);
|
|
|
this.updateFiles();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
handleFileActions(e) {
|
|
|
e.stopPropagation();
|
|
|
e.preventDefault();
|
|
|
let self = this;
|
|
|
let rawList = [];
|
|
|
let sortedList = [];
|
|
|
let notOnTheList = [];
|
|
|
switch(e.type){
|
|
|
case "dragover":
|
|
|
e.dataTransfer.dropEffect = "copy"; // Explicitly show this is a copy.
|
|
|
break;
|
|
|
case "change":
|
|
|
case "drop":
|
|
|
e.type == "drop" ? rawList = e.dataTransfer.files : rawList = e.target.files;
|
|
|
for(var i = 0, f; f = rawList[i]; i++)// check witch files are cool to upload
|
|
|
if (this.accetableFiles.includes(f.type)) sortedList.push(f);
|
|
|
else notOnTheList.push(f);
|
|
|
//send for sorting
|
|
|
self.sortFiles(sortedList);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
exports.default = FileManager;
|
|
|
|
|
|
},{"sortablejs":"4mik1","../utils/DataUtils":"eM6UW","./Notifications.js":"9GRdG","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"4mik1":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
parcelHelpers.export(exports, "MultiDrag", ()=>MultiDragPlugin);
|
|
|
parcelHelpers.export(exports, "Sortable", ()=>Sortable);
|
|
|
parcelHelpers.export(exports, "Swap", ()=>SwapPlugin);
|
|
|
/**!
|
|
|
* Sortable 1.15.0
|
|
|
* @author RubaXa <trash@rubaxa.org>
|
|
|
* @author owenm <owen23355@gmail.com>
|
|
|
* @license MIT
|
|
|
*/ function ownKeys(object, enumerableOnly) {
|
|
|
var keys = Object.keys(object);
|
|
|
if (Object.getOwnPropertySymbols) {
|
|
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
|
if (enumerableOnly) symbols = symbols.filter(function(sym) {
|
|
|
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
|
});
|
|
|
keys.push.apply(keys, symbols);
|
|
|
}
|
|
|
return keys;
|
|
|
}
|
|
|
function _objectSpread2(target) {
|
|
|
for(var i = 1; i < arguments.length; i++){
|
|
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
|
if (i % 2) ownKeys(Object(source), true).forEach(function(key) {
|
|
|
_defineProperty(target, key, source[key]);
|
|
|
});
|
|
|
else if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
|
else ownKeys(Object(source)).forEach(function(key) {
|
|
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
|
});
|
|
|
}
|
|
|
return target;
|
|
|
}
|
|
|
function _typeof(obj1) {
|
|
|
"@babel/helpers - typeof";
|
|
|
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") _typeof = function(obj) {
|
|
|
return typeof obj;
|
|
|
};
|
|
|
else _typeof = function(obj) {
|
|
|
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
|
};
|
|
|
return _typeof(obj1);
|
|
|
}
|
|
|
function _defineProperty(obj, key, value) {
|
|
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
|
value: value,
|
|
|
enumerable: true,
|
|
|
configurable: true,
|
|
|
writable: true
|
|
|
});
|
|
|
else obj[key] = value;
|
|
|
return obj;
|
|
|
}
|
|
|
function _extends() {
|
|
|
_extends = Object.assign || function(target) {
|
|
|
for(var i = 1; i < arguments.length; i++){
|
|
|
var source = arguments[i];
|
|
|
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
|
}
|
|
|
return target;
|
|
|
};
|
|
|
return _extends.apply(this, arguments);
|
|
|
}
|
|
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
if (source == null) return {};
|
|
|
var target = {};
|
|
|
var sourceKeys = Object.keys(source);
|
|
|
var key, i;
|
|
|
for(i = 0; i < sourceKeys.length; i++){
|
|
|
key = sourceKeys[i];
|
|
|
if (excluded.indexOf(key) >= 0) continue;
|
|
|
target[key] = source[key];
|
|
|
}
|
|
|
return target;
|
|
|
}
|
|
|
function _objectWithoutProperties(source, excluded) {
|
|
|
if (source == null) return {};
|
|
|
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
|
var key, i;
|
|
|
if (Object.getOwnPropertySymbols) {
|
|
|
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
|
for(i = 0; i < sourceSymbolKeys.length; i++){
|
|
|
key = sourceSymbolKeys[i];
|
|
|
if (excluded.indexOf(key) >= 0) continue;
|
|
|
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
|
target[key] = source[key];
|
|
|
}
|
|
|
}
|
|
|
return target;
|
|
|
}
|
|
|
function _toConsumableArray(arr) {
|
|
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
|
}
|
|
|
function _arrayWithoutHoles(arr) {
|
|
|
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
|
}
|
|
|
function _iterableToArray(iter) {
|
|
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
|
}
|
|
|
function _unsupportedIterableToArray(o, minLen) {
|
|
|
if (!o) return;
|
|
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
|
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
|
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
|
if (n === "Map" || n === "Set") return Array.from(o);
|
|
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
|
}
|
|
|
function _arrayLikeToArray(arr, len) {
|
|
|
if (len == null || len > arr.length) len = arr.length;
|
|
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
|
return arr2;
|
|
|
}
|
|
|
function _nonIterableSpread() {
|
|
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
|
}
|
|
|
var version = "1.15.0";
|
|
|
function userAgent(pattern) {
|
|
|
if (typeof window !== "undefined" && window.navigator) return !!/*@__PURE__*/ navigator.userAgent.match(pattern);
|
|
|
}
|
|
|
var IE11OrLess = userAgent(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i);
|
|
|
var Edge = userAgent(/Edge/i);
|
|
|
var FireFox = userAgent(/firefox/i);
|
|
|
var Safari = userAgent(/safari/i) && !userAgent(/chrome/i) && !userAgent(/android/i);
|
|
|
var IOS = userAgent(/iP(ad|od|hone)/i);
|
|
|
var ChromeForAndroid = userAgent(/chrome/i) && userAgent(/android/i);
|
|
|
var captureMode = {
|
|
|
capture: false,
|
|
|
passive: false
|
|
|
};
|
|
|
function on(el, event, fn) {
|
|
|
el.addEventListener(event, fn, !IE11OrLess && captureMode);
|
|
|
}
|
|
|
function off(el, event, fn) {
|
|
|
el.removeEventListener(event, fn, !IE11OrLess && captureMode);
|
|
|
}
|
|
|
function matches(/**HTMLElement*/ el, /**String*/ selector) {
|
|
|
if (!selector) return;
|
|
|
selector[0] === ">" && (selector = selector.substring(1));
|
|
|
if (el) try {
|
|
|
if (el.matches) return el.matches(selector);
|
|
|
else if (el.msMatchesSelector) return el.msMatchesSelector(selector);
|
|
|
else if (el.webkitMatchesSelector) return el.webkitMatchesSelector(selector);
|
|
|
} catch (_) {
|
|
|
return false;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
function getParentOrHost(el) {
|
|
|
return el.host && el !== document && el.host.nodeType ? el.host : el.parentNode;
|
|
|
}
|
|
|
function closest(/**HTMLElement*/ el, /**String*/ selector, /**HTMLElement*/ ctx, includeCTX) {
|
|
|
if (el) {
|
|
|
ctx = ctx || document;
|
|
|
do {
|
|
|
if (selector != null && (selector[0] === ">" ? el.parentNode === ctx && matches(el, selector) : matches(el, selector)) || includeCTX && el === ctx) return el;
|
|
|
if (el === ctx) break;
|
|
|
/* jshint boss:true */ }while (el = getParentOrHost(el));
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
var R_SPACE = /\s+/g;
|
|
|
function toggleClass(el, name, state) {
|
|
|
if (el && name) {
|
|
|
if (el.classList) el.classList[state ? "add" : "remove"](name);
|
|
|
else {
|
|
|
var className = (" " + el.className + " ").replace(R_SPACE, " ").replace(" " + name + " ", " ");
|
|
|
el.className = (className + (state ? " " + name : "")).replace(R_SPACE, " ");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
function css(el, prop, val) {
|
|
|
var style = el && el.style;
|
|
|
if (style) {
|
|
|
if (val === void 0) {
|
|
|
if (document.defaultView && document.defaultView.getComputedStyle) val = document.defaultView.getComputedStyle(el, "");
|
|
|
else if (el.currentStyle) val = el.currentStyle;
|
|
|
return prop === void 0 ? val : val[prop];
|
|
|
} else {
|
|
|
if (!(prop in style) && prop.indexOf("webkit") === -1) prop = "-webkit-" + prop;
|
|
|
style[prop] = val + (typeof val === "string" ? "" : "px");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
function matrix(el, selfOnly) {
|
|
|
var appliedTransforms = "";
|
|
|
if (typeof el === "string") appliedTransforms = el;
|
|
|
else do {
|
|
|
var transform = css(el, "transform");
|
|
|
if (transform && transform !== "none") appliedTransforms = transform + " " + appliedTransforms;
|
|
|
/* jshint boss:true */ }while (!selfOnly && (el = el.parentNode));
|
|
|
var matrixFn = window.DOMMatrix || window.WebKitCSSMatrix || window.CSSMatrix || window.MSCSSMatrix;
|
|
|
/*jshint -W056 */ return matrixFn && new matrixFn(appliedTransforms);
|
|
|
}
|
|
|
function find(ctx, tagName, iterator) {
|
|
|
if (ctx) {
|
|
|
var list = ctx.getElementsByTagName(tagName), i = 0, n = list.length;
|
|
|
if (iterator) for(; i < n; i++)iterator(list[i], i);
|
|
|
return list;
|
|
|
}
|
|
|
return [];
|
|
|
}
|
|
|
function getWindowScrollingElement() {
|
|
|
var scrollingElement = document.scrollingElement;
|
|
|
if (scrollingElement) return scrollingElement;
|
|
|
else return document.documentElement;
|
|
|
}
|
|
|
/**
|
|
|
* Returns the "bounding client rect" of given element
|
|
|
* @param {HTMLElement} el The element whose boundingClientRect is wanted
|
|
|
* @param {[Boolean]} relativeToContainingBlock Whether the rect should be relative to the containing block of (including) the container
|
|
|
* @param {[Boolean]} relativeToNonStaticParent Whether the rect should be relative to the relative parent of (including) the contaienr
|
|
|
* @param {[Boolean]} undoScale Whether the container's scale() should be undone
|
|
|
* @param {[HTMLElement]} container The parent the element will be placed in
|
|
|
* @return {Object} The boundingClientRect of el, with specified adjustments
|
|
|
*/ function getRect(el, relativeToContainingBlock, relativeToNonStaticParent, undoScale, container) {
|
|
|
if (!el.getBoundingClientRect && el !== window) return;
|
|
|
var elRect, top, left, bottom, right, height, width;
|
|
|
if (el !== window && el.parentNode && el !== getWindowScrollingElement()) {
|
|
|
elRect = el.getBoundingClientRect();
|
|
|
top = elRect.top;
|
|
|
left = elRect.left;
|
|
|
bottom = elRect.bottom;
|
|
|
right = elRect.right;
|
|
|
height = elRect.height;
|
|
|
width = elRect.width;
|
|
|
} else {
|
|
|
top = 0;
|
|
|
left = 0;
|
|
|
bottom = window.innerHeight;
|
|
|
right = window.innerWidth;
|
|
|
height = window.innerHeight;
|
|
|
width = window.innerWidth;
|
|
|
}
|
|
|
if ((relativeToContainingBlock || relativeToNonStaticParent) && el !== window) {
|
|
|
// Adjust for translate()
|
|
|
container = container || el.parentNode; // solves #1123 (see: https://stackoverflow.com/a/37953806/6088312)
|
|
|
// Not needed on <= IE11
|
|
|
if (!IE11OrLess) {
|
|
|
do if (container && container.getBoundingClientRect && (css(container, "transform") !== "none" || relativeToNonStaticParent && css(container, "position") !== "static")) {
|
|
|
var containerRect = container.getBoundingClientRect(); // Set relative to edges of padding box of container
|
|
|
top -= containerRect.top + parseInt(css(container, "border-top-width"));
|
|
|
left -= containerRect.left + parseInt(css(container, "border-left-width"));
|
|
|
bottom = top + elRect.height;
|
|
|
right = left + elRect.width;
|
|
|
break;
|
|
|
}
|
|
|
while (container = container.parentNode);
|
|
|
}
|
|
|
}
|
|
|
if (undoScale && el !== window) {
|
|
|
// Adjust for scale()
|
|
|
var elMatrix = matrix(container || el), scaleX = elMatrix && elMatrix.a, scaleY = elMatrix && elMatrix.d;
|
|
|
if (elMatrix) {
|
|
|
top /= scaleY;
|
|
|
left /= scaleX;
|
|
|
width /= scaleX;
|
|
|
height /= scaleY;
|
|
|
bottom = top + height;
|
|
|
right = left + width;
|
|
|
}
|
|
|
}
|
|
|
return {
|
|
|
top: top,
|
|
|
left: left,
|
|
|
bottom: bottom,
|
|
|
right: right,
|
|
|
width: width,
|
|
|
height: height
|
|
|
};
|
|
|
}
|
|
|
/**
|
|
|
* Checks if a side of an element is scrolled past a side of its parents
|
|
|
* @param {HTMLElement} el The element who's side being scrolled out of view is in question
|
|
|
* @param {String} elSide Side of the element in question ('top', 'left', 'right', 'bottom')
|
|
|
* @param {String} parentSide Side of the parent in question ('top', 'left', 'right', 'bottom')
|
|
|
* @return {HTMLElement} The parent scroll element that the el's side is scrolled past, or null if there is no such element
|
|
|
*/ function isScrolledPast(el, elSide, parentSide) {
|
|
|
var parent = getParentAutoScrollElement(el, true), elSideVal = getRect(el)[elSide];
|
|
|
/* jshint boss:true */ while(parent){
|
|
|
var parentSideVal = getRect(parent)[parentSide], visible = void 0;
|
|
|
if (parentSide === "top" || parentSide === "left") visible = elSideVal >= parentSideVal;
|
|
|
else visible = elSideVal <= parentSideVal;
|
|
|
if (!visible) return parent;
|
|
|
if (parent === getWindowScrollingElement()) break;
|
|
|
parent = getParentAutoScrollElement(parent, false);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
/**
|
|
|
* Gets nth child of el, ignoring hidden children, sortable's elements (does not ignore clone if it's visible)
|
|
|
* and non-draggable elements
|
|
|
* @param {HTMLElement} el The parent element
|
|
|
* @param {Number} childNum The index of the child
|
|
|
* @param {Object} options Parent Sortable's options
|
|
|
* @return {HTMLElement} The child at index childNum, or null if not found
|
|
|
*/ function getChild(el, childNum, options, includeDragEl) {
|
|
|
var currentChild = 0, i = 0, children = el.children;
|
|
|
while(i < children.length){
|
|
|
if (children[i].style.display !== "none" && children[i] !== Sortable.ghost && (includeDragEl || children[i] !== Sortable.dragged) && closest(children[i], options.draggable, el, false)) {
|
|
|
if (currentChild === childNum) return children[i];
|
|
|
currentChild++;
|
|
|
}
|
|
|
i++;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
/**
|
|
|
* Gets the last child in the el, ignoring ghostEl or invisible elements (clones)
|
|
|
* @param {HTMLElement} el Parent element
|
|
|
* @param {selector} selector Any other elements that should be ignored
|
|
|
* @return {HTMLElement} The last child, ignoring ghostEl
|
|
|
*/ function lastChild(el, selector) {
|
|
|
var last = el.lastElementChild;
|
|
|
while(last && (last === Sortable.ghost || css(last, "display") === "none" || selector && !matches(last, selector)))last = last.previousElementSibling;
|
|
|
return last || null;
|
|
|
}
|
|
|
/**
|
|
|
* Returns the index of an element within its parent for a selected set of
|
|
|
* elements
|
|
|
* @param {HTMLElement} el
|
|
|
* @param {selector} selector
|
|
|
* @return {number}
|
|
|
*/ function index(el, selector) {
|
|
|
var index1 = 0;
|
|
|
if (!el || !el.parentNode) return -1;
|
|
|
/* jshint boss:true */ while(el = el.previousElementSibling)if (el.nodeName.toUpperCase() !== "TEMPLATE" && el !== Sortable.clone && (!selector || matches(el, selector))) index1++;
|
|
|
return index1;
|
|
|
}
|
|
|
/**
|
|
|
* Returns the scroll offset of the given element, added with all the scroll offsets of parent elements.
|
|
|
* The value is returned in real pixels.
|
|
|
* @param {HTMLElement} el
|
|
|
* @return {Array} Offsets in the format of [left, top]
|
|
|
*/ function getRelativeScrollOffset(el) {
|
|
|
var offsetLeft = 0, offsetTop = 0, winScroller = getWindowScrollingElement();
|
|
|
if (el) do {
|
|
|
var elMatrix = matrix(el), scaleX = elMatrix.a, scaleY = elMatrix.d;
|
|
|
offsetLeft += el.scrollLeft * scaleX;
|
|
|
offsetTop += el.scrollTop * scaleY;
|
|
|
}while (el !== winScroller && (el = el.parentNode));
|
|
|
return [
|
|
|
offsetLeft,
|
|
|
offsetTop
|
|
|
];
|
|
|
}
|
|
|
/**
|
|
|
* Returns the index of the object within the given array
|
|
|
* @param {Array} arr Array that may or may not hold the object
|
|
|
* @param {Object} obj An object that has a key-value pair unique to and identical to a key-value pair in the object you want to find
|
|
|
* @return {Number} The index of the object in the array, or -1
|
|
|
*/ function indexOfObject(arr, obj) {
|
|
|
for(var i in arr){
|
|
|
if (!arr.hasOwnProperty(i)) continue;
|
|
|
for(var key in obj){
|
|
|
if (obj.hasOwnProperty(key) && obj[key] === arr[i][key]) return Number(i);
|
|
|
}
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
function getParentAutoScrollElement(el, includeSelf) {
|
|
|
// skip to window
|
|
|
if (!el || !el.getBoundingClientRect) return getWindowScrollingElement();
|
|
|
var elem = el;
|
|
|
var gotSelf = false;
|
|
|
do // we don't need to get elem css if it isn't even overflowing in the first place (performance)
|
|
|
if (elem.clientWidth < elem.scrollWidth || elem.clientHeight < elem.scrollHeight) {
|
|
|
var elemCSS = css(elem);
|
|
|
if (elem.clientWidth < elem.scrollWidth && (elemCSS.overflowX == "auto" || elemCSS.overflowX == "scroll") || elem.clientHeight < elem.scrollHeight && (elemCSS.overflowY == "auto" || elemCSS.overflowY == "scroll")) {
|
|
|
if (!elem.getBoundingClientRect || elem === document.body) return getWindowScrollingElement();
|
|
|
if (gotSelf || includeSelf) return elem;
|
|
|
gotSelf = true;
|
|
|
}
|
|
|
}
|
|
|
while (elem = elem.parentNode);
|
|
|
return getWindowScrollingElement();
|
|
|
}
|
|
|
function extend(dst, src) {
|
|
|
if (dst && src) {
|
|
|
for(var key in src)if (src.hasOwnProperty(key)) dst[key] = src[key];
|
|
|
}
|
|
|
return dst;
|
|
|
}
|
|
|
function isRectEqual(rect1, rect2) {
|
|
|
return Math.round(rect1.top) === Math.round(rect2.top) && Math.round(rect1.left) === Math.round(rect2.left) && Math.round(rect1.height) === Math.round(rect2.height) && Math.round(rect1.width) === Math.round(rect2.width);
|
|
|
}
|
|
|
var _throttleTimeout;
|
|
|
function throttle(callback, ms) {
|
|
|
return function() {
|
|
|
if (!_throttleTimeout) {
|
|
|
var args = arguments, _this = this;
|
|
|
if (args.length === 1) callback.call(_this, args[0]);
|
|
|
else callback.apply(_this, args);
|
|
|
_throttleTimeout = setTimeout(function() {
|
|
|
_throttleTimeout = void 0;
|
|
|
}, ms);
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
function cancelThrottle() {
|
|
|
clearTimeout(_throttleTimeout);
|
|
|
_throttleTimeout = void 0;
|
|
|
}
|
|
|
function scrollBy(el, x, y) {
|
|
|
el.scrollLeft += x;
|
|
|
el.scrollTop += y;
|
|
|
}
|
|
|
function clone(el) {
|
|
|
var Polymer = window.Polymer;
|
|
|
var $ = window.jQuery || window.Zepto;
|
|
|
if (Polymer && Polymer.dom) return Polymer.dom(el).cloneNode(true);
|
|
|
else if ($) return $(el).clone(true)[0];
|
|
|
else return el.cloneNode(true);
|
|
|
}
|
|
|
function setRect(el, rect) {
|
|
|
css(el, "position", "absolute");
|
|
|
css(el, "top", rect.top);
|
|
|
css(el, "left", rect.left);
|
|
|
css(el, "width", rect.width);
|
|
|
css(el, "height", rect.height);
|
|
|
}
|
|
|
function unsetRect(el) {
|
|
|
css(el, "position", "");
|
|
|
css(el, "top", "");
|
|
|
css(el, "left", "");
|
|
|
css(el, "width", "");
|
|
|
css(el, "height", "");
|
|
|
}
|
|
|
var expando = "Sortable" + new Date().getTime();
|
|
|
function AnimationStateManager() {
|
|
|
var animationStates = [], animationCallbackId;
|
|
|
return {
|
|
|
captureAnimationState: function captureAnimationState() {
|
|
|
animationStates = [];
|
|
|
if (!this.options.animation) return;
|
|
|
var children = [].slice.call(this.el.children);
|
|
|
children.forEach(function(child) {
|
|
|
if (css(child, "display") === "none" || child === Sortable.ghost) return;
|
|
|
animationStates.push({
|
|
|
target: child,
|
|
|
rect: getRect(child)
|
|
|
});
|
|
|
var fromRect = _objectSpread2({}, animationStates[animationStates.length - 1].rect); // If animating: compensate for current animation
|
|
|
if (child.thisAnimationDuration) {
|
|
|
var childMatrix = matrix(child, true);
|
|
|
if (childMatrix) {
|
|
|
fromRect.top -= childMatrix.f;
|
|
|
fromRect.left -= childMatrix.e;
|
|
|
}
|
|
|
}
|
|
|
child.fromRect = fromRect;
|
|
|
});
|
|
|
},
|
|
|
addAnimationState: function addAnimationState(state) {
|
|
|
animationStates.push(state);
|
|
|
},
|
|
|
removeAnimationState: function removeAnimationState(target) {
|
|
|
animationStates.splice(indexOfObject(animationStates, {
|
|
|
target: target
|
|
|
}), 1);
|
|
|
},
|
|
|
animateAll: function animateAll(callback) {
|
|
|
var _this = this;
|
|
|
if (!this.options.animation) {
|
|
|
clearTimeout(animationCallbackId);
|
|
|
if (typeof callback === "function") callback();
|
|
|
return;
|
|
|
}
|
|
|
var animating = false, animationTime = 0;
|
|
|
animationStates.forEach(function(state) {
|
|
|
var time = 0, target = state.target, fromRect = target.fromRect, toRect = getRect(target), prevFromRect = target.prevFromRect, prevToRect = target.prevToRect, animatingRect = state.rect, targetMatrix = matrix(target, true);
|
|
|
if (targetMatrix) {
|
|
|
// Compensate for current animation
|
|
|
toRect.top -= targetMatrix.f;
|
|
|
toRect.left -= targetMatrix.e;
|
|
|
}
|
|
|
target.toRect = toRect;
|
|
|
if (target.thisAnimationDuration) // Could also check if animatingRect is between fromRect and toRect
|
|
|
{
|
|
|
if (isRectEqual(prevFromRect, toRect) && !isRectEqual(fromRect, toRect) && (animatingRect.top - toRect.top) / (animatingRect.left - toRect.left) === (fromRect.top - toRect.top) / (fromRect.left - toRect.left)) // If returning to same place as started from animation and on same axis
|
|
|
time = calculateRealTime(animatingRect, prevFromRect, prevToRect, _this.options);
|
|
|
} // if fromRect != toRect: animate
|
|
|
if (!isRectEqual(toRect, fromRect)) {
|
|
|
target.prevFromRect = fromRect;
|
|
|
target.prevToRect = toRect;
|
|
|
if (!time) time = _this.options.animation;
|
|
|
_this.animate(target, animatingRect, toRect, time);
|
|
|
}
|
|
|
if (time) {
|
|
|
animating = true;
|
|
|
animationTime = Math.max(animationTime, time);
|
|
|
clearTimeout(target.animationResetTimer);
|
|
|
target.animationResetTimer = setTimeout(function() {
|
|
|
target.animationTime = 0;
|
|
|
target.prevFromRect = null;
|
|
|
target.fromRect = null;
|
|
|
target.prevToRect = null;
|
|
|
target.thisAnimationDuration = null;
|
|
|
}, time);
|
|
|
target.thisAnimationDuration = time;
|
|
|
}
|
|
|
});
|
|
|
clearTimeout(animationCallbackId);
|
|
|
if (!animating) {
|
|
|
if (typeof callback === "function") callback();
|
|
|
} else animationCallbackId = setTimeout(function() {
|
|
|
if (typeof callback === "function") callback();
|
|
|
}, animationTime);
|
|
|
animationStates = [];
|
|
|
},
|
|
|
animate: function animate(target, currentRect, toRect, duration) {
|
|
|
if (duration) {
|
|
|
css(target, "transition", "");
|
|
|
css(target, "transform", "");
|
|
|
var elMatrix = matrix(this.el), scaleX = elMatrix && elMatrix.a, scaleY = elMatrix && elMatrix.d, translateX = (currentRect.left - toRect.left) / (scaleX || 1), translateY = (currentRect.top - toRect.top) / (scaleY || 1);
|
|
|
target.animatingX = !!translateX;
|
|
|
target.animatingY = !!translateY;
|
|
|
css(target, "transform", "translate3d(" + translateX + "px," + translateY + "px,0)");
|
|
|
this.forRepaintDummy = repaint(target); // repaint
|
|
|
css(target, "transition", "transform " + duration + "ms" + (this.options.easing ? " " + this.options.easing : ""));
|
|
|
css(target, "transform", "translate3d(0,0,0)");
|
|
|
typeof target.animated === "number" && clearTimeout(target.animated);
|
|
|
target.animated = setTimeout(function() {
|
|
|
css(target, "transition", "");
|
|
|
css(target, "transform", "");
|
|
|
target.animated = false;
|
|
|
target.animatingX = false;
|
|
|
target.animatingY = false;
|
|
|
}, duration);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
function repaint(target) {
|
|
|
return target.offsetWidth;
|
|
|
}
|
|
|
function calculateRealTime(animatingRect, fromRect, toRect, options) {
|
|
|
return Math.sqrt(Math.pow(fromRect.top - animatingRect.top, 2) + Math.pow(fromRect.left - animatingRect.left, 2)) / Math.sqrt(Math.pow(fromRect.top - toRect.top, 2) + Math.pow(fromRect.left - toRect.left, 2)) * options.animation;
|
|
|
}
|
|
|
var plugins = [];
|
|
|
var defaults = {
|
|
|
initializeByDefault: true
|
|
|
};
|
|
|
var PluginManager = {
|
|
|
mount: function mount(plugin) {
|
|
|
// Set default static properties
|
|
|
for(var option in defaults)if (defaults.hasOwnProperty(option) && !(option in plugin)) plugin[option] = defaults[option];
|
|
|
plugins.forEach(function(p) {
|
|
|
if (p.pluginName === plugin.pluginName) throw "Sortable: Cannot mount plugin ".concat(plugin.pluginName, " more than once");
|
|
|
});
|
|
|
plugins.push(plugin);
|
|
|
},
|
|
|
pluginEvent: function pluginEvent(eventName, sortable, evt) {
|
|
|
var _this = this;
|
|
|
this.eventCanceled = false;
|
|
|
evt.cancel = function() {
|
|
|
_this.eventCanceled = true;
|
|
|
};
|
|
|
var eventNameGlobal = eventName + "Global";
|
|
|
plugins.forEach(function(plugin) {
|
|
|
if (!sortable[plugin.pluginName]) return; // Fire global events if it exists in this sortable
|
|
|
if (sortable[plugin.pluginName][eventNameGlobal]) sortable[plugin.pluginName][eventNameGlobal](_objectSpread2({
|
|
|
sortable: sortable
|
|
|
}, evt));
|
|
|
// Only fire plugin event if plugin is enabled in this sortable,
|
|
|
// and plugin has event defined
|
|
|
if (sortable.options[plugin.pluginName] && sortable[plugin.pluginName][eventName]) sortable[plugin.pluginName][eventName](_objectSpread2({
|
|
|
sortable: sortable
|
|
|
}, evt));
|
|
|
});
|
|
|
},
|
|
|
initializePlugins: function initializePlugins(sortable, el, defaults1, options) {
|
|
|
plugins.forEach(function(plugin) {
|
|
|
var pluginName = plugin.pluginName;
|
|
|
if (!sortable.options[pluginName] && !plugin.initializeByDefault) return;
|
|
|
var initialized = new plugin(sortable, el, sortable.options);
|
|
|
initialized.sortable = sortable;
|
|
|
initialized.options = sortable.options;
|
|
|
sortable[pluginName] = initialized; // Add default options from plugin
|
|
|
_extends(defaults1, initialized.defaults);
|
|
|
});
|
|
|
for(var option in sortable.options){
|
|
|
if (!sortable.options.hasOwnProperty(option)) continue;
|
|
|
var modified = this.modifyOption(sortable, option, sortable.options[option]);
|
|
|
if (typeof modified !== "undefined") sortable.options[option] = modified;
|
|
|
}
|
|
|
},
|
|
|
getEventProperties: function getEventProperties(name, sortable) {
|
|
|
var eventProperties = {};
|
|
|
plugins.forEach(function(plugin) {
|
|
|
if (typeof plugin.eventProperties !== "function") return;
|
|
|
_extends(eventProperties, plugin.eventProperties.call(sortable[plugin.pluginName], name));
|
|
|
});
|
|
|
return eventProperties;
|
|
|
},
|
|
|
modifyOption: function modifyOption(sortable, name, value) {
|
|
|
var modifiedValue;
|
|
|
plugins.forEach(function(plugin) {
|
|
|
// Plugin must exist on the Sortable
|
|
|
if (!sortable[plugin.pluginName]) return; // If static option listener exists for this option, call in the context of the Sortable's instance of this plugin
|
|
|
if (plugin.optionListeners && typeof plugin.optionListeners[name] === "function") modifiedValue = plugin.optionListeners[name].call(sortable[plugin.pluginName], value);
|
|
|
});
|
|
|
return modifiedValue;
|
|
|
}
|
|
|
};
|
|
|
function dispatchEvent(_ref) {
|
|
|
var sortable = _ref.sortable, rootEl1 = _ref.rootEl, name = _ref.name, targetEl = _ref.targetEl, cloneEl1 = _ref.cloneEl, toEl = _ref.toEl, fromEl = _ref.fromEl, oldIndex1 = _ref.oldIndex, newIndex1 = _ref.newIndex, oldDraggableIndex1 = _ref.oldDraggableIndex, newDraggableIndex1 = _ref.newDraggableIndex, originalEvent = _ref.originalEvent, putSortable1 = _ref.putSortable, extraEventProperties = _ref.extraEventProperties;
|
|
|
sortable = sortable || rootEl1 && rootEl1[expando];
|
|
|
if (!sortable) return;
|
|
|
var evt, options = sortable.options, onName = "on" + name.charAt(0).toUpperCase() + name.substr(1); // Support for new CustomEvent feature
|
|
|
if (window.CustomEvent && !IE11OrLess && !Edge) evt = new CustomEvent(name, {
|
|
|
bubbles: true,
|
|
|
cancelable: true
|
|
|
});
|
|
|
else {
|
|
|
evt = document.createEvent("Event");
|
|
|
evt.initEvent(name, true, true);
|
|
|
}
|
|
|
evt.to = toEl || rootEl1;
|
|
|
evt.from = fromEl || rootEl1;
|
|
|
evt.item = targetEl || rootEl1;
|
|
|
evt.clone = cloneEl1;
|
|
|
evt.oldIndex = oldIndex1;
|
|
|
evt.newIndex = newIndex1;
|
|
|
evt.oldDraggableIndex = oldDraggableIndex1;
|
|
|
evt.newDraggableIndex = newDraggableIndex1;
|
|
|
evt.originalEvent = originalEvent;
|
|
|
evt.pullMode = putSortable1 ? putSortable1.lastPutMode : undefined;
|
|
|
var allEventProperties = _objectSpread2(_objectSpread2({}, extraEventProperties), PluginManager.getEventProperties(name, sortable));
|
|
|
for(var option in allEventProperties)evt[option] = allEventProperties[option];
|
|
|
if (rootEl1) rootEl1.dispatchEvent(evt);
|
|
|
if (options[onName]) options[onName].call(sortable, evt);
|
|
|
}
|
|
|
var _excluded = [
|
|
|
"evt"
|
|
|
];
|
|
|
var pluginEvent = function pluginEvent(eventName, sortable) {
|
|
|
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, originalEvent = _ref.evt, data = _objectWithoutProperties(_ref, _excluded);
|
|
|
PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread2({
|
|
|
dragEl: dragEl,
|
|
|
parentEl: parentEl,
|
|
|
ghostEl: ghostEl,
|
|
|
rootEl: rootEl,
|
|
|
nextEl: nextEl,
|
|
|
lastDownEl: lastDownEl,
|
|
|
cloneEl: cloneEl,
|
|
|
cloneHidden: cloneHidden,
|
|
|
dragStarted: moved,
|
|
|
putSortable: putSortable,
|
|
|
activeSortable: Sortable.active,
|
|
|
originalEvent: originalEvent,
|
|
|
oldIndex: oldIndex,
|
|
|
oldDraggableIndex: oldDraggableIndex,
|
|
|
newIndex: newIndex,
|
|
|
newDraggableIndex: newDraggableIndex,
|
|
|
hideGhostForTarget: _hideGhostForTarget,
|
|
|
unhideGhostForTarget: _unhideGhostForTarget,
|
|
|
cloneNowHidden: function cloneNowHidden() {
|
|
|
cloneHidden = true;
|
|
|
},
|
|
|
cloneNowShown: function cloneNowShown() {
|
|
|
cloneHidden = false;
|
|
|
},
|
|
|
dispatchSortableEvent: function dispatchSortableEvent(name) {
|
|
|
_dispatchEvent({
|
|
|
sortable: sortable,
|
|
|
name: name,
|
|
|
originalEvent: originalEvent
|
|
|
});
|
|
|
}
|
|
|
}, data));
|
|
|
};
|
|
|
function _dispatchEvent(info) {
|
|
|
dispatchEvent(_objectSpread2({
|
|
|
putSortable: putSortable,
|
|
|
cloneEl: cloneEl,
|
|
|
targetEl: dragEl,
|
|
|
rootEl: rootEl,
|
|
|
oldIndex: oldIndex,
|
|
|
oldDraggableIndex: oldDraggableIndex,
|
|
|
newIndex: newIndex,
|
|
|
newDraggableIndex: newDraggableIndex
|
|
|
}, info));
|
|
|
}
|
|
|
var dragEl, parentEl, ghostEl, rootEl, nextEl, lastDownEl, cloneEl, cloneHidden, oldIndex, newIndex, oldDraggableIndex, newDraggableIndex, activeGroup, putSortable, awaitingDragStarted = false, ignoreNextClick = false, sortables = [], tapEvt, touchEvt, lastDx, lastDy, tapDistanceLeft, tapDistanceTop, moved, lastTarget, lastDirection, pastFirstInvertThresh = false, isCircumstantialInvert = false, targetMoveDistance, // For positioning ghost absolutely
|
|
|
ghostRelativeParent, ghostRelativeParentInitialScroll = [], // (left, top)
|
|
|
_silent = false, savedInputChecked = [];
|
|
|
/** @const */ var documentExists = typeof document !== "undefined", PositionGhostAbsolutely = IOS, CSSFloatProperty = Edge || IE11OrLess ? "cssFloat" : "float", // This will not pass for IE9, because IE9 DnD only works on anchors
|
|
|
supportDraggable = documentExists && !ChromeForAndroid && !IOS && "draggable" in document.createElement("div"), supportCssPointerEvents = function() {
|
|
|
if (!documentExists) return; // false when <= IE11
|
|
|
if (IE11OrLess) return false;
|
|
|
var el = document.createElement("x");
|
|
|
el.style.cssText = "pointer-events:auto";
|
|
|
return el.style.pointerEvents === "auto";
|
|
|
}(), _detectDirection = function _detectDirection(el, options) {
|
|
|
var elCSS = css(el), elWidth = parseInt(elCSS.width) - parseInt(elCSS.paddingLeft) - parseInt(elCSS.paddingRight) - parseInt(elCSS.borderLeftWidth) - parseInt(elCSS.borderRightWidth), child1 = getChild(el, 0, options), child2 = getChild(el, 1, options), firstChildCSS = child1 && css(child1), secondChildCSS = child2 && css(child2), firstChildWidth = firstChildCSS && parseInt(firstChildCSS.marginLeft) + parseInt(firstChildCSS.marginRight) + getRect(child1).width, secondChildWidth = secondChildCSS && parseInt(secondChildCSS.marginLeft) + parseInt(secondChildCSS.marginRight) + getRect(child2).width;
|
|
|
if (elCSS.display === "flex") return elCSS.flexDirection === "column" || elCSS.flexDirection === "column-reverse" ? "vertical" : "horizontal";
|
|
|
if (elCSS.display === "grid") return elCSS.gridTemplateColumns.split(" ").length <= 1 ? "vertical" : "horizontal";
|
|
|
if (child1 && firstChildCSS["float"] && firstChildCSS["float"] !== "none") {
|
|
|
var touchingSideChild2 = firstChildCSS["float"] === "left" ? "left" : "right";
|
|
|
return child2 && (secondChildCSS.clear === "both" || secondChildCSS.clear === touchingSideChild2) ? "vertical" : "horizontal";
|
|
|
}
|
|
|
return child1 && (firstChildCSS.display === "block" || firstChildCSS.display === "flex" || firstChildCSS.display === "table" || firstChildCSS.display === "grid" || firstChildWidth >= elWidth && elCSS[CSSFloatProperty] === "none" || child2 && elCSS[CSSFloatProperty] === "none" && firstChildWidth + secondChildWidth > elWidth) ? "vertical" : "horizontal";
|
|
|
}, _dragElInRowColumn = function _dragElInRowColumn(dragRect, targetRect, vertical) {
|
|
|
var dragElS1Opp = vertical ? dragRect.left : dragRect.top, dragElS2Opp = vertical ? dragRect.right : dragRect.bottom, dragElOppLength = vertical ? dragRect.width : dragRect.height, targetS1Opp = vertical ? targetRect.left : targetRect.top, targetS2Opp = vertical ? targetRect.right : targetRect.bottom, targetOppLength = vertical ? targetRect.width : targetRect.height;
|
|
|
return dragElS1Opp === targetS1Opp || dragElS2Opp === targetS2Opp || dragElS1Opp + dragElOppLength / 2 === targetS1Opp + targetOppLength / 2;
|
|
|
}, /**
|
|
|
* Detects first nearest empty sortable to X and Y position using emptyInsertThreshold.
|
|
|
* @param {Number} x X position
|
|
|
* @param {Number} y Y position
|
|
|
* @return {HTMLElement} Element of the first found nearest Sortable
|
|
|
*/ _detectNearestEmptySortable = function _detectNearestEmptySortable(x, y) {
|
|
|
var ret;
|
|
|
sortables.some(function(sortable) {
|
|
|
var threshold = sortable[expando].options.emptyInsertThreshold;
|
|
|
if (!threshold || lastChild(sortable)) return;
|
|
|
var rect = getRect(sortable), insideHorizontally = x >= rect.left - threshold && x <= rect.right + threshold, insideVertically = y >= rect.top - threshold && y <= rect.bottom + threshold;
|
|
|
if (insideHorizontally && insideVertically) return ret = sortable;
|
|
|
});
|
|
|
return ret;
|
|
|
}, _prepareGroup = function _prepareGroup(options) {
|
|
|
function toFn(value, pull) {
|
|
|
return function(to, from, dragEl1, evt) {
|
|
|
var sameGroup = to.options.group.name && from.options.group.name && to.options.group.name === from.options.group.name;
|
|
|
if (value == null && (pull || sameGroup)) // Default pull value
|
|
|
// Default pull and put value if same group
|
|
|
return true;
|
|
|
else if (value == null || value === false) return false;
|
|
|
else if (pull && value === "clone") return value;
|
|
|
else if (typeof value === "function") return toFn(value(to, from, dragEl1, evt), pull)(to, from, dragEl1, evt);
|
|
|
else {
|
|
|
var otherGroup = (pull ? to : from).options.group.name;
|
|
|
return value === true || typeof value === "string" && value === otherGroup || value.join && value.indexOf(otherGroup) > -1;
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
var group = {};
|
|
|
var originalGroup = options.group;
|
|
|
if (!originalGroup || _typeof(originalGroup) != "object") originalGroup = {
|
|
|
name: originalGroup
|
|
|
};
|
|
|
group.name = originalGroup.name;
|
|
|
group.checkPull = toFn(originalGroup.pull, true);
|
|
|
group.checkPut = toFn(originalGroup.put);
|
|
|
group.revertClone = originalGroup.revertClone;
|
|
|
options.group = group;
|
|
|
}, _hideGhostForTarget = function _hideGhostForTarget() {
|
|
|
if (!supportCssPointerEvents && ghostEl) css(ghostEl, "display", "none");
|
|
|
}, _unhideGhostForTarget = function _unhideGhostForTarget() {
|
|
|
if (!supportCssPointerEvents && ghostEl) css(ghostEl, "display", "");
|
|
|
}; // #1184 fix - Prevent click event on fallback if dragged but item not changed position
|
|
|
if (documentExists && !ChromeForAndroid) document.addEventListener("click", function(evt) {
|
|
|
if (ignoreNextClick) {
|
|
|
evt.preventDefault();
|
|
|
evt.stopPropagation && evt.stopPropagation();
|
|
|
evt.stopImmediatePropagation && evt.stopImmediatePropagation();
|
|
|
ignoreNextClick = false;
|
|
|
return false;
|
|
|
}
|
|
|
}, true);
|
|
|
var nearestEmptyInsertDetectEvent = function nearestEmptyInsertDetectEvent(evt) {
|
|
|
if (dragEl) {
|
|
|
evt = evt.touches ? evt.touches[0] : evt;
|
|
|
var nearest = _detectNearestEmptySortable(evt.clientX, evt.clientY);
|
|
|
if (nearest) {
|
|
|
// Create imitation event
|
|
|
var event = {};
|
|
|
for(var i in evt)if (evt.hasOwnProperty(i)) event[i] = evt[i];
|
|
|
event.target = event.rootEl = nearest;
|
|
|
event.preventDefault = void 0;
|
|
|
event.stopPropagation = void 0;
|
|
|
nearest[expando]._onDragOver(event);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
var _checkOutsideTargetEl = function _checkOutsideTargetEl(evt) {
|
|
|
if (dragEl) dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
|
|
|
};
|
|
|
/**
|
|
|
* @class Sortable
|
|
|
* @param {HTMLElement} el
|
|
|
* @param {Object} [options]
|
|
|
*/ function Sortable(el, options) {
|
|
|
if (!(el && el.nodeType && el.nodeType === 1)) throw "Sortable: `el` must be an HTMLElement, not ".concat(({}).toString.call(el));
|
|
|
this.el = el; // root element
|
|
|
this.options = options = _extends({}, options); // Export instance
|
|
|
el[expando] = this;
|
|
|
var defaults2 = {
|
|
|
group: null,
|
|
|
sort: true,
|
|
|
disabled: false,
|
|
|
store: null,
|
|
|
handle: null,
|
|
|
draggable: /^[uo]l$/i.test(el.nodeName) ? ">li" : ">*",
|
|
|
swapThreshold: 1,
|
|
|
// percentage; 0 <= x <= 1
|
|
|
invertSwap: false,
|
|
|
// invert always
|
|
|
invertedSwapThreshold: null,
|
|
|
// will be set to same as swapThreshold if default
|
|
|
removeCloneOnHide: true,
|
|
|
direction: function direction() {
|
|
|
return _detectDirection(el, this.options);
|
|
|
},
|
|
|
ghostClass: "sortable-ghost",
|
|
|
chosenClass: "sortable-chosen",
|
|
|
dragClass: "sortable-drag",
|
|
|
ignore: "a, img",
|
|
|
filter: null,
|
|
|
preventOnFilter: true,
|
|
|
animation: 0,
|
|
|
easing: null,
|
|
|
setData: function setData(dataTransfer, dragEl2) {
|
|
|
dataTransfer.setData("Text", dragEl2.textContent);
|
|
|
},
|
|
|
dropBubble: false,
|
|
|
dragoverBubble: false,
|
|
|
dataIdAttr: "data-id",
|
|
|
delay: 0,
|
|
|
delayOnTouchOnly: false,
|
|
|
touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
|
|
|
forceFallback: false,
|
|
|
fallbackClass: "sortable-fallback",
|
|
|
fallbackOnBody: false,
|
|
|
fallbackTolerance: 0,
|
|
|
fallbackOffset: {
|
|
|
x: 0,
|
|
|
y: 0
|
|
|
},
|
|
|
supportPointer: Sortable.supportPointer !== false && "PointerEvent" in window && !Safari,
|
|
|
emptyInsertThreshold: 5
|
|
|
};
|
|
|
PluginManager.initializePlugins(this, el, defaults2); // Set default options
|
|
|
for(var name in defaults2)!(name in options) && (options[name] = defaults2[name]);
|
|
|
_prepareGroup(options); // Bind all private methods
|
|
|
for(var fn in this)if (fn.charAt(0) === "_" && typeof this[fn] === "function") this[fn] = this[fn].bind(this);
|
|
|
// Setup drag mode
|
|
|
this.nativeDraggable = options.forceFallback ? false : supportDraggable;
|
|
|
if (this.nativeDraggable) // Touch start threshold cannot be greater than the native dragstart threshold
|
|
|
this.options.touchStartThreshold = 1;
|
|
|
// Bind events
|
|
|
if (options.supportPointer) on(el, "pointerdown", this._onTapStart);
|
|
|
else {
|
|
|
on(el, "mousedown", this._onTapStart);
|
|
|
on(el, "touchstart", this._onTapStart);
|
|
|
}
|
|
|
if (this.nativeDraggable) {
|
|
|
on(el, "dragover", this);
|
|
|
on(el, "dragenter", this);
|
|
|
}
|
|
|
sortables.push(this.el); // Restore sorting
|
|
|
options.store && options.store.get && this.sort(options.store.get(this) || []); // Add animation state manager
|
|
|
_extends(this, AnimationStateManager());
|
|
|
}
|
|
|
Sortable.prototype = /** @lends Sortable.prototype */ {
|
|
|
constructor: Sortable,
|
|
|
_isOutsideThisEl: function _isOutsideThisEl(target) {
|
|
|
if (!this.el.contains(target) && target !== this.el) lastTarget = null;
|
|
|
},
|
|
|
_getDirection: function _getDirection(evt, target) {
|
|
|
return typeof this.options.direction === "function" ? this.options.direction.call(this, evt, target, dragEl) : this.options.direction;
|
|
|
},
|
|
|
_onTapStart: function _onTapStart(/** Event|TouchEvent */ evt) {
|
|
|
if (!evt.cancelable) return;
|
|
|
var _this = this, el = this.el, options = this.options, preventOnFilter = options.preventOnFilter, type = evt.type, touch = evt.touches && evt.touches[0] || evt.pointerType && evt.pointerType === "touch" && evt, target = (touch || evt).target, originalTarget = evt.target.shadowRoot && (evt.path && evt.path[0] || evt.composedPath && evt.composedPath()[0]) || target, filter = options.filter;
|
|
|
_saveInputCheckedState(el); // Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
|
|
|
if (dragEl) return;
|
|
|
if (/mousedown|pointerdown/.test(type) && evt.button !== 0 || options.disabled) return; // only left button and enabled
|
|
|
// cancel dnd if original target is content editable
|
|
|
if (originalTarget.isContentEditable) return;
|
|
|
// Safari ignores further event handling after mousedown
|
|
|
if (!this.nativeDraggable && Safari && target && target.tagName.toUpperCase() === "SELECT") return;
|
|
|
target = closest(target, options.draggable, el, false);
|
|
|
if (target && target.animated) return;
|
|
|
if (lastDownEl === target) // Ignoring duplicate `down`
|
|
|
return;
|
|
|
// Get the index of the dragged element within its parent
|
|
|
oldIndex = index(target);
|
|
|
oldDraggableIndex = index(target, options.draggable); // Check filter
|
|
|
if (typeof filter === "function") {
|
|
|
if (filter.call(this, evt, target, this)) {
|
|
|
_dispatchEvent({
|
|
|
sortable: _this,
|
|
|
rootEl: originalTarget,
|
|
|
name: "filter",
|
|
|
targetEl: target,
|
|
|
toEl: el,
|
|
|
fromEl: el
|
|
|
});
|
|
|
pluginEvent("filter", _this, {
|
|
|
evt: evt
|
|
|
});
|
|
|
preventOnFilter && evt.cancelable && evt.preventDefault();
|
|
|
return; // cancel dnd
|
|
|
}
|
|
|
} else if (filter) {
|
|
|
filter = filter.split(",").some(function(criteria) {
|
|
|
criteria = closest(originalTarget, criteria.trim(), el, false);
|
|
|
if (criteria) {
|
|
|
_dispatchEvent({
|
|
|
sortable: _this,
|
|
|
rootEl: criteria,
|
|
|
name: "filter",
|
|
|
targetEl: target,
|
|
|
fromEl: el,
|
|
|
toEl: el
|
|
|
});
|
|
|
pluginEvent("filter", _this, {
|
|
|
evt: evt
|
|
|
});
|
|
|
return true;
|
|
|
}
|
|
|
});
|
|
|
if (filter) {
|
|
|
preventOnFilter && evt.cancelable && evt.preventDefault();
|
|
|
return; // cancel dnd
|
|
|
}
|
|
|
}
|
|
|
if (options.handle && !closest(originalTarget, options.handle, el, false)) return;
|
|
|
// Prepare `dragstart`
|
|
|
this._prepareDragStart(evt, touch, target);
|
|
|
},
|
|
|
_prepareDragStart: function _prepareDragStart(/** Event */ evt, /** Touch */ touch, /** HTMLElement */ target) {
|
|
|
var _this = this, el = _this.el, options = _this.options, ownerDocument = el.ownerDocument, dragStartFn;
|
|
|
if (target && !dragEl && target.parentNode === el) {
|
|
|
var dragRect = getRect(target);
|
|
|
rootEl = el;
|
|
|
dragEl = target;
|
|
|
parentEl = dragEl.parentNode;
|
|
|
nextEl = dragEl.nextSibling;
|
|
|
lastDownEl = target;
|
|
|
activeGroup = options.group;
|
|
|
Sortable.dragged = dragEl;
|
|
|
tapEvt = {
|
|
|
target: dragEl,
|
|
|
clientX: (touch || evt).clientX,
|
|
|
clientY: (touch || evt).clientY
|
|
|
};
|
|
|
tapDistanceLeft = tapEvt.clientX - dragRect.left;
|
|
|
tapDistanceTop = tapEvt.clientY - dragRect.top;
|
|
|
this._lastX = (touch || evt).clientX;
|
|
|
this._lastY = (touch || evt).clientY;
|
|
|
dragEl.style["will-change"] = "all";
|
|
|
dragStartFn = function dragStartFn() {
|
|
|
pluginEvent("delayEnded", _this, {
|
|
|
evt: evt
|
|
|
});
|
|
|
if (Sortable.eventCanceled) {
|
|
|
_this._onDrop();
|
|
|
return;
|
|
|
} // Delayed drag has been triggered
|
|
|
// we can re-enable the events: touchmove/mousemove
|
|
|
_this._disableDelayedDragEvents();
|
|
|
if (!FireFox && _this.nativeDraggable) dragEl.draggable = true;
|
|
|
// Bind the events: dragstart/dragend
|
|
|
_this._triggerDragStart(evt, touch); // Drag start event
|
|
|
_dispatchEvent({
|
|
|
sortable: _this,
|
|
|
name: "choose",
|
|
|
originalEvent: evt
|
|
|
}); // Chosen item
|
|
|
toggleClass(dragEl, options.chosenClass, true);
|
|
|
}; // Disable "draggable"
|
|
|
options.ignore.split(",").forEach(function(criteria) {
|
|
|
find(dragEl, criteria.trim(), _disableDraggable);
|
|
|
});
|
|
|
on(ownerDocument, "dragover", nearestEmptyInsertDetectEvent);
|
|
|
on(ownerDocument, "mousemove", nearestEmptyInsertDetectEvent);
|
|
|
on(ownerDocument, "touchmove", nearestEmptyInsertDetectEvent);
|
|
|
on(ownerDocument, "mouseup", _this._onDrop);
|
|
|
on(ownerDocument, "touchend", _this._onDrop);
|
|
|
on(ownerDocument, "touchcancel", _this._onDrop); // Make dragEl draggable (must be before delay for FireFox)
|
|
|
if (FireFox && this.nativeDraggable) {
|
|
|
this.options.touchStartThreshold = 4;
|
|
|
dragEl.draggable = true;
|
|
|
}
|
|
|
pluginEvent("delayStart", this, {
|
|
|
evt: evt
|
|
|
}); // Delay is impossible for native DnD in Edge or IE
|
|
|
if (options.delay && (!options.delayOnTouchOnly || touch) && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
|
|
|
if (Sortable.eventCanceled) {
|
|
|
this._onDrop();
|
|
|
return;
|
|
|
} // If the user moves the pointer or let go the click or touch
|
|
|
// before the delay has been reached:
|
|
|
// disable the delayed drag
|
|
|
on(ownerDocument, "mouseup", _this._disableDelayedDrag);
|
|
|
on(ownerDocument, "touchend", _this._disableDelayedDrag);
|
|
|
on(ownerDocument, "touchcancel", _this._disableDelayedDrag);
|
|
|
on(ownerDocument, "mousemove", _this._delayedDragTouchMoveHandler);
|
|
|
on(ownerDocument, "touchmove", _this._delayedDragTouchMoveHandler);
|
|
|
options.supportPointer && on(ownerDocument, "pointermove", _this._delayedDragTouchMoveHandler);
|
|
|
_this._dragStartTimer = setTimeout(dragStartFn, options.delay);
|
|
|
} else dragStartFn();
|
|
|
}
|
|
|
},
|
|
|
_delayedDragTouchMoveHandler: function _delayedDragTouchMoveHandler(/** TouchEvent|PointerEvent **/ e) {
|
|
|
var touch = e.touches ? e.touches[0] : e;
|
|
|
if (Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) >= Math.floor(this.options.touchStartThreshold / (this.nativeDraggable && window.devicePixelRatio || 1))) this._disableDelayedDrag();
|
|
|
},
|
|
|
_disableDelayedDrag: function _disableDelayedDrag() {
|
|
|
dragEl && _disableDraggable(dragEl);
|
|
|
clearTimeout(this._dragStartTimer);
|
|
|
this._disableDelayedDragEvents();
|
|
|
},
|
|
|
_disableDelayedDragEvents: function _disableDelayedDragEvents() {
|
|
|
var ownerDocument = this.el.ownerDocument;
|
|
|
off(ownerDocument, "mouseup", this._disableDelayedDrag);
|
|
|
off(ownerDocument, "touchend", this._disableDelayedDrag);
|
|
|
off(ownerDocument, "touchcancel", this._disableDelayedDrag);
|
|
|
off(ownerDocument, "mousemove", this._delayedDragTouchMoveHandler);
|
|
|
off(ownerDocument, "touchmove", this._delayedDragTouchMoveHandler);
|
|
|
off(ownerDocument, "pointermove", this._delayedDragTouchMoveHandler);
|
|
|
},
|
|
|
_triggerDragStart: function _triggerDragStart(/** Event */ evt, /** Touch */ touch) {
|
|
|
touch = touch || evt.pointerType == "touch" && evt;
|
|
|
if (!this.nativeDraggable || touch) {
|
|
|
if (this.options.supportPointer) on(document, "pointermove", this._onTouchMove);
|
|
|
else if (touch) on(document, "touchmove", this._onTouchMove);
|
|
|
else on(document, "mousemove", this._onTouchMove);
|
|
|
} else {
|
|
|
on(dragEl, "dragend", this);
|
|
|
on(rootEl, "dragstart", this._onDragStart);
|
|
|
}
|
|
|
try {
|
|
|
if (document.selection) // Timeout neccessary for IE9
|
|
|
_nextTick(function() {
|
|
|
document.selection.empty();
|
|
|
});
|
|
|
else window.getSelection().removeAllRanges();
|
|
|
} catch (err) {}
|
|
|
},
|
|
|
_dragStarted: function _dragStarted(fallback, evt) {
|
|
|
awaitingDragStarted = false;
|
|
|
if (rootEl && dragEl) {
|
|
|
pluginEvent("dragStarted", this, {
|
|
|
evt: evt
|
|
|
});
|
|
|
if (this.nativeDraggable) on(document, "dragover", _checkOutsideTargetEl);
|
|
|
var options = this.options; // Apply effect
|
|
|
!fallback && toggleClass(dragEl, options.dragClass, false);
|
|
|
toggleClass(dragEl, options.ghostClass, true);
|
|
|
Sortable.active = this;
|
|
|
fallback && this._appendGhost(); // Drag start event
|
|
|
_dispatchEvent({
|
|
|
sortable: this,
|
|
|
name: "start",
|
|
|
originalEvent: evt
|
|
|
});
|
|
|
} else this._nulling();
|
|
|
},
|
|
|
_emulateDragOver: function _emulateDragOver() {
|
|
|
if (touchEvt) {
|
|
|
this._lastX = touchEvt.clientX;
|
|
|
this._lastY = touchEvt.clientY;
|
|
|
_hideGhostForTarget();
|
|
|
var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
|
|
|
var parent = target;
|
|
|
while(target && target.shadowRoot){
|
|
|
target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
|
|
|
if (target === parent) break;
|
|
|
parent = target;
|
|
|
}
|
|
|
dragEl.parentNode[expando]._isOutsideThisEl(target);
|
|
|
if (parent) do {
|
|
|
if (parent[expando]) {
|
|
|
var inserted = void 0;
|
|
|
inserted = parent[expando]._onDragOver({
|
|
|
clientX: touchEvt.clientX,
|
|
|
clientY: touchEvt.clientY,
|
|
|
target: target,
|
|
|
rootEl: parent
|
|
|
});
|
|
|
if (inserted && !this.options.dragoverBubble) break;
|
|
|
}
|
|
|
target = parent; // store last element
|
|
|
}while (parent = parent.parentNode);
|
|
|
_unhideGhostForTarget();
|
|
|
}
|
|
|
},
|
|
|
_onTouchMove: function _onTouchMove(/**TouchEvent*/ evt) {
|
|
|
if (tapEvt) {
|
|
|
var options = this.options, fallbackTolerance = options.fallbackTolerance, fallbackOffset = options.fallbackOffset, touch = evt.touches ? evt.touches[0] : evt, ghostMatrix = ghostEl && matrix(ghostEl, true), scaleX = ghostEl && ghostMatrix && ghostMatrix.a, scaleY = ghostEl && ghostMatrix && ghostMatrix.d, relativeScrollOffset = PositionGhostAbsolutely && ghostRelativeParent && getRelativeScrollOffset(ghostRelativeParent), dx = (touch.clientX - tapEvt.clientX + fallbackOffset.x) / (scaleX || 1) + (relativeScrollOffset ? relativeScrollOffset[0] - ghostRelativeParentInitialScroll[0] : 0) / (scaleX || 1), dy = (touch.clientY - tapEvt.clientY + fallbackOffset.y) / (scaleY || 1) + (relativeScrollOffset ? relativeScrollOffset[1] - ghostRelativeParentInitialScroll[1] : 0) / (scaleY || 1); // only set the status to dragging, when we are actually dragging
|
|
|
if (!Sortable.active && !awaitingDragStarted) {
|
|
|
if (fallbackTolerance && Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) < fallbackTolerance) return;
|
|
|
this._onDragStart(evt, true);
|
|
|
}
|
|
|
if (ghostEl) {
|
|
|
if (ghostMatrix) {
|
|
|
ghostMatrix.e += dx - (lastDx || 0);
|
|
|
ghostMatrix.f += dy - (lastDy || 0);
|
|
|
} else ghostMatrix = {
|
|
|
a: 1,
|
|
|
b: 0,
|
|
|
c: 0,
|
|
|
d: 1,
|
|
|
e: dx,
|
|
|
f: dy
|
|
|
};
|
|
|
var cssMatrix = "matrix(".concat(ghostMatrix.a, ",").concat(ghostMatrix.b, ",").concat(ghostMatrix.c, ",").concat(ghostMatrix.d, ",").concat(ghostMatrix.e, ",").concat(ghostMatrix.f, ")");
|
|
|
css(ghostEl, "webkitTransform", cssMatrix);
|
|
|
css(ghostEl, "mozTransform", cssMatrix);
|
|
|
css(ghostEl, "msTransform", cssMatrix);
|
|
|
css(ghostEl, "transform", cssMatrix);
|
|
|
lastDx = dx;
|
|
|
lastDy = dy;
|
|
|
touchEvt = touch;
|
|
|
}
|
|
|
evt.cancelable && evt.preventDefault();
|
|
|
}
|
|
|
},
|
|
|
_appendGhost: function _appendGhost() {
|
|
|
// Bug if using scale(): https://stackoverflow.com/questions/2637058
|
|
|
// Not being adjusted for
|
|
|
if (!ghostEl) {
|
|
|
var container = this.options.fallbackOnBody ? document.body : rootEl, rect = getRect(dragEl, true, PositionGhostAbsolutely, true, container), options = this.options; // Position absolutely
|
|
|
if (PositionGhostAbsolutely) {
|
|
|
// Get relatively positioned parent
|
|
|
ghostRelativeParent = container;
|
|
|
while(css(ghostRelativeParent, "position") === "static" && css(ghostRelativeParent, "transform") === "none" && ghostRelativeParent !== document)ghostRelativeParent = ghostRelativeParent.parentNode;
|
|
|
if (ghostRelativeParent !== document.body && ghostRelativeParent !== document.documentElement) {
|
|
|
if (ghostRelativeParent === document) ghostRelativeParent = getWindowScrollingElement();
|
|
|
rect.top += ghostRelativeParent.scrollTop;
|
|
|
rect.left += ghostRelativeParent.scrollLeft;
|
|
|
} else ghostRelativeParent = getWindowScrollingElement();
|
|
|
ghostRelativeParentInitialScroll = getRelativeScrollOffset(ghostRelativeParent);
|
|
|
}
|
|
|
ghostEl = dragEl.cloneNode(true);
|
|
|
toggleClass(ghostEl, options.ghostClass, false);
|
|
|
toggleClass(ghostEl, options.fallbackClass, true);
|
|
|
toggleClass(ghostEl, options.dragClass, true);
|
|
|
css(ghostEl, "transition", "");
|
|
|
css(ghostEl, "transform", "");
|
|
|
css(ghostEl, "box-sizing", "border-box");
|
|
|
css(ghostEl, "margin", 0);
|
|
|
css(ghostEl, "top", rect.top);
|
|
|
css(ghostEl, "left", rect.left);
|
|
|
css(ghostEl, "width", rect.width);
|
|
|
css(ghostEl, "height", rect.height);
|
|
|
css(ghostEl, "opacity", "0.8");
|
|
|
css(ghostEl, "position", PositionGhostAbsolutely ? "absolute" : "fixed");
|
|
|
css(ghostEl, "zIndex", "100000");
|
|
|
css(ghostEl, "pointerEvents", "none");
|
|
|
Sortable.ghost = ghostEl;
|
|
|
container.appendChild(ghostEl); // Set transform-origin
|
|
|
css(ghostEl, "transform-origin", tapDistanceLeft / parseInt(ghostEl.style.width) * 100 + "% " + tapDistanceTop / parseInt(ghostEl.style.height) * 100 + "%");
|
|
|
}
|
|
|
},
|
|
|
_onDragStart: function _onDragStart(/**Event*/ evt, /**boolean*/ fallback) {
|
|
|
var _this = this;
|
|
|
var dataTransfer = evt.dataTransfer;
|
|
|
var options = _this.options;
|
|
|
pluginEvent("dragStart", this, {
|
|
|
evt: evt
|
|
|
});
|
|
|
if (Sortable.eventCanceled) {
|
|
|
this._onDrop();
|
|
|
return;
|
|
|
}
|
|
|
pluginEvent("setupClone", this);
|
|
|
if (!Sortable.eventCanceled) {
|
|
|
cloneEl = clone(dragEl);
|
|
|
cloneEl.removeAttribute("id");
|
|
|
cloneEl.draggable = false;
|
|
|
cloneEl.style["will-change"] = "";
|
|
|
this._hideClone();
|
|
|
toggleClass(cloneEl, this.options.chosenClass, false);
|
|
|
Sortable.clone = cloneEl;
|
|
|
} // #1143: IFrame support workaround
|
|
|
_this.cloneId = _nextTick(function() {
|
|
|
pluginEvent("clone", _this);
|
|
|
if (Sortable.eventCanceled) return;
|
|
|
if (!_this.options.removeCloneOnHide) rootEl.insertBefore(cloneEl, dragEl);
|
|
|
_this._hideClone();
|
|
|
_dispatchEvent({
|
|
|
sortable: _this,
|
|
|
name: "clone"
|
|
|
});
|
|
|
});
|
|
|
!fallback && toggleClass(dragEl, options.dragClass, true); // Set proper drop events
|
|
|
if (fallback) {
|
|
|
ignoreNextClick = true;
|
|
|
_this._loopId = setInterval(_this._emulateDragOver, 50);
|
|
|
} else {
|
|
|
// Undo what was set in _prepareDragStart before drag started
|
|
|
off(document, "mouseup", _this._onDrop);
|
|
|
off(document, "touchend", _this._onDrop);
|
|
|
off(document, "touchcancel", _this._onDrop);
|
|
|
if (dataTransfer) {
|
|
|
dataTransfer.effectAllowed = "move";
|
|
|
options.setData && options.setData.call(_this, dataTransfer, dragEl);
|
|
|
}
|
|
|
on(document, "drop", _this); // #1276 fix:
|
|
|
css(dragEl, "transform", "translateZ(0)");
|
|
|
}
|
|
|
awaitingDragStarted = true;
|
|
|
_this._dragStartId = _nextTick(_this._dragStarted.bind(_this, fallback, evt));
|
|
|
on(document, "selectstart", _this);
|
|
|
moved = true;
|
|
|
if (Safari) css(document.body, "user-select", "none");
|
|
|
},
|
|
|
// Returns true - if no further action is needed (either inserted or another condition)
|
|
|
_onDragOver: function _onDragOver(/**Event*/ evt) {
|
|
|
var el = this.el, target1 = evt.target, dragRect, targetRect, revert, options = this.options, group = options.group, activeSortable = Sortable.active, isOwner = activeGroup === group, canSort = options.sort, fromSortable = putSortable || activeSortable, vertical, _this = this, completedFired = false;
|
|
|
if (_silent) return;
|
|
|
function dragOverEvent(name, extra) {
|
|
|
pluginEvent(name, _this, _objectSpread2({
|
|
|
evt: evt,
|
|
|
isOwner: isOwner,
|
|
|
axis: vertical ? "vertical" : "horizontal",
|
|
|
revert: revert,
|
|
|
dragRect: dragRect,
|
|
|
targetRect: targetRect,
|
|
|
canSort: canSort,
|
|
|
fromSortable: fromSortable,
|
|
|
target: target1,
|
|
|
completed: completed,
|
|
|
onMove: function onMove(target, after) {
|
|
|
return _onMove(rootEl, el, dragEl, dragRect, target, getRect(target), evt, after);
|
|
|
},
|
|
|
changed: changed
|
|
|
}, extra));
|
|
|
} // Capture animation state
|
|
|
function capture() {
|
|
|
dragOverEvent("dragOverAnimationCapture");
|
|
|
_this.captureAnimationState();
|
|
|
if (_this !== fromSortable) fromSortable.captureAnimationState();
|
|
|
} // Return invocation when dragEl is inserted (or completed)
|
|
|
function completed(insertion) {
|
|
|
dragOverEvent("dragOverCompleted", {
|
|
|
insertion: insertion
|
|
|
});
|
|
|
if (insertion) {
|
|
|
// Clones must be hidden before folding animation to capture dragRectAbsolute properly
|
|
|
if (isOwner) activeSortable._hideClone();
|
|
|
else activeSortable._showClone(_this);
|
|
|
if (_this !== fromSortable) {
|
|
|
// Set ghost class to new sortable's ghost class
|
|
|
toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : activeSortable.options.ghostClass, false);
|
|
|
toggleClass(dragEl, options.ghostClass, true);
|
|
|
}
|
|
|
if (putSortable !== _this && _this !== Sortable.active) putSortable = _this;
|
|
|
else if (_this === Sortable.active && putSortable) putSortable = null;
|
|
|
// Animation
|
|
|
if (fromSortable === _this) _this._ignoreWhileAnimating = target1;
|
|
|
_this.animateAll(function() {
|
|
|
dragOverEvent("dragOverAnimationComplete");
|
|
|
_this._ignoreWhileAnimating = null;
|
|
|
});
|
|
|
if (_this !== fromSortable) {
|
|
|
fromSortable.animateAll();
|
|
|
fromSortable._ignoreWhileAnimating = null;
|
|
|
}
|
|
|
} // Null lastTarget if it is not inside a previously swapped element
|
|
|
if (target1 === dragEl && !dragEl.animated || target1 === el && !target1.animated) lastTarget = null;
|
|
|
// no bubbling and not fallback
|
|
|
if (!options.dragoverBubble && !evt.rootEl && target1 !== document) {
|
|
|
dragEl.parentNode[expando]._isOutsideThisEl(evt.target); // Do not detect for empty insert if already inserted
|
|
|
!insertion && nearestEmptyInsertDetectEvent(evt);
|
|
|
}
|
|
|
!options.dragoverBubble && evt.stopPropagation && evt.stopPropagation();
|
|
|
return completedFired = true;
|
|
|
} // Call when dragEl has been inserted
|
|
|
function changed() {
|
|
|
newIndex = index(dragEl);
|
|
|
newDraggableIndex = index(dragEl, options.draggable);
|
|
|
_dispatchEvent({
|
|
|
sortable: _this,
|
|
|
name: "change",
|
|
|
toEl: el,
|
|
|
newIndex: newIndex,
|
|
|
newDraggableIndex: newDraggableIndex,
|
|
|
originalEvent: evt
|
|
|
});
|
|
|
}
|
|
|
if (evt.preventDefault !== void 0) evt.cancelable && evt.preventDefault();
|
|
|
target1 = closest(target1, options.draggable, el, true);
|
|
|
dragOverEvent("dragOver");
|
|
|
if (Sortable.eventCanceled) return completedFired;
|
|
|
if (dragEl.contains(evt.target) || target1.animated && target1.animatingX && target1.animatingY || _this._ignoreWhileAnimating === target1) return completed(false);
|
|
|
ignoreNextClick = false;
|
|
|
if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = parentEl !== rootEl // Reverting item into the original list
|
|
|
) : putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, dragEl, evt)) && group.checkPut(this, activeSortable, dragEl, evt))) {
|
|
|
vertical = this._getDirection(evt, target1) === "vertical";
|
|
|
dragRect = getRect(dragEl);
|
|
|
dragOverEvent("dragOverValid");
|
|
|
if (Sortable.eventCanceled) return completedFired;
|
|
|
if (revert) {
|
|
|
parentEl = rootEl; // actualization
|
|
|
capture();
|
|
|
this._hideClone();
|
|
|
dragOverEvent("revert");
|
|
|
if (!Sortable.eventCanceled) {
|
|
|
if (nextEl) rootEl.insertBefore(dragEl, nextEl);
|
|
|
else rootEl.appendChild(dragEl);
|
|
|
}
|
|
|
return completed(true);
|
|
|
}
|
|
|
var elLastChild = lastChild(el, options.draggable);
|
|
|
if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) {
|
|
|
// Insert to end of list
|
|
|
// If already at end of list: Do not insert
|
|
|
if (elLastChild === dragEl) return completed(false);
|
|
|
// if there is a last element, it is the target
|
|
|
if (elLastChild && el === evt.target) target1 = elLastChild;
|
|
|
if (target1) targetRect = getRect(target1);
|
|
|
if (_onMove(rootEl, el, dragEl, dragRect, target1, targetRect, evt, !!target1) !== false) {
|
|
|
capture();
|
|
|
if (elLastChild && elLastChild.nextSibling) // the last draggable element is not the last node
|
|
|
el.insertBefore(dragEl, elLastChild.nextSibling);
|
|
|
else el.appendChild(dragEl);
|
|
|
parentEl = el; // actualization
|
|
|
changed();
|
|
|
return completed(true);
|
|
|
}
|
|
|
} else if (elLastChild && _ghostIsFirst(evt, vertical, this)) {
|
|
|
// Insert to start of list
|
|
|
var firstChild = getChild(el, 0, options, true);
|
|
|
if (firstChild === dragEl) return completed(false);
|
|
|
target1 = firstChild;
|
|
|
targetRect = getRect(target1);
|
|
|
if (_onMove(rootEl, el, dragEl, dragRect, target1, targetRect, evt, false) !== false) {
|
|
|
capture();
|
|
|
el.insertBefore(dragEl, firstChild);
|
|
|
parentEl = el; // actualization
|
|
|
changed();
|
|
|
return completed(true);
|
|
|
}
|
|
|
} else if (target1.parentNode === el) {
|
|
|
targetRect = getRect(target1);
|
|
|
var direction = 0, targetBeforeFirstSwap, differentLevel = dragEl.parentNode !== el, differentRowCol = !_dragElInRowColumn(dragEl.animated && dragEl.toRect || dragRect, target1.animated && target1.toRect || targetRect, vertical), side1 = vertical ? "top" : "left", scrolledPastTop = isScrolledPast(target1, "top", "top") || isScrolledPast(dragEl, "top", "top"), scrollBefore = scrolledPastTop ? scrolledPastTop.scrollTop : void 0;
|
|
|
if (lastTarget !== target1) {
|
|
|
targetBeforeFirstSwap = targetRect[side1];
|
|
|
pastFirstInvertThresh = false;
|
|
|
isCircumstantialInvert = !differentRowCol && options.invertSwap || differentLevel;
|
|
|
}
|
|
|
direction = _getSwapDirection(evt, target1, targetRect, vertical, differentRowCol ? 1 : options.swapThreshold, options.invertedSwapThreshold == null ? options.swapThreshold : options.invertedSwapThreshold, isCircumstantialInvert, lastTarget === target1);
|
|
|
var sibling;
|
|
|
if (direction !== 0) {
|
|
|
// Check if target is beside dragEl in respective direction (ignoring hidden elements)
|
|
|
var dragIndex = index(dragEl);
|
|
|
do {
|
|
|
dragIndex -= direction;
|
|
|
sibling = parentEl.children[dragIndex];
|
|
|
}while (sibling && (css(sibling, "display") === "none" || sibling === ghostEl));
|
|
|
} // If dragEl is already beside target: Do not insert
|
|
|
if (direction === 0 || sibling === target1) return completed(false);
|
|
|
lastTarget = target1;
|
|
|
lastDirection = direction;
|
|
|
var nextSibling = target1.nextElementSibling, after1 = false;
|
|
|
after1 = direction === 1;
|
|
|
var moveVector = _onMove(rootEl, el, dragEl, dragRect, target1, targetRect, evt, after1);
|
|
|
if (moveVector !== false) {
|
|
|
if (moveVector === 1 || moveVector === -1) after1 = moveVector === 1;
|
|
|
_silent = true;
|
|
|
setTimeout(_unsilent, 30);
|
|
|
capture();
|
|
|
if (after1 && !nextSibling) el.appendChild(dragEl);
|
|
|
else target1.parentNode.insertBefore(dragEl, after1 ? nextSibling : target1);
|
|
|
// Undo chrome's scroll adjustment (has no effect on other browsers)
|
|
|
if (scrolledPastTop) scrollBy(scrolledPastTop, 0, scrollBefore - scrolledPastTop.scrollTop);
|
|
|
parentEl = dragEl.parentNode; // actualization
|
|
|
// must be done before animation
|
|
|
if (targetBeforeFirstSwap !== undefined && !isCircumstantialInvert) targetMoveDistance = Math.abs(targetBeforeFirstSwap - getRect(target1)[side1]);
|
|
|
changed();
|
|
|
return completed(true);
|
|
|
}
|
|
|
}
|
|
|
if (el.contains(dragEl)) return completed(false);
|
|
|
}
|
|
|
return false;
|
|
|
},
|
|
|
_ignoreWhileAnimating: null,
|
|
|
_offMoveEvents: function _offMoveEvents() {
|
|
|
off(document, "mousemove", this._onTouchMove);
|
|
|
off(document, "touchmove", this._onTouchMove);
|
|
|
off(document, "pointermove", this._onTouchMove);
|
|
|
off(document, "dragover", nearestEmptyInsertDetectEvent);
|
|
|
off(document, "mousemove", nearestEmptyInsertDetectEvent);
|
|
|
off(document, "touchmove", nearestEmptyInsertDetectEvent);
|
|
|
},
|
|
|
_offUpEvents: function _offUpEvents() {
|
|
|
var ownerDocument = this.el.ownerDocument;
|
|
|
off(ownerDocument, "mouseup", this._onDrop);
|
|
|
off(ownerDocument, "touchend", this._onDrop);
|
|
|
off(ownerDocument, "pointerup", this._onDrop);
|
|
|
off(ownerDocument, "touchcancel", this._onDrop);
|
|
|
off(document, "selectstart", this);
|
|
|
},
|
|
|
_onDrop: function _onDrop(/**Event*/ evt) {
|
|
|
var el = this.el, options = this.options; // Get the index of the dragged element within its parent
|
|
|
newIndex = index(dragEl);
|
|
|
newDraggableIndex = index(dragEl, options.draggable);
|
|
|
pluginEvent("drop", this, {
|
|
|
evt: evt
|
|
|
});
|
|
|
parentEl = dragEl && dragEl.parentNode; // Get again after plugin event
|
|
|
newIndex = index(dragEl);
|
|
|
newDraggableIndex = index(dragEl, options.draggable);
|
|
|
if (Sortable.eventCanceled) {
|
|
|
this._nulling();
|
|
|
return;
|
|
|
}
|
|
|
awaitingDragStarted = false;
|
|
|
isCircumstantialInvert = false;
|
|
|
pastFirstInvertThresh = false;
|
|
|
clearInterval(this._loopId);
|
|
|
clearTimeout(this._dragStartTimer);
|
|
|
_cancelNextTick(this.cloneId);
|
|
|
_cancelNextTick(this._dragStartId); // Unbind events
|
|
|
if (this.nativeDraggable) {
|
|
|
off(document, "drop", this);
|
|
|
off(el, "dragstart", this._onDragStart);
|
|
|
}
|
|
|
this._offMoveEvents();
|
|
|
this._offUpEvents();
|
|
|
if (Safari) css(document.body, "user-select", "");
|
|
|
css(dragEl, "transform", "");
|
|
|
if (evt) {
|
|
|
if (moved) {
|
|
|
evt.cancelable && evt.preventDefault();
|
|
|
!options.dropBubble && evt.stopPropagation();
|
|
|
}
|
|
|
ghostEl && ghostEl.parentNode && ghostEl.parentNode.removeChild(ghostEl);
|
|
|
if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== "clone") // Remove clone(s)
|
|
|
cloneEl && cloneEl.parentNode && cloneEl.parentNode.removeChild(cloneEl);
|
|
|
if (dragEl) {
|
|
|
if (this.nativeDraggable) off(dragEl, "dragend", this);
|
|
|
_disableDraggable(dragEl);
|
|
|
dragEl.style["will-change"] = ""; // Remove classes
|
|
|
// ghostClass is added in dragStarted
|
|
|
if (moved && !awaitingDragStarted) toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : this.options.ghostClass, false);
|
|
|
toggleClass(dragEl, this.options.chosenClass, false); // Drag stop event
|
|
|
_dispatchEvent({
|
|
|
sortable: this,
|
|
|
name: "unchoose",
|
|
|
toEl: parentEl,
|
|
|
newIndex: null,
|
|
|
newDraggableIndex: null,
|
|
|
originalEvent: evt
|
|
|
});
|
|
|
if (rootEl !== parentEl) {
|
|
|
if (newIndex >= 0) {
|
|
|
// Add event
|
|
|
_dispatchEvent({
|
|
|
rootEl: parentEl,
|
|
|
name: "add",
|
|
|
toEl: parentEl,
|
|
|
fromEl: rootEl,
|
|
|
originalEvent: evt
|
|
|
}); // Remove event
|
|
|
_dispatchEvent({
|
|
|
sortable: this,
|
|
|
name: "remove",
|
|
|
toEl: parentEl,
|
|
|
originalEvent: evt
|
|
|
}); // drag from one list and drop into another
|
|
|
_dispatchEvent({
|
|
|
rootEl: parentEl,
|
|
|
name: "sort",
|
|
|
toEl: parentEl,
|
|
|
fromEl: rootEl,
|
|
|
originalEvent: evt
|
|
|
});
|
|
|
_dispatchEvent({
|
|
|
sortable: this,
|
|
|
name: "sort",
|
|
|
toEl: parentEl,
|
|
|
originalEvent: evt
|
|
|
});
|
|
|
}
|
|
|
putSortable && putSortable.save();
|
|
|
} else {
|
|
|
if (newIndex !== oldIndex) {
|
|
|
if (newIndex >= 0) {
|
|
|
// drag & drop within the same list
|
|
|
_dispatchEvent({
|
|
|
sortable: this,
|
|
|
name: "update",
|
|
|
toEl: parentEl,
|
|
|
originalEvent: evt
|
|
|
});
|
|
|
_dispatchEvent({
|
|
|
sortable: this,
|
|
|
name: "sort",
|
|
|
toEl: parentEl,
|
|
|
originalEvent: evt
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (Sortable.active) {
|
|
|
/* jshint eqnull:true */ if (newIndex == null || newIndex === -1) {
|
|
|
newIndex = oldIndex;
|
|
|
newDraggableIndex = oldDraggableIndex;
|
|
|
}
|
|
|
_dispatchEvent({
|
|
|
sortable: this,
|
|
|
name: "end",
|
|
|
toEl: parentEl,
|
|
|
originalEvent: evt
|
|
|
}); // Save sorting
|
|
|
this.save();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
this._nulling();
|
|
|
},
|
|
|
_nulling: function _nulling() {
|
|
|
pluginEvent("nulling", this);
|
|
|
rootEl = dragEl = parentEl = ghostEl = nextEl = cloneEl = lastDownEl = cloneHidden = tapEvt = touchEvt = moved = newIndex = newDraggableIndex = oldIndex = oldDraggableIndex = lastTarget = lastDirection = putSortable = activeGroup = Sortable.dragged = Sortable.ghost = Sortable.clone = Sortable.active = null;
|
|
|
savedInputChecked.forEach(function(el) {
|
|
|
el.checked = true;
|
|
|
});
|
|
|
savedInputChecked.length = lastDx = lastDy = 0;
|
|
|
},
|
|
|
handleEvent: function handleEvent(/**Event*/ evt) {
|
|
|
switch(evt.type){
|
|
|
case "drop":
|
|
|
case "dragend":
|
|
|
this._onDrop(evt);
|
|
|
break;
|
|
|
case "dragenter":
|
|
|
case "dragover":
|
|
|
if (dragEl) {
|
|
|
this._onDragOver(evt);
|
|
|
_globalDragOver(evt);
|
|
|
}
|
|
|
break;
|
|
|
case "selectstart":
|
|
|
evt.preventDefault();
|
|
|
break;
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
* Serializes the item into an array of string.
|
|
|
* @returns {String[]}
|
|
|
*/ toArray: function toArray() {
|
|
|
var order = [], el, children = this.el.children, i = 0, n = children.length, options = this.options;
|
|
|
for(; i < n; i++){
|
|
|
el = children[i];
|
|
|
if (closest(el, options.draggable, this.el, false)) order.push(el.getAttribute(options.dataIdAttr) || _generateId(el));
|
|
|
}
|
|
|
return order;
|
|
|
},
|
|
|
/**
|
|
|
* Sorts the elements according to the array.
|
|
|
* @param {String[]} order order of the items
|
|
|
*/ sort: function sort(order, useAnimation) {
|
|
|
var items = {}, rootEl2 = this.el;
|
|
|
this.toArray().forEach(function(id, i) {
|
|
|
var el = rootEl2.children[i];
|
|
|
if (closest(el, this.options.draggable, rootEl2, false)) items[id] = el;
|
|
|
}, this);
|
|
|
useAnimation && this.captureAnimationState();
|
|
|
order.forEach(function(id) {
|
|
|
if (items[id]) {
|
|
|
rootEl2.removeChild(items[id]);
|
|
|
rootEl2.appendChild(items[id]);
|
|
|
}
|
|
|
});
|
|
|
useAnimation && this.animateAll();
|
|
|
},
|
|
|
/**
|
|
|
* Save the current sorting
|
|
|
*/ save: function save() {
|
|
|
var store = this.options.store;
|
|
|
store && store.set && store.set(this);
|
|
|
},
|
|
|
/**
|
|
|
* For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
|
|
|
* @param {HTMLElement} el
|
|
|
* @param {String} [selector] default: `options.draggable`
|
|
|
* @returns {HTMLElement|null}
|
|
|
*/ closest: function closest$1(el, selector) {
|
|
|
return closest(el, selector || this.options.draggable, this.el, false);
|
|
|
},
|
|
|
/**
|
|
|
* Set/get option
|
|
|
* @param {string} name
|
|
|
* @param {*} [value]
|
|
|
* @returns {*}
|
|
|
*/ option: function option(name, value) {
|
|
|
var options = this.options;
|
|
|
if (value === void 0) return options[name];
|
|
|
else {
|
|
|
var modifiedValue = PluginManager.modifyOption(this, name, value);
|
|
|
if (typeof modifiedValue !== "undefined") options[name] = modifiedValue;
|
|
|
else options[name] = value;
|
|
|
if (name === "group") _prepareGroup(options);
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
* Destroy
|
|
|
*/ destroy: function destroy() {
|
|
|
pluginEvent("destroy", this);
|
|
|
var el1 = this.el;
|
|
|
el1[expando] = null;
|
|
|
off(el1, "mousedown", this._onTapStart);
|
|
|
off(el1, "touchstart", this._onTapStart);
|
|
|
off(el1, "pointerdown", this._onTapStart);
|
|
|
if (this.nativeDraggable) {
|
|
|
off(el1, "dragover", this);
|
|
|
off(el1, "dragenter", this);
|
|
|
} // Remove draggable attributes
|
|
|
Array.prototype.forEach.call(el1.querySelectorAll("[draggable]"), function(el) {
|
|
|
el.removeAttribute("draggable");
|
|
|
});
|
|
|
this._onDrop();
|
|
|
this._disableDelayedDragEvents();
|
|
|
sortables.splice(sortables.indexOf(this.el), 1);
|
|
|
this.el = el1 = null;
|
|
|
},
|
|
|
_hideClone: function _hideClone() {
|
|
|
if (!cloneHidden) {
|
|
|
pluginEvent("hideClone", this);
|
|
|
if (Sortable.eventCanceled) return;
|
|
|
css(cloneEl, "display", "none");
|
|
|
if (this.options.removeCloneOnHide && cloneEl.parentNode) cloneEl.parentNode.removeChild(cloneEl);
|
|
|
cloneHidden = true;
|
|
|
}
|
|
|
},
|
|
|
_showClone: function _showClone(putSortable2) {
|
|
|
if (putSortable2.lastPutMode !== "clone") {
|
|
|
this._hideClone();
|
|
|
return;
|
|
|
}
|
|
|
if (cloneHidden) {
|
|
|
pluginEvent("showClone", this);
|
|
|
if (Sortable.eventCanceled) return; // show clone at dragEl or original position
|
|
|
if (dragEl.parentNode == rootEl && !this.options.group.revertClone) rootEl.insertBefore(cloneEl, dragEl);
|
|
|
else if (nextEl) rootEl.insertBefore(cloneEl, nextEl);
|
|
|
else rootEl.appendChild(cloneEl);
|
|
|
if (this.options.group.revertClone) this.animate(dragEl, cloneEl);
|
|
|
css(cloneEl, "display", "");
|
|
|
cloneHidden = false;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
function _globalDragOver(/**Event*/ evt) {
|
|
|
if (evt.dataTransfer) evt.dataTransfer.dropEffect = "move";
|
|
|
evt.cancelable && evt.preventDefault();
|
|
|
}
|
|
|
function _onMove(fromEl, toEl, dragEl3, dragRect, targetEl, targetRect, originalEvent, willInsertAfter) {
|
|
|
var evt, sortable = fromEl[expando], onMoveFn = sortable.options.onMove, retVal; // Support for new CustomEvent feature
|
|
|
if (window.CustomEvent && !IE11OrLess && !Edge) evt = new CustomEvent("move", {
|
|
|
bubbles: true,
|
|
|
cancelable: true
|
|
|
});
|
|
|
else {
|
|
|
evt = document.createEvent("Event");
|
|
|
evt.initEvent("move", true, true);
|
|
|
}
|
|
|
evt.to = toEl;
|
|
|
evt.from = fromEl;
|
|
|
evt.dragged = dragEl3;
|
|
|
evt.draggedRect = dragRect;
|
|
|
evt.related = targetEl || toEl;
|
|
|
evt.relatedRect = targetRect || getRect(toEl);
|
|
|
evt.willInsertAfter = willInsertAfter;
|
|
|
evt.originalEvent = originalEvent;
|
|
|
fromEl.dispatchEvent(evt);
|
|
|
if (onMoveFn) retVal = onMoveFn.call(sortable, evt, originalEvent);
|
|
|
return retVal;
|
|
|
}
|
|
|
function _disableDraggable(el) {
|
|
|
el.draggable = false;
|
|
|
}
|
|
|
function _unsilent() {
|
|
|
_silent = false;
|
|
|
}
|
|
|
function _ghostIsFirst(evt, vertical, sortable) {
|
|
|
var rect = getRect(getChild(sortable.el, 0, sortable.options, true));
|
|
|
var spacer = 10;
|
|
|
return vertical ? evt.clientX < rect.left - spacer || evt.clientY < rect.top && evt.clientX < rect.right : evt.clientY < rect.top - spacer || evt.clientY < rect.bottom && evt.clientX < rect.left;
|
|
|
}
|
|
|
function _ghostIsLast(evt, vertical, sortable) {
|
|
|
var rect = getRect(lastChild(sortable.el, sortable.options.draggable));
|
|
|
var spacer = 10;
|
|
|
return vertical ? evt.clientX > rect.right + spacer || evt.clientX <= rect.right && evt.clientY > rect.bottom && evt.clientX >= rect.left : evt.clientX > rect.right && evt.clientY > rect.top || evt.clientX <= rect.right && evt.clientY > rect.bottom + spacer;
|
|
|
}
|
|
|
function _getSwapDirection(evt, target, targetRect, vertical, swapThreshold, invertedSwapThreshold, invertSwap, isLastTarget) {
|
|
|
var mouseOnAxis = vertical ? evt.clientY : evt.clientX, targetLength = vertical ? targetRect.height : targetRect.width, targetS1 = vertical ? targetRect.top : targetRect.left, targetS2 = vertical ? targetRect.bottom : targetRect.right, invert = false;
|
|
|
if (!invertSwap) {
|
|
|
// Never invert or create dragEl shadow when target movemenet causes mouse to move past the end of regular swapThreshold
|
|
|
if (isLastTarget && targetMoveDistance < targetLength * swapThreshold) {
|
|
|
// multiplied only by swapThreshold because mouse will already be inside target by (1 - threshold) * targetLength / 2
|
|
|
// check if past first invert threshold on side opposite of lastDirection
|
|
|
if (!pastFirstInvertThresh && (lastDirection === 1 ? mouseOnAxis > targetS1 + targetLength * invertedSwapThreshold / 2 : mouseOnAxis < targetS2 - targetLength * invertedSwapThreshold / 2)) // past first invert threshold, do not restrict inverted threshold to dragEl shadow
|
|
|
pastFirstInvertThresh = true;
|
|
|
if (!pastFirstInvertThresh) {
|
|
|
// dragEl shadow (target move distance shadow)
|
|
|
if (lastDirection === 1 ? mouseOnAxis < targetS1 + targetMoveDistance // over dragEl shadow
|
|
|
: mouseOnAxis > targetS2 - targetMoveDistance) return -lastDirection;
|
|
|
} else invert = true;
|
|
|
} else {
|
|
|
// Regular
|
|
|
if (mouseOnAxis > targetS1 + targetLength * (1 - swapThreshold) / 2 && mouseOnAxis < targetS2 - targetLength * (1 - swapThreshold) / 2) return _getInsertDirection(target);
|
|
|
}
|
|
|
}
|
|
|
invert = invert || invertSwap;
|
|
|
if (invert) {
|
|
|
// Invert of regular
|
|
|
if (mouseOnAxis < targetS1 + targetLength * invertedSwapThreshold / 2 || mouseOnAxis > targetS2 - targetLength * invertedSwapThreshold / 2) return mouseOnAxis > targetS1 + targetLength / 2 ? 1 : -1;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
/**
|
|
|
* Gets the direction dragEl must be swapped relative to target in order to make it
|
|
|
* seem that dragEl has been "inserted" into that element's position
|
|
|
* @param {HTMLElement} target The target whose position dragEl is being inserted at
|
|
|
* @return {Number} Direction dragEl must be swapped
|
|
|
*/ function _getInsertDirection(target) {
|
|
|
if (index(dragEl) < index(target)) return 1;
|
|
|
else return -1;
|
|
|
}
|
|
|
/**
|
|
|
* Generate id
|
|
|
* @param {HTMLElement} el
|
|
|
* @returns {String}
|
|
|
* @private
|
|
|
*/ function _generateId(el) {
|
|
|
var str = el.tagName + el.className + el.src + el.href + el.textContent, i = str.length, sum = 0;
|
|
|
while(i--)sum += str.charCodeAt(i);
|
|
|
return sum.toString(36);
|
|
|
}
|
|
|
function _saveInputCheckedState(root) {
|
|
|
savedInputChecked.length = 0;
|
|
|
var inputs = root.getElementsByTagName("input");
|
|
|
var idx = inputs.length;
|
|
|
while(idx--){
|
|
|
var el = inputs[idx];
|
|
|
el.checked && savedInputChecked.push(el);
|
|
|
}
|
|
|
}
|
|
|
function _nextTick(fn) {
|
|
|
return setTimeout(fn, 0);
|
|
|
}
|
|
|
function _cancelNextTick(id) {
|
|
|
return clearTimeout(id);
|
|
|
} // Fixed #973:
|
|
|
if (documentExists) on(document, "touchmove", function(evt) {
|
|
|
if ((Sortable.active || awaitingDragStarted) && evt.cancelable) evt.preventDefault();
|
|
|
});
|
|
|
// Export utils
|
|
|
Sortable.utils = {
|
|
|
on: on,
|
|
|
off: off,
|
|
|
css: css,
|
|
|
find: find,
|
|
|
is: function is(el, selector) {
|
|
|
return !!closest(el, selector, el, false);
|
|
|
},
|
|
|
extend: extend,
|
|
|
throttle: throttle,
|
|
|
closest: closest,
|
|
|
toggleClass: toggleClass,
|
|
|
clone: clone,
|
|
|
index: index,
|
|
|
nextTick: _nextTick,
|
|
|
cancelNextTick: _cancelNextTick,
|
|
|
detectDirection: _detectDirection,
|
|
|
getChild: getChild
|
|
|
};
|
|
|
/**
|
|
|
* Get the Sortable instance of an element
|
|
|
* @param {HTMLElement} element The element
|
|
|
* @return {Sortable|undefined} The instance of Sortable
|
|
|
*/ Sortable.get = function(element) {
|
|
|
return element[expando];
|
|
|
};
|
|
|
/**
|
|
|
* Mount a plugin to Sortable
|
|
|
* @param {...SortablePlugin|SortablePlugin[]} plugins Plugins being mounted
|
|
|
*/ Sortable.mount = function() {
|
|
|
for(var _len = arguments.length, plugins1 = new Array(_len), _key = 0; _key < _len; _key++)plugins1[_key] = arguments[_key];
|
|
|
if (plugins1[0].constructor === Array) plugins1 = plugins1[0];
|
|
|
plugins1.forEach(function(plugin) {
|
|
|
if (!plugin.prototype || !plugin.prototype.constructor) throw "Sortable: Mounted plugin must be a constructor function, not ".concat(({}).toString.call(plugin));
|
|
|
if (plugin.utils) Sortable.utils = _objectSpread2(_objectSpread2({}, Sortable.utils), plugin.utils);
|
|
|
PluginManager.mount(plugin);
|
|
|
});
|
|
|
};
|
|
|
/**
|
|
|
* Create sortable instance
|
|
|
* @param {HTMLElement} el
|
|
|
* @param {Object} [options]
|
|
|
*/ Sortable.create = function(el, options) {
|
|
|
return new Sortable(el, options);
|
|
|
}; // Export
|
|
|
Sortable.version = version;
|
|
|
var autoScrolls = [], scrollEl, scrollRootEl, scrolling = false, lastAutoScrollX, lastAutoScrollY, touchEvt$1, pointerElemChangedInterval;
|
|
|
function AutoScrollPlugin() {
|
|
|
function AutoScroll() {
|
|
|
this.defaults = {
|
|
|
scroll: true,
|
|
|
forceAutoScrollFallback: false,
|
|
|
scrollSensitivity: 30,
|
|
|
scrollSpeed: 10,
|
|
|
bubbleScroll: true
|
|
|
}; // Bind all private methods
|
|
|
for(var fn in this)if (fn.charAt(0) === "_" && typeof this[fn] === "function") this[fn] = this[fn].bind(this);
|
|
|
}
|
|
|
AutoScroll.prototype = {
|
|
|
dragStarted: function dragStarted(_ref) {
|
|
|
var originalEvent = _ref.originalEvent;
|
|
|
if (this.sortable.nativeDraggable) on(document, "dragover", this._handleAutoScroll);
|
|
|
else {
|
|
|
if (this.options.supportPointer) on(document, "pointermove", this._handleFallbackAutoScroll);
|
|
|
else if (originalEvent.touches) on(document, "touchmove", this._handleFallbackAutoScroll);
|
|
|
else on(document, "mousemove", this._handleFallbackAutoScroll);
|
|
|
}
|
|
|
},
|
|
|
dragOverCompleted: function dragOverCompleted(_ref2) {
|
|
|
var originalEvent = _ref2.originalEvent;
|
|
|
// For when bubbling is canceled and using fallback (fallback 'touchmove' always reached)
|
|
|
if (!this.options.dragOverBubble && !originalEvent.rootEl) this._handleAutoScroll(originalEvent);
|
|
|
},
|
|
|
drop: function drop() {
|
|
|
if (this.sortable.nativeDraggable) off(document, "dragover", this._handleAutoScroll);
|
|
|
else {
|
|
|
off(document, "pointermove", this._handleFallbackAutoScroll);
|
|
|
off(document, "touchmove", this._handleFallbackAutoScroll);
|
|
|
off(document, "mousemove", this._handleFallbackAutoScroll);
|
|
|
}
|
|
|
clearPointerElemChangedInterval();
|
|
|
clearAutoScrolls();
|
|
|
cancelThrottle();
|
|
|
},
|
|
|
nulling: function nulling() {
|
|
|
touchEvt$1 = scrollRootEl = scrollEl = scrolling = pointerElemChangedInterval = lastAutoScrollX = lastAutoScrollY = null;
|
|
|
autoScrolls.length = 0;
|
|
|
},
|
|
|
_handleFallbackAutoScroll: function _handleFallbackAutoScroll(evt) {
|
|
|
this._handleAutoScroll(evt, true);
|
|
|
},
|
|
|
_handleAutoScroll: function _handleAutoScroll(evt, fallback) {
|
|
|
var _this = this;
|
|
|
var x = (evt.touches ? evt.touches[0] : evt).clientX, y = (evt.touches ? evt.touches[0] : evt).clientY, elem = document.elementFromPoint(x, y);
|
|
|
touchEvt$1 = evt; // IE does not seem to have native autoscroll,
|
|
|
// Edge's autoscroll seems too conditional,
|
|
|
// MACOS Safari does not have autoscroll,
|
|
|
// Firefox and Chrome are good
|
|
|
if (fallback || this.options.forceAutoScrollFallback || Edge || IE11OrLess || Safari) {
|
|
|
autoScroll(evt, this.options, elem, fallback); // Listener for pointer element change
|
|
|
var ogElemScroller = getParentAutoScrollElement(elem, true);
|
|
|
if (scrolling && (!pointerElemChangedInterval || x !== lastAutoScrollX || y !== lastAutoScrollY)) {
|
|
|
pointerElemChangedInterval && clearPointerElemChangedInterval(); // Detect for pointer elem change, emulating native DnD behaviour
|
|
|
pointerElemChangedInterval = setInterval(function() {
|
|
|
var newElem = getParentAutoScrollElement(document.elementFromPoint(x, y), true);
|
|
|
if (newElem !== ogElemScroller) {
|
|
|
ogElemScroller = newElem;
|
|
|
clearAutoScrolls();
|
|
|
}
|
|
|
autoScroll(evt, _this.options, newElem, fallback);
|
|
|
}, 10);
|
|
|
lastAutoScrollX = x;
|
|
|
lastAutoScrollY = y;
|
|
|
}
|
|
|
} else {
|
|
|
// if DnD is enabled (and browser has good autoscrolling), first autoscroll will already scroll, so get parent autoscroll of first autoscroll
|
|
|
if (!this.options.bubbleScroll || getParentAutoScrollElement(elem, true) === getWindowScrollingElement()) {
|
|
|
clearAutoScrolls();
|
|
|
return;
|
|
|
}
|
|
|
autoScroll(evt, this.options, getParentAutoScrollElement(elem, false), false);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
return _extends(AutoScroll, {
|
|
|
pluginName: "scroll",
|
|
|
initializeByDefault: true
|
|
|
});
|
|
|
}
|
|
|
function clearAutoScrolls() {
|
|
|
autoScrolls.forEach(function(autoScroll1) {
|
|
|
clearInterval(autoScroll1.pid);
|
|
|
});
|
|
|
autoScrolls = [];
|
|
|
}
|
|
|
function clearPointerElemChangedInterval() {
|
|
|
clearInterval(pointerElemChangedInterval);
|
|
|
}
|
|
|
var autoScroll = throttle(function(evt, options, rootEl3, isFallback) {
|
|
|
// Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521
|
|
|
if (!options.scroll) return;
|
|
|
var x = (evt.touches ? evt.touches[0] : evt).clientX, y = (evt.touches ? evt.touches[0] : evt).clientY, sens = options.scrollSensitivity, speed = options.scrollSpeed, winScroller = getWindowScrollingElement();
|
|
|
var scrollThisInstance = false, scrollCustomFn; // New scroll root, set scrollEl
|
|
|
if (scrollRootEl !== rootEl3) {
|
|
|
scrollRootEl = rootEl3;
|
|
|
clearAutoScrolls();
|
|
|
scrollEl = options.scroll;
|
|
|
scrollCustomFn = options.scrollFn;
|
|
|
if (scrollEl === true) scrollEl = getParentAutoScrollElement(rootEl3, true);
|
|
|
}
|
|
|
var layersOut = 0;
|
|
|
var currentParent = scrollEl;
|
|
|
do {
|
|
|
var el = currentParent, rect = getRect(el), top = rect.top, bottom = rect.bottom, left = rect.left, right = rect.right, width = rect.width, height = rect.height, canScrollX = void 0, canScrollY = void 0, scrollWidth = el.scrollWidth, scrollHeight = el.scrollHeight, elCSS = css(el), scrollPosX = el.scrollLeft, scrollPosY = el.scrollTop;
|
|
|
if (el === winScroller) {
|
|
|
canScrollX = width < scrollWidth && (elCSS.overflowX === "auto" || elCSS.overflowX === "scroll" || elCSS.overflowX === "visible");
|
|
|
canScrollY = height < scrollHeight && (elCSS.overflowY === "auto" || elCSS.overflowY === "scroll" || elCSS.overflowY === "visible");
|
|
|
} else {
|
|
|
canScrollX = width < scrollWidth && (elCSS.overflowX === "auto" || elCSS.overflowX === "scroll");
|
|
|
canScrollY = height < scrollHeight && (elCSS.overflowY === "auto" || elCSS.overflowY === "scroll");
|
|
|
}
|
|
|
var vx = canScrollX && (Math.abs(right - x) <= sens && scrollPosX + width < scrollWidth) - (Math.abs(left - x) <= sens && !!scrollPosX);
|
|
|
var vy = canScrollY && (Math.abs(bottom - y) <= sens && scrollPosY + height < scrollHeight) - (Math.abs(top - y) <= sens && !!scrollPosY);
|
|
|
if (!autoScrolls[layersOut]) {
|
|
|
for(var i = 0; i <= layersOut; i++)if (!autoScrolls[i]) autoScrolls[i] = {};
|
|
|
}
|
|
|
if (autoScrolls[layersOut].vx != vx || autoScrolls[layersOut].vy != vy || autoScrolls[layersOut].el !== el) {
|
|
|
autoScrolls[layersOut].el = el;
|
|
|
autoScrolls[layersOut].vx = vx;
|
|
|
autoScrolls[layersOut].vy = vy;
|
|
|
clearInterval(autoScrolls[layersOut].pid);
|
|
|
if (vx != 0 || vy != 0) {
|
|
|
scrollThisInstance = true;
|
|
|
/* jshint loopfunc:true */ autoScrolls[layersOut].pid = setInterval((function() {
|
|
|
// emulate drag over during autoscroll (fallback), emulating native DnD behaviour
|
|
|
if (isFallback && this.layer === 0) Sortable.active._onTouchMove(touchEvt$1); // To move ghost if it is positioned absolutely
|
|
|
var scrollOffsetY = autoScrolls[this.layer].vy ? autoScrolls[this.layer].vy * speed : 0;
|
|
|
var scrollOffsetX = autoScrolls[this.layer].vx ? autoScrolls[this.layer].vx * speed : 0;
|
|
|
if (typeof scrollCustomFn === "function") {
|
|
|
if (scrollCustomFn.call(Sortable.dragged.parentNode[expando], scrollOffsetX, scrollOffsetY, evt, touchEvt$1, autoScrolls[this.layer].el) !== "continue") return;
|
|
|
}
|
|
|
scrollBy(autoScrolls[this.layer].el, scrollOffsetX, scrollOffsetY);
|
|
|
}).bind({
|
|
|
layer: layersOut
|
|
|
}), 24);
|
|
|
}
|
|
|
}
|
|
|
layersOut++;
|
|
|
}while (options.bubbleScroll && currentParent !== winScroller && (currentParent = getParentAutoScrollElement(currentParent, false)));
|
|
|
scrolling = scrollThisInstance; // in case another function catches scrolling as false in between when it is not
|
|
|
}, 30);
|
|
|
var drop = function drop(_ref) {
|
|
|
var originalEvent = _ref.originalEvent, putSortable3 = _ref.putSortable, dragEl4 = _ref.dragEl, activeSortable = _ref.activeSortable, dispatchSortableEvent = _ref.dispatchSortableEvent, hideGhostForTarget = _ref.hideGhostForTarget, unhideGhostForTarget = _ref.unhideGhostForTarget;
|
|
|
if (!originalEvent) return;
|
|
|
var toSortable = putSortable3 || activeSortable;
|
|
|
hideGhostForTarget();
|
|
|
var touch = originalEvent.changedTouches && originalEvent.changedTouches.length ? originalEvent.changedTouches[0] : originalEvent;
|
|
|
var target = document.elementFromPoint(touch.clientX, touch.clientY);
|
|
|
unhideGhostForTarget();
|
|
|
if (toSortable && !toSortable.el.contains(target)) {
|
|
|
dispatchSortableEvent("spill");
|
|
|
this.onSpill({
|
|
|
dragEl: dragEl4,
|
|
|
putSortable: putSortable3
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
function Revert() {}
|
|
|
Revert.prototype = {
|
|
|
startIndex: null,
|
|
|
dragStart: function dragStart(_ref2) {
|
|
|
var oldDraggableIndex2 = _ref2.oldDraggableIndex;
|
|
|
this.startIndex = oldDraggableIndex2;
|
|
|
},
|
|
|
onSpill: function onSpill(_ref3) {
|
|
|
var dragEl5 = _ref3.dragEl, putSortable4 = _ref3.putSortable;
|
|
|
this.sortable.captureAnimationState();
|
|
|
if (putSortable4) putSortable4.captureAnimationState();
|
|
|
var nextSibling = getChild(this.sortable.el, this.startIndex, this.options);
|
|
|
if (nextSibling) this.sortable.el.insertBefore(dragEl5, nextSibling);
|
|
|
else this.sortable.el.appendChild(dragEl5);
|
|
|
this.sortable.animateAll();
|
|
|
if (putSortable4) putSortable4.animateAll();
|
|
|
},
|
|
|
drop: drop
|
|
|
};
|
|
|
_extends(Revert, {
|
|
|
pluginName: "revertOnSpill"
|
|
|
});
|
|
|
function Remove() {}
|
|
|
Remove.prototype = {
|
|
|
onSpill: function onSpill(_ref4) {
|
|
|
var dragEl6 = _ref4.dragEl, putSortable5 = _ref4.putSortable;
|
|
|
var parentSortable = putSortable5 || this.sortable;
|
|
|
parentSortable.captureAnimationState();
|
|
|
dragEl6.parentNode && dragEl6.parentNode.removeChild(dragEl6);
|
|
|
parentSortable.animateAll();
|
|
|
},
|
|
|
drop: drop
|
|
|
};
|
|
|
_extends(Remove, {
|
|
|
pluginName: "removeOnSpill"
|
|
|
});
|
|
|
var lastSwapEl;
|
|
|
function SwapPlugin() {
|
|
|
function Swap() {
|
|
|
this.defaults = {
|
|
|
swapClass: "sortable-swap-highlight"
|
|
|
};
|
|
|
}
|
|
|
Swap.prototype = {
|
|
|
dragStart: function dragStart(_ref) {
|
|
|
var dragEl7 = _ref.dragEl;
|
|
|
lastSwapEl = dragEl7;
|
|
|
},
|
|
|
dragOverValid: function dragOverValid(_ref2) {
|
|
|
var completed = _ref2.completed, target = _ref2.target, onMove = _ref2.onMove, activeSortable = _ref2.activeSortable, changed = _ref2.changed, cancel = _ref2.cancel;
|
|
|
if (!activeSortable.options.swap) return;
|
|
|
var el = this.sortable.el, options = this.options;
|
|
|
if (target && target !== el) {
|
|
|
var prevSwapEl = lastSwapEl;
|
|
|
if (onMove(target) !== false) {
|
|
|
toggleClass(target, options.swapClass, true);
|
|
|
lastSwapEl = target;
|
|
|
} else lastSwapEl = null;
|
|
|
if (prevSwapEl && prevSwapEl !== lastSwapEl) toggleClass(prevSwapEl, options.swapClass, false);
|
|
|
}
|
|
|
changed();
|
|
|
completed(true);
|
|
|
cancel();
|
|
|
},
|
|
|
drop: function drop(_ref3) {
|
|
|
var activeSortable = _ref3.activeSortable, putSortable6 = _ref3.putSortable, dragEl8 = _ref3.dragEl;
|
|
|
var toSortable = putSortable6 || this.sortable;
|
|
|
var options = this.options;
|
|
|
lastSwapEl && toggleClass(lastSwapEl, options.swapClass, false);
|
|
|
if (lastSwapEl && (options.swap || putSortable6 && putSortable6.options.swap)) {
|
|
|
if (dragEl8 !== lastSwapEl) {
|
|
|
toSortable.captureAnimationState();
|
|
|
if (toSortable !== activeSortable) activeSortable.captureAnimationState();
|
|
|
swapNodes(dragEl8, lastSwapEl);
|
|
|
toSortable.animateAll();
|
|
|
if (toSortable !== activeSortable) activeSortable.animateAll();
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
nulling: function nulling() {
|
|
|
lastSwapEl = null;
|
|
|
}
|
|
|
};
|
|
|
return _extends(Swap, {
|
|
|
pluginName: "swap",
|
|
|
eventProperties: function eventProperties() {
|
|
|
return {
|
|
|
swapItem: lastSwapEl
|
|
|
};
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
function swapNodes(n1, n2) {
|
|
|
var p1 = n1.parentNode, p2 = n2.parentNode, i1, i2;
|
|
|
if (!p1 || !p2 || p1.isEqualNode(n2) || p2.isEqualNode(n1)) return;
|
|
|
i1 = index(n1);
|
|
|
i2 = index(n2);
|
|
|
if (p1.isEqualNode(p2) && i1 < i2) i2++;
|
|
|
p1.insertBefore(n2, p1.children[i1]);
|
|
|
p2.insertBefore(n1, p2.children[i2]);
|
|
|
}
|
|
|
var multiDragElements = [], multiDragClones = [], lastMultiDragSelect, // for selection with modifier key down (SHIFT)
|
|
|
multiDragSortable, initialFolding = false, // Initial multi-drag fold when drag started
|
|
|
folding = false, // Folding any other time
|
|
|
dragStarted = false, dragEl$1, clonesFromRect, clonesHidden;
|
|
|
function MultiDragPlugin() {
|
|
|
function MultiDrag(sortable) {
|
|
|
// Bind all private methods
|
|
|
for(var fn in this)if (fn.charAt(0) === "_" && typeof this[fn] === "function") this[fn] = this[fn].bind(this);
|
|
|
if (!sortable.options.avoidImplicitDeselect) {
|
|
|
if (sortable.options.supportPointer) on(document, "pointerup", this._deselectMultiDrag);
|
|
|
else {
|
|
|
on(document, "mouseup", this._deselectMultiDrag);
|
|
|
on(document, "touchend", this._deselectMultiDrag);
|
|
|
}
|
|
|
}
|
|
|
on(document, "keydown", this._checkKeyDown);
|
|
|
on(document, "keyup", this._checkKeyUp);
|
|
|
this.defaults = {
|
|
|
selectedClass: "sortable-selected",
|
|
|
multiDragKey: null,
|
|
|
avoidImplicitDeselect: false,
|
|
|
setData: function setData(dataTransfer, dragEl9) {
|
|
|
var data = "";
|
|
|
if (multiDragElements.length && multiDragSortable === sortable) multiDragElements.forEach(function(multiDragElement, i) {
|
|
|
data += (!i ? "" : ", ") + multiDragElement.textContent;
|
|
|
});
|
|
|
else data = dragEl9.textContent;
|
|
|
dataTransfer.setData("Text", data);
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
MultiDrag.prototype = {
|
|
|
multiDragKeyDown: false,
|
|
|
isMultiDrag: false,
|
|
|
delayStartGlobal: function delayStartGlobal(_ref) {
|
|
|
var dragged = _ref.dragEl;
|
|
|
dragEl$1 = dragged;
|
|
|
},
|
|
|
delayEnded: function delayEnded() {
|
|
|
this.isMultiDrag = ~multiDragElements.indexOf(dragEl$1);
|
|
|
},
|
|
|
setupClone: function setupClone(_ref2) {
|
|
|
var sortable = _ref2.sortable, cancel = _ref2.cancel;
|
|
|
if (!this.isMultiDrag) return;
|
|
|
for(var i = 0; i < multiDragElements.length; i++){
|
|
|
multiDragClones.push(clone(multiDragElements[i]));
|
|
|
multiDragClones[i].sortableIndex = multiDragElements[i].sortableIndex;
|
|
|
multiDragClones[i].draggable = false;
|
|
|
multiDragClones[i].style["will-change"] = "";
|
|
|
toggleClass(multiDragClones[i], this.options.selectedClass, false);
|
|
|
multiDragElements[i] === dragEl$1 && toggleClass(multiDragClones[i], this.options.chosenClass, false);
|
|
|
}
|
|
|
sortable._hideClone();
|
|
|
cancel();
|
|
|
},
|
|
|
clone: function clone(_ref3) {
|
|
|
var sortable = _ref3.sortable, rootEl4 = _ref3.rootEl, dispatchSortableEvent = _ref3.dispatchSortableEvent, cancel = _ref3.cancel;
|
|
|
if (!this.isMultiDrag) return;
|
|
|
if (!this.options.removeCloneOnHide) {
|
|
|
if (multiDragElements.length && multiDragSortable === sortable) {
|
|
|
insertMultiDragClones(true, rootEl4);
|
|
|
dispatchSortableEvent("clone");
|
|
|
cancel();
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
showClone: function showClone(_ref4) {
|
|
|
var cloneNowShown = _ref4.cloneNowShown, rootEl5 = _ref4.rootEl, cancel = _ref4.cancel;
|
|
|
if (!this.isMultiDrag) return;
|
|
|
insertMultiDragClones(false, rootEl5);
|
|
|
multiDragClones.forEach(function(clone1) {
|
|
|
css(clone1, "display", "");
|
|
|
});
|
|
|
cloneNowShown();
|
|
|
clonesHidden = false;
|
|
|
cancel();
|
|
|
},
|
|
|
hideClone: function hideClone(_ref5) {
|
|
|
var _this = this;
|
|
|
var sortable = _ref5.sortable, cloneNowHidden = _ref5.cloneNowHidden, cancel = _ref5.cancel;
|
|
|
if (!this.isMultiDrag) return;
|
|
|
multiDragClones.forEach(function(clone2) {
|
|
|
css(clone2, "display", "none");
|
|
|
if (_this.options.removeCloneOnHide && clone2.parentNode) clone2.parentNode.removeChild(clone2);
|
|
|
});
|
|
|
cloneNowHidden();
|
|
|
clonesHidden = true;
|
|
|
cancel();
|
|
|
},
|
|
|
dragStartGlobal: function dragStartGlobal(_ref6) {
|
|
|
var sortable = _ref6.sortable;
|
|
|
if (!this.isMultiDrag && multiDragSortable) multiDragSortable.multiDrag._deselectMultiDrag();
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
multiDragElement.sortableIndex = index(multiDragElement);
|
|
|
}); // Sort multi-drag elements
|
|
|
multiDragElements = multiDragElements.sort(function(a, b) {
|
|
|
return a.sortableIndex - b.sortableIndex;
|
|
|
});
|
|
|
dragStarted = true;
|
|
|
},
|
|
|
dragStarted: function dragStarted(_ref7) {
|
|
|
var _this2 = this;
|
|
|
var sortable = _ref7.sortable;
|
|
|
if (!this.isMultiDrag) return;
|
|
|
if (this.options.sort) {
|
|
|
// Capture rects,
|
|
|
// hide multi drag elements (by positioning them absolute),
|
|
|
// set multi drag elements rects to dragRect,
|
|
|
// show multi drag elements,
|
|
|
// animate to rects,
|
|
|
// unset rects & remove from DOM
|
|
|
sortable.captureAnimationState();
|
|
|
if (this.options.animation) {
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
if (multiDragElement === dragEl$1) return;
|
|
|
css(multiDragElement, "position", "absolute");
|
|
|
});
|
|
|
var dragRect = getRect(dragEl$1, false, true, true);
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
if (multiDragElement === dragEl$1) return;
|
|
|
setRect(multiDragElement, dragRect);
|
|
|
});
|
|
|
folding = true;
|
|
|
initialFolding = true;
|
|
|
}
|
|
|
}
|
|
|
sortable.animateAll(function() {
|
|
|
folding = false;
|
|
|
initialFolding = false;
|
|
|
if (_this2.options.animation) multiDragElements.forEach(function(multiDragElement) {
|
|
|
unsetRect(multiDragElement);
|
|
|
});
|
|
|
// Remove all auxiliary multidrag items from el, if sorting enabled
|
|
|
if (_this2.options.sort) removeMultiDragElements();
|
|
|
});
|
|
|
},
|
|
|
dragOver: function dragOver(_ref8) {
|
|
|
var target = _ref8.target, completed = _ref8.completed, cancel = _ref8.cancel;
|
|
|
if (folding && ~multiDragElements.indexOf(target)) {
|
|
|
completed(false);
|
|
|
cancel();
|
|
|
}
|
|
|
},
|
|
|
revert: function revert(_ref9) {
|
|
|
var fromSortable = _ref9.fromSortable, rootEl6 = _ref9.rootEl, sortable = _ref9.sortable, dragRect = _ref9.dragRect;
|
|
|
if (multiDragElements.length > 1) {
|
|
|
// Setup unfold animation
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
sortable.addAnimationState({
|
|
|
target: multiDragElement,
|
|
|
rect: folding ? getRect(multiDragElement) : dragRect
|
|
|
});
|
|
|
unsetRect(multiDragElement);
|
|
|
multiDragElement.fromRect = dragRect;
|
|
|
fromSortable.removeAnimationState(multiDragElement);
|
|
|
});
|
|
|
folding = false;
|
|
|
insertMultiDragElements(!this.options.removeCloneOnHide, rootEl6);
|
|
|
}
|
|
|
},
|
|
|
dragOverCompleted: function dragOverCompleted(_ref10) {
|
|
|
var sortable = _ref10.sortable, isOwner = _ref10.isOwner, insertion = _ref10.insertion, activeSortable = _ref10.activeSortable, parentEl1 = _ref10.parentEl, putSortable7 = _ref10.putSortable;
|
|
|
var options = this.options;
|
|
|
if (insertion) {
|
|
|
// Clones must be hidden before folding animation to capture dragRectAbsolute properly
|
|
|
if (isOwner) activeSortable._hideClone();
|
|
|
initialFolding = false; // If leaving sort:false root, or already folding - Fold to new location
|
|
|
if (options.animation && multiDragElements.length > 1 && (folding || !isOwner && !activeSortable.options.sort && !putSortable7)) {
|
|
|
// Fold: Set all multi drag elements's rects to dragEl's rect when multi-drag elements are invisible
|
|
|
var dragRectAbsolute = getRect(dragEl$1, false, true, true);
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
if (multiDragElement === dragEl$1) return;
|
|
|
setRect(multiDragElement, dragRectAbsolute); // Move element(s) to end of parentEl so that it does not interfere with multi-drag clones insertion if they are inserted
|
|
|
// while folding, and so that we can capture them again because old sortable will no longer be fromSortable
|
|
|
parentEl1.appendChild(multiDragElement);
|
|
|
});
|
|
|
folding = true;
|
|
|
} // Clones must be shown (and check to remove multi drags) after folding when interfering multiDragElements are moved out
|
|
|
if (!isOwner) {
|
|
|
// Only remove if not folding (folding will remove them anyways)
|
|
|
if (!folding) removeMultiDragElements();
|
|
|
if (multiDragElements.length > 1) {
|
|
|
var clonesHiddenBefore = clonesHidden;
|
|
|
activeSortable._showClone(sortable); // Unfold animation for clones if showing from hidden
|
|
|
if (activeSortable.options.animation && !clonesHidden && clonesHiddenBefore) multiDragClones.forEach(function(clone3) {
|
|
|
activeSortable.addAnimationState({
|
|
|
target: clone3,
|
|
|
rect: clonesFromRect
|
|
|
});
|
|
|
clone3.fromRect = clonesFromRect;
|
|
|
clone3.thisAnimationDuration = null;
|
|
|
});
|
|
|
} else activeSortable._showClone(sortable);
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
dragOverAnimationCapture: function dragOverAnimationCapture(_ref11) {
|
|
|
var dragRect = _ref11.dragRect, isOwner = _ref11.isOwner, activeSortable = _ref11.activeSortable;
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
multiDragElement.thisAnimationDuration = null;
|
|
|
});
|
|
|
if (activeSortable.options.animation && !isOwner && activeSortable.multiDrag.isMultiDrag) {
|
|
|
clonesFromRect = _extends({}, dragRect);
|
|
|
var dragMatrix = matrix(dragEl$1, true);
|
|
|
clonesFromRect.top -= dragMatrix.f;
|
|
|
clonesFromRect.left -= dragMatrix.e;
|
|
|
}
|
|
|
},
|
|
|
dragOverAnimationComplete: function dragOverAnimationComplete() {
|
|
|
if (folding) {
|
|
|
folding = false;
|
|
|
removeMultiDragElements();
|
|
|
}
|
|
|
},
|
|
|
drop: function drop(_ref12) {
|
|
|
var evt = _ref12.originalEvent, rootEl7 = _ref12.rootEl, parentEl2 = _ref12.parentEl, sortable = _ref12.sortable, dispatchSortableEvent = _ref12.dispatchSortableEvent, oldIndex2 = _ref12.oldIndex, putSortable8 = _ref12.putSortable;
|
|
|
var toSortable = putSortable8 || this.sortable;
|
|
|
if (!evt) return;
|
|
|
var options = this.options, children = parentEl2.children; // Multi-drag selection
|
|
|
if (!dragStarted) {
|
|
|
if (options.multiDragKey && !this.multiDragKeyDown) this._deselectMultiDrag();
|
|
|
toggleClass(dragEl$1, options.selectedClass, !~multiDragElements.indexOf(dragEl$1));
|
|
|
if (!~multiDragElements.indexOf(dragEl$1)) {
|
|
|
multiDragElements.push(dragEl$1);
|
|
|
dispatchEvent({
|
|
|
sortable: sortable,
|
|
|
rootEl: rootEl7,
|
|
|
name: "select",
|
|
|
targetEl: dragEl$1,
|
|
|
originalEvent: evt
|
|
|
}); // Modifier activated, select from last to dragEl
|
|
|
if (evt.shiftKey && lastMultiDragSelect && sortable.el.contains(lastMultiDragSelect)) {
|
|
|
var lastIndex = index(lastMultiDragSelect), currentIndex = index(dragEl$1);
|
|
|
if (~lastIndex && ~currentIndex && lastIndex !== currentIndex) {
|
|
|
// Must include lastMultiDragSelect (select it), in case modified selection from no selection
|
|
|
// (but previous selection existed)
|
|
|
var n, i;
|
|
|
if (currentIndex > lastIndex) {
|
|
|
i = lastIndex;
|
|
|
n = currentIndex;
|
|
|
} else {
|
|
|
i = currentIndex;
|
|
|
n = lastIndex + 1;
|
|
|
}
|
|
|
for(; i < n; i++){
|
|
|
if (~multiDragElements.indexOf(children[i])) continue;
|
|
|
toggleClass(children[i], options.selectedClass, true);
|
|
|
multiDragElements.push(children[i]);
|
|
|
dispatchEvent({
|
|
|
sortable: sortable,
|
|
|
rootEl: rootEl7,
|
|
|
name: "select",
|
|
|
targetEl: children[i],
|
|
|
originalEvent: evt
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
} else lastMultiDragSelect = dragEl$1;
|
|
|
multiDragSortable = toSortable;
|
|
|
} else {
|
|
|
multiDragElements.splice(multiDragElements.indexOf(dragEl$1), 1);
|
|
|
lastMultiDragSelect = null;
|
|
|
dispatchEvent({
|
|
|
sortable: sortable,
|
|
|
rootEl: rootEl7,
|
|
|
name: "deselect",
|
|
|
targetEl: dragEl$1,
|
|
|
originalEvent: evt
|
|
|
});
|
|
|
}
|
|
|
} // Multi-drag drop
|
|
|
if (dragStarted && this.isMultiDrag) {
|
|
|
folding = false; // Do not "unfold" after around dragEl if reverted
|
|
|
if ((parentEl2[expando].options.sort || parentEl2 !== rootEl7) && multiDragElements.length > 1) {
|
|
|
var dragRect = getRect(dragEl$1), multiDragIndex = index(dragEl$1, ":not(." + this.options.selectedClass + ")");
|
|
|
if (!initialFolding && options.animation) dragEl$1.thisAnimationDuration = null;
|
|
|
toSortable.captureAnimationState();
|
|
|
if (!initialFolding) {
|
|
|
if (options.animation) {
|
|
|
dragEl$1.fromRect = dragRect;
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
multiDragElement.thisAnimationDuration = null;
|
|
|
if (multiDragElement !== dragEl$1) {
|
|
|
var rect = folding ? getRect(multiDragElement) : dragRect;
|
|
|
multiDragElement.fromRect = rect; // Prepare unfold animation
|
|
|
toSortable.addAnimationState({
|
|
|
target: multiDragElement,
|
|
|
rect: rect
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
} // Multi drag elements are not necessarily removed from the DOM on drop, so to reinsert
|
|
|
// properly they must all be removed
|
|
|
removeMultiDragElements();
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
if (children[multiDragIndex]) parentEl2.insertBefore(multiDragElement, children[multiDragIndex]);
|
|
|
else parentEl2.appendChild(multiDragElement);
|
|
|
multiDragIndex++;
|
|
|
}); // If initial folding is done, the elements may have changed position because they are now
|
|
|
// unfolding around dragEl, even though dragEl may not have his index changed, so update event
|
|
|
// must be fired here as Sortable will not.
|
|
|
if (oldIndex2 === index(dragEl$1)) {
|
|
|
var update = false;
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
if (multiDragElement.sortableIndex !== index(multiDragElement)) {
|
|
|
update = true;
|
|
|
return;
|
|
|
}
|
|
|
});
|
|
|
if (update) dispatchSortableEvent("update");
|
|
|
}
|
|
|
} // Must be done after capturing individual rects (scroll bar)
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
unsetRect(multiDragElement);
|
|
|
});
|
|
|
toSortable.animateAll();
|
|
|
}
|
|
|
multiDragSortable = toSortable;
|
|
|
} // Remove clones if necessary
|
|
|
if (rootEl7 === parentEl2 || putSortable8 && putSortable8.lastPutMode !== "clone") multiDragClones.forEach(function(clone4) {
|
|
|
clone4.parentNode && clone4.parentNode.removeChild(clone4);
|
|
|
});
|
|
|
},
|
|
|
nullingGlobal: function nullingGlobal() {
|
|
|
this.isMultiDrag = dragStarted = false;
|
|
|
multiDragClones.length = 0;
|
|
|
},
|
|
|
destroyGlobal: function destroyGlobal() {
|
|
|
this._deselectMultiDrag();
|
|
|
off(document, "pointerup", this._deselectMultiDrag);
|
|
|
off(document, "mouseup", this._deselectMultiDrag);
|
|
|
off(document, "touchend", this._deselectMultiDrag);
|
|
|
off(document, "keydown", this._checkKeyDown);
|
|
|
off(document, "keyup", this._checkKeyUp);
|
|
|
},
|
|
|
_deselectMultiDrag: function _deselectMultiDrag(evt) {
|
|
|
if (typeof dragStarted !== "undefined" && dragStarted) return; // Only deselect if selection is in this sortable
|
|
|
if (multiDragSortable !== this.sortable) return; // Only deselect if target is not item in this sortable
|
|
|
if (evt && closest(evt.target, this.options.draggable, this.sortable.el, false)) return; // Only deselect if left click
|
|
|
if (evt && evt.button !== 0) return;
|
|
|
while(multiDragElements.length){
|
|
|
var el = multiDragElements[0];
|
|
|
toggleClass(el, this.options.selectedClass, false);
|
|
|
multiDragElements.shift();
|
|
|
dispatchEvent({
|
|
|
sortable: this.sortable,
|
|
|
rootEl: this.sortable.el,
|
|
|
name: "deselect",
|
|
|
targetEl: el,
|
|
|
originalEvent: evt
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
_checkKeyDown: function _checkKeyDown(evt) {
|
|
|
if (evt.key === this.options.multiDragKey) this.multiDragKeyDown = true;
|
|
|
},
|
|
|
_checkKeyUp: function _checkKeyUp(evt) {
|
|
|
if (evt.key === this.options.multiDragKey) this.multiDragKeyDown = false;
|
|
|
}
|
|
|
};
|
|
|
return _extends(MultiDrag, {
|
|
|
// Static methods & properties
|
|
|
pluginName: "multiDrag",
|
|
|
utils: {
|
|
|
/**
|
|
|
* Selects the provided multi-drag item
|
|
|
* @param {HTMLElement} el The element to be selected
|
|
|
*/ select: function select(el) {
|
|
|
var sortable = el.parentNode[expando];
|
|
|
if (!sortable || !sortable.options.multiDrag || ~multiDragElements.indexOf(el)) return;
|
|
|
if (multiDragSortable && multiDragSortable !== sortable) {
|
|
|
multiDragSortable.multiDrag._deselectMultiDrag();
|
|
|
multiDragSortable = sortable;
|
|
|
}
|
|
|
toggleClass(el, sortable.options.selectedClass, true);
|
|
|
multiDragElements.push(el);
|
|
|
},
|
|
|
/**
|
|
|
* Deselects the provided multi-drag item
|
|
|
* @param {HTMLElement} el The element to be deselected
|
|
|
*/ deselect: function deselect(el) {
|
|
|
var sortable = el.parentNode[expando], index2 = multiDragElements.indexOf(el);
|
|
|
if (!sortable || !sortable.options.multiDrag || !~index2) return;
|
|
|
toggleClass(el, sortable.options.selectedClass, false);
|
|
|
multiDragElements.splice(index2, 1);
|
|
|
}
|
|
|
},
|
|
|
eventProperties: function eventProperties() {
|
|
|
var _this3 = this;
|
|
|
var oldIndicies = [], newIndicies = [];
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
oldIndicies.push({
|
|
|
multiDragElement: multiDragElement,
|
|
|
index: multiDragElement.sortableIndex
|
|
|
}); // multiDragElements will already be sorted if folding
|
|
|
var newIndex2;
|
|
|
if (folding && multiDragElement !== dragEl$1) newIndex2 = -1;
|
|
|
else if (folding) newIndex2 = index(multiDragElement, ":not(." + _this3.options.selectedClass + ")");
|
|
|
else newIndex2 = index(multiDragElement);
|
|
|
newIndicies.push({
|
|
|
multiDragElement: multiDragElement,
|
|
|
index: newIndex2
|
|
|
});
|
|
|
});
|
|
|
return {
|
|
|
items: _toConsumableArray(multiDragElements),
|
|
|
clones: [].concat(multiDragClones),
|
|
|
oldIndicies: oldIndicies,
|
|
|
newIndicies: newIndicies
|
|
|
};
|
|
|
},
|
|
|
optionListeners: {
|
|
|
multiDragKey: function multiDragKey(key) {
|
|
|
key = key.toLowerCase();
|
|
|
if (key === "ctrl") key = "Control";
|
|
|
else if (key.length > 1) key = key.charAt(0).toUpperCase() + key.substr(1);
|
|
|
return key;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
function insertMultiDragElements(clonesInserted, rootEl8) {
|
|
|
multiDragElements.forEach(function(multiDragElement, i) {
|
|
|
var target = rootEl8.children[multiDragElement.sortableIndex + (clonesInserted ? Number(i) : 0)];
|
|
|
if (target) rootEl8.insertBefore(multiDragElement, target);
|
|
|
else rootEl8.appendChild(multiDragElement);
|
|
|
});
|
|
|
}
|
|
|
/**
|
|
|
* Insert multi-drag clones
|
|
|
* @param {[Boolean]} elementsInserted Whether the multi-drag elements are inserted
|
|
|
* @param {HTMLElement} rootEl
|
|
|
*/ function insertMultiDragClones(elementsInserted, rootEl9) {
|
|
|
multiDragClones.forEach(function(clone5, i) {
|
|
|
var target = rootEl9.children[clone5.sortableIndex + (elementsInserted ? Number(i) : 0)];
|
|
|
if (target) rootEl9.insertBefore(clone5, target);
|
|
|
else rootEl9.appendChild(clone5);
|
|
|
});
|
|
|
}
|
|
|
function removeMultiDragElements() {
|
|
|
multiDragElements.forEach(function(multiDragElement) {
|
|
|
if (multiDragElement === dragEl$1) return;
|
|
|
multiDragElement.parentNode && multiDragElement.parentNode.removeChild(multiDragElement);
|
|
|
});
|
|
|
}
|
|
|
Sortable.mount(new AutoScrollPlugin());
|
|
|
Sortable.mount(Remove, Revert);
|
|
|
exports.default = Sortable;
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"4SQpj":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
var _settingsActions = require("../actions/SettingsActions");
|
|
|
var _settingsActionsDefault = parcelHelpers.interopDefault(_settingsActions);
|
|
|
var _maintenanceManager = require("./MaintenanceManager");
|
|
|
var _maintenanceManagerDefault = parcelHelpers.interopDefault(_maintenanceManager);
|
|
|
var _fipamoAdminAPI = require("../../libraries/FipamoAdminAPI");
|
|
|
var _fipamoAdminAPIDefault = parcelHelpers.interopDefault(_fipamoAdminAPI);
|
|
|
var _dataEvent = require("../../../src/com/events/DataEvent");
|
|
|
var _mailer = require("../actions/Mailer");
|
|
|
var _mailerDefault = parcelHelpers.interopDefault(_mailer);
|
|
|
var _notifications = require("../ui/Notifications");
|
|
|
var _notificationsDefault = parcelHelpers.interopDefault(_notifications);
|
|
|
const notify = new (0, _notificationsDefault.default)();
|
|
|
class SettingsIndex {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){
|
|
|
this.processing = false;
|
|
|
this.start();
|
|
|
this.admin = new (0, _fipamoAdminAPIDefault.default)(null);
|
|
|
this.mm = new (0, _maintenanceManagerDefault.default)(null, null);
|
|
|
}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
start() {
|
|
|
let self = this; //handle save button
|
|
|
document.getElementById("save-toggle").addEventListener("click", ()=>new (0, _settingsActionsDefault.default)().getInfo().then((data)=>{
|
|
|
notify.alert("Saving Settings", null);
|
|
|
self.admin.sync((0, _fipamoAdminAPI.TASK_SYNC_SETTNIGS), data).then((r)=>{
|
|
|
if (r.type == _dataEvent.SETTINGS_UPDATED) notify.alert(r.message, true);
|
|
|
else notify.alert(r.message, true);
|
|
|
});
|
|
|
}).catch(()=>{})); //handle set up image uploads
|
|
|
document.getElementById("avatar").addEventListener("click", ()=>{
|
|
|
document.getElementById("avatar-upload").click();
|
|
|
});
|
|
|
document.getElementById("background").addEventListener("click", ()=>{
|
|
|
document.getElementById("background-upload").click();
|
|
|
});
|
|
|
document.getElementById("avatar-upload").addEventListener("change", (e)=>{
|
|
|
self.handleImageUpload(e.target.id, e.target.files);
|
|
|
}, false);
|
|
|
document.getElementById("background-upload").addEventListener("change", (e)=>{
|
|
|
self.handleImageUpload(e.target.id, e.target.files);
|
|
|
}, false); //handle api access toggle
|
|
|
var apiButton = document.getElementById("api-access-toggle");
|
|
|
var apiStatus = document.getElementById("api-status");
|
|
|
apiButton.addEventListener("click", (e)=>{
|
|
|
e.stopPropagation();
|
|
|
e.preventDefault();
|
|
|
if (apiButton.getAttribute("data-enabled") == "false") {
|
|
|
apiButton.setAttribute("data-enabled", "true");
|
|
|
apiStatus.innerHTML = "EXTERNAL API ACCESS IS ENABLED";
|
|
|
} else {
|
|
|
apiButton.setAttribute("data-enabled", "false");
|
|
|
apiStatus.innerHTML = "EXTERNAL API ACCESS IS NOT ENABLED";
|
|
|
}
|
|
|
}); //handle dynamic page rendering
|
|
|
var dynamicRenderButton = document.getElementById("dynamic-render-toggle");
|
|
|
var dynamicRenderStatus = document.getElementById("dynamic-render-status");
|
|
|
dynamicRenderButton.addEventListener("click", (e)=>{
|
|
|
e.stopPropagation();
|
|
|
e.preventDefault();
|
|
|
if (dynamicRenderButton.getAttribute("data-enabled") == "false") {
|
|
|
dynamicRenderButton.setAttribute("data-enabled", "true");
|
|
|
dynamicRenderStatus.innerHTML = "DYNAMIC PAGE RENDERING";
|
|
|
} else {
|
|
|
dynamicRenderButton.setAttribute("data-enabled", "false");
|
|
|
dynamicRenderStatus.innerHTML = "STATIC PAGE RENDERING";
|
|
|
}
|
|
|
});
|
|
|
document.getElementById("send-mail").addEventListener("click", (e)=>this.handleMailer(e));
|
|
|
document.getElementById("publish-pages").addEventListener("click", (e)=>this.handlePublished(e)); //handle page render on save toggle
|
|
|
document.getElementById("render-toggle").addEventListener("click", (e)=>this.toggleRender(e));
|
|
|
document.getElementById("render-toggle-icon").addEventListener("click", (e)=>this.toggleRender(e)); //handle theme toggle
|
|
|
let themeBtns = document.querySelectorAll(".theme-select");
|
|
|
for(var i = 0, length = themeBtns.length; i < length; i++)themeBtns[i].addEventListener("click", (e)=>this.handleThemes(e));
|
|
|
//handle mail options
|
|
|
let mailBtn = document.querySelectorAll(".mail-option");
|
|
|
for(i = 0, length = mailBtn.length; i < length; i++)mailBtn[i].addEventListener("click", (e)=>this.handleMailOptions(e));
|
|
|
//handle backup from settings [disabled]
|
|
|
document.getElementById("create-backup").addEventListener("click", (e)=>this.handleBackup(e));
|
|
|
/*
|
|
|
document
|
|
|
.getElementById("reindex-pages")
|
|
|
.addEventListener("click", (e) => this.handleReindex(e));
|
|
|
*/ }
|
|
|
// event handlers
|
|
|
//--------------------------
|
|
|
togglePrivacy(e) {
|
|
|
e.stopPropagation();
|
|
|
e.preventDefault();
|
|
|
if (e.target.getAttribute("data-private") == "false") {
|
|
|
e.target.setAttribute("data-private", "true");
|
|
|
e.target.innerHTML = "SITE IS PUBLIC";
|
|
|
} else {
|
|
|
e.target.setAttribute("data-private", "false");
|
|
|
e.target.innerHTML = "SITE IS PRIVATE";
|
|
|
}
|
|
|
}
|
|
|
toggleRender(e) {
|
|
|
e.stopPropagation();
|
|
|
e.preventDefault();
|
|
|
let button = document.getElementById("render-toggle");
|
|
|
if (button.getAttribute("data-render") == "false") button.setAttribute("data-render", "true"); //e.target.innerHTML = 'RENDER PAGES ON SAVE';
|
|
|
else button.setAttribute("data-render", "false"); //e.target.innerHTML = "DON'T RENDER PAGES ON SAVE";
|
|
|
}
|
|
|
handleMailer() {
|
|
|
let mailer = new (0, _mailerDefault.default)();
|
|
|
mailer.testMail(); //mailer.sendMail();
|
|
|
}
|
|
|
handleThemes(e) {
|
|
|
e.stopPropagation();
|
|
|
e.preventDefault();
|
|
|
let themes = document.querySelectorAll(".theme-select");
|
|
|
for(var i = 0, length = themes.length; i < length; i++)e.target.id == themes[i].id ? themes[i].setAttribute("data-enabled", "true") : themes[i].setAttribute("data-enabled", "false");
|
|
|
}
|
|
|
handleMailOptions(e) {
|
|
|
e.preventDefault();
|
|
|
e.stopPropagation();
|
|
|
let smtp = document.getElementById("mail-smtp");
|
|
|
let mailgun = document.getElementById("mail-mg");
|
|
|
let mail = document.querySelectorAll(".mail-option");
|
|
|
for(var i = 0, length = mail.length; i < length; i++)if (e.target.id == mail[i].id) {
|
|
|
mail[i].setAttribute("data-enabled", "true");
|
|
|
if (e.target.id == "option-smtp") {
|
|
|
smtp.setAttribute("data-enabled", "true");
|
|
|
mailgun.setAttribute("data-enabled", "false");
|
|
|
} else if (e.target.id == "option-none") {
|
|
|
smtp.setAttribute("data-enabled", "false");
|
|
|
mailgun.setAttribute("data-enabled", "false");
|
|
|
} else {
|
|
|
smtp.setAttribute("data-enabled", "false");
|
|
|
mailgun.setAttribute("data-enabled", "true");
|
|
|
}
|
|
|
} else mail[i].setAttribute("data-enabled", "false");
|
|
|
}
|
|
|
handleImageUpload(type, files) {
|
|
|
notify.alert("Uploading Image... ", null);
|
|
|
this.mm.imageUpload(type, files).then((r)=>{
|
|
|
if (r.type == _dataEvent.AVATAR_UPLOADED) {
|
|
|
notify.alert(r.message, true);
|
|
|
document.getElementById("avatar").src = r.url;
|
|
|
} else {
|
|
|
notify.alert(r.message, true);
|
|
|
document.getElementById("background").src = r.url;
|
|
|
}
|
|
|
}).catch(()=>{});
|
|
|
}
|
|
|
handlePublished(e) {
|
|
|
if (this.processing) return;
|
|
|
e.preventDefault();
|
|
|
e.stopPropagation();
|
|
|
let self = this;
|
|
|
let task = {
|
|
|
task: "PUBLISH_ALL"
|
|
|
};
|
|
|
this.processing = true;
|
|
|
notify.alert("Publishing site...", null);
|
|
|
this.admin.publish(task).then((r)=>{
|
|
|
self.processing = false;
|
|
|
notify.alert(r.message, true);
|
|
|
}).catch((err)=>{
|
|
|
self.processing = false;
|
|
|
notify.alert(err, false);
|
|
|
});
|
|
|
}
|
|
|
handleBackup(e) {
|
|
|
e.preventDefault();
|
|
|
e.stopPropagation();
|
|
|
notify.alert("Creating backup", null);
|
|
|
this.mm.backup().then((r)=>{
|
|
|
notify.alert(r.message, true);
|
|
|
}).catch((err)=>{
|
|
|
notify.alert(err, false);
|
|
|
});
|
|
|
}
|
|
|
handleReindex(e) {
|
|
|
if (this.processing) return;
|
|
|
let self = this;
|
|
|
e.preventDefault();
|
|
|
e.stopPropagation();
|
|
|
let task = {
|
|
|
task: "cleanup pages indexes"
|
|
|
};
|
|
|
this.processing = true;
|
|
|
notify.alert("Cleaning up page indexes", null);
|
|
|
this.admin.handleReindex(task).then((r)=>{
|
|
|
self.processing = false;
|
|
|
notify.alert(r.message, true);
|
|
|
}).catch((err)=>{
|
|
|
self.processing = false;
|
|
|
notify.alert(err, false);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
exports.default = SettingsIndex;
|
|
|
|
|
|
},{"../actions/SettingsActions":"dwGCY","./MaintenanceManager":"cYXLM","../../libraries/FipamoAdminAPI":"3dcvg","../../../src/com/events/DataEvent":"hCRFh","../actions/Mailer":"kqgKI","../ui/Notifications":"9GRdG","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"dwGCY":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
class SettingsActions {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
getInfo() {
|
|
|
let handle = document.getElementById("settings-handle").value;
|
|
|
let email = document.getElementById("settings-email").value;
|
|
|
let url = document.getElementById("settings-url").value;
|
|
|
let title = document.getElementById("settings-title").value;
|
|
|
let desc = document.getElementById("settings-desc").value; //let privacy = document.getElementById('privacy-toggle').getAttribute('data-private');
|
|
|
let render = document.getElementById("render-toggle").getAttribute("data-render");
|
|
|
let background = document.getElementById("background").src;
|
|
|
let selected = "";
|
|
|
let selects = document.querySelectorAll(".theme-select");
|
|
|
let smtpDomain = document.getElementById("smtp-domain").value;
|
|
|
let smtpEmail = document.getElementById("smtp-email").value;
|
|
|
let smtpPass = document.getElementById("smtp-pass").value;
|
|
|
let mgDomain = document.getElementById("mg-domain").value;
|
|
|
let mgKey = document.getElementById("mg-key").value;
|
|
|
let mailActive = "";
|
|
|
let mailOptions = document.querySelectorAll(".mail-option");
|
|
|
let apiStatus = document.getElementById("api-access-toggle").getAttribute("data-enabled");
|
|
|
let dynamicRenderStatus = document.getElementById("dynamic-render-toggle").getAttribute("data-enabled");
|
|
|
var i, count;
|
|
|
for(i = 0, count = selects.length; i < count; i++)if (selects[i].getAttribute("data-enabled") == "true") selected = selects[i].id;
|
|
|
for(i = 0, count = mailOptions.length; i < count; i++)if (mailOptions[i].getAttribute("data-enabled") == "true") mailActive = mailOptions[i].id;
|
|
|
let settingsData = {
|
|
|
global: {
|
|
|
base_url: url,
|
|
|
title: title,
|
|
|
descriptions: desc,
|
|
|
background: background,
|
|
|
private: false,
|
|
|
renderOnSave: render,
|
|
|
theme: selected,
|
|
|
externalAPI: apiStatus,
|
|
|
dynamicRender: dynamicRenderStatus
|
|
|
},
|
|
|
member: {
|
|
|
handle: handle,
|
|
|
email: email
|
|
|
},
|
|
|
email: {
|
|
|
active: mailActive,
|
|
|
smtp: {
|
|
|
domain: smtpDomain,
|
|
|
email: smtpEmail,
|
|
|
password: smtpPass
|
|
|
},
|
|
|
mailgun: {
|
|
|
domain: mgDomain,
|
|
|
key: mgKey
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
return new Promise(function(resolve) {
|
|
|
resolve(settingsData);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
exports.default = SettingsActions;
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"kqgKI":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
var _fipamoAdminAPI = require("../../libraries/FipamoAdminAPI");
|
|
|
var _fipamoAdminAPIDefault = parcelHelpers.interopDefault(_fipamoAdminAPI);
|
|
|
var _notifications = require("../ui/Notifications");
|
|
|
var _notificationsDefault = parcelHelpers.interopDefault(_notifications);
|
|
|
const notify = new (0, _notificationsDefault.default)();
|
|
|
class Mailer {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
sendMail() {
|
|
|
let mailData = {
|
|
|
content: "This is a test email"
|
|
|
};
|
|
|
let admin = new (0, _fipamoAdminAPIDefault.default)();
|
|
|
admin.sendMail(mailData).then((result)=>{
|
|
|
notify.alert(result.message, true);
|
|
|
}).catch((err)=>{
|
|
|
notify.alert(err.message, false);
|
|
|
});
|
|
|
}
|
|
|
testMail() {
|
|
|
let mailData = {
|
|
|
content: "This is a test email",
|
|
|
mail_task: "TESTING"
|
|
|
};
|
|
|
let admin = new (0, _fipamoAdminAPIDefault.default)();
|
|
|
admin.sendMail(mailData).then((result)=>{
|
|
|
notify.alert(result.message, true);
|
|
|
}).catch((err)=>{
|
|
|
notify.alert(err.message, false);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
exports.default = Mailer;
|
|
|
|
|
|
},{"../../libraries/FipamoAdminAPI":"3dcvg","../ui/Notifications":"9GRdG","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"6S99f":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
var _fipamoAdminAPI = require("../../libraries/FipamoAdminAPI");
|
|
|
var _fipamoAdminAPIDefault = parcelHelpers.interopDefault(_fipamoAdminAPI);
|
|
|
var _navActions = require("../actions/NavActions");
|
|
|
var _navActionsDefault = parcelHelpers.interopDefault(_navActions);
|
|
|
var _dataEvent = require("../events/DataEvent");
|
|
|
var _notifications = require("../ui/Notifications");
|
|
|
var _notificationsDefault = parcelHelpers.interopDefault(_notifications);
|
|
|
var _sortablejs = require("sortablejs");
|
|
|
var _sortablejsDefault = parcelHelpers.interopDefault(_sortablejs);
|
|
|
const notify = new (0, _notificationsDefault.default)();
|
|
|
class NavIndex {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){
|
|
|
this.processing = false;
|
|
|
this.admin = new (0, _fipamoAdminAPIDefault.default)(null);
|
|
|
this.start();
|
|
|
}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
start() {
|
|
|
//grabs elements and makes them sortables
|
|
|
let self = this;
|
|
|
(0, _sortablejsDefault.default).create(document.getElementById("nav-pages"), {
|
|
|
onUpdate: ()=>{
|
|
|
new (0, _navActionsDefault.default)().syncMenu().then((data)=>{
|
|
|
notify.alert("Updating Menu", null);
|
|
|
self.admin.sync((0, _fipamoAdminAPI.TASK_SYNC_NAV), data).then((r)=>{
|
|
|
if (r.type == _dataEvent.MENU_UPDATED) notify.alert(r.message, true);
|
|
|
else notify.alert(r.message, true);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
var nav = document.querySelectorAll(".nav-btn");
|
|
|
for(var i = 0, length = nav.length; i < length; i++)nav[i].addEventListener("click", (e)=>this.handleNavButton(e), false);
|
|
|
}
|
|
|
// event handlers
|
|
|
//--------------------------
|
|
|
handleNavButton(e) {
|
|
|
if (this.processing) return;
|
|
|
let id = "";
|
|
|
let self = this;
|
|
|
switch(e.target.id){
|
|
|
case "remove-item":
|
|
|
id = e.target.getAttribute("data-id");
|
|
|
new (0, _navActionsDefault.default)().removeItem(id);
|
|
|
new (0, _navActionsDefault.default)().syncMenu().then((data)=>{
|
|
|
data.remove = e.target.getAttribute("data-uuid");
|
|
|
notify.alert("Editing Menu", null);
|
|
|
self.processing = true;
|
|
|
self.admin.sync((0, _fipamoAdminAPI.TASK_SYNC_NAV), data).then((r)=>{
|
|
|
self.processing = false;
|
|
|
if (r.type == _dataEvent.MENU_UPDATED) notify.alert(r.message, true);
|
|
|
else notify.alert(r.message, true);
|
|
|
});
|
|
|
});
|
|
|
break;
|
|
|
case "edit-item":
|
|
|
self.processing = false;
|
|
|
window.location = "/dashboard/page/edit/" + e.target.getAttribute("data-id");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
exports.default = NavIndex;
|
|
|
|
|
|
},{"../../libraries/FipamoAdminAPI":"3dcvg","../actions/NavActions":"cBQfD","../events/DataEvent":"hCRFh","../ui/Notifications":"9GRdG","sortablejs":"4mik1","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"cBQfD":[function(require,module,exports) {
|
|
|
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
|
|
parcelHelpers.defineInteropFlag(exports);
|
|
|
class NavActions {
|
|
|
//--------------------------
|
|
|
// constructor
|
|
|
//--------------------------
|
|
|
constructor(){}
|
|
|
// methods
|
|
|
//--------------------------
|
|
|
syncMenu() {
|
|
|
let navData = [];
|
|
|
let items = document.getElementById("nav-pages").children;
|
|
|
for(let index = 0; index < items.length; index++)navData.push({
|
|
|
title: items[index].getElementsByTagName("label")[0].innerHTML,
|
|
|
id: items[index].id,
|
|
|
slug: items[index].getAttribute("data-slug"),
|
|
|
uuid: items[index].getAttribute("data-uuid"),
|
|
|
path: items[index].getAttribute("data-path")
|
|
|
});
|
|
|
let data = {
|
|
|
menu: navData,
|
|
|
remove: null
|
|
|
};
|
|
|
return new Promise(function(resolve) {
|
|
|
resolve(data);
|
|
|
});
|
|
|
}
|
|
|
removeItem(id) {
|
|
|
document.getElementById("nav-pages").removeChild(document.getElementById(id));
|
|
|
}
|
|
|
}
|
|
|
exports.default = NavActions;
|
|
|
|
|
|
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}]},["hHepG","7bZzU"], "7bZzU", "parcelRequiredac0")
|
|
|
|
|
|
//# sourceMappingURL=Start.js.map
|