solid-panes
Version:
Solid-compatible Panes: applets and views for the mashlib and databrowser
847 lines (826 loc) • 107 kB
JavaScript
"use strict";
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = _default;
var paneRegistry = _interopRequireWildcard(require("pane-registry"));
var $rdf = _interopRequireWildcard(require("rdflib"));
var UI = _interopRequireWildcard(require("solid-ui"));
var _solidLogic = require("solid-logic");
var _propertyViews = require("./propertyViews");
var _outlineIcons = require("./outlineIcons.js");
var _userInput = require("./userInput.js");
var queryByExample = _interopRequireWildcard(require("./queryByExample.js"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /* istanbul ignore file */ /* -*- coding: utf-8-dos -*-
Outline Mode Manager
*/ // @@ chec
/* global alert XPathResult sourceWidget */
// XPathResult?
// const iconHeight = '24px'
function _default(context) {
var dom = context.dom;
this.document = context.dom;
this.outlineIcons = _outlineIcons.outlineIcons;
this.labeller = this.labeller || {};
this.labeller.LanguagePreference = ''; // for now
var outline = this; // Kenny: do we need this?
var thisOutline = this;
var selection = [];
this.selection = selection;
this.ancestor = UI.utils.ancestor; // make available as outline.ancestor in callbacks
this.sparql = UI.rdf.UpdateManager;
this.kb = _solidLogic.store;
var kb = _solidLogic.store;
var sf = _solidLogic.store.fetcher;
dom.outline = this;
this.qs = new queryByExample.QuerySource(); // Track queries in queryByExample
// var selection = [] // Array of statements which have been selected
// this.focusTd // the <td> that is being observed
this.UserInput = new _userInput.UserInput(this);
this.clipboardAddress = 'tabulator:clipboard'; // Weird
this.UserInput.clipboardInit(this.clipboardAddress);
var outlineElement = this.outlineElement;
this.init = function () {
var table = getOutlineContainer();
table.outline = this;
};
/** benchmark a function **/
benchmark.lastkbsize = 0;
function benchmark(f) {
var args = [];
for (var i = arguments.length - 1; i > 0; i--) args[i - 1] = arguments[i];
// UI.log.debug('BENCHMARK: args=' + args.join());
var begin = new Date().getTime();
var returnValue = f.apply(f, args);
var end = new Date().getTime();
UI.log.info('BENCHMARK: kb delta: ' + (kb.statements.length - benchmark.lastkbsize) + ', time elapsed for ' + f + ' was ' + (end - begin) + 'ms');
benchmark.lastkbsize = kb.statements.length;
return returnValue;
} // benchmark
// / ////////////////////// Representing data
// Represent an object in summary form as a table cell
function appendRemoveIcon(node, subject, removeNode) {
var image = UI.utils.AJARImage(_outlineIcons.outlineIcons.src.icon_remove_node, 'remove', undefined, dom);
image.addEventListener('click', removeNodeIconMouseDownListener);
// image.setAttribute('align', 'right') Causes icon to be moved down
image.node = removeNode;
image.setAttribute('about', subject.toNT());
image.style.marginLeft = '5px';
image.style.marginRight = '10px';
// image.style.border='solid #777 1px';
node.appendChild(image);
return image;
}
this.appendAccessIcons = function (kb, node, obj) {
if (obj.termType !== 'NamedNode') return;
var uris = kb.uris(obj);
uris.sort();
var last = null;
for (var i = 0; i < uris.length; i++) {
if (uris[i] === last) continue;
last = uris[i];
thisOutline.appendAccessIcon(node, last);
}
};
this.appendAccessIcon = function (node, uri) {
if (!uri) return '';
var docuri = UI.rdf.uri.docpart(uri);
if (docuri.slice(0, 5) !== 'http:') return '';
var state = sf.getState(docuri);
var icon, alt, listener;
switch (state) {
case 'unrequested':
icon = _outlineIcons.outlineIcons.src.icon_unrequested;
alt = 'fetch';
listener = unrequestedIconMouseDownListener;
break;
case 'requested':
icon = _outlineIcons.outlineIcons.src.icon_requested;
alt = 'fetching';
listener = failedIconMouseDownListener; // new: can retry yello blob
break;
case 'fetched':
icon = _outlineIcons.outlineIcons.src.icon_fetched;
listener = fetchedIconMouseDownListener;
alt = 'loaded';
break;
case 'failed':
icon = _outlineIcons.outlineIcons.src.icon_failed;
alt = 'failed';
listener = failedIconMouseDownListener;
break;
case 'unpermitted':
icon = _outlineIcons.outlineIcons.src.icon_failed;
listener = failedIconMouseDownListener;
alt = 'no perm';
break;
case 'unfetchable':
icon = _outlineIcons.outlineIcons.src.icon_failed;
listener = failedIconMouseDownListener;
alt = 'cannot fetch';
break;
default:
UI.log.error('?? state = ' + state);
break;
} // switch
var img = UI.utils.AJARImage(icon, alt, _outlineIcons.outlineIcons.tooltips[icon].replace(/[Tt]his resource/, docuri), dom);
img.setAttribute('uri', uri);
img.addEventListener('click', listener); // @@ seemed to be missing 2017-08
addButtonCallbacks(img, docuri);
node.appendChild(img);
return img;
}; // appendAccessIcon
/** make the td for an object (grammatical object)
* @param obj - an RDF term
* @param view - a VIEW function (rather than a bool asImage)
**/
this.outlineObjectTD = function outlineObjectTD(obj, view, deleteNode, statement) {
var td = dom.createElement('td');
td.setAttribute('style', 'margin: 0.2em; border: none; padding: 0; vertical-align: top;');
td.setAttribute('notSelectable', 'false');
var theClass = 'obj';
// set about and put 'expand' icon
if (obj.termType === 'NamedNode' || obj.termType === 'BlankNode' || obj.termType === 'Literal' && obj.value.slice && (obj.value.slice(0, 6) === 'ftp://' || obj.value.slice(0, 8) === 'https://' || obj.value.slice(0, 7) === 'http://')) {
td.setAttribute('about', obj.toNT());
td.appendChild(UI.utils.AJARImage(UI.icons.originalIconBase + 'tbl-expand-trans.png', 'expand', undefined, dom)).addEventListener('click', expandMouseDownListener);
}
td.setAttribute('class', theClass); // this is how you find an object
// @@ TAKE CSS OUT OF STYLE SHEET
if (kb.whether(obj, UI.ns.rdf('type'), UI.ns.link('Request'))) {
td.className = 'undetermined';
} // @@? why-timbl
if (!view) {
// view should be a function pointer
view = viewAsBoringDefault;
}
td.appendChild(view(obj));
if (deleteNode) {
appendRemoveIcon(td, obj, deleteNode);
}
// set DOM methods
td.tabulatorSelect = function () {
setSelected(this, true);
};
td.tabulatorDeselect = function () {
setSelected(this, false);
};
td.addEventListener('click', selectableTDClickListener);
return td;
}; // outlineObjectTD
this.outlinePredicateTD = function outlinePredicateTD(predicate, newTr, inverse, internal) {
var predicateTD = dom.createElement('TD');
predicateTD.setAttribute('about', predicate.toNT());
predicateTD.setAttribute('class', internal ? 'pred internal' : 'pred');
var lab;
switch (predicate.termType) {
case 'BlankNode':
// TBD
predicateTD.className = 'undetermined';
break;
case 'NamedNode':
lab = UI.utils.predicateLabelForXML(predicate, inverse);
break;
case 'Collection':
// some choices of predicate
lab = UI.utils.predicateLabelForXML(predicate.elements[0], inverse);
}
lab = lab.slice(0, 1).toUpperCase() + lab.slice(1);
// if (kb.statementsMatching(predicate,rdf('type'), UI.ns.link('Request')).length) predicateTD.className='undetermined';
var labelTD = dom.createElement('TD');
labelTD.setAttribute('style', 'margin: 0.2em; border: none; padding: 0; vertical-align: top;');
labelTD.setAttribute('notSelectable', 'true');
labelTD.appendChild(dom.createTextNode(lab));
predicateTD.appendChild(labelTD);
labelTD.style.width = '100%';
predicateTD.appendChild(termWidget.construct(dom)); // termWidget is global???
for (var w in _outlineIcons.outlineIcons.termWidgets) {
if (!newTr || !newTr.AJAR_statement) break; // case for TBD as predicate
// alert(Icon.termWidgets[w]+' '+Icon.termWidgets[w].filter)
if (_outlineIcons.outlineIcons.termWidgets[w].filter && _outlineIcons.outlineIcons.termWidgets[w].filter(newTr.AJAR_statement, 'pred', inverse)) {
termWidget.addIcon(predicateTD, _outlineIcons.outlineIcons.termWidgets[w]);
}
}
// set DOM methods
predicateTD.tabulatorSelect = function () {
setSelected(this, true);
};
predicateTD.tabulatorDeselect = function () {
setSelected(this, false);
};
predicateTD.addEventListener('click', selectableTDClickListener);
return predicateTD;
}; // outlinePredicateTD
/**
* Render Tabbed set of home app panes
*
* @param {Object} [options] A set of options you can provide
* @param {string} [options.selectedTab] To open a specific dashboard pane
* @param {Function} [options.onClose] If given, will present an X for the dashboard, and call this method when clicked
* @returns Promise<{Element}> - the div that holds the dashboard
*/
function globalAppTabs() {
return _globalAppTabs.apply(this, arguments);
}
function _globalAppTabs() {
_globalAppTabs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
var options,
div,
me,
items,
renderTab,
renderMain,
_args = arguments;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
renderMain = function _renderMain(containerDiv, item) {
// Items are pane names
var pane = paneRegistry.byName(item.paneName); // 20190701
containerDiv.innerHTML = '';
var table = containerDiv.appendChild(dom.createElement('table'));
var me = _solidLogic.authn.currentUser();
thisOutline.GotoSubject(item.subject || me, true, pane, false, undefined, table);
};
renderTab = function _renderTab(div, item) {
div.dataset.globalPaneName = item.tabName || item.paneName;
div.textContent = item.label;
};
options = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
console.log('globalAppTabs @@');
div = dom.createElement('div');
me = _solidLogic.authn.currentUser();
if (me) {
_context.next = 9;
break;
}
alert('Must be logged in for this');
throw new Error('Not logged in');
case 9:
_context.next = 11;
return getDashboardItems();
case 11:
items = _context.sent;
div.appendChild(UI.tabs.tabWidget({
dom: dom,
subject: me,
items: items,
renderMain: renderMain,
renderTab: renderTab,
ordered: true,
orientation: 0,
backgroundColor: '#eeeeee',
// black?
selectedTab: options.selectedTab,
onClose: options.onClose
}));
return _context.abrupt("return", div);
case 14:
case "end":
return _context.stop();
}
}, _callee);
}));
return _globalAppTabs.apply(this, arguments);
}
this.getDashboard = globalAppTabs;
function getDashboardItems() {
return _getDashboardItems.apply(this, arguments);
}
function _getDashboardItems() {
_getDashboardItems = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
var me, div, _yield$Promise$all, _yield$Promise$all2, books, pods, getPods, _getPods, getAddressBooks, _getAddressBooks;
return _regeneratorRuntime().wrap(function _callee7$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
case 0:
_getAddressBooks = function _getAddressBooks3() {
_getAddressBooks = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
var _context6;
return _regeneratorRuntime().wrap(function _callee6$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
_context7.prev = 0;
_context7.next = 3;
return UI.login.findAppInstances({
me: me,
div: div,
dom: dom
}, ns.vcard('AddressBook'));
case 3:
_context6 = _context7.sent;
return _context7.abrupt("return", (_context6.instances || []).map(function (book, index) {
return {
paneName: 'contact',
tabName: "contact-".concat(index),
label: 'Contacts',
subject: book,
icon: UI.icons.iconBase + 'noun_15695.svg'
};
}));
case 7:
_context7.prev = 7;
_context7.t0 = _context7["catch"](0);
console.error('oops in globalAppTabs AddressBook');
case 10:
return _context7.abrupt("return", []);
case 11:
case "end":
return _context7.stop();
}
}, _callee6, null, [[0, 7]]);
}));
return _getAddressBooks.apply(this, arguments);
};
getAddressBooks = function _getAddressBooks2() {
return _getAddressBooks.apply(this, arguments);
};
_getPods = function _getPods3() {
_getPods = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
var addPodStorage, _addPodStorage, addPodStorageFromUrl, _addPodStorageFromUrl, pods, uri, podUrl, uniques;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
uniques = function _uniques(nodes) {
var uniqueNodes = [];
nodes.forEach(function (node) {
if (!uniqueNodes.find(function (uniqueNode) {
return uniqueNode.equals(node);
})) uniqueNodes.push(node);
});
return uniqueNodes;
};
_addPodStorageFromUrl = function _addPodStorageFromUrl3() {
_addPodStorageFromUrl = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(url) {
var podStorage, pathStorage;
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
podStorage = new URL(url); // check for predicate pim:Storage in containers up the path tree
pathStorage = podStorage.pathname;
case 2:
if (!pathStorage.length) {
_context4.next = 10;
break;
}
pathStorage = pathStorage.substring(0, pathStorage.lastIndexOf('/'));
_context4.next = 6;
return addPodStorage(kb.sym("".concat(podStorage.origin).concat(pathStorage, "/")));
case 6:
if (!_context4.sent) {
_context4.next = 8;
break;
}
return _context4.abrupt("return");
case 8:
_context4.next = 2;
break;
case 10:
case "end":
return _context4.stop();
}
}, _callee4);
}));
return _addPodStorageFromUrl.apply(this, arguments);
};
addPodStorageFromUrl = function _addPodStorageFromUrl2(_x8) {
return _addPodStorageFromUrl.apply(this, arguments);
};
_addPodStorage = function _addPodStorage3() {
_addPodStorage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(pod) {
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return loadContainerRepresentation(pod);
case 2:
if (!kb.holds(pod, ns.rdf('type'), ns.space('Storage'), pod.doc())) {
_context3.next = 5;
break;
}
pods.push(pod);
return _context3.abrupt("return", true);
case 5:
return _context3.abrupt("return", false);
case 6:
case "end":
return _context3.stop();
}
}, _callee3);
}));
return _addPodStorage.apply(this, arguments);
};
addPodStorage = function _addPodStorage2(_x7) {
return _addPodStorage.apply(this, arguments);
};
_context5.prev = 5;
_context5.next = 8;
return kb.fetcher.load(me.doc());
case 8:
_context5.next = 14;
break;
case 10:
_context5.prev = 10;
_context5.t0 = _context5["catch"](5);
console.error('Unable to load profile', _context5.t0);
return _context5.abrupt("return", []);
case 14:
// load pod's storages from profile
pods = kb.each(me, ns.space('storage'), null, me.doc());
pods.map(/*#__PURE__*/function () {
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(pod) {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return loadContainerRepresentation(pod);
case 2:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return function (_x9) {
return _ref.apply(this, arguments);
};
}());
_context5.prev = 16;
// if uri then SolidOS is a browse.html web app
uri = new URL(window.location.href).searchParams.get('uri');
podUrl = uri || window.location.href;
_context5.next = 21;
return addPodStorageFromUrl(podUrl);
case 21:
_context5.next = 26;
break;
case 23:
_context5.prev = 23;
_context5.t1 = _context5["catch"](16);
console.error('cannot load container', _context5.t1);
case 26:
pods = uniques(pods);
if (pods.length) {
_context5.next = 29;
break;
}
return _context5.abrupt("return", []);
case 29:
return _context5.abrupt("return", pods.map(function (pod, index) {
function split(item) {
return item.uri.split('//')[1].slice(0, -1);
}
var label = split(me).startsWith(split(pod)) ? 'Your storage' : split(pod);
return {
paneName: 'folder',
tabName: "folder-".concat(index),
label: label,
subject: pod,
icon: UI.icons.iconBase + 'noun_Cabinet_251723.svg'
};
}));
case 30:
case "end":
return _context5.stop();
}
}, _callee5, null, [[5, 10], [16, 23]]);
}));
return _getPods.apply(this, arguments);
};
getPods = function _getPods2() {
return _getPods.apply(this, arguments);
};
me = _solidLogic.authn.currentUser();
if (me) {
_context8.next = 7;
break;
}
return _context8.abrupt("return", []);
case 7:
div = dom.createElement('div');
_context8.next = 10;
return Promise.all([getAddressBooks(), getPods()]);
case 10:
_yield$Promise$all = _context8.sent;
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
books = _yield$Promise$all2[0];
pods = _yield$Promise$all2[1];
return _context8.abrupt("return", [{
paneName: 'home',
label: 'Your stuff',
icon: UI.icons.iconBase + 'noun_547570.svg'
}, {
paneName: 'basicPreferences',
label: 'Preferences',
icon: UI.icons.iconBase + 'noun_Sliders_341315_00000.svg'
}, {
paneName: 'profile',
label: 'Your Profile',
icon: UI.icons.iconBase + 'noun_15059.svg'
}, {
paneName: 'editProfile',
label: 'Edit your Profile',
icon: UI.icons.iconBase + 'noun_492246.svg'
}].concat(books).concat(pods));
case 15:
case "end":
return _context8.stop();
}
}, _callee7);
}));
return _getDashboardItems.apply(this, arguments);
}
this.getDashboardItems = getDashboardItems;
/**
* Call this method to show the global dashboard.
*
* @param {Object} [options] A set of options that can be passed
* @param {string} [options.pane] To open a specific dashboard pane
* @returns {Promise<void>}
*/
function showDashboard() {
return _showDashboard.apply(this, arguments);
}
function _showDashboard() {
_showDashboard = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
var options,
dashboardContainer,
outlineContainer,
_tab,
dashboard,
tab,
closeDashboard,
_args8 = arguments;
return _regeneratorRuntime().wrap(function _callee8$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:
closeDashboard = function _closeDashboard() {
dashboardContainer.style.display = 'none';
outlineContainer.style.display = 'inherit';
};
options = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : {};
dashboardContainer = getDashboardContainer();
outlineContainer = getOutlineContainer(); // reuse dashboard if already children already is inserted
if (!(dashboardContainer.childNodes.length > 0 && options.pane)) {
_context9.next = 12;
break;
}
outlineContainer.style.display = 'none';
dashboardContainer.style.display = 'inherit';
_tab = dashboardContainer.querySelector("[data-global-pane-name=\"".concat(options.pane, "\"]"));
if (!_tab) {
_context9.next = 11;
break;
}
_tab.click();
return _context9.abrupt("return");
case 11:
console.warn('Did not find the referred tab in global dashboard, will open first one');
case 12:
_context9.next = 14;
return globalAppTabs({
selectedTab: options.pane,
onClose: closeDashboard
});
case 14:
dashboard = _context9.sent;
// close the dashboard if user log out
_solidLogic.authSession.onLogout(closeDashboard);
// finally - switch to showing dashboard
outlineContainer.style.display = 'none';
dashboardContainer.appendChild(dashboard);
tab = dashboardContainer.querySelector("[data-global-pane-name=\"".concat(options.pane, "\"]"));
if (tab) {
tab.click();
}
case 20:
case "end":
return _context9.stop();
}
}, _callee8);
}));
return _showDashboard.apply(this, arguments);
}
this.showDashboard = showDashboard;
function getDashboardContainer() {
return getOrCreateContainer('GlobalDashboard');
}
function getOutlineContainer() {
return getOrCreateContainer('outline');
}
/**
* Get element with id or create a new on the fly with that id
*
* @param {string} id The ID of the element you want to get or create
* @returns {HTMLElement}
*/
function getOrCreateContainer(id) {
return document.getElementById(id) || function () {
var dashboardContainer = document.createElement('div');
dashboardContainer.id = id;
var mainContainer = document.querySelector('[role="main"]') || document.body;
return mainContainer.appendChild(dashboardContainer);
}();
}
function loadContainerRepresentation(_x) {
return _loadContainerRepresentation.apply(this, arguments);
}
function _loadContainerRepresentation() {
_loadContainerRepresentation = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(subject) {
var response, containerTurtle;
return _regeneratorRuntime().wrap(function _callee9$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
if (kb.any(subject, ns.ldp('contains'), undefined, subject.doc())) {
_context10.next = 6;
break;
}
_context10.next = 3;
return kb.fetcher.webOperation('GET', subject.uri, kb.fetcher.initFetchOptions(subject.uri, {
headers: {
accept: 'text/turtle'
}
}));
case 3:
response = _context10.sent;
containerTurtle = response.responseText;
$rdf.parse(containerTurtle, kb, subject.uri, 'text/turtle');
case 6:
case "end":
return _context10.stop();
}
}, _callee9);
}));
return _loadContainerRepresentation.apply(this, arguments);
}
function getRelevantPanes(_x2, _x3) {
return _getRelevantPanes.apply(this, arguments);
}
function _getRelevantPanes() {
_getRelevantPanes = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(subject, context) {
var panes, relevantPanes, filteredPanes, firstRelevantPaneIndex, firstFilteredPaneIndex;
return _regeneratorRuntime().wrap(function _callee10$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
case 0:
if (!subject.uri.endsWith('/')) {
_context11.next = 3;
break;
}
_context11.next = 3;
return loadContainerRepresentation(subject);
case 3:
panes = context.session.paneRegistry;
relevantPanes = panes.list.filter(function (pane) {
return pane.label(subject, context) && !pane.global;
});
if (!(relevantPanes.length === 0)) {
_context11.next = 7;
break;
}
return _context11.abrupt("return", [panes.byName('internal')]);
case 7:
_context11.next = 9;
return UI.login.filterAvailablePanes(relevantPanes);
case 9:
filteredPanes = _context11.sent;
if (!(filteredPanes.length === 0)) {
_context11.next = 12;
break;
}
return _context11.abrupt("return", [relevantPanes[0]]);
case 12:
firstRelevantPaneIndex = panes.list.indexOf(relevantPanes[0]);
firstFilteredPaneIndex = panes.list.indexOf(filteredPanes[0]); // if the first relevant pane is loaded before the panes available wrt role, we still want to offer the most relevant pane
return _context11.abrupt("return", firstRelevantPaneIndex < firstFilteredPaneIndex ? [relevantPanes[0]].concat(filteredPanes) : filteredPanes);
case 15:
case "end":
return _context11.stop();
}
}, _callee10);
}));
return _getRelevantPanes.apply(this, arguments);
}
function getPane(relevantPanes, subject) {
return relevantPanes.find(function (pane) {
return pane.shouldGetFocus && pane.shouldGetFocus(subject);
}) || relevantPanes[0];
}
function expandedHeaderTR(_x4, _x5, _x6) {
return _expandedHeaderTR.apply(this, arguments);
} // expandedHeaderTR
// / //////////////////////////////////////////////////////////////////////////
/* PANES
**
** Panes are regions of the outline view in which a particular subject is
** displayed in a particular way. They are like views but views are for query results.
** subject panes are currently stacked vertically.
*/
// / //////////////////// Specific panes are in panes/*.js
//
// The defaultPane is the first one registered for which the label method exists
// Those registered first take priority as a default pane.
// That is, those earlier in this file
/**
* Pane registration
*/
// the second argument indicates whether the query button is required
// / ///////////////////////////////////////////////////////////////////////////
// Remove a node from the DOM so that Firefox refreshes the screen OK
// Just deleting it cause whitespace to accumulate.
function _expandedHeaderTR() {
_expandedHeaderTR = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(subject, requiredPane, options) {
var renderPaneIconTray, _renderPaneIconTray, tr, td, header, showHeader, icon, strong;
return _regeneratorRuntime().wrap(function _callee12$(_context13) {
while (1) switch (_context13.prev = _context13.next) {
case 0:
_renderPaneIconTray = function _renderPaneIconTray3() {
_renderPaneIconTray = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(td) {
var options,
paneShownStyle,
paneHiddenStyle,
paneIconTray,
relevantPanes,
paneNumber,
_args11 = arguments;
return _regeneratorRuntime().wrap(function _callee11$(_context12) {
while (1) switch (_context12.prev = _context12.next) {
case 0:
options = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {};
paneShownStyle = 'width: 24px; border-radius: 0.5em; border-top: solid #222 1px; border-left: solid #222 0.1em; border-bottom: solid #eee 0.1em; border-right: solid #eee 0.1em; margin-left: 1em; padding: 3px; background-color: #ffd;';
paneHiddenStyle = 'width: 24px; border-radius: 0.5em; margin-left: 1em; padding: 3px';
paneIconTray = td.appendChild(dom.createElement('nav'));
paneIconTray.style = 'display:flex; justify-content: flex-start; align-items: center;';
if (!options.hideList) {
_context12.next = 9;
break;
}
_context12.t0 = [];
_context12.next = 12;
break;
case 9:
_context12.next = 11;
return getRelevantPanes(subject, context);
case 11:
_context12.t0 = _context12.sent;
case 12:
relevantPanes = _context12.t0;
tr.firstPane = requiredPane || getPane(relevantPanes, subject);
paneNumber = relevantPanes.indexOf(tr.firstPane);
if (relevantPanes.length !== 1) {
// if only one, simplify interface
relevantPanes.forEach(function (pane, index) {
var label = pane.label(subject, context);
var ico = UI.utils.AJARImage(pane.icon, label, label, dom);
ico.style = pane === tr.firstPane ? paneShownStyle : paneHiddenStyle; // init to something at least
// ico.setAttribute('align','right'); @@ Should be better, but ffox bug pushes them down
// ico.style.width = iconHeight
// ico.style.height = iconHeight
var listen = function listen(ico, pane) {
// Freeze scope for event time
ico.addEventListener('click', function (event) {
var containingTable;
// Find the containing table for this subject
for (containingTable = td; containingTable.parentNode; containingTable = containingTable.parentNode) {
if (containingTable.nodeName === 'TABLE') break;
}
if (containingTable.nodeName !== 'TABLE') {
throw new Error('outline: internal error.');
}
var removePanes = function removePanes(specific) {
for (var d = containingTable.firstChild; d; d = d.nextSibling) {
if (typeof d.pane !== 'undefined') {
if (!specific || d.pane === specific) {
if (d.paneButton) {
d.paneButton.setAttribute('class', 'paneHidden');
d.paneButton.style = paneHiddenStyle;
}
removeAndRefresh(d);
// If we just delete the node d, ffox doesn't refresh the display properly.
// state = 'paneHidden';
if (d.pane.requireQueryButton && containingTable.parentNode.className /* outer table */ && numberOfPanesRequiringQueryButton === 1 && dom.getElementById('queryButton')) {
dom.getElementById('queryButton').setAttribute('style', 'display:none;');
}
}
}
}
};
var renderPane = function renderPane(pane) {
var paneDiv;
UI.log.info('outline: Rendering pane (2): ' + pane.name);
try {
paneDiv = pane.render(subject, context, options);
} catch (e) {
// Easier debugging for pane developers
paneDiv = dom.createElement('div');
paneDiv.setAttribute('class', 'exceptionPane');
var pre = dom.createElement('pre');
paneDiv.appendChild(pre);
pre.appendChild(dom.createTextNode(UI.utils.stackString(e)));