Skip to content

Commit

Permalink
bumb dependencies and cleanup chunk loading
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Apr 2, 2019
1 parent 913bae0 commit dc26463
Show file tree
Hide file tree
Showing 18 changed files with 795 additions and 1,202 deletions.
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description><![CDATA[Markdown Editor extends the Nextcloud text editor with a live preview for markdown files.
A full list of features can be found [in the README](https://github.com/icewind1991/files_markdown)]]></description>
<version>2.0.5</version>
<version>2.0.6</version>
<licence>agpl</licence>
<author>Robin Appelman</author>

Expand Down Expand Up @@ -42,6 +42,6 @@ A full list of features can be found [in the README](https://github.com/icewind1
</screenshot>

<dependencies>
<nextcloud min-version="11" max-version="16"/>
<nextcloud min-version="14" max-version="16"/>
</dependencies>
</info>
10 changes: 0 additions & 10 deletions js/CheckboxPlugin.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions js/MermaidPlugin.d.ts

This file was deleted.

11 changes: 0 additions & 11 deletions js/PasteImage.d.ts

This file was deleted.

26 changes: 0 additions & 26 deletions js/PreviewPlugin.d.ts

This file was deleted.

24 changes: 11 additions & 13 deletions js/PreviewPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {Renderer} from './Renderer';
import {UnderscoreStatic} from "underscore";
import {throttle, debounce} from 'throttle-debounce';
import {PasteImage} from './PasteImage';
import Thenable = JQuery.Thenable;
import TextEditorPreviewPlugin = OCA.Files_Texteditor.TextEditorPreviewPlugin;

declare const _: UnderscoreStatic;

declare const aceEditor: AceAjax.Editor;

type onPopstate = (this: Window, ev: PopStateEvent) => any;
Expand Down Expand Up @@ -64,7 +62,7 @@ export class PreviewPlugin implements TextEditorPreviewPlugin {
}
}

preview = _.throttle((text: string, element) => {
preview = throttle(500, (text: string, element) => {
this.initAceHooks();
this.initPreviewHooks(element);
window.onpopstate = this.onHashChange;
Expand All @@ -76,7 +74,7 @@ export class PreviewPlugin implements TextEditorPreviewPlugin {
}, 500);
});
});
}, 500);
});

initCheckboxHandler(element) {
const Range = this.rangeConstructor;
Expand All @@ -91,16 +89,16 @@ export class PreviewPlugin implements TextEditorPreviewPlugin {
});
}

buildOffsetMap = _.throttle((element) => {
buildOffsetMap = throttle(1000, (element) => {
const previewOffset = (element.offset() as { top: number }).top;
const offsetMap: number[] = [];
element.find('[data-line]').each(function () {
offsetMap[parseInt(this.dataset.line, 10)] = ($(this).offset() as { top: number }).top - previewOffset;
});
this.offsetMap = offsetMap;
}, 1000);
});

onScrollEditor = _.throttle((top: number) => {
onScrollEditor = throttle(100, (top: number) => {
if (this.scrollMode === 'preview') {
return;
}
Expand All @@ -111,9 +109,9 @@ export class PreviewPlugin implements TextEditorPreviewPlugin {
$('#preview').scrollTop(previewOffset);
}
this.resetScrollMode();
}, 100);
});

onScrollPreview = _.throttle(() => {
onScrollPreview = throttle(100, () => {
if (this.scrollMode === 'editor') {
return;
}
Expand All @@ -125,11 +123,11 @@ export class PreviewPlugin implements TextEditorPreviewPlugin {
});
}
this.resetScrollMode();
}, 100);
});

resetScrollMode = _.debounce(() => {
resetScrollMode = debounce(500, () => {
this.scrollMode = null;
}, 500);
});

