forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding type definitions for Quill JS (http://quilljs.com)
- Loading branch information
Sumit Kumar Maitra
committed
Jan 25, 2016
1 parent
7b3d5a6
commit 38095e4
Showing
2 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/// <reference path="quill.d.ts" /> | ||
/// <reference path="../requirejs/require.d.ts"/> | ||
|
||
export var Quill = require("quill"); | ||
|
||
function test_quill() { | ||
|
||
var quillEditor = new Quill('#editor', { | ||
modules: | ||
{ | ||
"toolbar": { container: "#toolbar" } | ||
}, | ||
theme: 'snow' | ||
}); | ||
} | ||
|
||
function test_getText() { | ||
var quillEditor = new Quill('#editor'); | ||
var strValue: string = quillEditor.getText(); | ||
} | ||
|
||
function test_getText_StartingAt() { | ||
var quillEditor = new Quill('#editor'); | ||
var strValue: string = quillEditor.getText(10); | ||
} | ||
|
||
function test_getText_substring() { | ||
var quillEditor = new Quill('#editor'); | ||
var strValue: string = quillEditor.getText(0, 10); | ||
} | ||
|
||
function test_getLength() { | ||
var quillEditor = new Quill('#editor'); | ||
var num: number = quillEditor.getLength(); | ||
} | ||
|
||
function test_getContents() { | ||
var quillEditor = new Quill('#editor'); | ||
var delta: DeltaStatic = quillEditor.getContents(); | ||
} | ||
|
||
function test_insertText() { | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.insertText(0, "Hello World"); | ||
} | ||
|
||
function test_deleteText() { | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.deleteText(0, 10); | ||
} | ||
|
||
function test_formatText() { | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.formatText(0, 5, 'bold', true); | ||
} | ||
|
||
function test_formatText2() { | ||
var quillEditor = new Quill('#editor'); | ||
|
||
quillEditor.formatText(0, 5, { | ||
'bold': false, | ||
'color': 'rgb(0, 0, 255)' | ||
}); | ||
} | ||
|
||
function test_formatLine() { | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.formatLine(1, 3, 'align', 'right'); | ||
} | ||
|
||
function test_insertEmbed() { | ||
var quillEditor = new Quill('#editor'); | ||
|
||
quillEditor.insertEmbed(10, 'image', 'http://quilljs.com/images/cloud.png'); | ||
} | ||
|
||
function test_updateContents() { | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.updateContents({ | ||
ops: [ | ||
{ retain: 6 }, // Keep 'Hello ' | ||
{ delete: 5 }, // 'World' is deleted | ||
{ insert: 'Quill' }, // Insert 'Quill' | ||
{ retain: 1, attributes: { bold: true } } // Apply bold to exclamation mark | ||
] | ||
}); | ||
} | ||
|
||
function test_setContents() { | ||
var quillEditor = new Quill('#editor'); | ||
|
||
quillEditor.setContents([ | ||
{ insert: 'Hello ' }, | ||
{ insert: 'World!', attributes: { bold: true } }, | ||
{ insert: '\n' } | ||
]); | ||
} | ||
|
||
function test_setHTML() { | ||
var quillEditor = new Quill('#editor'); | ||
|
||
quillEditor.setHTML('<div>Hello</div>'); | ||
} | ||
|
||
function test_setText() { | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.setText('Hello\n'); | ||
} | ||
|
||
|
||
function test_getSelection() { | ||
var quillEditor = new Quill('#editor'); | ||
|
||
var range = quillEditor.getSelection(); | ||
if (range) { | ||
if (range.start == range.end) { | ||
console.log('User cursor is at index', range.start); | ||
} else { | ||
var text = quillEditor.getText(range.start, range.end); | ||
console.log('User has highlighted: ', text); | ||
} | ||
} else { | ||
console.log('User cursor is not in editor'); | ||
} | ||
} | ||
|
||
function test_setSelection() { | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.setSelection(0, 5); | ||
} | ||
|
||
function test_prepareFormat() { | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.prepareFormat('bold', true); | ||
} | ||
|
||
function test_focus() { | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.focus(); | ||
} | ||
|
||
function test_getBounds() { | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.setText('Hello\nWorld\n'); | ||
} | ||
|
||
function test_addModule() { | ||
var quillEditor = new Quill('#editor'); | ||
|
||
var toolbar = quillEditor.addModule('toolbar', { | ||
container: '#toolbar-container' | ||
}); | ||
} | ||
|
||
function test_getModule() | ||
{ | ||
var quillEditor = new Quill('#editor'); | ||
|
||
var toolbar = quillEditor.getModule('toolbar'); | ||
} | ||
|
||
|
||
function test_addFormat() | ||
{ | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.addFormat('strike', { tag: 'S', prepare: 'strikeThrough' }); | ||
} | ||
|
||
function test_addContainer() | ||
{ | ||
var quillEditor = new Quill('#editor'); | ||
quillEditor.addContainer('ql-custom'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Type definitions for Quill | ||
// Project: http://quilljs.com | ||
// Definitions by: Sumit <https://github.com/sumitkm> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
///<reference path="../eventemitter2/eventemitter2.d.ts" /> | ||
|
||
declare interface DeltaStatic{ | ||
ops : Array<any>; | ||
} | ||
|
||
declare interface QuillStatic { | ||
on(eventName: string, callback: (delta: DeltaStatic, source: string) => void): EventEmitter2; | ||
addModule(id: string, options: any) : Object; | ||
|
||
getText(): string; | ||
getText(start: number): string; | ||
getText(start: number, end: number): string; | ||
|
||
getLength(): number; | ||
|
||
getContents(): DeltaStatic; | ||
getContents(start: number): DeltaStatic; | ||
getContents(start: number, end: number): DeltaStatic; | ||
|
||
getHTML(): string; | ||
|
||
insertText(index: number, text: string): void; | ||
insertText(index: number, text: string, name: string, value: string): void; | ||
insertText(index: number, text: string, formats: any): void; | ||
insertText(index: number, text: string, source: string) : void; | ||
insertText(index: number, text: string, name: string, value: string, source: string): void; | ||
insertText(index: number, text: string, formats: any, source: string): void; | ||
|
||
deleteText(start: number, end: number): void; | ||
deleteText(start: number, end: number, source: string): void; | ||
|
||
formatText(start: number, end: number): void; | ||
formatText(start: number, end: number, name: string, value: string): void; | ||
formatText(start: number, end: number, formats: any): void; | ||
formatText(start: number, end: number, source: string): void; | ||
formatText(start: number, end: number, name: string, value: string, source: string): void; | ||
formatText(start: number, end: number, formats: string, source: string): void; | ||
|
||
|
||
formatLine(start: number, end: number): void; | ||
formatLine(start: number, end: number, name: string, value: string): void; | ||
formatLine(start: number, end: number, formats: any): void; | ||
formatLine(start: number, end: number, source: string): void; | ||
formatLine(start: number, end: number, name: string, value: string, source: string): void; | ||
formatLine(start: number, end: number, formats: any, source: string): void; | ||
|
||
|
||
insertEmbed(index: number, type: string, url: string): void; | ||
insertEmbed(index: number, type: string, url: string, source: string): void; | ||
|
||
updateContents(delta: DeltaStatic): void; | ||
|
||
setContents(delta: DeltaStatic): void; | ||
|
||
setHTML(html: string): void; | ||
|
||
setText(text: string): void; | ||
|
||
getSelection(): string; | ||
|
||
setSelection(start: number, end: number): void; | ||
setSelection(start: number, end: number, source: string): void; | ||
setSelection(range: any): void; | ||
setSelection(range: any, source: string): void; | ||
|
||
prepareFormat(format: string, value: string): void; | ||
|
||
focus(): void; | ||
|
||
getBounds(index: number): any; | ||
|
||
registerModule(name: string, callback: (quill: QuillStatic, options: any) => {}): any; | ||
|
||
addModule(name: string, options: any): any; | ||
|
||
getModule(name: string): any; | ||
|
||
onModuleLoad(name: string, callback: (input: any) => {}): void; | ||
|
||
addFormat(name: string, config: any): void; | ||
|
||
addContainer(cssClass: string, before: number): HTMLDivElement; | ||
} | ||
|
||
declare var Quill: QuillStatic; | ||
|
||
declare var Delta: DeltaStatic; | ||
|
||
declare module "Delta"{ | ||
export = Delta; | ||
} | ||
declare module "Quill" { | ||
export = Quill; | ||
} |