From 4e6b0876e9368ca2c9fb8670237104681d3c7bb1 Mon Sep 17 00:00:00 2001 From: Franklin Tse Date: Wed, 16 Jan 2019 21:32:41 +0800 Subject: [PATCH 1/6] Initial commit --- package-lock.json | 30 ++++++++++ package.json | 6 +- types/easymde-test.ts | 10 ++++ types/easymde.d.ts | 129 ++++++++++++++++++++++++++++++++++++++++++ types/tsconfig.json | 8 +++ 5 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 types/easymde-test.ts create mode 100644 types/easymde.d.ts create mode 100644 types/tsconfig.json diff --git a/package-lock.json b/package-lock.json index 7558d81..5abacbc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,30 @@ "js-tokens": "^4.0.0" } }, + "@types/codemirror": { + "version": "0.0.71", + "resolved": "https://registry.npmjs.org/@types/codemirror/-/codemirror-0.0.71.tgz", + "integrity": "sha512-b2oEEnno1LIGKMR7uBEsr40al1UijF1HEpRn0+Yf1xOLl24iQgB7DBpZVMM7y54G5wCNoclDrRO65E6KHPNO2w==", + "dev": true, + "requires": { + "@types/tern": "*" + } + }, + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, + "@types/tern": { + "version": "0.22.1", + "resolved": "https://registry.npmjs.org/@types/tern/-/tern-0.22.1.tgz", + "integrity": "sha512-CRzPRkg8hYLwunsj61r+rqPJQbiCIEQqlMMY/0k7krgIsoSaFgGg1ZH2f9qaR1YpenaMl6PnlTtUkCbNH/uo+A==", + "dev": true, + "requires": { + "@types/estree": "*" + } + }, "JSONStream": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", @@ -5198,6 +5222,12 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "typescript": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.2.tgz", + "integrity": "sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==", + "dev": true + }, "typo-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/typo-js/-/typo-js-1.0.3.tgz", diff --git a/package.json b/package.json index ae333d9..386ece5 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "fontawesome" ], "main": "./src/js/easymde.js", + "types": "types/easymde.d.ts", "license": "MIT", "author": "Jeroen Akkerman", "bugs": { @@ -21,6 +22,7 @@ "marked": "^0.5.1" }, "devDependencies": { + "@types/codemirror": "0.0.71", "browserify": "^16.2.3", "gulp": "^4.0.0", "gulp-clean-css": "^3.10.0", @@ -29,6 +31,7 @@ "gulp-header": "^2.0.5", "gulp-rename": "^1.4.0", "gulp-uglify": "^3.0.1", + "typescript": "^3.2.2", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^2.0.0" }, @@ -37,6 +40,7 @@ "url": "https://github.com/ionaru/easy-markdown-editor" }, "scripts": { - "prepare": "gulp" + "prepare": "gulp", + "test:types": "tsc --project types/tsconfig.json" } } diff --git a/types/easymde-test.ts b/types/easymde-test.ts new file mode 100644 index 0000000..1fbc55b --- /dev/null +++ b/types/easymde-test.ts @@ -0,0 +1,10 @@ +new EasyMDE({ + autoDownloadFontAwesome: false, + element: document.getElementById("mdEditor")!, + hideIcons: ["side-by-side", "fullscreen"], + shortcuts: { + drawTable: "Cmd-Alt-T", + toggleFullScreen: null + }, + spellChecker: false +}); diff --git a/types/easymde.d.ts b/types/easymde.d.ts new file mode 100644 index 0000000..423f7dd --- /dev/null +++ b/types/easymde.d.ts @@ -0,0 +1,129 @@ +/// + +declare namespace EasyMDE { + interface AutoSaveOptions { + enabled?: boolean; + delay?: number; + uniqueId: string; + } + + interface BlockStyleOptions { + bold?: string; + code?: string; + italic?: string; + } + + interface InsertTextOptions { + horizontalRule?: string[]; + image?: string[]; + link?: string[]; + table?: string[]; + } + + interface ParsingOptions { + allowAtxHeaderWithoutSpace?: boolean; + strikethrough?: boolean; + underscoresBreakWords?: boolean; + } + + interface RenderingOptions { + singleLineBreaks?: boolean; + codeSyntaxHighlighting: boolean; + } + + interface ShortcutsArray { + [action: string]: string | undefined | null; + toggleBlockquote?: string | null; + toggleBold?: string | null; + cleanBlock?: string | null; + toggleHeadingSmaller?: string | null; + toggleItalic?: string | null; + drawLink?: string | null; + toggleUnorderedList?: string | null; + togglePreview?: string | null; + toggleCodeBlock?: string | null; + drawImage?: string | null; + toggleOrderedList?: string | null; + toggleHeadingBigger?: string | null; + toggleSideBySide?: string | null; + toggleFullScreen?: string | null; + } + + interface StatusBarItem { + className: string; + defaultValue: (element: HTMLElement) => void; + onUpdate: (element: HTMLElement) => void; + } + + interface ToolbarIcon { + name: string; + action: string|((editor: EasyMDE) => void); + className: string; + title: string; + } + + interface Options { + autoDownloadFontAwesome?: boolean; + autofocus?: boolean; + autosave?: AutoSaveOptions; + blockStyles?: BlockStyleOptions; + element?: HTMLElement; + forceSync?: boolean; + hideIcons?: string[]; + indentWithTabs?: boolean; + initialValue?: string; + insertTexts?: InsertTextOptions; + lineWrapping?: boolean; + parsingConfig?: ParsingOptions; + placeholder?: string; + previewRender?: (markdownPlaintext: string, previewElement: HTMLElement) => string; + promptURLs?: boolean; + renderingConfig?: RenderingOptions; + shortcuts?: ShortcutsArray; + showIcons?: string[]; + spellChecker?: boolean; + status?: boolean|Array; + styleSelectedText?: boolean; + tabSize?: number; + toolbar?: boolean|Array; + toolbarTips?: boolean; + } +} + +declare class EasyMDE { + constructor(options?: EasyMDE.Options); + value(): string; + value(val: string): void; + codemirror: CodeMirror.Editor; + toTextArea(): void; + isPreviewActive(): boolean; + isSideBySideActive(): boolean; + isFullscreenActive(): boolean; + clearAutosavedValue(): void; + + static toggleBold: (editor: EasyMDE) => void; + static toggleItalic: (editor: EasyMDE) => void; + static toggleStrikethrough: (editor: EasyMDE) => void; + static toggleHeadingSmaller: (editor: EasyMDE) => void; + static toggleHeadingBigger: (editor: EasyMDE) => void; + static toggleHeading1: (editor: EasyMDE) => void; + static toggleHeading2: (editor: EasyMDE) => void; + static toggleHeading3: (editor: EasyMDE) => void; + static toggleCodeBlock: (editor: EasyMDE) => void; + static toggleBlockquote: (editor: EasyMDE) => void; + static toggleUnorderedList: (editor: EasyMDE) => void; + static toggleOrderedList: (editor: EasyMDE) => void; + static cleanBlock: (editor: EasyMDE) => void; + static drawLink: (editor: EasyMDE) => void; + static drawImage: (editor: EasyMDE) => void; + static drawTable: (editor: EasyMDE) => void; + static drawHorizontalRule: (editor: EasyMDE) => void; + static togglePreview: (editor: EasyMDE) => void; + static toggleSideBySide: (editor: EasyMDE) => void; + static toggleFullScreen: (editor: EasyMDE) => void; + static undo: (editor: EasyMDE) => void; + static redo: (editor: EasyMDE) => void; +} + +export as namespace EasyMDE; +export = EasyMDE; diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..8449997 --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "es3", + "strict": true, + "noImplicitReturns": true, + "noEmit": true + } +} From ce4171a3b724df18ee581f35720e6e8bf2c085cf Mon Sep 17 00:00:00 2001 From: Franklin Tse Date: Wed, 16 Jan 2019 22:07:52 +0800 Subject: [PATCH 2/6] Add license, use ReadonlyArray --- types/easymde.d.ts | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/types/easymde.d.ts b/types/easymde.d.ts index 423f7dd..efe951c 100644 --- a/types/easymde.d.ts +++ b/types/easymde.d.ts @@ -1,3 +1,24 @@ +// This file is based on https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/simplemde/index.d.ts, +// which is written by Scalesoft and licensed under the MIT license: +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + /// declare namespace EasyMDE { @@ -14,10 +35,10 @@ declare namespace EasyMDE { } interface InsertTextOptions { - horizontalRule?: string[]; - image?: string[]; - link?: string[]; - table?: string[]; + horizontalRule?: ReadonlyArray; + image?: ReadonlyArray; + link?: ReadonlyArray; + table?: ReadonlyArray; } interface ParsingOptions { @@ -31,7 +52,7 @@ declare namespace EasyMDE { codeSyntaxHighlighting: boolean; } - interface ShortcutsArray { + interface Shortcuts { [action: string]: string | undefined | null; toggleBlockquote?: string | null; toggleBold?: string | null; @@ -69,7 +90,7 @@ declare namespace EasyMDE { blockStyles?: BlockStyleOptions; element?: HTMLElement; forceSync?: boolean; - hideIcons?: string[]; + hideIcons?: ReadonlyArray; indentWithTabs?: boolean; initialValue?: string; insertTexts?: InsertTextOptions; @@ -79,13 +100,13 @@ declare namespace EasyMDE { previewRender?: (markdownPlaintext: string, previewElement: HTMLElement) => string; promptURLs?: boolean; renderingConfig?: RenderingOptions; - shortcuts?: ShortcutsArray; - showIcons?: string[]; + shortcuts?: Shortcuts; + showIcons?: ReadonlyArray; spellChecker?: boolean; - status?: boolean|Array; + status?: boolean|ReadonlyArray; styleSelectedText?: boolean; tabSize?: number; - toolbar?: boolean|Array; + toolbar?: boolean|ReadonlyArray; toolbarTips?: boolean; } } From 88a14114622c89c6bff39ff6f8491279de2852c2 Mon Sep 17 00:00:00 2001 From: Jeroen Akkerman Date: Wed, 16 Jan 2019 23:04:19 +0800 Subject: [PATCH 3/6] Update types/easymde.d.ts Co-Authored-By: FranklinWhale --- types/easymde.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/easymde.d.ts b/types/easymde.d.ts index efe951c..6eadffe 100644 --- a/types/easymde.d.ts +++ b/types/easymde.d.ts @@ -108,6 +108,8 @@ declare namespace EasyMDE { tabSize?: number; toolbar?: boolean|ReadonlyArray; toolbarTips?: boolean; + onToggleFullScreen?: (goingIntoFullScreen: boolean) => void; + theme?: string; } } From 2ad0d26127b5b42947dc409df41b5846c2287ad3 Mon Sep 17 00:00:00 2001 From: Jeroen Akkerman Date: Thu, 17 Jan 2019 09:46:57 +0100 Subject: [PATCH 4/6] Automatic Travis tests & consistency * Added `test:types` to travis run script. * Changed `main` value in package.json to match `types` value style. --- .travis.yml | 4 +++- package.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3bca039..ecb55fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,9 @@ node_js: - '6' # EOL: April 2019 before_script: - npm install -g gulp -script: gulp +script: +- gulp +- test:types deploy: - provider: npm email: info@saturnserver.org diff --git a/package.json b/package.json index 386ece5..da5ea7d 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "javascript", "fontawesome" ], - "main": "./src/js/easymde.js", + "main": "src/js/easymde.js", "types": "types/easymde.d.ts", "license": "MIT", "author": "Jeroen Akkerman", From 5a37a534dc348bdc9fe72c68271b576e8c5d6953 Mon Sep 17 00:00:00 2001 From: Jeroen Akkerman Date: Thu, 17 Jan 2019 09:50:54 +0100 Subject: [PATCH 5/6] Forgot `npm run` in the command, added. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ecb55fe..fbf5b9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_script: - npm install -g gulp script: - gulp -- test:types +- npm run test:types deploy: - provider: npm email: info@saturnserver.org From 5b01fba882d9e1d4a3dd9092fd4511bbbc892502 Mon Sep 17 00:00:00 2001 From: Jeroen Akkerman Date: Thu, 17 Jan 2019 11:12:40 +0100 Subject: [PATCH 6/6] Added more tests for the types file. --- types/easymde-test.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/types/easymde-test.ts b/types/easymde-test.ts index 1fbc55b..e448e4c 100644 --- a/types/easymde-test.ts +++ b/types/easymde-test.ts @@ -1,4 +1,5 @@ -new EasyMDE({ +// Create new instance +const editor = new EasyMDE({ autoDownloadFontAwesome: false, element: document.getElementById("mdEditor")!, hideIcons: ["side-by-side", "fullscreen"], @@ -6,5 +7,20 @@ new EasyMDE({ drawTable: "Cmd-Alt-T", toggleFullScreen: null }, - spellChecker: false + spellChecker: false, + onToggleFullScreen: (full: boolean) => { console.log('FullscreenToggled', full); }, + theme: 'someOtherTheme', }); + +// Editor functions +const value = editor.value() as string; +editor.value(value.toUpperCase()); + +const sbs = editor.isSideBySideActive() as boolean; +const fullscreen = editor.isFullscreenActive() as boolean; + +// Access to codemirror object +editor.codemirror.setOption('readOnly', true); + +// Static properties +EasyMDE.toggleItalic = (editor: EasyMDE) => { console.log('SomeButtonOverride'); };