fix (public): linter in frontend rewrite

This commit is contained in:
MickaelK 2024-02-26 00:23:39 +11:00
parent 6ab60bb38d
commit d5b0abb2d9
70 changed files with 536 additions and 547 deletions

View file

@ -1,10 +1,8 @@
import rxjs, { ajax } from "../lib/rx.js";
import { loadJS } from "../helpers/loader.js";
// import { setup_cache } from "../helpers/cache.js";
import { init as setup_loader } from "../helpers/loader.js";
import { init as setup_loader, loadJS } from "../helpers/loader.js";
import { report } from "../helpers/log.js";
export default async function main() {
try {
await Promise.all([ // procedure with no outside dependencies

View file

@ -1,8 +1,7 @@
import { animate, slideYOut, slideYIn, slideXIn, opacityOut } from "../lib/animate.js";
import { animate, slideYOut, slideYIn, opacityOut } from "../lib/animate.js";
import { loadCSS } from "../helpers/loader.js";
class ComponentBreadcrumb extends window.HTMLDivElement {
constructor() {
super();
if (new window.URL(location.href).searchParams.get("nav") === "false") {
@ -30,12 +29,12 @@ class ComponentBreadcrumb extends window.HTMLDivElement {
switch (name) {
case "path":
if (newValue == "") return;
if (newValue === "") return;
return this.renderPath({ path: newValue, previous: oldValue || null });
case "indicator":
return this.renderIndicator()
return this.renderIndicator();
}
throw new Error("component::breadcrumb.js unknow attribute name: "+ name)
throw new Error("component::breadcrumb.js unknow attribute name: "+ name);
}
static get observedAttributes() {
@ -45,7 +44,7 @@ class ComponentBreadcrumb extends window.HTMLDivElement {
async renderPath({ path = "", previous }) {
path = this.__normalised(path);
previous = this.__normalised(previous);
let pathChunks = path.split("/");
const pathChunks = path.split("/");
// STEP1: leaving animation on elements that will be removed
if (previous !== null && previous.indexOf(path) >= 0) {
@ -97,7 +96,7 @@ class ComponentBreadcrumb extends window.HTMLDivElement {
${limitSize(label, true)}
</span>
`;
return `<div>${limitSize(label)}</div>`
return `<div>${limitSize(label)}</div>`;
})();
return `
@ -133,17 +132,21 @@ class ComponentBreadcrumb extends window.HTMLDivElement {
if (state && this.getAttribute("indicator") !== "false") state = true;
const $indicator = this.querySelector(`[data-bind="path"]`)
.lastChild
.querySelector("span");
.lastChild
.querySelector("span");
if (state) {
$indicator.style.opacity = 1;
$indicator.innerHTML = `<div class="component_saving">*</div>`;
await animate($indicator, { time: 500, keyframes: [
{ transform: "scale(0)", offset: 0 },
{ transform: "scale(1.5)", offset: 0.3 },
{ transform: "scale(1)", offset: 1 },
], fill: "none"});
await animate($indicator, {
time: 500,
keyframes: [
{ transform: "scale(0)", offset: 0 },
{ transform: "scale(1.5)", offset: 0.3 },
{ transform: "scale(1)", offset: 1 },
],
fill: "none"
});
} else {
$indicator.style.opacity = 0;
await animate($indicator, { time: 200, keyframes: opacityOut(), fill: "none" });

View file

@ -29,13 +29,13 @@ export default function(ctrl) {
ctrl(createRender($main));
ctrlSidebar(createRender(qs($page, `[data-bind="sidebar"]`)));
onDestroy(async () => {
onDestroy(async() => {
if ((history.state.previous || "").startsWith("/view/") && location.pathname.startsWith("/files/")) {
await animate($main, { time: 100, keyframes: slideYOut(20), fill: "none" });
$main.classList.add("hidden");
}
});
}
};
}
async function ctrlSidebar(render) {

View file

@ -15,7 +15,7 @@ export default class ComponentDropdown extends HTMLDivElement {
}
render() {
this.classList.add("component_dropdown", "view", "sort")
this.classList.add("component_dropdown", "view", "sort");
this.appendChild(createFragment(`
<div class="dropdown_button">
<img class="component_icon" draggable="false" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzODQgNTEyIj4KICA8cGF0aCBmaWxsPSIjZjJmMmYyIiBkPSJNIDM2MCw0NjAgSCAyNCBDIDEwLjcsNDYwIDAsNDUzLjMgMCw0NDAgdiAtMTIgYyAwLC0xMy4zIDEwLjcsLTIwIDI0LC0yMCBoIDMzNiBjIDEzLjMsMCAyNCw2LjcgMjQsMjAgdiAxMiBjIDAsMTMuMyAtMTAuNywyMCAtMjQsMjAgeiIgLz4KICA8cGF0aCBmaWxsPSIjZjJmMmYyIiBkPSJNIDIyNi41NTM5LDIzNC44ODQyOCBWIDUyLjk0MzI4MyBjIDAsLTYuNjI3IC01LjM3MywtMTIgLTEyLC0xMiBoIC00NCBjIC02LjYyNywwIC0xMiw1LjM3MyAtMTIsMTIgViAyMzQuODg0MjggaCAtNTIuMDU5IGMgLTIxLjM4MiwwIC0zMi4wOSwyNS44NTEgLTE2Ljk3MSw0MC45NzEgbCA4Ni4wNTksODYuMDU5IGMgOS4zNzMsOS4zNzMgMjQuNTY5LDkuMzczIDMzLjk0MSwwIGwgODYuMDU5LC04Ni4wNTkgYyAxNS4xMTksLTE1LjExOSA0LjQxMSwtNDAuOTcxIC0xNi45NzEsLTQwLjk3MSB6IiAvPgo8L3N2Zz4K" alt="download_white">

View file

@ -46,7 +46,7 @@ class Loader extends window.HTMLElement {
customElements.define("component-loader", Loader);
export function createLoader($parent, opts = {}) {
const { wait = 500 } = opts
const { wait = 500 } = opts;
const cancel = effect(new rxjs.Observable((observer) => {
const $icon = createElement(`
<div class="component_loader">

View file

@ -1,4 +1,3 @@
import { createElement } from "../lib/skeleton/index.js";
import { animate, slideYIn } from "../lib/animate.js";
import { basename } from "../lib/path.js";
import assert from "../lib/assert.js";
@ -10,7 +9,7 @@ export default class ComponentMenubar extends window.HTMLElement {
constructor() {
super();
this.classList.add("component_menubar")
this.classList.add("component_menubar");
this.innerHTML = `
<div class="component_container">
<span>

View file

@ -6,7 +6,7 @@ export async function loadJS(baseURL, path, opts = {}) {
const $script = document.createElement("script");
const link = new URL(path, baseURL) + "?version=" + version;
$script.setAttribute("src", link.toString());
for (let key in opts) {
for (const key in opts) {
$script.setAttribute(key, opts[key]);
}
if (typeof type === "string") ;

View file

@ -20,7 +20,8 @@ export function animate($node, opts = {}) {
return new Promise((done) => {
$node.animate(keyframes, {
duration: time,
fill, easing,
fill,
easing,
}).onfinish = done;
});
}

View file

@ -1,15 +1,15 @@
export default class assert {
static type(object, type, msg) {
if (object instanceof type) return;
throw new Error(msg ? msg : `assertion failed - unexpected type for ${object.toString()}`);
throw new Error(msg || `assertion failed - unexpected type for ${object.toString()}`);
}
static truthy(object, msg) {
if (object) return;
throw new Error(msg ? msg : `assertion failed - object is not truthy`);
throw new Error(msg || `assertion failed - object is not truthy`);
}
static fail(object, msg) {
throw new Error(msg ? msg : `assertion failed - ${object}`);
throw new Error(msg || `assertion failed - ${object}`);
}
}

View file

@ -1,7 +1,7 @@
class ChromecastManager {
init() {
// TODO: additional rules for setup
let src = "https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1";
const src = "https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1";
if (document.head.querySelector(`script[src="${src}"]`)) return Promise.resolve();
return new Promise((done) => {
@ -9,13 +9,13 @@ class ChromecastManager {
script.src = src;
script.onerror = () => done();
window["__onGCastApiAvailable"] = function(isAvailable) {
if (isAvailable) cast.framework.CastContext.getInstance().setOptions({
receiverApplicationId: chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,
autoJoinPolicy: chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED,
if (isAvailable) window.cast.framework.CastContext.getInstance().setOptions({
receiverApplicationId: window.chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,
autoJoinPolicy: window.chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED,
});
done();
};
document.head.appendChild(script)
document.head.appendChild(script);
});
}
@ -45,20 +45,22 @@ class ChromecastManager {
// url. Once we have that app, the authorisation will come from a customData field
// of a chrome.cast.media.LoadRequest
const target = new URL(mediaInfo.contentId);
target.searchParams.append("authorization", Session.authorization);
target.searchParams.append("authorization", window.Session.authorization);
mediaInfo.contentId = target.toString();
return new chrome.cast.media.LoadRequest(mediaInfo);
return new window.chrome.cast.media.LoadRequest(mediaInfo);
}
context() {
if (!this.isAvailable()) return
if (!this.isAvailable()) return;
return window.cast.framework.CastContext.getInstance();
}
session() {
const context = this.context();
if (!context) return;
return context.getCurrentSession();
}
media() {
const session = this.session();
if (!session) return;

View file

@ -1,3 +0,0 @@
export function pluck() {} // TODO
export functon spread() {} // TODO

View file

@ -1,4 +1,4 @@
import { createElement, createRender } from "../../lib/skeleton/index.js";
import { createElement } from "../../lib/skeleton/index.js";
import rxjs, { effect, applyMutations, applyMutation, onClick } from "../../lib/rx.js";
import { createForm } from "../../lib/form.js";
import { qs, qsa } from "../../lib/dom.js";

View file

@ -14,7 +14,7 @@ export async function initStorage() {
rxjs.map(({ connections }) => connections),
rxjs.tap((connections) => {
if (backendsEnabled$.value !== undefined) return;
backendsEnabled$.next(Array.isArray(connections) ? connections : [])
backendsEnabled$.next(Array.isArray(connections) ? connections : []);
}),
).toPromise();
}

View file

@ -1,4 +1,4 @@
import { createElement, createRender } from "../../lib/skeleton/index.js";
import { createElement } from "../../lib/skeleton/index.js";
import rxjs, { effect, applyMutation } from "../../lib/rx.js";
import { qs, qsa } from "../../lib/dom.js";
import { createForm, mutateForm } from "../../lib/form.js";

View file

@ -55,7 +55,7 @@ export default async function(render) {
let n = parseInt(settings_get("login_tab"));
if (Number.isNaN(n)) n = (conns.length || 0) / 2 - 1;
if (n < 0 || n >= conns.length) n = 0;
return n
return n;
}),
rxjs.tap((current) => setCurrentBackend(Math.round(current))),
));
@ -171,7 +171,7 @@ export default async function(render) {
if (Object.keys(p).length > 0) {
url += "&state=" + btoa(JSON.stringify(p));
}
location.href = url
location.href = url;
return rxjs.EMPTY;
}),
rxjs.mergeMap((formData) => { // CASE 2: oauth2 related backends like dropbox and gdrive

View file

@ -75,7 +75,6 @@ trace: ${err.stack || "N/A"}`;
return [msg, trace.trim()];
}
const css = `
.error-page {
width: 80%;

View file

@ -2,7 +2,7 @@ import { createElement, createRender } from "../lib/skeleton/index.js";
import rxjs, { effect } from "../lib/rx.js";
import { qs } from "../lib/dom.js";
import { loadCSS } from "../helpers/loader.js";
import WithShell, { init as initShell } from "../components/decorator_shell_filemanager.js"
import WithShell, { init as initShell } from "../components/decorator_shell_filemanager.js";
import { getState$ } from "./filespage/ctrl_filesystem_state.js";
import componentFilesystem, { init as initFilesystem } from "./filespage/ctrl_filesystem.js";
@ -30,7 +30,7 @@ export default WithShell(function(render) {
componentFilesystem(createRender(qs($page, "[is=\"component_filesystem\"]")));
// feature3: render the menubar
componentSubmenu(createRender(qs($page, "[is=\"component_submenu\"]")))
componentSubmenu(createRender(qs($page, "[is=\"component_submenu\"]")));
});
export function init() {

View file

@ -18,7 +18,7 @@ const mime$ = getConfig().pipe(
);
function loadModule(appName) {
switch(appName) {
switch (appName) {
case "editor":
return import("./viewerpage/application_editor.js");
case "pdf":
@ -55,8 +55,7 @@ export default WithShell(async function(render) {
)),
rxjs.catchError(ctrlError()),
));
})
});
export async function init() {
return Promise.all([

View file

@ -8,7 +8,7 @@ import { createLoader } from "../../components/loader.js";
import ctrlError from "../ctrl_error.js";
import { createThing } from "./thing.js";
import { handleError, getFiles } from "./ctrl_filesystem_state.js";
// import { handleError, getFiles } from "./ctrl_filesystem_state.js";
import { ls } from "./model_files.js";
export default async function(render) {
@ -51,13 +51,13 @@ export default async function(render) {
animate($list, { time: 200, keyframes: slideYIn(5) });
$list.appendChild($fs);
/////////////////////////////////////////
/// //////////////////////////////////////
// CASE 1: virtual scroll isn't enabled
if (files.length <= VIRTUAL_SCROLL_MINIMUM_TRIGGER) {
return rxjs.EMPTY;
}
/////////////////////////////////////////
/// //////////////////////////////////////
// CASE 2: with virtual scroll
const $listBefore = qs($page, ".ifscroll-before");
const $listAfter = qs($page, ".ifscroll-after");
@ -74,13 +74,16 @@ export default async function(render) {
$listAfter.style.height = `${height - size}px`;
};
setHeight(0);
const top = ($node) => $node.getBoundingClientRect().top;
// const top = ($node) => $node.getBoundingClientRect().top;
return rxjs.of({
files, path,
files,
path,
currentState: 0,
$list,
setHeight,
FILE_HEIGHT, BLOCK_SIZE, COLUMN_PER_ROW,
FILE_HEIGHT,
BLOCK_SIZE,
COLUMN_PER_ROW,
MARGIN: 35, // TODO: top($list) - top($list.closest(".scroll-y"));
});
}),
@ -130,7 +133,7 @@ export default async function(render) {
// nearest COLUMN_PER_ROW
fileEnd += 1;
if (fileEnd % COLUMN_PER_ROW === 0) {
break
break;
}
}
}
@ -142,7 +145,7 @@ export default async function(render) {
const file = files[i];
if (file === undefined) $fs.appendChild(createThing({
type: "hidden",
}))
}));
else $fs.appendChild(createThing({
name: file.name,
// name: `file ${i}`,

View file

@ -36,4 +36,4 @@ export const onSearch = () => {
console.log("SEARCH");
};
export const getFiles = (n) => {}
export const getFiles = (n) => {};

View file

@ -1,4 +1,4 @@
import { onDestroy, createElement, createRender, createFragment } from "../../lib/skeleton/index.js";
import { onDestroy, createElement, createFragment } from "../../lib/skeleton/index.js";
import rxjs, { effect, applyMutation, onClick } from "../../lib/rx.js";
import { animate } from "../../lib/animate.js";
import { loadCSS } from "../../helpers/loader.js";
@ -11,14 +11,14 @@ export default async function(render) {
const $page = createElement(`<div class="component_submenu container"></div>`);
render($page);
const $scroll = $page.closest(".scroll-y")
const $scroll = $page.closest(".scroll-y");
effect(rxjs.fromEvent($scroll, "scroll", { passive: true }).pipe(
rxjs.map((e) => e.target.scrollTop > 30),
rxjs.distinctUntilChanged(),
rxjs.startWith(false),
rxjs.tap((scrolling) => scrolling ?
$scroll.classList.add("scrolling") :
$scroll.classList.remove("scrolling")),
rxjs.tap((scrolling) => scrolling
? $scroll.classList.add("scrolling")
: $scroll.classList.remove("scrolling")),
));
onDestroy(() => clearSelection());

View file

@ -2,9 +2,9 @@ import { createElement } from "../../lib/skeleton/index.js";
import { addSelection } from "./model_files.js";
const IMAGE = {
"FILE": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBoZWlnaHQ9IjE2IiB3aWR0aD0iMTYiPgogIDxwYXRoIHN0eWxlPSJjb2xvcjojMDAwMDAwO3RleHQtaW5kZW50OjA7dGV4dC10cmFuc2Zvcm06bm9uZTtmaWxs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Dc4MyB6IiAvPgogIDwvZz4KPC9zdmc+Cg=="
};
const $tmpl = createElement(`
<div class="component_thing view-grid not-selected" draggable="true">
@ -41,9 +41,9 @@ export function createThing({
// permissions = {}
}) {
const $thing = $tmpl.cloneNode(true);
if (!$thing instanceof window.HTMLElement) throw new Error("assertion failed: $thing must be an HTMLELement");
if (!($thing instanceof window.HTMLElement)) throw new Error("assertion failed: $thing must be an HTMLELement");
const $label = $thing.querySelector(".component_filename .file-details > span");
if (!$label instanceof window.HTMLElement) throw new Error("assertion failed: $label must be an HTMLELement");
if (!($label instanceof window.HTMLElement)) throw new Error("assertion failed: $label must be an HTMLELement");
$label.textContent = name;
$thing.querySelector("a").setAttribute("href", link);
@ -54,6 +54,6 @@ export function createThing({
e.preventDefault();
e.stopPropagation();
addSelection(name, type);
}
};
return $thing;
}

View file

@ -6,7 +6,7 @@ import { join } from "../../lib/path.js";
import { createLoader } from "../../components/loader.js";
import { getDownloadUrl } from "./common.js";
import * as THREE from "../../lib/vendor/three/three.module.js"
import * as THREE from "../../lib/vendor/three/three.module.js";
import { OrbitControls } from "../../lib/vendor/three/OrbitControls.js";
import { GLTFLoader } from "../../lib/vendor/three/GLTFLoader.js";
import { OBJLoader } from "../../lib/vendor/three/OBJLoader.js";
@ -70,15 +70,15 @@ export default function(render, { mime }) {
// resize handler
const onResize = () => {
camera.aspect = $page.clientWidth / $page.clientHeight;
camera.updateProjectionMatrix();
camera.updateProjectionMatrix();
renderer.setSize($page.clientWidth, $page.clientHeight);
};
window.addEventListener("resize", onResize);
onDestroy(() => window.removeEventListener("resize", onResize));
return rxjs.animationFrames().pipe(rxjs.tap(() => {
controls.update();
renderer.render(scene, camera);
controls.update();
renderer.render(scene, camera);
}));
}),
rxjs.catchError(ctrlError()),
@ -87,7 +87,7 @@ export default function(render, { mime }) {
function getLoader(mime) {
const identity = (s) => s;
switch(mime) {
switch (mime) {
case "application/object":
return [new OBJLoader(), identity];
case "model/3dm":

View file

@ -6,7 +6,6 @@ import { loadCSS, loadJS } from "../../helpers/loader.js";
import { settings_get, settings_put } from "../../lib/settings.js";
import Chromecast from "../../lib/chromecast.js";
import assert from "../../lib/assert.js";
import { basename, extname } from "../../lib/path.js";
import ctrlError from "../ctrl_error.js";
import { render as renderMenubar } from "../../components/menubar.js";
@ -16,14 +15,9 @@ import { ICON } from "./common_icon.js";
import { formatTimecode } from "./common_player.js";
import { transition, getDownloadUrl } from "./common.js";
import { getSession } from "../../model/session.js";
import { get as getConfig } from "../../model/config.js";
import "../../components/menubar.js";
const STATUS_PLAYING = "PLAYING";
const STATUS_PAUSED = "PAUSED";
const STATUS_BUFFERING = "BUFFERING";
// const STATUS_BUFFERING = "BUFFERING";
export default function(render, { mime }) {
const $page = createElement(`
@ -80,7 +74,7 @@ export default function(render, { mime }) {
const currentTime$ = new rxjs.BehaviorSubject([
0, // starting time - does change when seeking to another point
0, // offset to align the audio context currentTime. otherwise when seeking, the
// currentTime keep growing and progress bar goes haywire
// currentTime keep growing and progress bar goes haywire
]);
const currentTime = (wavesurfer) => {
return currentTime$.value[0] + (wavesurfer.backend.ac.currentTime - currentTime$.value[1]);
@ -125,7 +119,7 @@ export default function(render, { mime }) {
default:
assert.fail(status);
}
}
};
const setSeek = (newTime, wavesurfer) => {
currentTime$.next([newTime, wavesurfer.backend.ac.currentTime]);
wavesurfer.backend.source.stop(0);
@ -137,7 +131,7 @@ export default function(render, { mime }) {
// feature1: setup the dom
const setup$ = rxjs.of(qs($page, "#waveform")).pipe(
rxjs.mergeMap(($node) => Promise.resolve(WaveSurfer.create({
rxjs.mergeMap(($node) => Promise.resolve(window.WaveSurfer.create({
container: $node,
interact: false,
@ -151,13 +145,13 @@ export default function(render, { mime }) {
rxjs.tap((wavesurfer) => {
wavesurfer.load(getDownloadUrl());
wavesurfer.on("error", (err) => { // TODO: one liner to check
throw new Error(err)
throw new Error(err);
});
wavesurfer.on("ready", () => {
$control.main.classList.remove("hidden");
qs($control.main, "#totalDuration").textContent = formatTimecode(wavesurfer.getDuration());
});
onDestroy(() => wavesurfer.destroy())
onDestroy(() => wavesurfer.destroy());
}),
rxjs.catchError(ctrlError()),
rxjs.shareReplay(1),
@ -188,7 +182,7 @@ export default function(render, { mime }) {
wavesurfer.on("ready", () => observer.next(wavesurfer));
})),
rxjs.share(),
)
);
effect(ready$.pipe(rxjs.tap((wavesurfer) => {
wavesurfer.backend.createSource();
wavesurfer.backend.startPosition = 0;
@ -207,7 +201,7 @@ export default function(render, { mime }) {
rxjs.mergeMap((status) => setup$.pipe(rxjs.tap((wavesurfer) => setStatus(status, wavesurfer)))),
rxjs.switchMap((wavesurfer) => rxjs.animationFrames().pipe(
rxjs.tap(() => {
const _currentTime = currentTime(wavesurfer)
const _currentTime = currentTime(wavesurfer);
const percent = _currentTime / wavesurfer.getDuration();
if (percent > 1) return;
wavesurfer.drawer.progress(percent);
@ -254,12 +248,13 @@ export default function(render, { mime }) {
rxjs.switchMap((wavesurfer) => rxjs.fromEvent(document, "keydown").pipe(
rxjs.map((e) => e.code),
rxjs.tap((code) => {
switch(code) {
switch (code) {
case "Space":
case "KeyK":
setStatus(
wavesurfer.backend.ac.state === "suspended" ?
STATUS_PLAYING : STATUS_PAUSED,
wavesurfer.backend.ac.state === "suspended"
? STATUS_PLAYING
: STATUS_PAUSED,
wavesurfer,
);
break;
@ -276,7 +271,7 @@ export default function(render, { mime }) {
setSeek(Math.min(wavesurfer.getDuration(), currentTime(wavesurfer) + 10), wavesurfer);
break;
case "KeyF":
chromecastLoader();
// chromecastLoader();
break;
case "KeyJ":
setSeek(Math.max(0, currentTime(wavesurfer) - 10), wavesurfer);
@ -374,7 +369,7 @@ export function init() {
function setup_chromecast() {
if (!("chrome" in window)) {
return Promise.resolve();
} else if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
} else if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
return Promise.resolve();
}
// if (!CONFIG.enable_chromecast) {

View file

@ -23,8 +23,8 @@ export default function(render) {
// feature1: setup the dom
const setup$ = rxjs.of(qs($page, `[data-bind="epub"]`)).pipe(
rxjs.mergeMap(async ($epub) => {
const book = new ePub.Book({
rxjs.mergeMap(async($epub) => {
const book = new window.ePub.Book({
replacements: "blobUrl",
});
const rendition = book.renderTo($epub, {
@ -60,7 +60,7 @@ export default function(render) {
rendition$.pipe(rxjs.mergeMap(() => rxjs.fromEvent(qs(document, "iframe").contentDocument.body, "keydown"))),
)),
rxjs.map((e) => {
switch(e.code) {
switch (e.code) {
case "Space": return (r) => r.next();
case "ArrowRight": return (r) => r.next();
case "PageDown": return (r) => r.next();
@ -69,10 +69,12 @@ export default function(render) {
}
return null;
}),
rxjs.mergeMap((fn) => fn === null ? rxjs.EMPTY : rendition$.asObservable().pipe(
rxjs.first(),
rxjs.tap((rendition) => fn(rendition))
)),
rxjs.mergeMap((fn) => fn === null
? rxjs.EMPTY
: rendition$.asObservable().pipe(
rxjs.first(),
rxjs.tap((rendition) => fn(rendition))
)),
rxjs.catchError(ctrlError()),
));
}

View file

@ -72,7 +72,7 @@ export default async function(render) {
const editor = window.CodeMirror($editor, {
value: content,
lineNumbers: true,
mode: CodeMirror.__mode,
mode: window.CodeMirror.__mode,
keyMap: ["emacs", "vim"].indexOf(config["editor"]) === -1 ? "sublime" : config["editor"],
lineWrapping: true,
readOnly: !/PUT/.test(acl),
@ -110,20 +110,20 @@ export default async function(render) {
effect(setup$.pipe(
rxjs.switchMap((editor) => new rxjs.Observable((observer) => editor.on("change", (cm) => observer.next(cm)))),
rxjs.mergeMap((editor) => content$.pipe(rxjs.map((oldContent) => [editor, editor.getValue(), oldContent]))),
rxjs.tap(async ([editor, newContent = "", oldContent = ""]) => {
rxjs.tap(async([editor, newContent = "", oldContent = ""]) => {
if ($fab.disabled) return;
const $breadcrumb = qs(document.body, `[is="component-breadcrumb"]`);
if (newContent === oldContent) {
await animate($fab, { time: 100, keyframes: opacityOut() });
$fab.classList.add("hidden");
$breadcrumb.removeAttribute("indicator");
return
return;
}
$breadcrumb.setAttribute("indicator", "true");
const shouldAnimate = $fab.classList.contains("hidden");
$fab.classList.remove("hidden");
$fab.render($ICON.SAVING);
$fab.onclick = () => CodeMirror.commands.save(editor);
$fab.onclick = () => window.CodeMirror.commands.save(editor);
if (shouldAnimate) await animate($fab, { time: 100, keyframes: slideXIn(40) });
}),
@ -132,11 +132,11 @@ export default async function(render) {
// feature4: save
effect(setup$.pipe(
rxjs.mergeMap((editor) => new rxjs.Observable((observer) => {
CodeMirror.commands.save = (cm) => observer.next(cm);
window.CodeMirror.commands.save = (cm) => observer.next(cm);
})),
rxjs.mergeMap((cm) => {
$fab.classList.remove("hidden");
$fab.render($ICON.LOADING)
$fab.render($ICON.LOADING);
$fab.disabled = true;
return rxjs.of(cm.getValue()).pipe(
saveFile$(),
@ -151,7 +151,7 @@ export default async function(render) {
// feature5: save on exit
effect(setup$.pipe(
rxjs.tap((cm) => window.history.block = async (href) => {
rxjs.tap((cm) => window.history.block = async(href) => {
const block = qs(document.body, `[is="component-breadcrumb"]`).hasAttribute("indicator");
if (block === false) return false;
@ -173,10 +173,10 @@ export default async function(render) {
<div style="text-align:center;padding-bottom:5px;">
Do you want to save the changes ?
</div>
`, { onQuit: () => {done(false)} }));
})
`, { onQuit: () => { done(false); } }));
});
}),
))
));
}
function has_binary(str) {

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/clike/clike.js";
CodeMirror.__mode = "text/x-c++src";
export default CodeMirror;
window.CodeMirror.__mode = "text/x-c++src";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/clojure/clojure.js";
CodeMirror.__mode = "clojure";
export default CodeMirror;
window.CodeMirror.__mode = "clojure";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/cmake/cmake.js";
CodeMirror.__mode = "cmake";
export default CodeMirror;
window.CodeMirror.__mode = "cmake";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/commonlisp/commonlisp.js";
CodeMirror.__mode = "commonlisp";
export default CodeMirror;
window.CodeMirror.__mode = "commonlisp";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/css/css.js";
CodeMirror.__mode = "css";
export default CodeMirror;
window.CodeMirror.__mode = "css";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/diff/diff.js";
CodeMirror.__mode = "diff";
export default CodeMirror;
window.CodeMirror.__mode = "diff";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/dockerfile/dockerfile.js";
CodeMirror.__mode = "dockerfile";
export default CodeMirror;
window.CodeMirror.__mode = "dockerfile";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/elm/elm.js";
CodeMirror.__mode = "elm";
export default CodeMirror;
window.CodeMirror.__mode = "elm";
export default window.CodeMirror;

View file

@ -3,7 +3,6 @@ export const org_cycle = (cm) => {
isFold(cm, pos) ? unfold(cm, pos) : fold(cm, pos);
};
const state = {
stab: "CONTENT",
};
@ -29,7 +28,6 @@ export const org_shifttab = (cm) => {
return state.stab;
};
function set_folding_mode(cm, mode) {
if (mode === "OVERVIEW") {
folding_mode_overview(cm);
@ -43,7 +41,7 @@ function set_folding_mode(cm, mode) {
function folding_mode_overview(cm) {
cm.operation(function() {
for (let i = cm.firstLine(), e = cm.lastLine(); i <= e; i++) {
fold(cm, CodeMirror.Pos(i, 0));
fold(cm, window.CodeMirror.Pos(i, 0));
}
});
}
@ -51,15 +49,15 @@ function set_folding_mode(cm, mode) {
cm.operation(function() {
let previous_header = null;
for (let i = cm.firstLine(), e = cm.lastLine(); i <= e; i++) {
fold(cm, CodeMirror.Pos(i, 0));
if (/header/.test(cm.getTokenTypeAt(CodeMirror.Pos(i, 0))) === true) {
fold(cm, window.CodeMirror.Pos(i, 0));
if (/header/.test(cm.getTokenTypeAt(window.CodeMirror.Pos(i, 0))) === true) {
const level = cm.getLine(i).replace(/^(\*+).*/, "$1").length;
if (previous_header && level > previous_header.level) {
unfold(cm, CodeMirror.Pos(previous_header.line, 0));
unfold(cm, window.CodeMirror.Pos(previous_header.line, 0));
}
previous_header = {
line: i,
level: level,
level,
};
}
}
@ -68,15 +66,14 @@ function set_folding_mode(cm, mode) {
function folding_mode_all(cm) {
cm.operation(function() {
for (let i = cm.firstLine(), e = cm.lastLine(); i <= e; i++) {
if (/header/.test(cm.getTokenTypeAt(CodeMirror.Pos(i, 0))) === true) {
unfold(cm, CodeMirror.Pos(i, 0));
if (/header/.test(cm.getTokenTypeAt(window.CodeMirror.Pos(i, 0))) === true) {
unfold(cm, window.CodeMirror.Pos(i, 0));
}
}
});
}
}
/*
* Promote heading or move table column to left.
*/
@ -177,19 +174,18 @@ export const org_meta_return = (cm) => {
rearrange_list(cm, line);
} else if (p = isTitle(cm, line)) {
const tmp = previousOfType(cm, "title", line);
const level = tmp && tmp.level || 1;
cm.replaceRange("\n"+"*".repeat(level)+" ", { line: line, ch: content.length });
const level = (tmp && tmp.level) || 1;
cm.replaceRange("\n"+"*".repeat(level)+" ", { line, ch: content.length });
cm.setCursor({ line: line+1, ch: level+1 });
} else if (content.trim() === "") {
cm.replaceRange("* ", { line: line, ch: 0 });
cm.setCursor({ line: line, ch: 2 });
cm.replaceRange("* ", { line, ch: 0 });
cm.setCursor({ line, ch: 2 });
} else {
cm.replaceRange("\n\n* ", { line: line, ch: content.length });
cm.replaceRange("\n\n* ", { line, ch: content.length });
cm.setCursor({ line: line + 2, ch: 2 });
}
};
const TODO_CYCLES = ["TODO", "DONE", ""];
/*
* Cycle the thing at point or in the current line, depending on context.
@ -210,8 +206,8 @@ export const org_shiftleft = (cm) => {
params["status"] = cycles[cycles.indexOf(params["status"]) + 1];
cm.replaceRange(
makeTitle(params),
{ line: line, ch: 0 },
{ line: line, ch: content.length },
{ line, ch: 0 },
{ line, ch: content.length },
);
};
/*
@ -234,8 +230,8 @@ export const org_shiftright = (cm) => {
params["status"] = cycles[cycles.indexOf(params["status"]) + 1];
cm.replaceRange(
makeTitle(params),
{ line: line, ch: 0 },
{ line: line, ch: content.length },
{ line, ch: 0 },
{ line, ch: content.length },
);
});
};
@ -262,20 +258,19 @@ export const org_insert_todo_heading = (cm) => {
cm.setCursor({ line: p.end+1, ch: level*3+7 });
rearrange_list(cm, line);
} else if (p = isTitle(cm, line)) {
const level = p && p.level || 1;
cm.replaceRange("\n"+"*".repeat(level)+" TODO ", { line: line, ch: content.length });
const level = (p && p.level) || 1;
cm.replaceRange("\n"+"*".repeat(level)+" TODO ", { line, ch: content.length });
cm.setCursor({ line: line+1, ch: level+6 });
} else if (content.trim() === "") {
cm.replaceRange("* TODO ", { line: line, ch: 0 });
cm.setCursor({ line: line, ch: 7 });
cm.replaceRange("* TODO ", { line, ch: 0 });
cm.setCursor({ line, ch: 7 });
} else {
cm.replaceRange("\n\n* TODO ", { line: line, ch: content.length });
cm.replaceRange("\n\n* TODO ", { line, ch: content.length });
cm.setCursor({ line: line + 2, ch: 7 });
}
});
};
/*
* Move subtree up or move table row up.
* Calls org-move-subtree-up or org-table-move-row or
@ -347,7 +342,6 @@ export const org_metadown = (cm) => {
});
};
export const org_shiftmetaright = function(cm) {
cm.operation(() => {
const line = cm.getCursor().line;
@ -379,7 +373,6 @@ export const org_shiftmetaleft = function(cm) {
});
};
function makeTitle(p) {
let content = "*".repeat(p["level"])+" ";
if (p["status"]) {
@ -421,7 +414,7 @@ function isItemList(cm, line) {
level: padding / 2,
content: content.trimLeft().replace(/^\s*\-\s(.*)$/, "$1"),
start: line,
end: function(_cm, _line) {
end: (function(_cm, _line) {
let line_candidate = _line;
let content = null;
do {
@ -437,7 +430,7 @@ function isItemList(cm, line) {
}
} while (_line <= _cm.lineCount());
return line_candidate;
}(cm, line),
}(cm, line)),
};
function findRootLine(_cm, _line) {
@ -467,7 +460,7 @@ function isNumberedList(cm, line) {
level: padding / 3,
content: content.trimLeft().replace(/^[0-9]+[\.\)]\s(.*)$/, "$1"),
start: line,
end: function(_cm, _line) {
end: (function(_cm, _line) {
let line_candidate = _line;
let content = null;
do {
@ -483,7 +476,7 @@ function isNumberedList(cm, line) {
}
} while (_line <= _cm.lineCount());
return line_candidate;
}(cm, line),
}(cm, line)),
// specific
n: parseInt(content.trimLeft().replace(/^([0-9]+).*$/, "$1")),
separator: content.trimLeft().replace(/^[0-9]+([\.\)]).*$/, "$1"),
@ -514,7 +507,7 @@ function isTitle(cm, line, level) {
level: reference_level,
content: match[3],
start: line,
end: function(_cm, _line) {
end: (function(_cm, _line) {
let line_candidate = _line;
let content = null;
do {
@ -524,7 +517,7 @@ function isTitle(cm, line, level) {
const match = content.match(/^(\*+)\s.*/);
if (
match && match[1] &&
( match[1].length === reference_level || match[1].length < reference_level)
(match[1].length === reference_level || match[1].length < reference_level)
) {
break;
} else {
@ -533,7 +526,7 @@ function isTitle(cm, line, level) {
}
} while (_line <= _cm.lineCount());
return line_candidate;
}(cm, line),
}(cm, line)),
// specific
status: match[2].trim(),
};
@ -566,7 +559,6 @@ function rearrange_list(cm, line) {
}
}
if (p = (isNumberedList(cm, i) || isItemList(cm, i))) {
// rearrange spacing levels in list
if (last_p) {
@ -582,7 +574,6 @@ function rearrange_list(cm, line) {
}
}
last_p = p;
// we can process content block instead of line
if (p) {
@ -607,13 +598,13 @@ function rearrange_list(cm, line) {
let i;
for (i=range[0]; i<=range[1]; i++) {
content = cm.getLine(i).trimLeft();
const n_spaces = function(_level, _line, _type) {
const n_spaces = (function(_level, _line, _type) {
let spaces = _level * 3;
if (_line > 0) {
spaces += _type === "numbered" ? 3 : 2;
}
return spaces;
}(level, i - range[0], type);
}(level, i - range[0], type));
content = " ".repeat(n_spaces) + content;
cm.replaceRange(
@ -629,8 +620,8 @@ function rearrange_list(cm, line) {
const new_content = content.replace(/[0-9]+\./, level+".");
cm.replaceRange(
new_content,
{ line: line, ch: 0 },
{ line: line, ch: content.length },
{ line, ch: 0 },
{ line, ch: content.length },
);
}
@ -720,9 +711,9 @@ export function unfold(cm, start) {
}
export function isFold(cm, start) {
const line = start.line;
const marks = cm.findMarks(CodeMirror.Pos(line, 0), CodeMirror.Pos(line + 1, 0));
const marks = cm.findMarks(window.CodeMirror.Pos(line, 0), window.CodeMirror.Pos(line + 1, 0));
for (let i = 0; i < marks.length; ++i) {
if (marks[i].__isFold && marks[i].find().from.line == line) return marks[i];
if (marks[i].__isFold && marks[i].find().from.line === line) return marks[i];
}
return false;
}

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/erlang/erlang.js";
CodeMirror.__mode = "erlang";
export default CodeMirror;
window.CodeMirror.__mode = "erlang";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/go/go.js";
CodeMirror.__mode = "go";
export default CodeMirror;
window.CodeMirror.__mode = "go";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/htmlmixed/htmlmixed.js";
CodeMirror.__mode = "htmlmixed";
export default CodeMirror;
window.CodeMirror.__mode = "htmlmixed";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "./clike.js";
CodeMirror.__mode = "text/x-java";
export default CodeMirror;
window.CodeMirror.__mode = "text/x-java";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/javascript/javascript.js";
CodeMirror.__mode = "javascript";
export default CodeMirror;
window.CodeMirror.__mode = "javascript";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/jsx/jsx.js";
CodeMirror.__mode = "jsx";
export default CodeMirror;
window.CodeMirror.__mode = "jsx";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/lua/lua.js";
CodeMirror.__mode = "lua";
export default CodeMirror;
window.CodeMirror.__mode = "lua";
export default window.CodeMirror;

View file

@ -1,313 +1,310 @@
import "../../../lib/vendor/codemirror/addon/mode/simple.js";
import {
org_cycle, org_shifttab, org_metaleft, org_metaright, org_meta_return, org_metaup,
org_metadown, org_insert_todo_heading, org_shiftleft, org_shiftright, fold, unfold,
isFold, org_set_fold, org_shiftmetaleft, org_shiftmetaright,
} from "./emacs-org.js";
// import "../../../lib/vendor/codemirror/addon/mode/simple.js";
// import {
// org_cycle, org_shifttab, org_metaleft, org_metaright, org_meta_return, org_metaup,
// org_metadown, org_insert_todo_heading, org_shiftleft, org_shiftright, fold, unfold,
// isFold, org_set_fold, org_shiftmetaleft, org_shiftmetaright,
// } from "./emacs-org.js";
// TODO:
// import { pathBuilder, dirname, currentShare } from "../../../helpers/";
// // TODO:
// // import { pathBuilder, dirname, currentShare } from "../../../helpers/";
const CodeMirror = window.CodeMirror;
// const CodeMirror = window.CodeMirror;
CodeMirror.__mode = "orgmode";
// CodeMirror.__mode = "orgmode";
CodeMirror.defineSimpleMode("orgmode", {
start: [
{ regex: /(\*\s)(TODO|DOING|WAITING|NEXT|PENDING|)(CANCELLED|CANCELED|CANCEL|DONE|REJECTED|STOP|STOPPED|)(\s+\[\#[A-C]\]\s+|)(.*?)(?:(\s{10,}|))(\:[\S]+\:|)$/, sol: true, token: ["header level1 org-level-star", "header level1 org-todo", "header level1 org-done", "header level1 org-priority", "header level1", "header level1 void", "header level1 comment"] },
{ regex: /(\*{1,}\s)(TODO|DOING|WAITING|NEXT|PENDING|)(CANCELLED|CANCELED|CANCEL|DEFERRED|DONE|REJECTED|STOP|STOPPED|)(\s+\[\#[A-C]\]\s+|)(.*?)(?:(\s{10,}|))(\:[\S]+\:|)$/, sol: true, token: ["header org-level-star", "header org-todo", "header org-done", "header org-priority", "header", "header void", "header comment"] },
{ regex: /(\+[^\+]+\+)/, token: ["strikethrough"] },
{ regex: /(\*[^\*]+\*)/, token: ["strong"] },
{ regex: /(\/[^\/]+\/)/, token: ["em"] },
{ regex: /(\_[^\_]+\_)/, token: ["link"] },
{ regex: /(\~[^\~]+\~)/, token: ["comment"] },
{ regex: /(\=[^\=]+\=)/, token: ["comment"] },
{ regex: /\[\[[^\[\]]+\]\[[^\[\]]+\]\]/, token: "org-url" }, // links
{ regex: /\[\[[^\[\]]+\]\]/, token: "org-image" }, // image
{ regex: /\[[xX\s\-\_]\]/, token: "qualifier org-toggle" }, // checkbox
{ regex: /\#\+(?:(BEGIN|begin))_[a-zA-Z]*/, token: "comment", next: "env", sol: true }, // comments
{ regex: /:?[A-Z_]+\:.*/, token: "comment", sol: true }, // property drawers
{ regex: /(\#\+[a-zA-Z_]*)(\:.*)/, token: ["keyword", "qualifier"], sol: true }, // environments
{ regex: /(CLOCK\:|SHEDULED\:|DEADLINE\:)(\s.+)/, token: ["comment", "keyword"] },
],
env: [
{ regex: /\#\+(?:(END|end))_[a-zA-Z]*/, token: "comment", next: "start", sol: true },
{ regex: /.*/, token: "comment" },
],
});
CodeMirror.registerHelper("fold", "orgmode", function(cm, start) {
// init
const levelToMatch = headerLevel(start.line);
// CodeMirror.defineSimpleMode("orgmode", {
// start: [
// { regex: /(\*\s)(TODO|DOING|WAITING|NEXT|PENDING|)(CANCELLED|CANCELED|CANCEL|DONE|REJECTED|STOP|STOPPED|)(\s+\[\#[A-C]\]\s+|)(.*?)(?:(\s{10,}|))(\:[\S]+\:|)$/, sol: true, token: ["header level1 org-level-star", "header level1 org-todo", "header level1 org-done", "header level1 org-priority", "header level1", "header level1 void", "header level1 comment"] },
// { regex: /(\*{1,}\s)(TODO|DOING|WAITING|NEXT|PENDING|)(CANCELLED|CANCELED|CANCEL|DEFERRED|DONE|REJECTED|STOP|STOPPED|)(\s+\[\#[A-C]\]\s+|)(.*?)(?:(\s{10,}|))(\:[\S]+\:|)$/, sol: true, token: ["header org-level-star", "header org-todo", "header org-done", "header org-priority", "header", "header void", "header comment"] },
// { regex: /(\+[^\+]+\+)/, token: ["strikethrough"] },
// { regex: /(\*[^\*]+\*)/, token: ["strong"] },
// { regex: /(\/[^\/]+\/)/, token: ["em"] },
// { regex: /(\_[^\_]+\_)/, token: ["link"] },
// { regex: /(\~[^\~]+\~)/, token: ["comment"] },
// { regex: /(\=[^\=]+\=)/, token: ["comment"] },
// { regex: /\[\[[^\[\]]+\]\[[^\[\]]+\]\]/, token: "org-url" }, // links
// { regex: /\[\[[^\[\]]+\]\]/, token: "org-image" }, // image
// { regex: /\[[xX\s\-\_]\]/, token: "qualifier org-toggle" }, // checkbox
// { regex: /\#\+(?:(BEGIN|begin))_[a-zA-Z]*/, token: "comment", next: "env", sol: true }, // comments
// { regex: /:?[A-Z_]+\:.*/, token: "comment", sol: true }, // property drawers
// { regex: /(\#\+[a-zA-Z_]*)(\:.*)/, token: ["keyword", "qualifier"], sol: true }, // environments
// { regex: /(CLOCK\:|SHEDULED\:|DEADLINE\:)(\s.+)/, token: ["comment", "keyword"] },
// ],
// env: [
// { regex: /\#\+(?:(END|end))_[a-zA-Z]*/, token: "comment", next: "start", sol: true },
// { regex: /.*/, token: "comment" },
// ],
// });
// CodeMirror.registerHelper("fold", "orgmode", function(cm, start) {
// // init
// const levelToMatch = headerLevel(start.line);
// no folding needed
if (levelToMatch === null) return;
// // no folding needed
// if (levelToMatch === null) return;
// find folding limits
const lastLine = cm.lastLine();
let end = start.line;
while (end < lastLine) {
end += 1;
const level = headerLevel(end);
if (level && level <= levelToMatch) {
end = end - 1;
break;
};
}
// // find folding limits
// const lastLine = cm.lastLine();
// let end = start.line;
// while (end < lastLine) {
// end += 1;
// const level = headerLevel(end);
// if (level && level <= levelToMatch) {
// end = end - 1;
// break;
// };
// }
return {
from: CodeMirror.Pos(start.line, cm.getLine(start.line).length),
to: CodeMirror.Pos(end, cm.getLine(end).length),
};
// return {
// from: CodeMirror.Pos(start.line, cm.getLine(start.line).length),
// to: CodeMirror.Pos(end, cm.getLine(end).length),
// };
function headerLevel(lineNo) {
const line = cm.getLine(lineNo);
const match = /^\*+/.exec(line);
if (match && match.length === 1 && /header/.test(cm.getTokenTypeAt(CodeMirror.Pos(lineNo, 0)))) {
return match[0].length;
}
return null;
}
});
CodeMirror.registerGlobalHelper("fold", "drawer", function(mode) {
return mode.name === "orgmode" ? true : false;
}, function(cm, start) {
const drawer = isBeginningOfADrawer(start.line);
if (drawer === false) return;
// function headerLevel(lineNo) {
// const line = cm.getLine(lineNo);
// const match = /^\*+/.exec(line);
// if (match && match.length === 1 && /header/.test(cm.getTokenTypeAt(CodeMirror.Pos(lineNo, 0)))) {
// return match[0].length;
// }
// return null;
// }
// });
// CodeMirror.registerGlobalHelper("fold", "drawer", function(mode) {
// return mode.name === "orgmode";
// }, function(cm, start) {
// const drawer = isBeginningOfADrawer(start.line);
// if (drawer === false) return;
// find folding limits
const lastLine = cm.lastLine();
let end = start.line;
while (end < lastLine) {
end += 1;
if (isEndOfADrawer(end)) {
break;
}
}
// // find folding limits
// const lastLine = cm.lastLine();
// let end = start.line;
// while (end < lastLine) {
// end += 1;
// if (isEndOfADrawer(end)) {
// break;
// }
// }
return {
from: CodeMirror.Pos(start.line, cm.getLine(start.line).length),
to: CodeMirror.Pos(end, cm.getLine(end).length),
};
// return {
// from: CodeMirror.Pos(start.line, cm.getLine(start.line).length),
// to: CodeMirror.Pos(end, cm.getLine(end).length),
// };
function isBeginningOfADrawer(lineNo) {
const line = cm.getLine(lineNo);
const match = /^\:.*\:$/.exec(line);
if (match && match.length === 1 && match[0] !== ":END:") {
return true;
}
return false;
}
function isEndOfADrawer(lineNo) {
const line = cm.getLine(lineNo);
return line.trim() === ":END:" ? true : false;
}
});
// function isBeginningOfADrawer(lineNo) {
// const line = cm.getLine(lineNo);
// const match = /^\:.*\:$/.exec(line);
// if (match && match.length === 1 && match[0] !== ":END:") {
// return true;
// }
// return false;
// }
// function isEndOfADrawer(lineNo) {
// const line = cm.getLine(lineNo);
// return line.trim() === ":END:";
// }
// });
// CodeMirror.registerHelper("orgmode", "init", (editor, fn) => {
// editor.setOption("extraKeys", {
// Tab: (cm) => org_cycle(cm),
// "Shift-Tab": (cm) => fn("shifttab", org_shifttab(cm)),
// "Alt-Left": (cm) => org_metaleft(cm),
// "Alt-Right": (cm) => org_metaright(cm),
// "Alt-Enter": (cm) => org_meta_return(cm),
// "Alt-Up": (cm) => org_metaup(cm),
// "Alt-Down": (cm) => org_metadown(cm),
// "Shift-Alt-Left": (cm) => org_shiftmetaleft(cm),
// "Shift-Alt-Right": (cm) => org_shiftmetaright(cm),
// "Shift-Alt-Enter": (cm) => org_insert_todo_heading(cm),
// "Shift-Left": (cm) => org_shiftleft(cm),
// "Shift-Right": (cm) => org_shiftright(cm),
// });
// fn("shifttab", org_set_fold(editor));
CodeMirror.registerHelper("orgmode", "init", (editor, fn) => {
editor.setOption("extraKeys", {
"Tab": (cm) => org_cycle(cm),
"Shift-Tab": (cm) => fn("shifttab", org_shifttab(cm)),
"Alt-Left": (cm) => org_metaleft(cm),
"Alt-Right": (cm) => org_metaright(cm),
"Alt-Enter": (cm) => org_meta_return(cm),
"Alt-Up": (cm) => org_metaup(cm),
"Alt-Down": (cm) => org_metadown(cm),
"Shift-Alt-Left": (cm) => org_shiftmetaleft(cm),
"Shift-Alt-Right": (cm) => org_shiftmetaright(cm),
"Shift-Alt-Enter": (cm) => org_insert_todo_heading(cm),
"Shift-Left": (cm) => org_shiftleft(cm),
"Shift-Right": (cm) => org_shiftright(cm),
});
fn("shifttab", org_set_fold(editor));
// editor.on("mousedown", toggleHandler);
// editor.on("touchstart", toggleHandler);
// editor.on("gutterClick", foldLine);
editor.on("mousedown", toggleHandler);
editor.on("touchstart", toggleHandler);
editor.on("gutterClick", foldLine);
// // fold everything except headers by default
// editor.operation(function() {
// for (let i = 0; i < editor.lineCount(); i++) {
// if (/header/.test(editor.getTokenTypeAt(CodeMirror.Pos(i, 0))) === false) {
// fold(editor, CodeMirror.Pos(i, 0));
// }
// }
// });
// return CodeMirror.orgmode.destroy.bind(this, editor);
// });
// fold everything except headers by default
editor.operation(function() {
for (let i = 0; i < editor.lineCount(); i++) {
if (/header/.test(editor.getTokenTypeAt(CodeMirror.Pos(i, 0))) === false) {
fold(editor, CodeMirror.Pos(i, 0));
}
}
});
return CodeMirror.orgmode.destroy.bind(this, editor);
});
// CodeMirror.registerHelper("orgmode", "destroy", (editor) => {
// editor.off("mousedown", toggleHandler);
// editor.off("touchstart", toggleHandler);
// editor.off("gutterClick", foldLine);
// });
CodeMirror.registerHelper("orgmode", "destroy", (editor) => {
editor.off("mousedown", toggleHandler);
editor.off("touchstart", toggleHandler);
editor.off("gutterClick", foldLine);
});
// function foldLine(cm, line) {
// const cursor = { line, ch: 0 };
// isFold(cm, cursor) ? unfold(cm, cursor) : fold(cm, cursor);
// }
function foldLine(cm, line) {
const cursor = { line: line, ch: 0 };
isFold(cm, cursor) ? unfold(cm, cursor) : fold(cm, cursor);
}
// let widgets = [];
// function toggleHandler(cm, e) {
// const position = cm.coordsChar({
// left: e.clientX || (e.targetTouches && e.targetTouches[0].clientX),
// top: e.clientY || (e.targetTouches && e.targetTouches[0].clientY),
// }, "page");
// const token = cm.getTokenAt(position);
// _disableSelection();
// if (/org-level-star/.test(token.type)) {
// _preventIfShould();
// _foldHeadline();
// _disableSelection();
// } else if (/org-toggle/.test(token.type)) {
// _preventIfShould();
// _toggleCheckbox();
// _disableSelection();
// } else if (/org-todo/.test(token.type)) {
// _preventIfShould();
// _toggleTodo();
// _disableSelection();
// } else if (/org-done/.test(token.type)) {
// _preventIfShould();
// _toggleDone();
// _disableSelection();
// } else if (/org-priority/.test(token.type)) {
// _preventIfShould();
// _togglePriority();
// _disableSelection();
// } else if (/org-url/.test(token.type)) {
// _disableSelection();
// _navigateLink();
// } else if (/org-image/.test(token.type)) {
// _disableSelection();
// _toggleImageWidget();
// }
let widgets = [];
function toggleHandler(cm, e) {
const position = cm.coordsChar({
left: e.clientX || (e.targetTouches && e.targetTouches[0].clientX),
top: e.clientY || (e.targetTouches && e.targetTouches[0].clientY),
}, "page");
const token = cm.getTokenAt(position);
// function _preventIfShould() {
// if ("ontouchstart" in window) e.preventDefault();
// }
// function _disableSelection() {
// cm.on("beforeSelectionChange", _onSelectionChangeHandler);
// function _onSelectionChangeHandler(cm, obj) {
// obj.update([{
// anchor: position,
// head: position,
// }]);
// cm.off("beforeSelectionChange", _onSelectionChangeHandler);
// }
// }
_disableSelection();
if (/org-level-star/.test(token.type)) {
_preventIfShould();
_foldHeadline();
_disableSelection();
} else if (/org-toggle/.test(token.type)) {
_preventIfShould();
_toggleCheckbox();
_disableSelection();
} else if (/org-todo/.test(token.type)) {
_preventIfShould();
_toggleTodo();
_disableSelection();
} else if (/org-done/.test(token.type)) {
_preventIfShould();
_toggleDone();
_disableSelection();
} else if (/org-priority/.test(token.type)) {
_preventIfShould();
_togglePriority();
_disableSelection();
} else if (/org-url/.test(token.type)) {
_disableSelection();
_navigateLink();
} else if (/org-image/.test(token.type)) {
_disableSelection();
_toggleImageWidget();
}
// function _foldHeadline() {
// const line = position.line;
// if (line >= 0) {
// const cursor = { line, ch: 0 };
// isFold(cm, cursor) ? unfold(cm, cursor) : fold(cm, cursor);
// }
// }
function _preventIfShould() {
if ("ontouchstart" in window) e.preventDefault();
}
function _disableSelection() {
cm.on("beforeSelectionChange", _onSelectionChangeHandler);
function _onSelectionChangeHandler(cm, obj) {
obj.update([{
anchor: position,
head: position,
}]);
cm.off("beforeSelectionChange", _onSelectionChangeHandler);
}
}
// function _toggleCheckbox() {
// const line = position.line;
// const content = cm.getRange(
// { line, ch: token.start },
// { line, ch: token.end },
// );
// const new_content = content === "[X]" || content === "[x]" ? "[ ]" : "[X]";
// cm.replaceRange(
// new_content,
// { line, ch: token.start },
// { line, ch: token.end },
// );
// }
function _foldHeadline() {
const line = position.line;
if (line >= 0) {
const cursor = { line: line, ch: 0 };
isFold(cm, cursor) ? unfold(cm, cursor) : fold(cm, cursor);
}
}
// function _toggleTodo() {
// const line = position.line;
// cm.replaceRange(
// "DONE",
// { line, ch: token.start },
// { line, ch: token.end },
// );
// }
function _toggleCheckbox() {
const line = position.line;
const content = cm.getRange(
{ line: line, ch: token.start },
{ line: line, ch: token.end },
);
const new_content = content === "[X]" || content === "[x]" ? "[ ]" : "[X]";
cm.replaceRange(
new_content,
{ line: line, ch: token.start },
{ line: line, ch: token.end },
);
}
// function _toggleDone() {
// const line = position.line;
// cm.replaceRange(
// "TODO",
// { line, ch: token.start },
// { line, ch: token.end },
// );
// }
function _toggleTodo() {
const line = position.line;
cm.replaceRange(
"DONE",
{ line: line, ch: token.start },
{ line: line, ch: token.end },
);
}
// function _togglePriority() {
// const PRIORITIES = [" [#A] ", " [#B] ", " [#C] ", " [#A] "];
// const line = position.line;
// const content = cm.getRange({ line, ch: token.start }, { line, ch: token.end });
// const new_content = PRIORITIES[PRIORITIES.indexOf(content) + 1];
// cm.replaceRange(
// new_content,
// { line, ch: token.start },
// { line, ch: token.end },
// );
// }
function _toggleDone() {
const line = position.line;
cm.replaceRange(
"TODO",
{ line: line, ch: token.start },
{ line: line, ch: token.end },
);
}
// function _toggleImageWidget() {
// const exist = !!widgets
// .filter((line) => line === position.line)[0];
function _togglePriority() {
const PRIORITIES = [" [#A] ", " [#B] ", " [#C] ", " [#A] "];
const line = position.line;
const content = cm.getRange({ line: line, ch: token.start }, { line: line, ch: token.end });
const new_content = PRIORITIES[PRIORITIES.indexOf(content) + 1];
cm.replaceRange(
new_content,
{ line: line, ch: token.start },
{ line: line, ch: token.end },
);
}
// if (exist === false) {
// if (!token.string.match(/\[\[(.*)\]\]/)) return null;
// const $node = _buildImage(RegExp.$1);
// const widget = cm.addLineWidget(position.line, $node, { coverGutter: false });
// widgets.push(position.line);
// $node.addEventListener("click", closeWidget);
function _toggleImageWidget() {
const exist = !!widgets
.filter((line) => line === position.line)[0];
// function closeWidget() {
// widget.clear();
// $node.removeEventListener("click", closeWidget);
// widgets = widgets.filter((line) => line !== position.line);
// }
// }
// function _buildImage(src) {
// const $el = document.createElement("div");
// const $img = document.createElement("img");
if (exist === false) {
if (!token.string.match(/\[\[(.*)\]\]/)) return null;
const $node = _buildImage(RegExp.$1);
const widget = cm.addLineWidget(position.line, $node, { coverGutter: false });
widgets.push(position.line);
$node.addEventListener("click", closeWidget);
// if (/^https?\:\/\//.test(src)) {
// $img.src = src;
// } else {
// const root_path = dirname(window.location.pathname.replace(/^\/view/, ""));
// const img_path = src;
// $img.src = "/api/files/cat?path="+encodeURIComponent(pathBuilder(root_path, img_path));
// }
// $el.appendChild($img);
// return $el;
// }
// return null;
// }
function closeWidget() {
widget.clear();
$node.removeEventListener("click", closeWidget);
widgets = widgets.filter((line) => line !== position.line);
}
}
function _buildImage(src) {
const $el = document.createElement("div");
const $img = document.createElement("img");
// function _navigateLink() {
// token.string.match(/\[\[(.*?)\]\[/);
// const link = RegExp.$1;
// if (!link) return;
if (/^https?\:\/\//.test(src)) {
$img.src = src;
} else {
const root_path = dirname(window.location.pathname.replace(/^\/view/, ""));
const img_path = src;
$img.src = "/api/files/cat?path="+encodeURIComponent(pathBuilder(root_path, img_path));
}
$el.appendChild($img);
return $el;
}
return null;
}
// let open = "_blank";
// const isMobile = screen.availWidth < screen.availHeight;
// if (!document.querySelector(".component_fab img.component_icon[alt=\"save\"]")) {
// open = "_self";
// } else if (isMobile) {
// open = "_self";
// }
function _navigateLink() {
token.string.match(/\[\[(.*?)\]\[/);
const link = RegExp.$1;
if (!link) return;
// if (/^https?\:\/\//.test(link)) {
// window.open(link, open);
// } else {
// const root_path = dirname(window.location.pathname.replace(/^\/view/, ""));
// const share = currentShare();
// const url = share ? "/view"+pathBuilder(root_path, link)+"?share="+share : "/view"+pathBuilder(root_path, link);
// window.open(url, open);
// }
// }
// }
let open = "_blank";
const isMobile = screen.availWidth < screen.availHeight;
if (!document.querySelector(".component_fab img.component_icon[alt=\"save\"]")) {
open = "_self";
} else if (isMobile) {
open = "_self";
}
if (/^https?\:\/\//.test(link)) {
window.open(link, open);
} else {
const root_path = dirname(window.location.pathname.replace(/^\/view/, ""));
const share = currentShare();
const url = share ? "/view"+pathBuilder(root_path, link)+"?share="+share : "/view"+pathBuilder(root_path, link);
window.open(url, open);
}
}
}
export default CodeMirror;
// export default CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/perl/perl.js";
CodeMirror.__mode = "perl";
export default CodeMirror;
window.CodeMirror.__mode = "perl";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/php/php.js";
CodeMirror.__mode = "php";
export default CodeMirror;
window.CodeMirror.__mode = "php";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/properties/properties.js";
CodeMirror.__mode = "properties";
export default CodeMirror;
window.CodeMirror.__mode = "properties";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/python/python.js";
CodeMirror.__mode = "python";
export default CodeMirror;
window.CodeMirror.__mode = "python";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/r/r.js";
CodeMirror.__mode = "r";
export default CodeMirror;
window.CodeMirror.__mode = "r";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/ruby/ruby.js";
CodeMirror.__mode = "ruby";
export default CodeMirror;
window.CodeMirror.__mode = "ruby";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/rust/rust.js";
CodeMirror.__mode = "rust";
export default CodeMirror;
window.CodeMirror.__mode = "rust";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/sass/sass.js";
CodeMirror.__mode = "sass";
export default CodeMirror;
window.CodeMirror.__mode = "sass";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/shell/shell.js";
CodeMirror.__mode = "shell";
export default CodeMirror;
window.CodeMirror.__mode = "shell";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/sparql/sparql.js";
CodeMirror.__mode = "sparql";
export default CodeMirror;
window.CodeMirror.__mode = "sparql";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/spreadsheet/spreadsheet.js";
CodeMirror.__mode = "spreadsheet";
export default CodeMirror;
window.CodeMirror.__mode = "spreadsheet";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/sql/sql.js";
CodeMirror.__mode = "sql";
export default CodeMirror;
window.CodeMirror.__mode = "sql";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/stex/stex.js";
CodeMirror.__mode = "stex";
export default CodeMirror;
window.CodeMirror.__mode = "stex";
export default window.CodeMirror;

View file

@ -1 +1 @@
export default CodeMirror;
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/xml/xml.js";
CodeMirror.__mode = "xml";
export default CodeMirror;
window.CodeMirror.__mode = "xml";
export default window.CodeMirror;

View file

@ -1,4 +1,4 @@
import "../../../lib/vendor/codemirror/mode/gfm/gfm.js";
import "../../../lib/vendor/codemirror/mode/yaml-frontmatter/yaml-frontmatter.js";
CodeMirror.__mode = "yaml-frontmatter";
export default CodeMirror;
window.CodeMirror.__mode = "yaml-frontmatter";
export default window.CodeMirror;

View file

@ -1,3 +1,3 @@
import "../../../lib/vendor/codemirror/mode/yaml/yaml.js";
CodeMirror.__mode = "yaml";
export default CodeMirror;
window.CodeMirror.__mode = "yaml";
export default window.CodeMirror;

View file

@ -1,5 +1,5 @@
export default function(editor) {
CodeMirror.orgmode.init(editor, (key, value) => {
window.CodeMirror.orgmode.init(editor, (key, value) => {
if (key === "shifttab") {
// org_shifttab(this.state.editor)
// this.props.onFoldChange(value);

View file

@ -3,7 +3,7 @@ import rxjs, { effect, applyMutation, onClick } from "../../lib/rx.js";
import { animate, slideXIn, opacityOut } from "../../lib/animate.js";
import { qs, qsa } from "../../lib/dom.js";
import { loadCSS } from "../../helpers/loader.js";
import { createForm, mutateForm } from "../../lib/form.js";
import { createForm } from "../../lib/form.js";
import { formTmpl } from "../../components/form.js";
import ctrlError from "../ctrl_error.js";
@ -77,10 +77,10 @@ export default function(render) {
),
).pipe(
rxjs.map((originalState) => {
const smod = (key, value) => value ? value : undefined;
const smod = (key, value) => value || undefined;
return JSON.stringify(originalState, smod) !== JSON.stringify(formState(), smod);
}),
rxjs.mergeMap(async (isSaveButtonVisible) => {
rxjs.mergeMap(async(isSaveButtonVisible) => {
if (isSaveButtonVisible && $fab.classList.contains("hidden")) {
$fab.render($ICON.SAVING);
$fab.classList.remove("hidden");
@ -96,7 +96,7 @@ export default function(render) {
// feature3: submit the form
effect(onClick($fab).pipe(
rxjs.tap(() => {
$fab.render($ICON.LOADING)
$fab.render($ICON.LOADING);
$fab.disabled = true;
}),
rxjs.mergeMap(($fab) => rxjs.of(JSON.stringify(formState())).pipe(

View file

@ -17,13 +17,13 @@ export default function(render, opts = {}) {
effect(rxjs.fromEvent(window, "message").pipe(
rxjs.filter((event) => event.origin === location.origin),
rxjs.tap((event) => { // TODO: notification
switch(event.data.type) {
switch (event.data.type) {
case "notify::info":
notify.send(t(event.data.message), "info");
// notify.send(t(event.data.message), "info");
break;
case "notify::error":
notify.send(t(event.data.message), "error");
break
// notify.send(t(event.data.message), "error");
break;
}
}),
));

View file

@ -9,7 +9,7 @@ import ctrlError from "../ctrl_error.js";
import { transition, getDownloadUrl } from "./common.js";
import componentMetadata from "./application_image_metadata.js";
import componentPager, { init as initPager} from "./component_pager.js";
import componentPager, { init as initPager } from "./component_pager.js";
import "../../components/menubar.js";
@ -36,13 +36,14 @@ export default function(render) {
rxjs.tap(($node) => {
$node.classList.remove("hidden");
animate($node, {
time: 300, easing: "cubic-bezier(.51,.92,.24,1.15)",
time: 300,
easing: "cubic-bezier(.51,.92,.24,1.15)",
keyframes: [
{ opacity: 0, transform: "scale(.97)" },
{ opacity: 1 },
{ opacity: 1, transform: "scale(1)" },
{ opacity: 1, transform: "scale(1)" },
],
})
});
}),
rxjs.catchError((err) => {
if (err.target instanceof window.HTMLElement && err.type === "error") {
@ -73,5 +74,5 @@ export function init() {
return Promise.all([
loadCSS(import.meta.url, "./application_image.css"),
initPager(), // initMetadata(),
])
]);
}

View file

@ -6,7 +6,8 @@ import { loadCSS, loadJS } from "../../helpers/loader.js";
import { join } from "../../lib/path.js";
import ctrlError from "../ctrl_error.js";
import { transition, getFilename, getDownloadUrl } from "./common.js";
import { transition, getDownloadUrl } from "./common.js";
import { buildMenubar, menubarDownload } from "./common_menubar.js";
import "../../components/menubar.js";
import "../../components/icon.js";
@ -16,6 +17,7 @@ const hasNativePDF = () => "application/pdf" in window.navigator.mimeTypes;
export default async function(render) {
const ctrl = hasNativePDF() ? ctrlPDFNative : ctrlPDFJs;
ctrl(render);
buildMenubar(menubarDownload());
}
function ctrlPDFNative(render) {
@ -40,8 +42,6 @@ function ctrlPDFNative(render) {
rxjs.tap(($embed) => transition($embed)),
rxjs.catchError(ctrlError()),
));
}
async function ctrlPDFJs(render) {
@ -58,7 +58,7 @@ async function ctrlPDFJs(render) {
const removeLoader = createLoader($container);
effect(rxjs.from(window.pdfjsLib.getDocument(getDownloadUrl()).promise).pipe(
removeLoader,
rxjs.mergeMap(async (pdf) => {
rxjs.mergeMap(async(pdf) => {
createBr();
for (let i=0; i<pdf.numPages; i++) {
const page = await pdf.getPage(i + 1);
@ -69,14 +69,14 @@ async function ctrlPDFJs(render) {
) / page.getViewport({ scale: 1 }).width,
});
const $canvas = document.createElement("canvas");
$canvas.height = viewport.height;
$canvas.width = viewport.width;
$canvas.height = viewport.height;
$canvas.width = viewport.width;
$container.appendChild($canvas);
if (window.env === "test") $canvas.getContext = () => null;
await page.render({
canvasContext: $canvas.getContext("2d"),
viewport: viewport,
});
await page.render({
canvasContext: $canvas.getContext("2d"),
viewport,
});
await new Promise((done) => window.requestAnimationFrame(done));
}
createBr();

View file

@ -13,8 +13,8 @@ import ctrlError from "../ctrl_error.js";
import { transition, getDownloadUrl } from "./common.js";
import { formatTimecode } from "./common_player.js";
import { ICON } from "./common_icon.js";
import { menubarDownload, buildMenubar } from "./common_menubar.js";
import { render as renderMenubar } from "../../components/menubar.js";
// import { menubarDownload, buildMenubar } from "./common_menubar.js";
// import { render as renderMenubar } from "../../components/menubar.js";
import "../../components/icon.js";
@ -122,7 +122,7 @@ export default function(render, { mime }) {
}
};
const setStatus = (status) => {
switch(status) {
switch (status) {
case "PLAYING":
$control.play.classList.add("hidden");
$control.pause.classList.remove("hidden");
@ -144,9 +144,9 @@ export default function(render, { mime }) {
assert.fail(status);
}
};
const setSeek = (newTime, shouldSet = false) => {
const setSeek = (newTime, shouldSet = false) => {
if (shouldSet) $video.currentTime = newTime;
const width = 100 * (newTime / $video.duration)
const width = 100 * (newTime / $video.duration);
qs($page, ".progress .progress-active").style.width = `${width}%`;
if (!isNaN($video.duration)) {
qs($page, ".timecode .current").textContent = formatTimecode($video.currentTime) + " / " + formatTimecode($video.duration);
@ -173,25 +173,28 @@ export default function(render, { mime }) {
rxjs.mergeMap(() => {
const $loader = qs($page, ".loader");
$loader.replaceChildren(createElement(`<img style="height:170px;cursor:pointer;filter:brightness(0.5) invert(1);" src="${ICON.PLAY}" />`));
animate($loader, { time: 150, keyframes: [
{ transform: "scale(0.7)" },
{ transform: "scale(1)" },
]});
animate($loader, {
time: 150,
keyframes: [
{ transform: "scale(0.7)" },
{ transform: "scale(1)" },
],
});
setSeek(0);
return rxjs.fromEvent($loader, "click").pipe(rxjs.mapTo($loader));
}),
rxjs.tap(($loader) => {
$loader.classList.add("hidden")
$loader.classList.add("hidden");
const $control = qs($page, ".videoplayer_control");
$control.classList.remove("hidden");
animate($control, { time: 300, keyframes: slideYIn(5) })
animate($control, { time: 300, keyframes: slideYIn(5) });
setStatus(STATUS_PLAYING);
}),
rxjs.share(),
);
effect(setup$);
effect(setup$.pipe(rxjs.mergeMap(() => rxjs.fromEvent($video, "error").pipe(rxjs.tap(() => {
console.error(err);
// console.error(err);
// notify.send(t("Not supported"), "error");
// setIsPlaying(false);
// setIsLoading(false);
@ -235,7 +238,7 @@ export default function(render, { mime }) {
$hint.style.left = x;
$hint.textContent = formatTimecode(time);
}),
))
));
effect(setup$.pipe(
rxjs.switchMap(() => rxjs.fromEvent(qs($page, ".progress"), "mouseleave")),
rxjs.tap(() => $hint.classList.add("hidden")),
@ -246,7 +249,7 @@ export default function(render, { mime }) {
rxjs.switchMap(() => rxjs.fromEvent(qs($page, ".progress"), "click").pipe(
rxjs.map((e) => { // TODO: use onClick instead?
let $progress = e.target;
if (e.target.classList.contains("progress") == false) {
if (e.target.classList.contains("progress") === false) {
$progress = e.target.parentElement;
}
const rec = $progress.getBoundingClientRect();
@ -266,7 +269,7 @@ export default function(render, { mime }) {
effect(setup$.pipe(
rxjs.switchMap(() => rxjs.fromEvent(document, "keydown").pipe(rxjs.map((e) => e.code))),
rxjs.tap((code) => {
switch(code) {
switch (code) {
case "Space":
case "KeyK":
setStatus($video.paused ? STATUS_PLAYING : STATUS_PAUSED);
@ -340,7 +343,7 @@ export default function(render, { mime }) {
return $video.buffered.start(i) / $video.duration * 100;
};
const $container = qs($page, `[data-bind="progress-buffer"]`);
if ($video.buffered.length !== $container.children.length ) {
if ($video.buffered.length !== $container.children.length) {
$container.innerHTML = "";
const $fragment = document.createDocumentFragment();
Array.apply(null, { length: $video.buffered.length })
@ -349,8 +352,7 @@ export default function(render, { mime }) {
`)));
$container.appendChild($fragment);
}
for (let i=0;i<$video.buffered.length;i++) {
for (let i=0; i<$video.buffered.length; i++) {
$container.children[i].style.left = calcLeft(i) + "%";
$container.children[i].style.width = calcWidth(i) + "%";
}
@ -364,7 +366,7 @@ export function init() {
loadCSS(import.meta.url, "./application_video.css"),
loadCSS(import.meta.url, "./component_pager.css"),
loadJS(import.meta.url, "/overrides/video-transcoder.js"),
]).then(async () => {
]).then(async() => {
if (typeof window.overrides["video-map-sources"] !== "function") window.overrides["video-map-sources"] = (s) => (s);
});
}

View file

@ -36,6 +36,6 @@ export function getCurrentPath() {
// return encodeURIComponent(decodeURIComponent(path.replace(/%/g, "%25")));
// }
function appendShareToUrl() {
// TODO
}
// function appendShareToUrl() {
// // TODO
// }

View file

@ -12,7 +12,7 @@ export function menubarDownload() {
`);
$fragment.querySelector(".download-button").onclick = () => {
console.log("CLICK");
}
};
return $fragment;
}

View file

@ -1,6 +1,6 @@
export function formatTimecode(seconds) {
return String(parseInt(seconds / 60)).padStart(2, "0") +
":"+
":" +
String(parseInt(seconds % 60)).padStart(2, "0");
}

View file

@ -24,7 +24,7 @@ export function opener(file = "", mimes) {
return ["form", { mime }];
} else if (type === "video" || mime === "application/ogg") {
return ["video", { mime }];
} else if(["application/epub+zip"].indexOf(mime) !== -1) {
} else if (["application/epub+zip"].indexOf(mime) !== -1) {
return ["ebook", { mime }];
} else if (type === "model" || ["application/object", "application/fbx"].indexOf(mime) !== -1) {
return ["3d", { mime }];