-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trix.ts
169 lines (156 loc) · 5.07 KB
/
Trix.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//
// WIP type definitions for the Trix editor.
// Use at your own risk––there are any's all over the place because
// the only areas that have been properly typed are the areas that
// touch the supporting project.
//
/** */
declare class HTMLTrixElement extends HTMLElement
{
readonly editor: TrixEditor;
readonly composition: any;
readonly filters: any;
readonly selectionManager: any;
readonly undoManager: any;
insertFiles(...args: File[]): void;
}
/** */
declare class TrixEditor
{
getDocument(): TrixDocument;
getSelectedRange(): TrixRange;
setSelectedRange(range: number | [number] | TrixRange): void;
moveCursorInDirection(direction: TrixDirection): void;
expandSelectionInDirection(direction: TrixDirection): void;
deleteInDirection(direction: TrixDirection): void;
getClientRectAtPosition(characterPosition: number): DOMRect;
insertString(value: string): void;
insertHTML(html: string): void;
insertFile(file: File): void;
insertFiles(...files: File[]): void;
insertAttachment(attachment: any): void;
insertLineBreak(): void;
activateAttribute(attr: TrixAttribute, param?: string): void;
deactivateAttribute(attr: TrixAttribute): void;
increaseNestingLevel(): void;
decreaseNestingLevel(): void;
undo(): void;
redo(): void;
recordUndoEntry(description: string): void;
loadDocument(...args: any[]): void;
loadHTML(html: string): void;
loadJSON(json: ITrixSerializedObject): void;
loadSnapshot(...args: any[]): void;
canUndo(): boolean;
canRedo(): boolean;
canActivateAttribute(attr: TrixAttribute): boolean;
canIncreaseIndentLevel(): boolean;
canDecreaseIndentLevel(): boolean;
attributeIsActive(attr: TrixAttribute): boolean;
toJSON(): ITrixSerializedObject;
}
type TrixDirection = "backward" | "forward";
type TrixAttribute = "bold" | "italic" | "href" | "strike" | "heading1" | "quote" | "code" | "bullet" | "number";
type TrixRange = [number, number];
/** */
declare class TrixDocument
{
toString(): string;
isEqualTo(other: TrixDocument): boolean;
addAttribute(t: any, e: any): any;
addAttributeAtRange(t: any, e: any, i: any): any;
applyBlockAttributeAtRange(t: any, e: any, i: any): any;
consolidateBlocksAtRange(t: any): any;
convertLineBreaksToBlockBreaksInRange(t: any): any;
copy(t: any): any;
copyUsingObjectMap(t: any): any;
copyUsingObjectsFromDocument(t: any): any;
copyWithBaseBlockAttributes(t: any): any;
eachBlock(t: any): any;
eachBlockAtRange(t: any, e: any): any;
expandRangeToLineBreaksAndSplitBlocks(t: any): any;
findRangesForBlockAttribute(t: any): any;
findRangesForTextAttribute(t: any, e: any): any;
getAttachmentById(t: any): any;
getAttachmentPieceForAttachment(t: any): any;
getAttachmentPieces(): any;
getAttachments(): any;
getBaseBlockAttributes(): any;
getBlockAtIndex(t: any): any;
getBlockAtPosition(t: any): any;
getBlockCount(): number;
getBlocks(): any;
getCharacterAtPosition(t: any): any;
getCommonAttributesAtPosition(t: any): any;
getCommonAttributesAtRange(t: any): any;
getDocumentAtRange(t: any): any;
getEditCount(): number;
getLength(): number;
getLocationRangeOfAttachment(t: any): any;
getObjects(): any;
getPieceAtPosition(t: any): any;
getPieces(): any;
getRangeOfAttachment(t: any): any;
getRangeOfCommonAttributeAtPosition(attributeName: TrixAttribute, position: number): TrixRange;
getStringAtRange(range: TrixRange): string;
getTextAtIndex(index: number): any;
getTextAtPosition(position: number): any;
getTexts(): any;
insertBlockBreakAtRange(t: any): any;
insertDocumentAtRange(t: any, e: any): any;
insertTextAtRange(t: any, e: any): any;
isEmpty(): boolean;
isEqualTo(otherDocument: TrixDocument): boolean;
locationFromPosition(position: number): any;
locationRangeFromPosition(position: number): TrixRange;
locationRangeFromRange(t: any): any;
mergeDocumentAtRange(e: any, n: any): any;
moveTextFromRangeToPosition(t: any, e: any): any;
positionFromLocation(t: any): any;
rangeFromLocationRange(t: any): any;
removeAttributeAtRange(t: any, e: any): any;
removeAttributeForAttachment(t: any, e: any): any;
removeBlockAttributesAtRange(t: any): any;
removeLastListAttributeAtRange(t: any, e: any): any;
removeLastTerminalAttributeAtRange(t: any): any;
removeTextAtRange(t: any): any;
replaceBlock(t: any, e: any): any;
toConsole(): any;
toJSON(): ITrixSerializedBlock[];
toSerializableDocument(): ITrixSerializedBlock[];
toString(): string;
updateAttributesForAttachment(t: any, e: any): any;
}
/**
* Defines the shape of the JSON data object that is generated
* as a result of calling the .toJSON method of the TrixEditor.
*/
interface ITrixSerializedObject
{
document: ITrixSerializedBlock[];
selectedRange: TrixRange;
}
/** */
interface ITrixSerializedBlock
{
text: ITrixSerializedNode[];
attributes: TrixAttribute[];
}
/** */
interface ITrixSerializedNode
{
type: "string" | "attachment";
attributes: Partial<SerializedAttributes>;
attachment?: {
contentType: string;
filename: string;
filesize: number;
width: number;
height: number;
};
string: string;
}
/** */
type SerializedAttributes = {
[K in TrixAttribute | "blockBreak"]: K extends "href" ? string : boolean;
}