Skip to content

Commit

Permalink
bumb dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Jan 24, 2019
1 parent 74bedef commit 913bae0
Show file tree
Hide file tree
Showing 21 changed files with 5,704 additions and 3,555 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"presets": [
[
"es2015",
"env",
{
"modules": false
}
]
]
}
}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sources=$(wildcard js/*.ts) $(wildcard js/*/*.ts) tsconfig.json .babelrc webpack

.PHONY: watch
watch: node_modules
node_modules/.bin/webpack --watch
node_modules/.bin/webpack --watch --mode development

clean:
rm -rf $(build_dir) node_modules
Expand All @@ -19,7 +19,7 @@ node_modules: package.json
npm install

build/editor.js: $(sources) node_modules
NODE_ENV=production node_modules/.bin/webpack
node_modules/.bin/webpack --mode production

appstore: build/editor.js
mkdir -p $(sign_dir)
Expand Down
10 changes: 10 additions & 0 deletions js/CheckboxPlugin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import MarkdownIt from "markdown-it";
export interface CheckboxPluginOptions {
divWrap: boolean;
divClass: string;
idPrefix: string;
readonly: boolean;
checkboxClass: string;
}
export declare function CheckBoxReplacer(md: MarkdownIt, userOptions: Partial<CheckboxPluginOptions>): MarkdownIt.Rule;
export declare function CheckboxPlugin(md: MarkdownIt, options: CheckboxPluginOptions): void;
200 changes: 100 additions & 100 deletions js/CheckboxPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,121 +1,121 @@
// based on https://github.com/mcecot/markdown-it-checkbox

import * as MarkdownIt from "markdown-it";
import {Token} from "markdown-it";
import MarkdownIt from "markdown-it";
import Token from 'markdown-it/lib/token';
import StateCore from "markdown-it/lib/rules_core/state_core";

export interface CheckboxPluginOptions {
divWrap: boolean;
divClass: string;
idPrefix: string;
readonly: boolean;
checkboxClass: string;
divWrap: boolean;
divClass: string;
idPrefix: string;
readonly: boolean;
checkboxClass: string;
}

interface TokenConstructor {
new (name: string, tagName: string, someNumber: number): Token;
new(name: string, tagName: string, someNumber: number): Token;
}

