UNPKG

solid-ui

Version:

UI library for Solid applications

1,105 lines (1,049 loc) • 1.34 MB
import * as __WEBPACK_EXTERNAL_MODULE_rdflib__ from "rdflib"; import * as __WEBPACK_EXTERNAL_MODULE_solid_logic_bb75353e__ from "solid-logic"; /******/ var __webpack_modules__ = ({ /***/ 6466 (__unused_webpack_module, __webpack_exports__, __webpack_require__) { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ v: () => (/* binding */ AccessController) /* harmony export */ }); /* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(467); /* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3029); /* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2901); /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4756); /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var _acl__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5619); /* harmony import */ var rdflib__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(4961); /* harmony import */ var _access_groups__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(1214); /* harmony import */ var _acl_control__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(7367); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(9612); /* harmony import */ var _debug__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(7423); /* harmony import */ var _style__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(675); /** * Contains the [[AccessController]] class * @packageDocumentation */ /** * Rendered HTML component used in the databrowser's Sharing pane. */ var AccessController = /*#__PURE__*/function () { function AccessController(subject, noun, context, statusElement, targetIsProtected, targetDoc, targetACLDoc, defaultHolder, defaultACLDoc, prospectiveDefaultHolder, store, dom) { (0,_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A)(this, AccessController); this.subject = subject; this.noun = noun; this.context = context; this.statusElement = statusElement; this.targetIsProtected = targetIsProtected; this.targetDoc = targetDoc; this.targetACLDoc = targetACLDoc; this.defaultHolder = defaultHolder; this.defaultACLDoc = defaultACLDoc; this.prospectiveDefaultHolder = prospectiveDefaultHolder; this.store = store; this.dom = dom; this.rootElement = dom.createElement('div'); this.rootElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.aclGroupContent); this.isContainer = targetDoc.uri.slice(-1) === '/'; // Give default for all directories if (defaultHolder && defaultACLDoc) { this.isUsingDefaults = true; var aclDefaultStore = (0,_acl__WEBPACK_IMPORTED_MODULE_4__/* .adoptACLDefault */ ._E)(this.targetDoc, targetACLDoc, defaultHolder, defaultACLDoc); this.mainCombo = new _access_groups__WEBPACK_IMPORTED_MODULE_6__/* .AccessGroups */ .h(targetDoc, targetACLDoc, this, aclDefaultStore, { defaults: this.isContainer }); this.defaultsCombo = null; this.defaultsDiffer = false; } else { this.isUsingDefaults = false; this.mainCombo = new _access_groups__WEBPACK_IMPORTED_MODULE_6__/* .AccessGroups */ .h(targetDoc, targetACLDoc, this, store); this.defaultsCombo = new _access_groups__WEBPACK_IMPORTED_MODULE_6__/* .AccessGroups */ .h(targetDoc, targetACLDoc, this, store, { defaults: this.isContainer }); this.defaultsDiffer = !(0,_acl__WEBPACK_IMPORTED_MODULE_4__/* .sameACL */ .P3)(this.mainCombo.aclMap, this.defaultsCombo.aclMap); } } return (0,_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .A)(AccessController, [{ key: "isEditable", get: function get() { return !this.isUsingDefaults; } }, { key: "render", value: function render() { this.rootElement.innerHTML = ''; if (this.isUsingDefaults) { this.renderStatus("The sharing for this ".concat(this.noun, " is the default for folder ")); if (this.defaultHolder) { var defaultHolderLink = this.statusElement.appendChild(this.dom.createElement('a')); defaultHolderLink.href = this.defaultHolder.uri; defaultHolderLink.innerText = (0,_acl_control__WEBPACK_IMPORTED_MODULE_7__/* .shortNameForFolder */ .DR)(this.defaultHolder); } } else if (!this.defaultsDiffer && this.isContainer) { this.renderStatus('This is also the default for things in this folder.'); } else { this.renderStatus(''); } this.rootElement.appendChild(this.mainCombo.render()); if (this.defaultsCombo && this.defaultsDiffer) { this.rootElement.appendChild(this.renderRemoveDefaultsController()); this.rootElement.appendChild(this.defaultsCombo.render()); } else if (this.isEditable && this.isContainer) { this.rootElement.appendChild(this.renderAddDefaultsController()); } if (!this.targetIsProtected && this.isUsingDefaults) { this.rootElement.appendChild(this.renderAddAclsController()); } else if (!this.targetIsProtected) { this.rootElement.appendChild(this.renderRemoveAclsController()); } return this.rootElement; } }, { key: "renderRemoveAclsController", value: function renderRemoveAclsController() { var _this = this; var useDefaultButton = this.dom.createElement('button'); useDefaultButton.innerText = "Remove custom sharing settings for this ".concat(this.noun, " -- just use default").concat(this.prospectiveDefaultHolder ? " for ".concat(_utils__WEBPACK_IMPORTED_MODULE_8__/* .label */ .P(this.prospectiveDefaultHolder)) : ''); useDefaultButton.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.bigButton); useDefaultButton.addEventListener('click', function () { return _this.removeAcls().then(function () { return _this.render(); })["catch"](function (error) { return _this.renderStatus(error); }); }); return useDefaultButton; } }, { key: "renderAddAclsController", value: function renderAddAclsController() { var _this2 = this; var addAclButton = this.dom.createElement('button'); addAclButton.innerText = "Set specific sharing for this ".concat(this.noun); addAclButton.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.bigButton); addAclButton.addEventListener('click', function () { return _this2.addAcls().then(function () { return _this2.render(); })["catch"](function (error) { return _this2.renderStatus(error); }); }); return addAclButton; } }, { key: "renderAddDefaultsController", value: function renderAddDefaultsController() { var _this3 = this; var containerElement = this.dom.createElement('div'); containerElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.defaultsController); var noticeElement = containerElement.appendChild(this.dom.createElement('div')); noticeElement.innerText = 'Sharing for things within the folder currently tracks sharing for the folder.'; noticeElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.defaultsControllerNotice); var button = containerElement.appendChild(this.dom.createElement('button')); button.innerText = 'Set the sharing of folder contents separately from the sharing for the folder'; button.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.bigButton); button.addEventListener('click', function () { return _this3.addDefaults().then(function () { return _this3.render(); }); }); return containerElement; } }, { key: "renderRemoveDefaultsController", value: function renderRemoveDefaultsController() { var _this4 = this; var containerElement = this.dom.createElement('div'); containerElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.defaultsController); var noticeElement = containerElement.appendChild(this.dom.createElement('div')); noticeElement.innerText = 'Access to things within this folder:'; noticeElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.defaultsControllerNotice); var button = containerElement.appendChild(this.dom.createElement('button')); button.innerText = 'Set default for folder contents to just track the sharing for the folder'; button.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.bigButton); button.addEventListener('click', function () { return _this4.removeDefaults().then(function () { return _this4.render(); })["catch"](function (error) { return _this4.renderStatus(error); }); }); return containerElement; } }, { key: "renderTemporaryStatus", value: function renderTemporaryStatus(message) { var _this5 = this; // @@ TODO Introduce better system for error notification to user https://github.com/solidos/mashlib/issues/87 this.statusElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.aclControlBoxStatusRevealed); this.statusElement.innerText = message; this.statusElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.temporaryStatusInit); setTimeout(function () { _this5.statusElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.temporaryStatusEnd); }); setTimeout(function () { _this5.statusElement.innerText = ''; }, 5000); } }, { key: "renderStatus", value: function renderStatus(message) { // @@ TODO Introduce better system for error notification to user https://github.com/solidos/mashlib/issues/87 if (!message) { this.statusElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_10__/* .style */ .i.aclControlBoxStatusRevealed); } this.statusElement.innerText = message; } }, { key: "addAcls", value: function () { var _addAcls = (0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A)(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default().mark(function _callee() { var _this6 = this; var message, aclGraph, _message, _t; return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default().wrap(function (_context) { while (1) switch (_context.prev = _context.next) { case 0: if (!(!this.defaultHolder || !this.defaultACLDoc)) { _context.next = 1; break; } message = 'Unable to find defaults to copy'; _debug__WEBPACK_IMPORTED_MODULE_9__/* .error */ .z3(message); return _context.abrupt("return", Promise.reject(message)); case 1: aclGraph = (0,_acl__WEBPACK_IMPORTED_MODULE_4__/* .adoptACLDefault */ ._E)(this.targetDoc, this.targetACLDoc, this.defaultHolder, this.defaultACLDoc); aclGraph.statements.forEach(function (st) { return _this6.store.add(st.subject, st.predicate, st.object, _this6.targetACLDoc); }); _context.prev = 2; _context.next = 3; return this.store.fetcher.putBack(this.targetACLDoc); case 3: this.isUsingDefaults = false; return _context.abrupt("return", Promise.resolve()); case 4: _context.prev = 4; _t = _context["catch"](2); _message = " Error writing back access control file! ".concat(_t); _debug__WEBPACK_IMPORTED_MODULE_9__/* .error */ .z3(_message); return _context.abrupt("return", Promise.reject(_message)); case 5: case "end": return _context.stop(); } }, _callee, this, [[2, 4]]); })); function addAcls() { return _addAcls.apply(this, arguments); } return addAcls; }() }, { key: "addDefaults", value: function () { var _addDefaults = (0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A)(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default().mark(function _callee2() { return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default().wrap(function (_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: this.defaultsCombo = new _access_groups__WEBPACK_IMPORTED_MODULE_6__/* .AccessGroups */ .h(this.targetDoc, this.targetACLDoc, this, this.store, { defaults: true }); this.defaultsDiffer = true; case 1: case "end": return _context2.stop(); } }, _callee2, this); })); function addDefaults() { return _addDefaults.apply(this, arguments); } return addDefaults; }() }, { key: "removeAcls", value: function () { var _removeAcls = (0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A)(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default().mark(function _callee3() { var message, _t2, _t3; return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default().wrap(function (_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: _context3.prev = 0; _context3.next = 1; return this.store.fetcher["delete"](this.targetACLDoc.uri, {}); case 1: this.isUsingDefaults = true; _context3.prev = 2; _context3.next = 3; return (0,_acl__WEBPACK_IMPORTED_MODULE_4__/* .getProspectiveHolder */ .L$)(this.targetDoc.uri); case 3: this.prospectiveDefaultHolder = _context3.sent; _context3.next = 5; break; case 4: _context3.prev = 4; _t2 = _context3["catch"](2); // No need to show this error in status, but good to warn about it in console _debug__WEBPACK_IMPORTED_MODULE_9__/* .warn */ .R8(_t2); case 5: _context3.next = 7; break; case 6: _context3.prev = 6; _t3 = _context3["catch"](0); message = "Error deleting access control file: ".concat(this.targetACLDoc, ": ").concat(_t3); _debug__WEBPACK_IMPORTED_MODULE_9__/* .error */ .z3(message); return _context3.abrupt("return", Promise.reject(message)); case 7: case "end": return _context3.stop(); } }, _callee3, this, [[0, 6], [2, 4]]); })); function removeAcls() { return _removeAcls.apply(this, arguments); } return removeAcls; }() }, { key: "removeDefaults", value: function () { var _removeDefaults = (0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A)(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default().mark(function _callee4() { var fallbackCombo, _t4; return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_3___default().wrap(function (_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: fallbackCombo = this.defaultsCombo; _context4.prev = 1; this.defaultsCombo = null; this.defaultsDiffer = false; _context4.next = 2; return this.save(); case 2: _context4.next = 4; break; case 3: _context4.prev = 3; _t4 = _context4["catch"](1); this.defaultsCombo = fallbackCombo; this.defaultsDiffer = true; _debug__WEBPACK_IMPORTED_MODULE_9__/* .error */ .z3(_t4); return _context4.abrupt("return", Promise.reject(_t4)); case 4: case "end": return _context4.stop(); } }, _callee4, this, [[1, 3]]); })); function removeDefaults() { return _removeDefaults.apply(this, arguments); } return removeDefaults; }() }, { key: "save", value: function save() { var _this7 = this; // build graph var newAClGraph = (0,rdflib__WEBPACK_IMPORTED_MODULE_5__.graph)(); if (!this.isContainer) { (0,_acl__WEBPACK_IMPORTED_MODULE_4__/* .makeACLGraphbyCombo */ .cl)(newAClGraph, this.targetDoc, this.mainCombo.byCombo, this.targetACLDoc, true); } else if (this.defaultsCombo && this.defaultsDiffer) { // Pair of controls (0,_acl__WEBPACK_IMPORTED_MODULE_4__/* .makeACLGraphbyCombo */ .cl)(newAClGraph, this.targetDoc, this.mainCombo.byCombo, this.targetACLDoc, true); (0,_acl__WEBPACK_IMPORTED_MODULE_4__/* .makeACLGraphbyCombo */ .cl)(newAClGraph, this.targetDoc, this.defaultsCombo.byCombo, this.targetACLDoc, false, true); } else { // Linked controls (0,_acl__WEBPACK_IMPORTED_MODULE_4__/* .makeACLGraphbyCombo */ .cl)(newAClGraph, this.targetDoc, this.mainCombo.byCombo, this.targetACLDoc, true, true); } // add authenticated fetcher newAClGraph.fetcher = (0,rdflib__WEBPACK_IMPORTED_MODULE_5__.fetcher)(newAClGraph, { fetch: this.store.fetcher._fetch }); var updater = newAClGraph.updater || new rdflib__WEBPACK_IMPORTED_MODULE_5__.UpdateManager(newAClGraph); // save ACL resource return new Promise(function (resolve, reject) { updater.put(_this7.targetACLDoc, newAClGraph.statementsMatching(undefined, undefined, undefined, _this7.targetACLDoc), 'text/turtle', function (uri, ok, message) { if (!ok) { return reject(new Error("ACL file save failed: ".concat(message))); } _this7.store.fetcher.unload(_this7.targetACLDoc); _this7.store.add(newAClGraph.statements); _this7.store.fetcher.requested[_this7.targetACLDoc.uri] = 'done'; // missing: save headers _this7.mainCombo.store = _this7.store; if (_this7.defaultsCombo) { _this7.defaultsCombo.store = _this7.store; } _this7.defaultsDiffer = !!_this7.defaultsCombo && !(0,_acl__WEBPACK_IMPORTED_MODULE_4__/* .sameACL */ .P3)(_this7.mainCombo.aclMap, _this7.defaultsCombo.aclMap); _debug__WEBPACK_IMPORTED_MODULE_9__/* .log */ .Rm('ACL modification: success!'); resolve(); }); }); } }]); }(); /***/ }, /***/ 1214 (__unused_webpack_module, __webpack_exports__, __webpack_require__) { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ h: () => (/* binding */ AccessGroups) /* harmony export */ }); /* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(467); /* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3453); /* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3029); /* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2901); /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(4756); /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4__); /* harmony import */ var rdflib__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(4961); /* harmony import */ var _acl__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(5619); /* harmony import */ var _widgets__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(386); /* harmony import */ var _widgets__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(3291); /* harmony import */ var _ns__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(1795); /* harmony import */ var _add_agent_buttons__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(1928); /* harmony import */ var _debug__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(7423); /* harmony import */ var _style__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(675); /** * Contains the [[AccessGroups]] * and [[AccessGroupsOptions]] classes * @packageDocumentation */ var ACL = _ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.acl; var COLLOQUIAL = { 13: 'Owners', 9: 'Owners (write locked)', 5: 'Editors', 3: 'Posters', 2: 'Submitters', 1: 'Viewers' }; var RECOMMENDED = { 13: true, 5: true, 3: true, 2: true, 1: true }; var EXPLANATION = { 13: 'can read, write, and control sharing.', 9: 'can read and control sharing, currently write-locked.', 5: 'can read and change information', 3: 'can add new information, and read but not change existing information', 2: 'can add new information but not read any', 1: 'can read but not change information' }; /** * Type for the options parameter of [[AccessGroups]] */ /** * Renders the table of Owners, Editors, Posters, Submitters, Viewers * for https://github.com/solidos/userguide/blob/main/views/sharing/userguide.md */ var AccessGroups = /*#__PURE__*/function () { // @@ was LiveStore but does not need to be connected to web function AccessGroups(doc, aclDoc, controller, store) { var _options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; (0,_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .A)(this, AccessGroups); this.doc = doc; this.aclDoc = aclDoc; this.controller = controller; this._options = _options; this.defaults = this._options.defaults || false; this._store = store; this.aclMap = (0,_acl__WEBPACK_IMPORTED_MODULE_6__/* .readACL */ .fg)(doc, aclDoc, store, this.defaults); this.byCombo = (0,_acl__WEBPACK_IMPORTED_MODULE_6__/* .ACLbyCombination */ .xw)(this.aclMap); this.addAgentButton = new _add_agent_buttons__WEBPACK_IMPORTED_MODULE_10__/* .AddAgentButtons */ .g(this); this.rootElement = this.controller.dom.createElement('div'); this.rootElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.accessGroupList); } return (0,_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .A)(AccessGroups, [{ key: "store", get: function get() { return this._store; }, set: function set(store) { this._store = store; this.aclMap = (0,_acl__WEBPACK_IMPORTED_MODULE_6__/* .readACL */ .fg)(this.doc, this.aclDoc, store, this.defaults); this.byCombo = (0,_acl__WEBPACK_IMPORTED_MODULE_6__/* .ACLbyCombination */ .xw)(this.aclMap); } }, { key: "render", value: function render() { var _this = this; this.rootElement.innerHTML = ''; this.renderGroups().forEach(function (group) { return _this.rootElement.appendChild(group); }); if (this.controller.isEditable) { this.rootElement.appendChild(this.addAgentButton.render()); } return this.rootElement; } }, { key: "renderGroups", value: function renderGroups() { var groupElements = []; for (var comboIndex = 15; comboIndex > 0; comboIndex--) { var combo = kToCombo(comboIndex); if (this.controller.isEditable && RECOMMENDED[comboIndex] || this.byCombo[combo]) { groupElements.push(this.renderGroup(comboIndex, combo)); } } return groupElements; } }, { key: "renderGroup", value: function renderGroup(comboIndex, combo) { var _this2 = this; var groupRow = this.controller.dom.createElement('div'); groupRow.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.accessGroupListItem); _widgets__WEBPACK_IMPORTED_MODULE_7__/* .makeDropTarget */ .DK(groupRow, function (uris) { return _this2.handleDroppedUris(uris, combo).then(function () { return _this2.controller.render(); })["catch"](function (error) { return _this2.controller.renderStatus(error); }); }); var groupColumns = this.renderGroupElements(comboIndex, combo); groupColumns.forEach(function (column) { return groupRow.appendChild(column); }); return groupRow; } }, { key: "renderGroupElements", value: function renderGroupElements(comboIndex, combo) { var _this3 = this; var groupNameColumn = this.controller.dom.createElement('div'); groupNameColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group); if (this.controller.isEditable) { switch (comboIndex) { case 1: groupNameColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group1); break; case 2: groupNameColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group2); break; case 3: groupNameColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group3); break; case 5: groupNameColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group5); break; case 9: groupNameColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group9); break; case 13: groupNameColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group13); break; default: groupNameColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group); } } groupNameColumn.innerText = COLLOQUIAL[comboIndex] || ktToList(comboIndex); var groupAgentsColumn = this.controller.dom.createElement('div'); groupAgentsColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group); if (this.controller.isEditable) { switch (comboIndex) { case 1: groupAgentsColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group1); break; case 2: groupAgentsColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group2); break; case 3: groupAgentsColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group3); break; case 5: groupAgentsColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group5); break; case 9: groupAgentsColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group9); break; case 13: groupAgentsColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group13); break; default: groupAgentsColumn.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group); } } var groupAgentsTable = groupAgentsColumn.appendChild(this.controller.dom.createElement('table')); var combos = this.byCombo[combo] || []; combos.map(function (_ref) { var _ref2 = (0,_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A)(_ref, 2), pred = _ref2[0], obj = _ref2[1]; return _this3.renderAgent(groupAgentsTable, combo, pred, obj); }).forEach(function (agentElement) { return groupAgentsTable.appendChild(agentElement); }); var groupDescriptionElement = this.controller.dom.createElement('div'); groupDescriptionElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group); if (this.controller.isEditable) { switch (comboIndex) { case 1: groupDescriptionElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group1); break; case 2: groupDescriptionElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group2); break; case 3: groupDescriptionElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group3); break; case 5: groupDescriptionElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group5); break; case 9: groupDescriptionElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group9); break; case 13: groupDescriptionElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group13); break; default: groupDescriptionElement.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_12__/* .style */ .i.group); } } groupDescriptionElement.innerText = EXPLANATION[comboIndex] || 'Unusual combination'; return [groupNameColumn, groupAgentsColumn, groupDescriptionElement]; } }, { key: "renderAgent", value: function renderAgent(groupAgentsTable, combo, pred, obj) { var _this4 = this; var personRow = _widgets__WEBPACK_IMPORTED_MODULE_8__/* .personTR */ .Cl(this.controller.dom, ACL(pred), (0,rdflib__WEBPACK_IMPORTED_MODULE_5__.sym)(obj), this.controller.isEditable ? { deleteFunction: function deleteFunction() { return _this4.deleteAgent(combo, pred, obj).then(function () { return groupAgentsTable.removeChild(personRow); })["catch"](function (error) { return _this4.controller.renderStatus(error); }); } } : {}); return personRow; } }, { key: "deleteAgent", value: function () { var _deleteAgent = (0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A)(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default().mark(function _callee(combo, pred, obj) { var combos, comboToRemove; return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default().wrap(function (_context) { while (1) switch (_context.prev = _context.next) { case 0: combos = this.byCombo[combo] || []; comboToRemove = combos.find(function (_ref3) { var _ref4 = (0,_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A)(_ref3, 2), comboPred = _ref4[0], comboObj = _ref4[1]; return comboPred === pred && comboObj === obj; }); if (comboToRemove) { combos.splice(combos.indexOf(comboToRemove), 1); } _context.next = 1; return this.controller.save(); case 1: case "end": return _context.stop(); } }, _callee, this); })); function deleteAgent(_x, _x2, _x3) { return _deleteAgent.apply(this, arguments); } return deleteAgent; }() }, { key: "addNewURI", value: function () { var _addNewURI = (0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A)(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default().mark(function _callee2(uri) { return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default().wrap(function (_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _context2.next = 1; return this.handleDroppedUri(uri, kToCombo(1)); case 1: _context2.next = 2; return this.controller.save(); case 2: case "end": return _context2.stop(); } }, _callee2, this); })); function addNewURI(_x4) { return _addNewURI.apply(this, arguments); } return addNewURI; }() }, { key: "handleDroppedUris", value: function () { var _handleDroppedUris = (0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A)(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default().mark(function _callee3(uris, combo) { var _this5 = this; var _t; return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default().wrap(function (_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: _context3.prev = 0; _context3.next = 1; return Promise.all(uris.map(function (uri) { return _this5.handleDroppedUri(uri, combo); })); case 1: _context3.next = 2; return this.controller.save(); case 2: _context3.next = 4; break; case 3: _context3.prev = 3; _t = _context3["catch"](0); return _context3.abrupt("return", Promise.reject(_t)); case 4: case "end": return _context3.stop(); } }, _callee3, this, [[0, 3]]); })); function handleDroppedUris(_x5, _x6) { return _handleDroppedUris.apply(this, arguments); } return handleDroppedUris; }() }, { key: "handleDroppedUri", value: function () { var _handleDroppedUri = (0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A)(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default().mark(function _callee4(uri, combo) { var secondAttempt, agent, thing, _this$_store, message, detectedTypes, typeDetails, error, _args4 = arguments, _t2; return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_4___default().wrap(function (_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: secondAttempt = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : false; agent = findAgent(uri, this.store); // eg 'agent', 'origin', agentClass' thing = (0,rdflib__WEBPACK_IMPORTED_MODULE_5__.sym)(uri); if (!(!agent && !secondAttempt)) { _context4.next = 5; break; } _debug__WEBPACK_IMPORTED_MODULE_11__/* .log */ .Rm(" Not obvious: looking up dropped thing ".concat(thing)); _context4.prev = 1; _context4.next = 2; return (_this$_store = this._store) === null || _this$_store === void 0 || (_this$_store = _this$_store.fetcher) === null || _this$_store === void 0 ? void 0 : _this$_store.load(thing.doc()); case 2: _context4.next = 4; break; case 3: _context4.prev = 3; _t2 = _context4["catch"](1); message = "Ignore error looking up dropped thing: ".concat(_t2); _debug__WEBPACK_IMPORTED_MODULE_11__/* .error */ .z3(message); return _context4.abrupt("return", Promise.reject(new Error(message))); case 4: return _context4.abrupt("return", this.handleDroppedUri(uri, combo, true)); case 5: if (agent) { _context4.next = 6; break; } detectedTypes = Object.keys(this.store.findTypeURIs(thing)); typeDetails = detectedTypes.length > 0 ? "Detected RDF types: ".concat(detectedTypes.join(', ')) : 'No RDF type was detected for this URI.'; error = "Error: Failed to add access target: ".concat(uri, " is not a recognized ACL target type.") + " Expected one of: vcard:WebID, vcard:Group, foaf:Person, foaf:Agent, solid:AppProvider, solid:AppProviderClass, or recognized ACL classes." + ' Hint: try dropping a WebID profile URI, a vcard:Group URI, or a web app origin.' + typeDetails; _debug__WEBPACK_IMPORTED_MODULE_11__/* .error */ .z3(error); return _context4.abrupt("return", Promise.reject(new Error(error))); case 6: this.setACLCombo(combo, uri, agent, this.controller.subject); case 7: case "end": return _context4.stop(); } }, _callee4, this, [[1, 3]]); })); function handleDroppedUri(_x7, _x8) { return _handleDroppedUri.apply(this, arguments); } return handleDroppedUri; }() }, { key: "setACLCombo", value: function setACLCombo(combo, uri, res, subject) { if (!(combo in this.byCombo)) { this.byCombo[combo] = []; } this.removeAgentFromCombos(uri); // Combos are mutually distinct this.byCombo[combo].push([res.pred, res.obj.uri]); _debug__WEBPACK_IMPORTED_MODULE_11__/* .log */ .Rm("ACL: setting access to ".concat(subject, " by ").concat(res.pred, ": ").concat(res.obj)); } }, { key: "removeAgentFromCombos", value: function removeAgentFromCombos(uri) { for (var k = 0; k < 16; k++) { var combos = this.byCombo[kToCombo(k)]; if (combos) { for (var i = 0; i < combos.length; i++) { while (i < combos.length && combos[i][1] === uri) { combos.splice(i, 1); } } } } } }]); }(); function kToCombo(k) { var y = ['Read', 'Append', 'Write', 'Control']; var combo = []; for (var i = 0; i < 4; i++) { if (k & 1 << i) { combo.push('http://www.w3.org/ns/auth/acl#' + y[i]); } } combo.sort(); return combo.join('\n'); } function ktToList(k) { var list = ''; var y = ['Read', 'Append', 'Write', 'Control']; for (var i = 0; i < 4; i++) { if (k & 1 << i) { list += y[i]; } } return list; } function findAgent(uri, kb) { var obj = (0,rdflib__WEBPACK_IMPORTED_MODULE_5__.sym)(uri); var types = kb.findTypeURIs(obj); for (var ty in types) { _debug__WEBPACK_IMPORTED_MODULE_11__/* .log */ .Rm(' drop object type includes: ' + ty); } // An Origin URI is one like https://fred.github.io eith no trailing slash if (uri.startsWith('http') && uri.split('/').length === 3) { // there is no third slash return { pred: 'origin', obj: obj }; // The only way to know an origin alas } // @@ This is an almighty kludge needed because drag and drop adds extra slashes to origins if (uri.startsWith('http') && uri.split('/').length === 4 && uri.endsWith('/')) { // there IS third slash _debug__WEBPACK_IMPORTED_MODULE_11__/* .log */ .Rm('Assuming final slash on dragged origin URI was unintended!'); return { pred: 'origin', obj: (0,rdflib__WEBPACK_IMPORTED_MODULE_5__.sym)(uri.slice(0, -1)) }; // Fix a URI where the drag and drop system has added a spurious slash } if (_ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.vcard('WebID').uri in types) return { pred: 'agent', obj: obj }; if (_ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.vcard('Group').uri in types) { return { pred: 'agentGroup', obj: obj }; // @@ note vcard membership not RDFs } if (obj.sameTerm(_ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.foaf('Agent')) || obj.sameTerm(_ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.acl('AuthenticatedAgent')) || // AuthenticatedAgent obj.sameTerm(_ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.rdf('Resource')) || obj.sameTerm(_ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.owl('Thing'))) { return { pred: 'agentClass', obj: obj }; } if (_ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.vcard('Individual').uri in types || _ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.foaf('Person').uri in types || _ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.foaf('Agent').uri in types) { var pref = kb.any(obj, _ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.foaf('preferredURI')); if (pref) return { pred: 'agent', obj: (0,rdflib__WEBPACK_IMPORTED_MODULE_5__.sym)(pref) }; return { pred: 'agent', obj: obj }; } if (_ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.solid('AppProvider').uri in types) { return { pred: 'origin', obj: obj }; } if (_ns__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.solid('AppProviderClass').uri in types) { return { pred: 'originClass', obj: obj }; } _debug__WEBPACK_IMPORTED_MODULE_11__/* .log */ .Rm(' Triage fails for ' + uri); return null; } /***/ }, /***/ 7367 (__unused_webpack_module, __webpack_exports__, __webpack_require__) { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ DR: () => (/* binding */ shortNameForFolder), /* harmony export */ Fp: () => (/* binding */ preventBrowserDropEvents), /* harmony export */ wR: () => (/* binding */ ACLControlBox5) /* harmony export */ }); /* unused harmony exports preventDrag, handleDrop, setGlobalWindow */ /* harmony import */ var _babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(467); /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4756); /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var _ns__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(1795); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9612); /* harmony import */ var _acl__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5619); /* harmony import */ var _access_controller__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(6466); /* harmony import */ var _style__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(675); /* harmony import */ var _debug__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(7423); /** * Functions for rendering the ACL User Interface. * See https://github.com/solidos/userguide/blob/main/views/sharing/userguide.md#view * for a screenshot. * @packageDocumentation */ var global = window; var preventBrowserDropEventsDone = Symbol('prevent double triggering of drop event'); /** * See https://coshx.com/preventing-drag-and-drop-disasters-with-a-chrome-userscript * Without this dropping anything onto a browser page will cause chrome etc to jump to diff page * throwing away all the user's work. * * In apps which may use drag and drop, this utility takes care of the fact * by default in a browser, an uncaught user drop into a browser window * causes the browser to lose all its work in that window and navigate to another page * * @param document The DOM * @returns void */ function preventBrowserDropEvents(document) { (0,_debug__WEBPACK_IMPORTED_MODULE_7__/* .log */ .Rm)('preventBrowserDropEvents called.'); if (typeof global !== 'undefined') { if (global[preventBrowserDropEventsDone]) return; global[preventBrowserDropEventsDone] = true; } document.addEventListener('drop', handleDrop, false); document.addEventListener('dragenter', preventDrag, false); document.addEventListener('dragover', preventDrag, false); } /** @internal */ function preventDrag(e) { e.stopPropagation(); e.preventDefault(); } /** @internal */ function handleDrop(e) { if (e.dataTransfer.files.length > 0) { if (!global.confirm('Are you sure you want to drop this file here? (Cancel opens it in a new tab)')) { e.stopPropagation(); e.preventDefault(); (0,_debug__WEBPACK_IMPORTED_MODULE_7__/* .log */ .Rm)('@@@@ document-level DROP suppressed: ' + e.dataTransfer.dropEffect); } } } /** * Get a folder's own filename in the directory tree. Also works for * domain names; the URL protocol ('https://') acts as the tree root * with short name '/' (see also test/unit/acl/acl-control.test.ts). * * ```typescript * shortNameForFolder($rdf.namedNode('http://example.com/some/folder/')) * // 'folder' * * shortNameForFolder($rdf.namedNode('http://example.com/some/folder')) * // 'folder' * * shortNameForFolder($rdf.namedNode('http://example.com/')) * // 'example.com' * * shortNameForFolder($rdf.namedNode('http://example.com')) * // 'example.com' * * shortNameForFolder($rdf.namedNode('http://')) * // '/' * ``` * * It also works with relative URLs: * ```typescript * shortNameForFolder($rdf.namedNode('../folder/')) * // 'folder' * ``` * * @param x RDF Node for the folder URL * @returns Short name for the folder */ function shortNameForFolder(x) { var str = x.uri; // Strip the trailing slash if (str.slice(-1) === '/') { str = str.slice(0, -1); } // Remove the path if present, keeping only the part // after the last slash. var slash = str.lastIndexOf('/'); if (slash >= 0) { str = str.slice(slash + 1); } // Return the folder's filename, or '/' if nothing found // (but see https://github.com/solidos/solid-ui/issues/196 // regarding whether this happens at the domain root or // not) return str || '/'; } /** * A wrapper that retrieves ACL data and uses it * to render an [[AccessController]] component. * Presumably the '5' is a version number of some sort, * but all we know is it was already called ACLControlBox5 * when it was introduced into solid-ui in * https://github.com/solidos/solid-ui/commit/948b874bd93e7bf5160e6e224821b888f07d15f3#diff-4192a29f38a0ababd563b36b47eba5bbR54 */ function ACLControlBox5(subject, context, noun, kb) { var dom = context.dom; var doc = subject.doc(); // The ACL is actually to the doc describing the thing var container = dom.createElement('div'); container.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_6__/* .style */ .i.aclControlBoxContainer); var header = container.appendChild(dom.createElement('h1')); header.textContent = "Sharing for ".concat(noun, " ").concat(_utils__WEBPACK_IMPORTED_MODULE_3__/* .label */ .P(subject)); header.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_6__/* .style */ .i.aclControlBoxHeader); var status = container.appendChild(dom.createElement('div')); status.setAttribute('style', _style__WEBPACK_IMPORTED_MODULE_6__/* .style */ .i.aclControlBoxStatus); try { loadController(doc, kb, subject, noun, context, dom, status).then(function (controller) { return container.appendChild(controller.render()); }); } catch (error) { status.innerText = error; } return container; } function loadController(_x, _x2, _x3, _x4, _x5, _x6, _x7) { return _loadController.apply(this, arguments); } function _loadController() { _loadController = (0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A)(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default().mark(function _callee2(doc, kb, subject, noun, context, dom, status) { return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default().wrap(function (_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: return _context2.abrupt("return", new Promise(function (resolve, reject) { return (0,_acl__WEBPACK_IMPORTED_MODULE_4__/* .getACLorDefault */ .VM)(doc, /*#__PURE__*/function () { var _ref = (0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A)(/*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default().mark(function _callee(ok, isDirectACL, targetDoc, targetACLDoc, defaultHolder, defaultACLDoc) { var targetDirectory, targetIsProtected, prospectiveDefaultHolder, getController, _t; return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_1___default().wrap(function (_context) { while (1) switch (_context.prev = _context.next) { case 0: getController = function _getController(prospectiveDefaultHolder) { return new _access_controller__WEBPACK_IMPORTED_MODULE_5__/* .AccessController */ .v(subject, noun, context, status, targetIsProtected, targetDoc, targetACLDoc, defaultHolder, defaultACLDoc, prospectiveDefaultHolder, kb, dom); }; if (ok) { _context.next = 1; break; } return _context.abrupt("return", reject(new Error("Error reading ".concat(isDirectACL ? '' : ' default ', "ACL. status ").concat(targetDoc, ": ").concat(targetACLDoc)))); case 1: targetDirectory = getDirectory(targetDoc); targetIsProtected = isStorage