handleImage = (image: HTMLImageElement, file) => {
OC.dialogs.prompt('Enter the name for the image', 'Upload image', (ok, name) => {
Expand Down
7 changes: 0 additions & 7 deletions js/PublicPreview.d.ts

This file was deleted.

8 changes: 2 additions & 6 deletions js/PublicPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import {Renderer} from "./Renderer";
export class PublicPreview {
private renderer: Renderer;

private initPromise: JQueryPromise<void> | null = null;
private initPromise: Promise<void> | null = null;

init() {
if (!this.initPromise) {
const deferred = $.Deferred();
require.ensure(['./Renderer'], () => {
const {Renderer} = require('./Renderer');
this.initPromise = import('./Renderer').then(({Renderer}) => {
this.renderer = new Renderer(true);
deferred.resolve();
});
this.initPromise = deferred.promise();
}
return this.initPromise;
}
Expand Down
21 changes: 0 additions & 21 deletions js/Renderer.d.ts

This file was deleted.

38 changes: 13 additions & 25 deletions js/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import morphdom from 'morphdom';

import 'katex/dist/katex.min.css';
import 'highlight.js/styles/github.css';
import Thenable = JQuery.Thenable;

const slugifyHeading = name => 'editor/' + slugify(name).toLowerCase();

Expand All @@ -26,34 +25,21 @@ export interface PluginMap {
}

function loadKaTeX() {
const deferred = $.Deferred();
require.ensure([
'katex',
'markdown-it-texmath'
], () => {
deferred.resolve(require('markdown-it-texmath').use(require('katex')));
return Promise.all([
import('katex'),
import('markdown-it-texmath'),
]).then(([katex, {default: texmath}]) => {
texmath.use(katex);
return texmath;
});
return deferred.promise();
}

function loadMermaid() {
const deferred = $.Deferred();
require.ensure([
'./MermaidPlugin'
], () => {
deferred.resolve(require('./MermaidPlugin').MermaidPlugin);
});
return deferred.promise();
return import('./MermaidPlugin').then(module => module.MermaidPlugin);
}

function loadHighlight() {
const deferred = $.Deferred();
require.ensure([
'markdown-it-highlightjs'
], () => {
deferred.resolve(require('markdown-it-highlightjs'));
});
return deferred.promise();
return import('markdown-it-highlightjs').then(module => module.default);
}

export class Renderer {
Expand Down Expand Up @@ -142,7 +128,7 @@ export class Renderer {
}
}

renderText(text: string, element): Thenable<void> {
renderText(text: string, element): Promise<void> {
return this.loadPlugins(text).then(() => {
const html = this.md.render(text);
morphdom(element[0], `<div>${html}</div>`, {
Expand All @@ -153,12 +139,14 @@ export class Renderer {
}

loadPlugins(text: string) {
return $.when.apply($, Object.keys(this.plugins)
return Promise.all(Object.keys(this.plugins)
.map(pluginName => {
const plugin = this.plugins[pluginName];
if (!plugin.loaded && plugin.checker(text)) {
plugin.loaded = true;
return plugin.module().then(this.md.use.bind(this.md));
return plugin.module().then(plugin => {
this.md.use(plugin);
});
}
})
);
Expand Down
8 changes: 0 additions & 8 deletions js/SidebarPreview.d.ts

This file was deleted.

12 changes: 4 additions & 8 deletions js/SidebarPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import {Renderer} from "./Renderer";
export class SidebarPreview implements SidebarPreviewPlugin {
private renderer: Renderer;

private initPromise: JQueryPromise<void> | null = null;
private initPromise: Promise<void> | null = null;

init() {
if (!this.initPromise) {
const deferred = $.Deferred();
require.ensure(['./Renderer'], () => {
const {Renderer} = require('./Renderer');
this.renderer = new Renderer();
deferred.resolve();
this.initPromise = import('./Renderer').then(({Renderer}) => {
this.renderer = new Renderer(true);
});
this.initPromise = deferred.promise();
}
return this.initPromise;
}
Expand Down Expand Up @@ -47,4 +43,4 @@ export class SidebarPreview implements SidebarPreviewPlugin {
const url = OC.linkToRemoteBase('files' + path);
return $.get(url);
}
}
}
14 changes: 0 additions & 14 deletions js/VideoPlugin.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion js/editor.d.ts

This file was deleted.

Loading

0 comments on commit dc26463

Please sign in to comment.