UNPKG

solid-panes

Version:

Solid-compatible Panes: applets and views for the mashlib and databrowser

74 lines (68 loc) 3.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var UI = _interopRequireWildcard(require("solid-ui")); var $rdf = _interopRequireWildcard(require("rdflib")); var mime = _interopRequireWildcard(require("mime-types")); var _new = _interopRequireDefault(require("./new.js")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } /* Human-readable editable "Dokieli" Pane ** ** This outline pane contains the document contents for a Dokieli document ** The dokeili system allows the user to edit a document including anotations ** review. It does not use turtle, but RDF/a */ // const DOKIELI_TEMPLATE_URI = 'https://dokie.li/new' // Copy to make new dok // Distributed with this library var _default = exports.default = { icon: UI.icons.iconBase + 'dokieli-logo.png', // @@ improve? more like doccument? name: 'Dokieli', mintClass: UI.ns.solid('DokieliDocument'), // @@ A better class? // Don't provide viewing - let humanReadablePane handle that with appropriate icon label: function (subject, context) { return null; // Viewing now handled by humanReadablePane }, // Create a new folder in a Solid system, with a dokieli editable document in it mintNew: function (context, newPaneOptions) { const kb = context.session.store; let newInstance = newPaneOptions.newInstance; if (!newInstance) { let uri = newPaneOptions.newBase; if (uri.endsWith('/')) { uri = uri.slice(0, -1); newPaneOptions.newBase = uri; } newInstance = kb.sym(uri); } const contentType = mime.lookup(newInstance.uri); if (!contentType || !contentType.includes('html')) { newInstance = $rdf.sym(newInstance.uri + '.html'); } newPaneOptions.newInstance = newInstance; // Save for creation system // console.log('New dokieli will make: ' + newInstance) let htmlContents = _new.default; let filename = newInstance.uri.split('/').slice(-1)[0]; filename = decodeURIComponent(filename.split('.')[0]); const encodedTitle = filename.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); htmlContents = htmlContents.replace('<title>', '<title>' + encodedTitle); htmlContents = htmlContents.replace('</article>', '<h1>' + encodedTitle + '</h1></article>'); // console.log('@@ New HTML for Dok:' + htmlContents) return new Promise(function (resolve) { kb.fetcher.webOperation('PUT', newInstance.uri, { data: htmlContents, contentType: 'text/html' }).then(function () { console.log('new Dokieli document created at ' + newPaneOptions.newInstance); resolve(newPaneOptions); }).catch(function (err) { console.log('Error creating dokieli doc at ' + newPaneOptions.newInstance + ': ' + err); }); }); } // render: removed - now handled by humanReadablePane with appropriate dokieli icon }; // ends