1+ import { Key } from "readline" ;
2+
13// Type definitions for medium-editor 5.0.0
2- // Project: medium-editor
4+ // Project: https://yabwe.github.io/ medium-editor
35// Definitions by: Ashinze Ekene <https://github.com/ashinzekene>
46
57export as namespace MediumEditor ;
@@ -8,7 +10,21 @@ export = MediumEditor;
810
911declare class MediumEditor {
1012 constructor ( element : string | HTMLElement | string [ ] | NodeList | HTMLCollection , options : MediumEditor . MediumOptions ) ;
13+
14+ /**
15+ * Given an editor element, retrieves the instance of `MediumEditor` which created/is monitoring the element
16+ */
17+ static getEditorFromElement : ( element : HTMLElement ) => MediumEditor
18+
19+ /**
20+ * Object containing data about the version of the current MediumEditor library
21+ */
22+ static version : MediumEditor . VersionObject
1123
24+ static Extension : {
25+ extend : ( any ) // TODO:Extension type
26+ }
27+
1228 /**
1329 * Tear down the editor if already setup
1430 * - Calling the destroy() method on each extension within the editor.
@@ -41,7 +57,7 @@ declare class MediumEditor {
4157 * So, every element you pass to `addElements` will turn into a fully supported contenteditable too
4258 * even earlier calls to `editor.subscribe(..)` for custom events will work on the newly added element(s)
4359 */
44- addElements : ( element : string | HTMLElement | string [ ] | NodeList | HTMLCollection ) => void
60+ addElements : ( element : string | HTMLElement | string [ ] | NodeList | HTMLCollection ) => boolean
4561
4662 /**
4763 * Remove one or more elements from an already initialized instance of MediumEditor
@@ -78,7 +94,7 @@ declare class MediumEditor {
7894 * useCapture argument for addEventListener(type, listener, useCapture)
7995 */
8096 useCapture : boolean | AddEventListenerOptions ,
81- ) => void
97+ ) => MediumEditor
8298
8399 /**
84100 * Detach an event listener from a specific element or elements via the browser's built-in
@@ -101,7 +117,7 @@ declare class MediumEditor {
101117 * useCapture argument for addEventListener(type, listener, useCapture)
102118 */
103119 useCapture : boolean | AddEventListenerOptions ,
104- ) => void
120+ ) => MediumEditor
105121
106122 /**
107123 * Attaches a listener for the specified custom event name
@@ -116,7 +132,7 @@ declare class MediumEditor {
116132 * Listener method that will be called whenever the custom event is triggered
117133 */
118134 listener : MediumEditor . CutstomEventListener
119- ) => void
135+ ) => MediumEditor
120136
121137 unsubscribe : (
122138 /**
@@ -129,7 +145,7 @@ declare class MediumEditor {
129145 * **NOTE:** Calling `destroy()` on the MediumEditor object will automatically remove all custom event listeners
130146 */
131147 listener : MediumEditor . CutstomEventListener
132- ) => void
148+ ) => MediumEditor
133149
134150 /**
135151 * Manually triggers a custom event
@@ -148,10 +164,227 @@ declare class MediumEditor {
148164 * The `<div contenteditable=true></div>` element to pass to all of the listeners to this custom event
149165 */
150166 editable : HTMLElement
167+ ) => MediumEditor
168+
169+ /**
170+ * If the toolbar is enabled, manually forces the toolbar to update based on the user's
171+ * current selection. This includes hiding/showing the toolbar, positioning the toolbar,
172+ * and updating the enabled/disable state of the toolbar buttons
173+ */
174+ checkSelection : ( ) => void
175+
176+ /**
177+ * Returns a data representation of the selected text, which can be applied via
178+ * `importSelection(selectionState)`. This data will include the beginning and end of the
179+ * selection, as well as which of the editor **elements** the selection was within
180+ */
181+ exportSelection : ( ) => void
182+
183+ /**
184+ * Restores the selection using a data representation of previously selected text
185+ * (ie value returned by `exportSelection())
186+ * @param selectionState Data representing the state of the selection to restore
187+ * @param favorLaterSelectionAnchor If true, import the cursor immediately subsequent to an anchor tag
188+ * if it would otherwise be placed right at the trailing edge inside the anchor.
189+ * This cursor positioning, even though visually equivalent to the user, can affect behavior in Internet Explorer
190+ */
191+ importSelection : ( selectionState : object , favorLaterSelectionAnchor : boolean ) => void
192+
193+ /**
194+ * Returns a reference to the editor element that currently has focus (if the editor has focus)
195+ * TODO: Verify return
196+ */
197+ getFocusedElement : ( ) => HTMLElement
198+
199+ /**
200+ * Returns a reference to the editor *element* that the user's selection is currently within
201+ */
202+ getSelectedParentElement : (
203+ /**
204+ * The Range to find the selection parent element within.
205+ * If no element is provided, the editor will use the current range within the selection of the editor's contentWindow
206+ */
207+ range ?: Range
208+ ) => HTMLElement
209+
210+ /**
211+ * Restores the selection to what was selected the last time `saveSelection()` was called
212+ */
213+ restoreSelection : ( ) => void
214+
215+ /**
216+ * Internally stores the user's current selection. This can be restored by calling `restoreSelection()`
217+ */
218+ saveSelection : ( ) => void
219+
220+ /**
221+ * Expands the selection to contain all text within the focused editor *element*
222+ */
223+ selectAllContents : ( ) => void
224+
225+ /**
226+ * Change the user's selection to select the contents of the
227+ * provided element and update the toolbar to reflect this change
228+ */
229+ selectElement : (
230+ /**
231+ * DOM Element -- which is a descendant of one of the editor's elements -- to select
232+ */
233+ element : HTMLElement
151234 ) => void
235+
236+ /**
237+ * Stop the toolbar from updating to reflect changes in the user's selection
238+ */
239+ stopSelectionUpdates : ( ) => void
240+
241+ /**
242+ * Enable the toolbar to start updating based on the user's selection,
243+ * after a call to `stopSelectionUpdates()`
244+ */
245+ startSelectionUpdates : ( ) => void
246+
247+ /**
248+ * Convert text to plaintext and replace current selection with result
249+ */
250+ cleanPaste : (
251+ /**
252+ * Content to be pasted at the location of the current selection/cursor
253+ */
254+ text : string
255+ ) => void
256+
257+ /**
258+ * creates a link via the native `document.execCommand('createLink')` command
259+ */
260+ createLink : (
261+ options : {
262+ /**
263+ * he url to set as the `href` of the created link.
264+ * A non-empty value must be provided for the link to be created
265+ */
266+ value : string ,
267+ /**
268+ * Attribute to set as the `target` attribute of the created link. Passing 'self'
269+ * or not passing this option at all are equivalent in that they will just ensure that
270+ *`target="_blank"` will NOT be present on the created link
271+ * **NOTE** If the `targetBlank` option on the editor is set to true, the `target`
272+ * property of opts will be ignored and `target="_blank"` will be added to all created links
273+ */
274+ target ?: string ,
275+ /**
276+ * Class (or classes) to append to the `class` attribute of the created link
277+ */
278+ buttonClass ?: string ,
279+ }
280+ ) => void
281+
282+ /**
283+ * Executes an built-in action via `document.execCommand`
284+ */
285+ execAction : (
286+ /**
287+ * Action to be passed as the 'command' argument
288+ * to `document.execCommand(command, showDefaultUI, value)`
289+ */
290+ action : string ,
291+ /**
292+ * Object containing additional properties for specific commands
293+ * https://github.com/yabwe/medium-editor/blob/master/API.md#execactionaction-opts
294+ */
295+ options ?: object
296+ ) => boolean
297+
298+ /**
299+ * Replace the current selection with html
300+ */
301+ pasteHTML : (
302+ html : string ,
303+ options ?: MediumEditor . PasteOptions
304+ ) => void
305+
306+ /**
307+ * Wrapper around the browser's built in `document.queryCommandState(command)`
308+ * for checking whether a specific action has already been applied to the selection
309+ */
310+ queryCommandState : (
311+ /**
312+ * Action to be passed as the 'command' argument to `document.queryCommandState(command)`
313+ */
314+ action : string
315+ ) => boolean
316+
317+ /**
318+ * Trigger the editor to check for updates to the html, and trigger the `editableInput` event if needed
319+ */
320+ checkContentEditable : (
321+ /**
322+ * The `<div contenteditable=true></div>` element that contains the html that may have changed
323+ * If no element is provided, the editor will check the currently 'active' editor element (the element with focus)
324+ */
325+ editable : HTMLElement
326+ ) => void
327+
328+ /**
329+ * Delay any function from being executed by the amount of time passed as the delay option
330+ */
331+ delay : ( fn : ( ) => any ) => void
332+
333+ /**
334+ * Returns the trimmed html content for the first editor element, or the element at `index`
335+ */
336+ getContext : (
337+ /**
338+ * Index of the editor *element* to retrieve the content from.
339+ * Defaults to 0 when not provided (returns content of the first editor *element*)
340+ */
341+ index ?: number
342+ ) => void
343+
344+ /**
345+ * Get a reference to an extension with the specified name.
346+ * TODO: Extension type
347+ */
348+ getExtensionByName : ( name : string ) => any
349+
350+ /**
351+ * Reset the content of all editor elements to their value at the time they were added
352+ * to the editor. If a specific editor element is provided, only the content of that element will be reset
353+ */
354+ resetContent : ( element ?: HTMLElement ) => void
355+
356+ /**
357+ * Returns a JSON object including the content of each of the elements inside the editor
358+ */
359+ serialize : ( ) => string
360+
361+ /**
362+ * Sets the html content for the first editor **element**, or the **element** at `index`.
363+ * Ensures the the `editableInput` event is triggered
364+ */
365+ setContent : (
366+ /**
367+ * The content to set the element to
368+ */
369+ html : string ,
370+ /**
371+ * Index of the editor element to set the content of.
372+ * Defaults to `0` when not provided (sets content of the first editor element)
373+ */
374+ index ?: number
375+ ) => void
376+
152377}
153378
154379declare namespace MediumEditor {
380+ interface VersionObject {
381+ major : number ,
382+ minor : number ,
383+ revision : number ,
384+ preRelease : string ,
385+ toString : ( ) => string
386+ }
387+
155388 interface CutstomEventListener {
156389 (
157390 /**
@@ -547,5 +780,5 @@ declare namespace MediumEditor {
547780 */
548781 updateOnEmptySelection : boolean
549782 }
550-
783+
551784}
0 commit comments