forked from ThomasAitken/ckeditor5-footnotes
-
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.
- Loading branch information
1 parent
271a749
commit bf34816
Showing
13 changed files
with
189 additions
and
1 deletion.
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
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,7 @@ | ||
declare global { | ||
interface Window { | ||
editor: ClassicEditor; | ||
} | ||
} | ||
import { ClassicEditor } from 'ckeditor5'; | ||
import 'ckeditor5/ckeditor5.css'; |
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,6 @@ | ||
import type { Footnotes } from './index.js'; | ||
declare module '@ckeditor/ckeditor5-core' { | ||
interface PluginsMap { | ||
[Footnotes.pluginName]: Footnotes; | ||
} | ||
} |
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,31 @@ | ||
export declare const TOOLBAR_COMPONENT_NAME = "footnote"; | ||
export declare const DATA_FOOTNOTE_ID = "data-footnote-id"; | ||
export declare const ELEMENTS: { | ||
footnoteItem: string; | ||
footnoteReference: string; | ||
footnoteSection: string; | ||
footnoteContent: string; | ||
footnoteBackLink: string; | ||
}; | ||
export declare const CLASSES: { | ||
footnoteContent: string; | ||
footnoteItem: string; | ||
footnoteReference: string; | ||
footnoteSection: string; | ||
footnoteBackLink: string; | ||
footnotes: string; | ||
hidden: string; | ||
}; | ||
export declare const COMMANDS: { | ||
insertFootnote: string; | ||
}; | ||
export declare const ATTRIBUTES: { | ||
footnoteContent: string; | ||
footnoteId: string; | ||
footnoteIndex: string; | ||
footnoteItem: string; | ||
footnoteReference: string; | ||
footnoteSection: string; | ||
footnoteBackLink: string; | ||
footnoteBackLinkHref: string; | ||
}; |
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,6 @@ | ||
import { type Editor } from 'ckeditor5/src/core.js'; | ||
import { type Element } from 'ckeditor5/src/engine.js'; | ||
/** | ||
* Adds functionality to support creating footnotes using markdown syntax, e.g. `[^1]`. | ||
*/ | ||
export declare const addFootnoteAutoformatting: (editor: Editor, rootElement: Element) => void; |
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,5 @@ | ||
import { type Editor } from 'ckeditor5/src/core.js'; | ||
/** | ||
* Defines methods for converting between model, data view, and editing view representations of each element type. | ||
*/ | ||
export declare const defineConverters: (editor: Editor) => void; |
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,59 @@ | ||
/** | ||
* CKEditor dataview nodes can be converted to a output view or an editor view via downcasting | ||
* * Upcasting is converting to the platonic ckeditor version. | ||
* * Downcasting is converting to the output version. | ||
*/ | ||
import { type RootElement } from 'ckeditor5/src/engine.js'; | ||
import { Autoformat } from "@ckeditor/ckeditor5-autoformat"; | ||
import { Plugin } from "ckeditor5/src/core.js"; | ||
import { Widget } from 'ckeditor5/src/widget.js'; | ||
import '../footnote.css'; | ||
export default class FootnoteEditing extends Plugin { | ||
static get requires(): readonly [typeof Widget, typeof Autoformat]; | ||
/** | ||
* The root element of the document. | ||
*/ | ||
get rootElement(): RootElement; | ||
init(): void; | ||
/** | ||
* This method broadly deals with deletion of text and elements, and updating the model | ||
* accordingly. In particular, the following cases are handled: | ||
* 1. If the footnote section gets deleted, all footnote references are removed. | ||
* 2. If a delete operation happens in an empty footnote, the footnote is deleted. | ||
*/ | ||
private _handleDelete; | ||
/** | ||
* Clear the children of the provided footnoteContent element, | ||
* leaving an empty paragraph behind. This allows users to empty | ||
* a footnote without deleting it. modelWriter is passed in to | ||
* batch these changes with the ones that instantiated them, | ||
* such that the set can be undone with a single action. | ||
*/ | ||
private _clearContents; | ||
/** | ||
* Removes a footnote and its references, and renumbers subsequent footnotes. When a footnote's | ||
* id attribute changes, it's references automatically update from a dispatcher event in converters.js, | ||
* which triggers the `updateReferenceIds` method. modelWriter is passed in to batch these changes with | ||
* the ones that instantiated them, such that the set can be undone with a single action. | ||
*/ | ||
private _removeFootnote; | ||
/** | ||
* Deletes all references to the footnote with the given id. If no id is provided, | ||
* all references are deleted. modelWriter is passed in to batch these changes with | ||
* the ones that instantiated them, such that the set can be undone with a single action. | ||
*/ | ||
private _removeReferences; | ||
/** | ||
* Updates all references for a single footnote. This function is called when | ||
* the index attribute of an existing footnote changes, which happens when a footnote | ||
* with a lower index is deleted. batch is passed in to group these changes with | ||
* the ones that instantiated them. | ||
*/ | ||
private _updateReferenceIndices; | ||
/** | ||
* Reindexes footnotes such that footnote references occur in order, and reorders | ||
* footnote items in the footer section accordingly. batch is passed in to group changes with | ||
* the ones that instantiated them. | ||
*/ | ||
private _orderFootnotes; | ||
} |
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,7 @@ | ||
import type { Schema } from 'ckeditor5/src/engine.js'; | ||
/** | ||
* Declares the custom element types used by the footnotes plugin. | ||
* See here for the meanings of each rule: | ||
* https://ckeditor.com/docs/ckeditor5/latest/api/module_engine_model_schema-SchemaItemDefinition.html#member-isObject | ||
*/ | ||
export declare const defineSchema: (schema: Schema) => void; |
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,7 @@ | ||
import { Plugin } from 'ckeditor5/src/core.js'; | ||
import { type ListDropdownItemDefinition } from '@ckeditor/ckeditor5-ui'; | ||
import { Collection } from '@ckeditor/ckeditor5-utils'; | ||
export default class FootnoteUI extends Plugin { | ||
init(): void; | ||
getDropdownItemsDefinitions(): Collection<ListDropdownItemDefinition>; | ||
} |
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,7 @@ | ||
import { Plugin } from 'ckeditor5/src/core.js'; | ||
import FootnoteEditing from './footnote-editing/footnote-editing.js'; | ||
import FootnoteUI from './footnote-ui.js'; | ||
export default class Footnotes extends Plugin { | ||
static get pluginName(): "Footnotes"; | ||
static get requires(): readonly [typeof FootnoteEditing, typeof FootnoteUI]; | ||
} |
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,5 @@ | ||
import './augmentation.js'; | ||
export { default as Footnotes } from './footnotes.js'; | ||
export declare const icons: { | ||
insertFootnoteIcon: string; | ||
}; |
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,21 @@ | ||
import { Command } from 'ckeditor5/src/core.js'; | ||
export default class InsertFootnoteCommand extends Command { | ||
/** | ||
* Creates a footnote reference with the given index, and creates a matching | ||
* footnote if one doesn't already exist. Also creates the footnote section | ||
* if it doesn't exist. If `footnoteIndex` is 0 (or not provided), the added | ||
* footnote is given the next unused index--e.g. 7, if 6 footnotes exist so far. | ||
*/ | ||
execute({ footnoteIndex }?: { | ||
footnoteIndex?: number; | ||
}): void; | ||
/** | ||
* Called automatically when changes are applied to the document. Sets `isEnabled` | ||
* to determine whether footnote creation is allowed at the current location. | ||
*/ | ||
refresh(): void; | ||
/** | ||
* Returns the footnote section if it exists, or creates on if it doesn't. | ||
*/ | ||
private _getFootnoteSection; | ||
} |
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,27 @@ | ||
import { type Editor } from 'ckeditor5/src/core.js'; | ||
import { Element, Text, TextProxy, ViewElement } from 'ckeditor5/src/engine.js'; | ||
/** | ||
* Returns an array of all descendant elements of | ||
* the root for which the provided predicate returns true. | ||
*/ | ||
export declare const modelQueryElementsAll: (editor: Editor, rootElement: Element, predicate?: (item: Element) => boolean) => Array<Element>; | ||
/** | ||
* Returns an array of all descendant text nodes and text proxies of | ||
* the root for which the provided predicate returns true. | ||
*/ | ||
export declare const modelQueryTextAll: (editor: Editor, rootElement: Element, predicate?: (item: Text | TextProxy) => boolean) => Array<Text | TextProxy>; | ||
/** | ||
* Returns the first descendant element of the root for which the provided | ||
* predicate returns true, or null if no such element is found. | ||
*/ | ||
export declare const modelQueryElement: (editor: Editor, rootElement: Element, predicate?: (item: Element) => boolean) => Element | null; | ||
/** | ||
* Returns the first descendant text node or text proxy of the root for which the provided | ||
* predicate returns true, or null if no such element is found. | ||
*/ | ||
export declare const modelQueryText: (editor: Editor, rootElement: Element, predicate?: (item: Text | TextProxy) => boolean) => Text | TextProxy | null; | ||
/** | ||
* Returns the first descendant element of the root for which the provided | ||
* predicate returns true, or null if no such element is found. | ||
*/ | ||
export declare const viewQueryElement: (editor: Editor, rootElement: ViewElement, predicate?: (item: ViewElement) => boolean) => ViewElement | null; |