Skip to content

Commit

Permalink
fix(build): missing typings
Browse files Browse the repository at this point in the history
  • Loading branch information
eliandoran committed Jan 6, 2025
1 parent 271a749 commit bf34816
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@triliumnext/ckeditor5-footnotes",
"version": "0.0.4-hotfix9",
"version": "0.0.4-hotfix10",
"description": "A plugin for CKEditor 5 to allow footnotes.",
"keywords": [
"ckeditor",
Expand Down
7 changes: 7 additions & 0 deletions sample/ckeditor.d.ts
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';
6 changes: 6 additions & 0 deletions src/augmentation.d.ts
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;
}
}
31 changes: 31 additions & 0 deletions src/constants.d.ts
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;
};
6 changes: 6 additions & 0 deletions src/footnote-editing/auto-formatting.d.ts
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;
5 changes: 5 additions & 0 deletions src/footnote-editing/converters.d.ts
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;
59 changes: 59 additions & 0 deletions src/footnote-editing/footnote-editing.d.ts
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;
}
7 changes: 7 additions & 0 deletions src/footnote-editing/schema.d.ts
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;
7 changes: 7 additions & 0 deletions src/footnote-ui.d.ts
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>;
}
7 changes: 7 additions & 0 deletions src/footnotes.d.ts
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];
}
5 changes: 5 additions & 0 deletions src/index.d.ts
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;
};
21 changes: 21 additions & 0 deletions src/insert-footnote-command.d.ts
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;
}
27 changes: 27 additions & 0 deletions src/utils.d.ts
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;

0 comments on commit bf34816

Please sign in to comment.