interface CheckboxReplacerState {
tokens: Token[];
Token: TokenConstructor;
interface CheckboxReplacerState extends StateCore {
Token: TokenConstructor;
}

export function CheckBoxReplacer(md: MarkdownIt.MarkdownIt, userOptions: Partial<CheckboxPluginOptions>): MarkdownIt.Rule {
let lastId = 0;
const defaults: CheckboxPluginOptions = {
divWrap: false,
divClass: 'checkbox',
idPrefix: 'checkbox',
readonly: true,
checkboxClass: ''
};
const options = $.extend(defaults, userOptions);
const pattern = /\[(X|\s|\_|\-)\]\s(.*)/i;
const createTokens = function (checked: boolean, label: string, Token: TokenConstructor, line: number): Token[] {
const nodes: Token[] = [];
let token: Token;
export function CheckBoxReplacer(md: MarkdownIt, userOptions: Partial<CheckboxPluginOptions>): MarkdownIt.Rule {
let lastId = 0;
const defaults: CheckboxPluginOptions = {
divWrap: false,
divClass: 'checkbox',
idPrefix: 'checkbox',
readonly: true,
checkboxClass: ''
};
const options = $.extend(defaults, userOptions);
const pattern = /\[(X|\s|\_|\-)\]\s(.*)/i;
const createTokens = function (checked: boolean, label: string, Token: TokenConstructor, line: number): Token[] {
const nodes: Token[] = [];
let token: Token;

/**
* <div class="checkbox">
*/
if (options.divWrap) {
token = new Token("checkbox_open", "div", 1);
token.attrs = [["class", options.divClass]];
nodes.push(token);
}
/**
* <div class="checkbox">
*/
if (options.divWrap) {
token = new Token("checkbox_open", "div", 1);
token.attrs = [["class", options.divClass]];
nodes.push(token);
}

/**
* <input type="checkbox" id="checkbox{n}" checked="true data-line="{n}">
*/
const id = options.idPrefix + lastId;
lastId += 1;
token = new Token("checkbox_input", "input", 0);
token.attrs = [["type", "checkbox"], ["id", id]];
if (checked === true) {
token.attrs.push(["checked", "true"]);
}
if (options.readonly) {
token.attrs.push(["disabled", "disabled"]);
}
if (options.checkboxClass) {
token.attrs.push(["class", options.checkboxClass]);
}
token.attrs.push(["data-line", String(line)]);
nodes.push(token);
/**
* <input type="checkbox" id="checkbox{n}" checked="true data-line="{n}">
*/
const id = options.idPrefix + lastId;
lastId += 1;
token = new Token("checkbox_input", "input", 0);
token.attrs = [["type", "checkbox"], ["id", id]];
if (checked === true) {
token.attrs.push(["checked", "true"]);
}
if (options.readonly) {
token.attrs.push(["disabled", "disabled"]);
}
if (options.checkboxClass) {
token.attrs.push(["class", options.checkboxClass]);
}
token.attrs.push(["data-line", String(line)]);
nodes.push(token);

/**
* <label for="checkbox{n}">
*/
token = new Token("label_open", "label", 1);
token.attrs = [["for", id]];
nodes.push(token);
/**
* <label for="checkbox{n}">
*/
token = new Token("label_open", "label", 1);
token.attrs = [["for", id]];
nodes.push(token);

/**
* content of label tag
*/
token = new Token("text", "", 0);
token.content = label;
nodes.push(token);
/**
* content of label tag
*/
token = new Token("text", "", 0);
token.content = label;
nodes.push(token);

/**
* closing tags
*/
nodes.push(new Token("label_close", "label", -1));
if (options.divWrap) {
nodes.push(new Token("checkbox_close", "div", -1));
}
return nodes;
};
/**
* closing tags
*/
nodes.push(new Token("label_close", "label", -1));
if (options.divWrap) {
nodes.push(new Token("checkbox_close", "div", -1));
}
return nodes;
};

const splitTextToken = function (original: Token, Token: TokenConstructor, line: number): Token[] {
const text = original.content;
const matches = text.match(pattern);
if (matches === null) {
return [original];
}
const value = matches[1];
const label = matches[2];
const checked = (value === "X" || value === "x");
return createTokens(checked, label, Token, line);
};
const splitTextToken = function (original: Token, Token: TokenConstructor, line: number): Token[] {
const text = original.content;
const matches = text.match(pattern);
if (matches === null) {
return [original];
}
const value = matches[1];
const label = matches[2];
const checked = (value === "X" || value === "x");
return createTokens(checked, label, Token, line);
};

return function (state: CheckboxReplacerState) {
for (const token of state.tokens) {
if (token.type === "inline") {
let currentLine = token.map ? token.map[0] : 0;
let newChildren: Token[] = [];
for (const childToken of token.children) {
if (childToken.type === 'hardbreak' || childToken.type === 'softbreak') {
currentLine++;
}
newChildren = newChildren.concat(splitTextToken(childToken, state.Token, currentLine))
}
token.children = newChildren;
}
}
};
return function (state: CheckboxReplacerState) {
for (const token of state.tokens) {
if (token.type === "inline") {
let currentLine = token.map ? token.map[0] : 0;
let newChildren: Token[] = [];
for (const childToken of token.children) {
if (childToken.type === 'hardbreak' || childToken.type === 'softbreak') {
currentLine++;
}
newChildren = newChildren.concat(splitTextToken(childToken, state.Token, currentLine))
}
token.children = newChildren;
}
}
};
}

export function CheckboxPlugin(md: MarkdownIt.MarkdownIt, options: CheckboxPluginOptions) {
md.core.ruler.push("checkbox", CheckBoxReplacer(md, options));
export function CheckboxPlugin(md: MarkdownIt, options: CheckboxPluginOptions) {
md.core.ruler.push("checkbox", CheckBoxReplacer(md, options));
}
2 changes: 2 additions & 0 deletions js/MermaidPlugin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import MarkdownIt from "markdown-it";
export declare const MermaidPlugin: (md: MarkdownIt) => void;
10 changes: 6 additions & 4 deletions js/MermaidPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// based on https://github.com/tylingsoft/markdown-it-mermaid

import MarkdownIt = require("markdown-it");
import * as mermaid from 'mermaid';
import MarkdownIt from "markdown-it";
import Token from 'markdown-it/lib/token';
import mermaid from 'mermaid';

// workaround missing import in dependency
// see: https://github.com/tylingsoft/dagre-d3-renderer/pull/1
Expand All @@ -11,6 +12,7 @@ window['d3'] = d3;
mermaid.mermaidAPI.initialize({
startOnLoad: true,
logLevel: 3,
theme: 'forest'
});

let chartCounter = 0;
Expand All @@ -36,9 +38,9 @@ const mermaidChart = (code: string): string => {
}
};

export const MermaidPlugin = (md: MarkdownIt.MarkdownIt) => {
export const MermaidPlugin = (md: MarkdownIt) => {
const originalRenderer = md.renderer.rules.fence.bind(md.renderer.rules);
md.renderer.rules.fence = (tokens: MarkdownIt.Token[], idx: number, options, env, slf) => {
md.renderer.rules.fence = (tokens: Token[], idx: number, options, env, slf) => {
const token = tokens[idx];
const code = token.content.trim();
if (token.info === 'mermaid') {
Expand Down
8 changes: 7 additions & 1 deletion js/Nextcloud.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ declare namespace OC {

function confirmHtml(text: string, title: string, callback: (result: boolean) => void, modal?: boolean): void;

function prompt(text: string, title: string, callback: (result: string) => void, modal?: boolean, name?: string, password?: boolean): void;
function prompt(text: string, title: string, callback: (ok: boolean, result: string) => void, modal?: boolean, name?: string, password?: boolean): void;

function filepicket(title: string, callback: (result: string | string[]) => void, multiselect?: boolean, mimetypeFilter?: string, modal?: boolean): void;
}
Expand All @@ -90,8 +90,14 @@ declare namespace OC {

function linkToOCS(service: string, version: number): string;

function linkToRemote(path: string): string;

function linkToRemoteBase(path: string): string;

function imagePath(app: string, file: string): string;

function filePath(app: string, type: string, file: string): string;

const PERMISSION_CREATE = 4;
const PERMISSION_READ = 1;
const PERMISSION_UPDATE = 2;
Expand Down
11 changes: 11 additions & 0 deletions js/PasteImage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export declare type PasteListener = (image: HTMLImageElement, file: File) => void;
export declare class PasteImage {
private initialized;
private listeners;
private listenForPaste;
private init;
private pasteHandler;
private getURLObj;
private createImage;
listen(handler: PasteListener): void;
}
26 changes: 26 additions & 0 deletions js/PreviewPlugin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <reference types="underscore" />
import Thenable = JQuery.Thenable;
import TextEditorPreviewPlugin = OCA.Files_Texteditor.TextEditorPreviewPlugin;
export declare class PreviewPlugin implements TextEditorPreviewPlugin {
private renderer;
private rangeConstructor;
private initPromise;
private textEditorOnHashChange;
private offsetMap;
private session;
private previewElement;
private scrollMode;
init(): Promise<void>;
initAceHooks(): void;
initPreviewHooks(element: any): void;
onHashChange(e: PopStateEvent): void;
preview: ((text: string, element: any) => void) & import("underscore").Cancelable;
initCheckboxHandler(element: any): void;
buildOffsetMap: ((element: any) => void) & import("underscore").Cancelable;
onScrollEditor: ((top: number) => void) & import("underscore").Cancelable;
onScrollPreview: (() => void) & import("underscore").Cancelable;
resetScrollMode: (() => void) & import("underscore").Cancelable;
handleImage: (image: HTMLImageElement, file: any) => void;
uploadImage(name: string, file: File): Thenable<void>;
getCurrentPath(): string | undefined;
}
18 changes: 10 additions & 8 deletions js/PreviewPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,16 @@ export class PreviewPlugin implements TextEditorPreviewPlugin {
const reader = new FileReader();
const deferred = $.Deferred();
reader.onloadend = (e) => {
$.ajax({
url: url,
processData: false,
data: reader.result,
type: 'PUT',
success: deferred.resolve.bind(deferred),
error: deferred.reject.bind(deferred)
});
if (reader.result) {
$.ajax({
url: url,
processData: false,
data: reader.result.toString(),
type: 'PUT',
success: deferred.resolve.bind(deferred),
error: deferred.reject.bind(deferred)
});
}
};
reader.readAsArrayBuffer(file);
return deferred.promise();
Expand Down
7 changes: 7 additions & 0 deletions js/PublicPreview.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export declare class PublicPreview {
private renderer;
private initPromise;
init(): JQueryPromise<void>;
attach(previewElement: JQuery, shareToken: string): void;
getFileContent(shareToken: string): JQuery.jqXHR<any>;
}
Loading

0 comments on commit 913bae0

Please sign in to comment.