solid-panes
Version:
Solid-compatible Panes: applets and views for the mashlib and databrowser
136 lines (105 loc) • 5.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _solidUi = require("solid-ui");
var _profile = require("./profile.dom");
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
var thisPane = {
global: false,
icon: _solidUi.icons.iconBase + 'noun_15059.svg',
name: 'profile',
label: function label(subject, context) {
var t = context.session.store.findTypeURIs(subject);
if (t[_solidUi.ns.vcard('Individual').uri] || t[_solidUi.ns.vcard('Organization').uri] || t[_solidUi.ns.foaf('Person').uri] || t[_solidUi.ns.schema('Person').uri]) {
return 'Profile';
}
return null;
},
render: function render(subject, context) {
var store = context.session.store;
function doRender(_x, _x2, _x3) {
return _doRender.apply(this, arguments);
}
function _doRender() {
_doRender = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(container, subject, dom) {
var profile, otherProfiles, backgroundColor, highlightColor, table, main, bottom, statusArea, heading, contactDisplay;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
heading = function _heading(str) {
var h = main.appendChild(dom.createElement('h3'));
h.setAttribute('style', "font-size: 120%; color:".concat(highlightColor, ";"));
h.textContent = str;
return h;
};
if (subject) {
_context.next = 3;
break;
}
throw new Error('subject missing');
case 3:
profile = subject.doc();
otherProfiles = store.each(subject, _solidUi.ns.rdfs('seeAlso'), null, profile);
if (!(otherProfiles.length > 0)) {
_context.next = 14;
break;
}
_context.prev = 6;
_context.next = 9;
return store.fetcher.load(otherProfiles);
case 9:
_context.next = 14;
break;
case 11:
_context.prev = 11;
_context.t0 = _context["catch"](6);
container.appendChild(_solidUi.widgets.errorMessageBlock(_context.t0));
case 14:
backgroundColor = store.anyValue(subject, _solidUi.ns.solid('profileBackgroundColor'), null, subject.doc()) || '#ffffff'; // Todo: check format of color matches regexp and not too dark
container.style.backgroundColor = backgroundColor; // @@ Limit to pale?
highlightColor = store.anyValue(subject, _solidUi.ns.solid('profileHighlightColor', null, subject.doc())) || '#090'; // @@ beware injection attack
container.style.border = "0.3em solid ".concat(highlightColor);
container.style.borderRadius = '0.5em';
container.style.padding = '0.7em';
container.style.marginTop = '0.7em';
table = container.appendChild(dom.createElement('table')); // const top = table.appendChild(dom.createElement('tr'))
main = table.appendChild(dom.createElement('tr'));
bottom = table.appendChild(dom.createElement('tr'));
statusArea = bottom.appendChild(dom.createElement('div'));
statusArea.setAttribute('style', 'padding: 0.7em;');
// Todo: only show this if there is vcard info
heading('Contact');
contactDisplay = (0, _profile.paneDiv)(context, subject, 'contact');
contactDisplay.style.border = '0em'; // override form
main.appendChild(contactDisplay);
if (store.holds(subject, _solidUi.ns.foaf('knows'))) {
heading('Solid Friends');
_solidUi.widgets.attachmentList(dom, subject, container, {
doc: profile,
modify: false,
predicate: _solidUi.ns.foaf('knows'),
noun: 'friend'
});
}
case 31:
case "end":
return _context.stop();
}
}
}, _callee, null, [[6, 11]]);
}));
return _doRender.apply(this, arguments);
}
var dom = context.dom;
var container = dom.createElement('div');
doRender(container, subject, dom); // async
return container; // initially unpopulated
} // render()
}; //
var _default = thisPane; // ENDS
exports["default"] = _default;
//# sourceMappingURL=profile.view.js.map