chore (rewrite): editor highlight and unsaved nav block

This commit is contained in:
MickaelK
2024-01-01 10:35:46 +11:00
parent 68a0df1189
commit 80a28d88e7
7 changed files with 47 additions and 9 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ export default class ComponentMenubar extends window.HTMLElement {
$title.style.opacity = 0; $title.style.opacity = 0;
this.timeoutID = setTimeout(() => { this.timeoutID = setTimeout(() => {
animate($title, { time: 250, keyframes: slideYIn(2) }); animate($title, { time: 250, keyframes: slideYIn(2) });
}, 300); }, 100);
} }
disconnectedCallback() { disconnectedCallback() {
+6 -1
View File
@@ -9,7 +9,12 @@ export async function init($root) {
}); });
} }
export function navigate(href) { export async function navigate(href) {
if (typeof window.history.block === "function") {
const block = await window.history.block(href);
if (block) return;
}
delete window.history.block;
window.history.pushState({ window.history.pushState({
...window.history, ...window.history,
previous: window.location.pathname, previous: window.location.pathname,
+2 -2
View File
@@ -3,7 +3,7 @@ import rxjs, { effect } from "../lib/rx.js";
import { ApplicationError } from "../lib/error.js"; import { ApplicationError } from "../lib/error.js";
import { basename } from "../lib/path.js"; import { basename } from "../lib/path.js";
import { loadCSS } from "../helpers/loader.js"; import { loadCSS } from "../helpers/loader.js";
import WithShell from "../components/decorator_shell_filemanager.js"; import WithShell, { init as initShell } from "../components/decorator_shell_filemanager.js";
import { get as getConfig } from "../model/config.js"; import { get as getConfig } from "../model/config.js";
import ctrlError from "./ctrl_error.js"; import ctrlError from "./ctrl_error.js";
@@ -61,7 +61,7 @@ export default WithShell(async function(render) {
export async function init() { export async function init() {
return Promise.all([ return Promise.all([
loadCSS(import.meta.url, "./ctrl_viewerpage.css"), loadCSS(import.meta.url, "./ctrl_viewerpage.css"),
loadCSS(import.meta.url, "../components/decorator_shell_filemanager.css"), initShell(),
mime$.pipe( mime$.pipe(
rxjs.map((mimes) => opener(basename(getCurrentPath()), mimes)), rxjs.map((mimes) => opener(basename(getCurrentPath()), mimes)),
rxjs.mergeMap(([opener]) => loadModule(opener)), rxjs.mergeMap(([opener]) => loadModule(opener)),
@@ -22,7 +22,6 @@ export default async function(render) {
`); `);
render($page); render($page);
// feature: virtual scrolling // feature: virtual scrolling
const removeLoader = createLoader($page); const removeLoader = createLoader($page);
const path = location.pathname.replace(new RegExp("^/files"), ""); const path = location.pathname.replace(new RegExp("^/files"), "");
@@ -3,6 +3,7 @@ import rxjs, { effect } from "../../lib/rx.js";
import { animate, slideXIn, opacityOut } from "../../lib/animate.js"; import { animate, slideXIn, opacityOut } from "../../lib/animate.js";
import { qs } from "../../lib/dom.js"; import { qs } from "../../lib/dom.js";
import { createLoader } from "../../components/loader.js"; import { createLoader } from "../../components/loader.js";
import modal from "../../components/modal.js";
import { loadCSS, loadJS } from "../../helpers/loader.js"; import { loadCSS, loadJS } from "../../helpers/loader.js";
import ajax from "../../lib/ajax.js"; import ajax from "../../lib/ajax.js";
import { extname } from "../../lib/path.js"; import { extname } from "../../lib/path.js";
@@ -71,7 +72,7 @@ export default async function(render) {
const editor = window.CodeMirror($editor, { const editor = window.CodeMirror($editor, {
value: content, value: content,
lineNumbers: true, lineNumbers: true,
mode, mode: CodeMirror.__mode,
keyMap: ["emacs", "vim"].indexOf(config["editor"]) === -1 ? "sublime" : config["editor"], keyMap: ["emacs", "vim"].indexOf(config["editor"]) === -1 ? "sublime" : config["editor"],
lineWrapping: true, lineWrapping: true,
readOnly: !/PUT/.test(acl), readOnly: !/PUT/.test(acl),
@@ -134,6 +135,7 @@ export default async function(render) {
CodeMirror.commands.save = (cm) => observer.next(cm); CodeMirror.commands.save = (cm) => observer.next(cm);
})), })),
rxjs.mergeMap((cm) => { rxjs.mergeMap((cm) => {
$fab.classList.remove("hidden");
$fab.render($ICON.LOADING) $fab.render($ICON.LOADING)
$fab.disabled = true; $fab.disabled = true;
return rxjs.of(cm.getValue()).pipe( return rxjs.of(cm.getValue()).pipe(
@@ -146,6 +148,35 @@ export default async function(render) {
}), }),
rxjs.catchError(ctrlError()), rxjs.catchError(ctrlError()),
)); ));
// feature5: save on exit
effect(setup$.pipe(
rxjs.tap((cm) => window.history.block = async (href) => {
const block = qs(document.body, `[is="component-breadcrumb"]`).hasAttribute("indicator");
if (block === false) return false;
// confirm.now(
// <div style={{ textAlign: "center", paddingBottom: "5px" }}>
// { t("Do you want to save the changes ?") }
// </div>,
// () =>{
// return this.save()
// .then(() => this.props.history.push(nextLocation));
// },
// () => {
// this.props.needSavingUpdate(false)
// .then(() => this.props.history.push(nextLocation));
// },
// );
return new Promise((done) => {
modal.open(createElement(`
<div style="text-align:center;padding-bottom:5px;">
Do you want to save the changes ?
</div>
`, { onQuit: () => {done(false)} }));
})
}),
))
} }
function has_binary(str) { function has_binary(str) {
@@ -233,8 +264,8 @@ function loadMode(ext) {
else if (ext === "diff" || ext === "patch") mode = "diff"; else if (ext === "diff" || ext === "patch") mode = "diff";
else if (ext === "sparql") mode = "sparql"; else if (ext === "sparql") mode = "sparql";
else if (ext === "properties") mode = "properties"; else if (ext === "properties") mode = "properties";
else if (ext === "c" || ext === "cpp" || ext === "java" || else if (ext === "c" || ext === "cpp" || ext === "h") mode = "clike";
ext === "h") mode = "clike"; else if (ext === "java") mode = "java";
return before.then(() => loadJS(import.meta.url, `./application_editor/${mode}.js`, { type: "module" })) return before.then(() => loadJS(import.meta.url, `./application_editor/${mode}.js`, { type: "module" }))
.catch(() => loadJS(import.meta.url, "./application_editor/text.js", { type: "module" })) .catch(() => loadJS(import.meta.url, "./application_editor/text.js", { type: "module" }))
@@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/clike/clike.js"; import "../../../lib/vendor/codemirror/mode/clike/clike.js";
CodeMirror.__mode = "clike"; CodeMirror.__mode = "text/x-c++src";
export default CodeMirror; export default CodeMirror;
@@ -0,0 +1,3 @@
import "./clike.js";
CodeMirror.__mode = "text/x-java";
export default CodeMirror;