From 2137b35a465ae9f830519c5a8bd49cb388fd552d Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 1 Nov 2022 10:38:20 +0100 Subject: Wiki: Rebundle Content Tools. Content Tools was previously wrapped into an ECMAScript module through the use of Snowpack. This mechanism broke some time ago, making the wiki uneditable. Content Tools is now imported as is, which simplifies its packaging and restores it to a working state. Change-Id: I49d2d625bc955a260a63c47bcaceb23b61366123 --- .../resources/META-INF/resources/cms2/base.css | 5 +- src/main/resources/META-INF/resources/lib.js | 1 + src/main/resources/META-INF/resources/package.json | 2 +- .../resources/META-INF/resources/wiki/wikiPage.js | 53 +++++++++++++++++++++ .../resources/templates/benki/wiki/wikiPage.html | 55 +--------------------- 5 files changed, 60 insertions(+), 56 deletions(-) create mode 100644 src/main/resources/META-INF/resources/wiki/wikiPage.js (limited to 'src/main') diff --git a/src/main/resources/META-INF/resources/cms2/base.css b/src/main/resources/META-INF/resources/cms2/base.css index 14d4f7a..0cec83c 100644 --- a/src/main/resources/META-INF/resources/cms2/base.css +++ b/src/main/resources/META-INF/resources/cms2/base.css @@ -11,8 +11,11 @@ /* Sanitize.css */ @import "../web_modules/sanitize.css/forms.css"; @import "../web_modules/sanitize.css/typography.css"; -/* */ +/* Content Tools */ +@import "../web_modules/ContentTools/build/content-tools.min.css"; + +/* Fonts */ @import "./fonts/fira.css"; @import "./fonts/firacode.css"; @import "./fonts/iosevka.css"; diff --git a/src/main/resources/META-INF/resources/lib.js b/src/main/resources/META-INF/resources/lib.js index 7a59751..f64586d 100644 --- a/src/main/resources/META-INF/resources/lib.js +++ b/src/main/resources/META-INF/resources/lib.js @@ -4,6 +4,7 @@ import './lazychat/MlkLazychatSubmissionForm.js'; import './lazychat/newLazychatMessage.js'; import './posts/commentBox.js'; import './posts/postList.js'; +import './wiki/wikiPage.js'; import './web_modules/elix/define/Button.js'; import './web_modules/elix/define/ExpandablePanel.js'; diff --git a/src/main/resources/META-INF/resources/package.json b/src/main/resources/META-INF/resources/package.json index e64f3a4..21ce087 100644 --- a/src/main/resources/META-INF/resources/package.json +++ b/src/main/resources/META-INF/resources/package.json @@ -27,8 +27,8 @@ "snowpack": { "plugins": [], "install": [ - "ContentTools", "ContentTools/build/content-tools.min.css", + "ContentTools/build/content-tools.min.js", "ContentTools/build/images/*", "bosonic", "elix/define/*.js", diff --git a/src/main/resources/META-INF/resources/wiki/wikiPage.js b/src/main/resources/META-INF/resources/wiki/wikiPage.js new file mode 100644 index 0000000..9f96732 --- /dev/null +++ b/src/main/resources/META-INF/resources/wiki/wikiPage.js @@ -0,0 +1,53 @@ +import '../web_modules/ContentTools/build/content-tools.min.js'; + +window.addEventListener('DOMContentLoaded', () => { + let editor = ContentTools.EditorApp.get(); + editor.init('*[data-editable]', 'data-name'); + + editor.addEventListener('saved', async function (ev) { + document.getElementById("warning-panel").close(); + + let {regions} = ev.detail(); + if (Object.getOwnPropertyNames(regions).length === 0) { + // Nothing changed. + return; + } + + this.busy(true); + + let requestParams = new URLSearchParams(); + for (let name of Object.getOwnPropertyNames(regions)) { + requestParams.append(name, regions[name]); + } + + let {pageTitle} = document.getElementById('wiki-page').dataset; + + let response = await fetch(`/wiki/${pageTitle}`, { + method: 'POST', + body: requestParams + }); + + if (!response.ok) { + document.getElementById("warning-panel").open(); + document.getElementById("warning-text").innerText = `Failed to save page: ${response.statusText}`; + this.busy(false); + +return; + } + + let status = await response.json(); + if (status.status !== "ok") { + document.getElementById("warning-panel").open(); + document.getElementById("warning-text").innerText = `Failed to save page: ${JSON.stringify(status)}`; + this.busy(false); + +return; + } + + if (status.hasOwnProperty("content")) { + document.getElementById("wiki-content").innerHTML = status.content; + } + + this.busy(false); + }); +}); diff --git a/src/main/resources/templates/benki/wiki/wikiPage.html b/src/main/resources/templates/benki/wiki/wikiPage.html index 63d9950..b456475 100644 --- a/src/main/resources/templates/benki/wiki/wikiPage.html +++ b/src/main/resources/templates/benki/wiki/wikiPage.html @@ -7,7 +7,6 @@ {#nav}{#navbar siteSection="Wiki" /} {#head} - - - {/head} {#body} -
+

{page.title}

-- cgit v1.2.3