diff --git a/types/ckeditor__ckeditor5-utils/ckeditor__ckeditor5-utils-tests.ts b/types/ckeditor__ckeditor5-utils/ckeditor__ckeditor5-utils-tests.ts new file mode 100644 index 0000000000..82c272a6ec --- /dev/null +++ b/types/ckeditor__ckeditor5-utils/ckeditor__ckeditor5-utils-tests.ts @@ -0,0 +1,594 @@ +import * as utils from "ckeditor__ckeditor5-utils"; + +declare const document: Document; +declare const locale: utils.Locale; +declare let bool: boolean; +declare let changes: utils.Change[]; +declare let emitter: utils.Emitter; +declare let htmlElement: HTMLElement; +declare let map: Map; +declare let num: number; +declare let rect: utils.Rect; +declare let rectOrNull: utils.Rect | null; +declare let str: string; + +// utils/dom + +utils.createElement(document, "p"); +utils.createElement(document, "p", {class: "foo"}); +utils.createElement(document, "p", null, "foo"); +utils.createElement(document, "p", null, ["foo", utils.createElement(document, "img")]); + +// TODO? utils/dom/emittermixin + +utils.getAncestors(htmlElement); + +utils.getBorderWidths(htmlElement); + +utils.getCommonAncestor(htmlElement, htmlElement); + +str = utils.getDataFromElement(htmlElement); + +let strNull: HTMLElement | null = utils.getPositionedAncestor(); +strNull = utils.getPositionedAncestor(htmlElement); + +num = utils.indexOf(htmlElement); + +utils.insertAt(htmlElement, 2, htmlElement); + +bool = utils.isNode(htmlElement); +bool = utils.isNode(new Date()); + +bool = utils.isRange(new Range()); +bool = utils.isRange(new Date()); + +bool = utils.isText(new Text("foo")); +bool = utils.isText(new Date()); + +bool = utils.isWindow(window); +bool = utils.isWindow(new Date()); + +let position: utils.Position; + +position = utils.getOptimalPosition({ + element: htmlElement, + target: () => htmlElement, + positions: [(targetRect, elementRect) => ({ + top: targetRect.top, + left: targetRect.left + elementRect.width, + name: "right" + })] +}); + +position = utils.getOptimalPosition({ + element: htmlElement, + target: htmlElement, + positions: [ + (targetRect) => ({ + top: targetRect.bottom, + left: targetRect.left, + name: "mySouthEastPosition" + }), + (targetRect, elementRect) => ({ + top: targetRect.top - elementRect.height, + left: targetRect.left, + name: "myNorthEastPosition" + }) + ], + limiter: document.body, + fitInViewport: true, +}); + +rect = new utils.Rect(document.body); +rect = new utils.Rect(document.getSelection()!.getRangeAt(0)); +rect = new utils.Rect(window); +rect = new utils.Rect({top: 0, right: 10, bottom: 10, left: 0, width: 10, height: 10}); +rect = new utils.Rect(rect); +rect = new utils.Rect(document.body.getClientRects().item(0)!); + +rect = rect.clone(); +bool = rect.contains(rect); +rect = rect.excludeScrollbarsAndBorders(); +num = rect.getArea(); +rect = rect.getIntersection(rect); +num = rect.getIntersectionArea(rect); +rectOrNull = rect.getVisible(); +bool = rect.isEqual(rect); +rect = rect.moveBy(1, 1); +rect = rect.moveTo(1, 1); + +utils.remove(htmlElement); + +utils.scrollAncestorsToShowTarget(new Range()); +utils.scrollAncestorsToShowTarget(htmlElement); + +utils.scrollViewportToShowTarget({target: new Range()}); +utils.scrollViewportToShowTarget({target: htmlElement}); +utils.scrollViewportToShowTarget({target: new Range(), viewportOffset: 30}); +utils.scrollViewportToShowTarget({target: htmlElement, viewportOffset: 30}); + +utils.setDataInElement(htmlElement, "foo"); + +str = utils.toUnit("rem")(10); + +// utils/ckeditorerror ======================================================== + +const regularError = new Error("foo"); +let ckeditorError: utils.CKEditorError; + +const data = {bar: 1}; +ckeditorError = new utils.CKEditorError("foo"); +ckeditorError = new utils.CKEditorError("foo", data); + +utils.CKEditorError.isCKEditorError(ckeditorError); +utils.CKEditorError.isCKEditorError(regularError); + +// utils/collection =========================================================== + +interface Foo { + foo: number; +} + +interface Props { + id: string; +} + +interface PropsStr { + id: string; + name: string; +} + +declare let foo: Foo; +let items: PropsStr[]; +let itemOrNull: Props | null; +let itemOrUndef: Props | undefined; + +const item1 = {id: "id1"}; +const item2 = {id: "id2"}; +const itemStr1 = {id: "foo", name: "yy"}; +const itemStr2 = {id: "foo", name: "xx"}; + +const coll = new utils.Collection(); +const collStr = new utils.Collection({idProperty: "name"}); + +coll.add(item1); +coll.add(item2); +collStr.add(itemStr1); +collStr.add(itemStr2); + +coll.add(item1, 0); +coll.add(item1).add(item2); + +coll.clear(); + +items = collStr.filter((item) => item.name === "yy"); +items = collStr.filter((_, idx) => idx > 0); +items = collStr.filter(function(this: Foo, _, idx) {return this.foo > 0 && idx === 0; }, foo); + +itemOrUndef = collStr.find((item) => item.name === "yy"); +itemOrUndef = collStr.find((_, idx) => idx === 3); +itemOrUndef = collStr.find(function(this: Foo, _, idx) {return this.foo > 0 && idx === 0; }, foo); + +itemOrNull = coll.get(0); +itemOrNull = coll.get("id1"); + +num = coll.getIndex("id1"); +num = coll.getIndex(item1); + +coll.remove(0); +coll.remove("id1"); +coll.remove(item1); + +const strings: string[] = collStr.map((item) => item.name); +const nums: number[] = collStr.map((_, idx) => idx); +const bools: boolean[] = collStr.map(function(this: Foo, _, idx) {return this.foo === idx; }, foo); + +// collection#bindTo + +interface LabelObj { + label: string; +} + +interface LabelValueObj { + label: {value: string}; +} + +interface HiddenObj { + hidden: boolean; +} + +class FactoryClass { + factoryLabel: string; + constructor(data: LabelObj) { + this.factoryLabel = data.label; + } +} + +const source1 = new utils.Collection({idProperty: "label"}); +const target1 = new utils.Collection(); + +target1.bindTo(source1).as(FactoryClass); + +source1.add({label: "foo"}); +source1.add({label: "bar"}); + +source1.remove(0); +console.log(target1.length); +console.log(target1.get(0)!.factoryLabel); + +class FooClass { + fooLabel: string; + constructor(data: LabelObj) { + this.fooLabel = data.label; + } +} + +class BarClass { + barLabel: string; + constructor(data: LabelObj) { + this.barLabel = data.label; + } +} + +const source2 = new utils.Collection({idProperty: "label"}); +const target2 = new utils.Collection(); + +target2.bindTo(source2).using((item) => { + if (item.label === "foo") { + return new FooClass(item); + } else { + return new BarClass(item); + } +}); + +source2.add({label: "foo"}); +source2.add({label: "bar"}); + +console.log(target2.length); +console.log(target2.get(0)! instanceof FooClass); +console.log(target2.get(1)! instanceof BarClass); + +const source3 = new utils.Collection({idProperty: "label"}); +const target3 = new utils.Collection(); + +target3.bindTo(source2).using("label"); + +source3.add({label: {value: "foo"}}); +source3.add({label: {value: "bar"}}); + +console.log(target3.length); +console.log(target3.get(0)!.value); +console.log(target3.get(1)!.value); + +const source4 = new utils.Collection(); +const target4 = new utils.Collection(); + +target4.bindTo(source4).using(item => { + if (item.hidden) { + return null; + } + + return item; +}); + +source4.add({hidden: true}); +source4.add({hidden: false}); + +// utils/comparearrays ======================================================== + +utils.compareArrays([0, 2], [0, 2, 1]); +utils.compareArrays(["abc", 0 ], ["abc", 0, 3]); + +// utils/config =============================================================== + +let strOrUndef: string | undefined; +let config: utils.Config; +const defaultConfig = { + foo: 1, bar: 2, +}; + +config = new utils.Config(); +config = new utils.Config({foo: 10}); +config = new utils.Config({}, defaultConfig); +config = new utils.Config({foo: 10}, defaultConfig); + +config.define({ + resize: { + minHeight: 400, + hidden: true + } +}); + +config.define("resize", {minHeight: 400, hidden: true}); +config.define("language", "en"); +config.define("resize.minHeight", 400); + +str = config.get("language"); +num = config.get("resize.minHeight"); + +config.define("language", undefined); +strOrUndef = config.get("language"); + +// utils/count ================================================================ + +num = utils.count([1, 2, 3, 4, 5]); + +// utils/diff ================================================================= + +changes = utils.diff("aba", "acca"); +changes = utils.diff(Array.from("aba"), Array.from("acca")); + +// utils/difftochanges ======================================================== + +const input = Array.from("abc"); +const output = Array.from("xaby"); +const allChanges = utils.diffToChanges(utils.diff(input, output), output); +allChanges.forEach(change => { + if (change.type === "insert") { + input.splice(change.index, 0, ...change.values); + } else if (change.type === "delete") { + input.splice(change.index, change.howMany); + } +}); + +// utils/elementreplacer ====================================================== + +const replacer = new utils.ElementReplacer(); + +replacer.replace(htmlElement, htmlElement); +replacer.replace(htmlElement); + +replacer.restore(); + +// utils/emittermixin + +emitter = utils.EmitterMixin; +emitter = Object.create(utils.EmitterMixin); + +emitter.delegate("foo") ; +emitter.delegate("foo", "bar"); +emitter.delegate("foo").to(emitter); +emitter.delegate("foo").to(emitter, "bar"); +emitter.delegate("foo").to(emitter, name => name + "-delegated"); + +emitter.fire("foo"); +emitter.fire("foo", 1, "b", true); +emitter.fire("getSelectedContent", (evt: utils.EventInfo) => { + evt.return = new DocumentFragment(); + evt.stop(); +}); + +emitter.listenTo(emitter, "foo", () => {}); +emitter.listenTo(emitter, "foo", () => {}, {priority: 10}); +emitter.listenTo(emitter, "foo", () => {}, {priority: "highest"}); + +emitter.off("foo"); +emitter.off("foo", () => {}); + +emitter.on("foo", () => {}); +emitter.on("foo", () => {}, {priority: 10}); +emitter.on("foo", () => {}, {priority: "normal"}); + +emitter.once("foo", () => {}); +emitter.once("foo", () => {}, {priority: 10}); +emitter.once("foo", () => {}, {priority: "lowest"}); + +emitter.stopDelegating(); +emitter.stopDelegating("foo"); +emitter.stopDelegating("foo", emitter); + +emitter.stopListening(); +emitter.stopListening(emitter); +emitter.stopListening(emitter, "foo"); +emitter.stopListening(emitter, "foo", () => {}); + +// utils/env ================================================================== + +bool = utils.env.isEdge; +bool = utils.env.isMac; + +// utils/eventinfo ============================================================ + +const event = new utils.EventInfo({a: 1}, "test"); +num = event.source.a; +str = event.name; + +event.path[0]; + +event.stop(); +event.off(); + +bool = event.stop.called; +bool = event.off.called; + +// utils/fastdiff ============================================================= + +utils.fastDiff(str, "2ab").forEach(change => { + if (change.type === "insert") { + str = str.substring(0, change.index) + change.values.join("") + str.substring(change.index); + } else if (change.type === "delete") { + str = str.substring(0, change.index) + str.substring(change.index + change.howMany); + } +}); + +// utils/first ================================================================ + +const collection = [ 11, 22 ]; +const iterator = collection[Symbol.iterator](); + +utils.first(iterator); + +// utils/focustracker ========================================================= + +const focusTracker = new utils.FocusTracker(); +htmlElement = focusTracker.focusedElement; +bool = focusTracker.isFocused; +focusTracker.add(htmlElement); +focusTracker.remove(htmlElement); + +// utils/isiterable =========================================================== + +bool = utils.isIterable(str); +bool = utils.isIterable([1, 2, 3]); + +// utils/keyboard ============================================================= + +num = utils.keyCodes.a; +num = utils.keyCodes["a"]; + +num = utils.getCode("0"); +num = utils.getCode({keyCode: 48}) ; +num = utils.getCode({keyCode: 48, altKey: true, ctrlKey: true, shiftKey: true}); + +str = utils.getEnvKeystrokeText("alt+A"); + +num = utils.parseKeystroke("Ctrl+A"); +num = utils.parseKeystroke(["ctrl", "a"]); +num = utils.parseKeystroke(["shift", 33]); + +// utils/keystrokehandler ===================================================== + +declare const keystroke: utils.KeystrokeInfo; +const keystrokes = new utils.KeystrokeHandler(); + +const spy = utils.spy(); +keystrokes.set("Ctrl+A", spy); +keystrokes.set(["Ctrl", "A"], spy); +keystrokes.set(["Ctrl", "A"], spy, {priority: "high"}); +keystrokes.set(["Ctrl", 33], spy, {priority: 10}); + +const emitterMixxin = Object.create(utils.EmitterMixin) as utils.Emitter; +keystrokes.listenTo(emitterMixxin); + +bool = keystrokes.press(keystroke); + +keystrokes.destroy(); + +// utils/locale =============================================================== + +locale.t("Label"); +locale.t('Created file "%0" in %1ms.', ["fileName", "100"]); + +// utils/log ================================================================== + +utils.log.warn("message"); +utils.log.warn('plugin-load: It was not possible to load the "{$pluginName}" plugin in module "{$moduleName}', { + pluginName: "foo", + moduleName: "bar" +}); + +utils.log.error("message"); +utils.log.error('plugin-load: It was not possible to load the "{$pluginName}" plugin in module "{$moduleName}', { + pluginName: "foo", + moduleName: "bar" +}); + +// utils/mapsequal ============================================================ + +utils.mapsEqual(map, map); + +// utils/mix ================================================================== + +class Editor { + b: () => number; +} + +interface SomeMixin { + a: () => string; +} + +const SomeMixin = { + a() { + return "a"; + } +}; + +utils.mix(Editor, SomeMixin); +const mixEditor = new Editor() as Editor & SomeMixin; +mixEditor.a(); +mixEditor.b(); + +// utils/nth ================================================================== + +function* getGenerator() { + yield 11; + yield 22; + yield 33; +} + +utils.nth(2, getGenerator()); + +// utils/objecttomap ========================================================== + +const objMap: Map = utils.objectToMap({foo: 1, bar: 2}); +num = objMap.get("foo")!; + +// utils/observablemixin ====================================================== + +const observable: utils.Observable = utils.ObservableMixin; + +const vehicle = Object.create(utils.ObservableMixin) as utils.Observable; +const car = Object.create(utils.ObservableMixin) as utils.Observable; + +vehicle.bind("color"); +vehicle.bind("color", "year"); +vehicle.bind("color", "year").to(car); +vehicle.bind("color", "year").to(car, "color"); +vehicle.bind("color", "year").to(car, "color", car, "year"); +vehicle.bind("year").to(car, "color", car, "year", (a: string, b: number) => a + b); +vehicle.bind("custom").to(car, "color", car, "year", car, "hue", (...args: Array) => args.join("/")); // TS 3.0: [string, number, string] +vehicle.bind("color").toMany([car, car], "color", () => {}); + +vehicle.decorate("method"); + +car.set("color", "red"); +car.set("seats", undefined); +car.set({ + color: "blue", + wheels: 4, + seats: 5, +}); + +vehicle.unbind(); +vehicle.unbind("color"); +vehicle.unbind("color", "year"); + +// utils/priorities =========================================================== + +num = utils.priorities.get(2); +num = utils.priorities.get("normal"); + +// utils/spy + +const fn1 = utils.spy(); +fn1(); +bool = fn1.called; + +// utils/tomap + +map = utils.toMap({foo: 1, bar: 2}); +map = utils.toMap([["foo", 1], ["bar", 2]]); +map = utils.toMap(map); + +// utils/translation-service ================================================== + +utils.add("pl", { + OK: "OK", + "Cancel [context: reject]": "Anuluj" +}); + +utils.translate("pl", "Cancel [context: reject]"); + +// utils/uid ================================================================== + +str = utils.uid(); + +// utils/unicode ============================================================== + +bool = utils.isCombiningMark("a"); +bool = utils.isHighSurrogateHalf("a"); +bool = utils.isInsideCombinedSymbol(str, 2); +bool = utils.isInsideSurrogatePair(str, 2); +bool = utils.isLowSurrogateHalf(String.fromCharCode(57166)); + +// utils/version ============================================================== diff --git a/types/ckeditor__ckeditor5-utils/index.d.ts b/types/ckeditor__ckeditor5-utils/index.d.ts new file mode 100644 index 0000000000..8d9d50e889 --- /dev/null +++ b/types/ckeditor__ckeditor5-utils/index.d.ts @@ -0,0 +1,471 @@ +// Type definitions for @ckeditor/ckeditor5-utils 10.2 +// Project: https://github.com/ckeditor/ckeditor5-utils +// Definitions by: denisname +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +// Helpers + +export interface DeleteChange { + index: number; + type: "delete"; + howMany: number; +} + +export interface InsertChange { + index: number; + type: "insert"; + values: string[]; +} + +export interface BindChain { + to(observable: Observable, ...bindProperties: Array): void; + toMany(observable: Observable[], ...bindProperties: Array): void; +} + +export interface CollectionBindTo { + as: (Class: {new(item: T): K}) => void; + using: (callbackOrProperty: keyof T | ((item: T) => K)) => void; +} + +// utils/dom + +export function createElement(doc: Document, name: string, attributes?: object | null, children?: Node | string | Array): Element; + +// TODO? utils/dom/emittermixin + +export function getAncestors(node: Node): Array; + +export function getBorderWidths(element: HTMLElement): {top: number, right: number, bottom: number, left: number}; + +export function getCommonAncestor(nodeA: Node, nodeB: Node): Node | DocumentFragment | Document | null; + +export function getDataFromElement(el: HTMLElement): string; + +export function getPositionedAncestor(element?: HTMLElement): HTMLElement | null; + +export function indexOf(node: Node): number; + +export function insertAt(parentElement: Element, index: number, nodeToInsert: Node): void; + +export function isNode(obj: any): obj is Node; + +export function isRange(obj: any): obj is Range; + +export function isText(obj: any): obj is Text; + +export function isWindow(obj: any): obj is Window; + +export interface Options { + element: HTMLElement; + fitInViewport?: boolean; + limiter?: HTMLElement | Range | ClientRect | Rect | (() => HTMLElement | Range | ClientRect | Rect); + positions: Array<(targetRect: Rect, elementRect: Rect) => Position>; + target: HTMLElement | Range | ClientRect | Rect | (() => HTMLElement | Range | ClientRect | Rect); +} + +export interface Position { + left: number; + name: string; + top: number; +} + +export function getOptimalPosition(options: Options): Position; + +export class Rect { + readonly bottom: number; + readonly height: number; + readonly left: number; + readonly right: number; + readonly top: number; + readonly width: number; + + constructor(source: HTMLElement | Range | Window | ClientRect | Rect | object); + clone(): Rect; + contains(anotherRect: Rect): boolean; + excludeScrollbarsAndBorders(): Rect; + getArea(): number; + getIntersection(anotherRect: Rect): Rect; + getIntersectionArea(anotherRect: Rect): number; + getVisible(): Rect | null; + isEqual(rect: Rect): boolean; + moveBy(x: number, y: number): Rect; + moveTo(x: number, y: number): Rect; + + static getDomRangeRects(range: Range): Rect[]; +} + +export function remove(node: Node): void; + +export function scrollAncestorsToShowTarget(target: HTMLElement | Range): void; + +export function scrollViewportToShowTarget(options: {target: HTMLElement | Range, viewportOffset?: number}): void; + +export function setDataInElement(el: HTMLElement, data: string): void; + +export function toUnit(unit: string): (value: number) => string; + +// utils/ckeditorerror + +export const DOCUMENTATION_URL: string; + +export class CKEditorError extends Error { + data: object | undefined; + name: string; + + constructor(message: string, data?: object); + + static isCKEditorError(error: Error): boolean; +} + +export function attachLinkToDocumentation(message: string): string; + +// utils/collection + +export function as(Class: Function): void; +export function using(callbackOrProperty: Function | string): void; + +export class Collection implements Iterable, Emitter { + first: T | null; + last: T | null; + length: number; + + constructor(options?: {idProperty?: keyof T}); + add(item: T, index?: number): this; + bindTo(externalCollection: Collection): CollectionBindTo; + clear(): void; + filter(callbackfn: (item: T, index: number) => boolean, thisArg?: any): T[]; + find(predicate: (item: T, index: number) => boolean, thisArg?: any): T | undefined; + get(idOrIndex: string | number): T | null; + getIndex(idOrItem: string | T): number; + map(callbackfn: (item: T, index: number) => U, thisArg?: any): U[]; + remove(subject: T | number | string): T; + + // Iterable + [Symbol.iterator](): Iterator; + + // Emitter + delegate(...events: string[]): EmitterMixinDelegateChain; + fire(eventOrInfo: string | EventInfo, ...args: any[]): any; + listenTo(emitter: Emitter, event: string, callback: Function, options?: {priority?: PriorityString | number }): void; + off(event: string, callback?: Function): void; + on(event: string, callback: Function, options?: {priority: PriorityString | number}): void; + once(event: string, callback: Function, options?: {priority: PriorityString | number}): void; + stopDelegating(event?: string, emitter?: Emitter): void; + stopListening(emitter?: Emitter, event?: string, callback?: Function): void; +} + +// utils/comparearrays + +export type ArrayRelation = "extension" | "same" | "prefix"; + +export function compareArrays(a: ReadonlyArray, b: ReadonlyArray): number | ArrayRelation; + +// utils/config + +export class Config { + constructor(configurations?: object, defaultConfigurations?: object); + define(name: object): void; + define(name: string, value: any): void; + get(name: string): any /*| undefined*/; + set(name: string, value: any /*| undefined*/): void; +} + +// utils/count + +export function count(iterator: Iterable): number; + +// utils/diff + +export type Change = "equal" | "insert" | "delete"; + +export function diff(a: string, b: string, cmp?: (a: string, b: string) => boolean): Change[]; +export function diff(a: ReadonlyArray, b: ReadonlyArray, cmp?: (a: string, b: string) => boolean): Change[]; + +// utils/difftochanges + +export function diffToChanges(diff: Change[], output: string | string[]): Array; + +// utils/elementreplacer + +export class ElementReplacer { + replace(element: HTMLElement, newElement?: HTMLElement): void; + restore(): void; +} + +// utils/emittermixin + +export const EmitterMixin: Emitter; + +export interface Emitter { + delegate(...events: string[]): EmitterMixinDelegateChain; + fire(eventOrInfo: string | EventInfo, ...args: any[]): any; + listenTo(emitter: Emitter, event: string, callback: Function, options?: {priority?: PriorityString | number }): void; + off(event: string, callback?: Function): void; + on(event: string, callback: Function, options?: {priority: PriorityString | number}): void; + once(event: string, callback: Function, options?: {priority: PriorityString | number}): void; + stopDelegating(event?: string, emitter?: Emitter): void; + stopListening(emitter?: Emitter, event?: string, callback?: Function): void; +} + +export interface EmitterMixinDelegateChain { + to(emitter: Emitter, nameOrFunction?: string | ((name: string) => string)): void; +} + +// utils/env + +export namespace env { + const isEdge: boolean; + const isMac: boolean; +} + +// utils/eventinfo + +export class EventInfo { + readonly name: string; + readonly path: object[]; + return: any /*| undefined*/; + readonly source: T; + + constructor(source: T, name: string); + off: { + (): void; + called: boolean; + }; + stop: { + (): void; + called: boolean; + }; +} + +// utils/fastdiff + +export function fastDiff(oldText: string, newText: string): Array; + +// utils/first + +export function first(iterable: Iterable): T; + +// utils/focustracker + +export class FocusTracker implements Observable { + readonly focusedElement: HTMLElement; + readonly isFocused: boolean; + + add(element: HTMLElement): void; + remove(element: HTMLElement): void; + + // Observable + bind(...bindProperties: string[]): BindChain; + decorate(methodName: string): void; + set(name: object): void; + set(name: string, value: any): void; + unbind(...unbindProperties: string[]): void; + + // Observable (Emitter) + delegate(...events: string[]): EmitterMixinDelegateChain; + fire(eventOrInfo: string | EventInfo, ...args: any[]): any; + listenTo(emitter: Emitter, event: string, callback: Function, options?: {priority?: PriorityString | number }): void; + off(event: string, callback?: Function): void; + on(event: string, callback: Function, options?: {priority: PriorityString | number}): void; + once(event: string, callback: Function, options?: {priority: PriorityString | number}): void; + stopDelegating(event?: string, emitter?: Emitter): void; + stopListening(emitter?: Emitter, event?: string, callback?: Function): void; +} + +// utils/isiterable + +export function isIterable(value: any): value is Iterable; + +// utils/keyboard + +export const keyCodes: { + a: 65, + b: 66, + c: 67; + d: 68; + e: 69; + f: 70; + g: 71; + h: 72; + i: 73; + j: 74; + k: 75; + l: 76; + m: 77; + n: 78; + o: 79; + p: 80; + q: 81; + r: 82; + s: 83; + t: 84; + u: 85; + v: 86; + w: 87; + x: 88; + y: 89; + z: 90; + + 0: 48; + 1: 49; + 2: 50; + 3: 51; + 4: 52; + 5: 53; + 6: 54; + 7: 55; + 8: 56; + 9: 57; + + f1: 112; + f2: 113; + f3: 114; + f4: 115; + f5: 116; + f6: 117; + f7: 118; + f8: 118; + f9: 120; + f10: 121; + f11: 122; + f12: 123; + + arrowleft: 37, + arrowup: 38, + arrowright: 39, + arrowdown: 40, + backspace: 8, + "delete": 46, + enter: 13, + space: 32, + esc: 27, + tab: 9, + ctrl: 0x110000, + cmd: 0x110000, + shift: 0x220000, + alt: 0x440000 +}; + +export interface KeystrokeInfo { + altKey?: boolean; + ctrlKey?: boolean; + keyCode: number; + shiftKey?: boolean; +} + +export function getCode(key: string | KeystrokeInfo): number; + +export function getEnvKeystrokeText(keystroke: string): string; + +export function parseKeystroke(keystroke: string | Array): number; + +// utils/keystrokehandler + +export class KeystrokeHandler { + constructor(); + destroy(): void; + listenTo(emitter: Emitter): void; + press(keyEvtData: KeystrokeInfo): boolean; + set(keystroke: string | Array, callback: Function, options?: {priority?: PriorityString | number}): void; +} + +// utils/locale + +export class Locale { + readonly language: string; + + constructor(language?: string); + t(str: string, values?: string[]): string; +} + +// utils/log + +export namespace log { + function error(message: string, data?: object): void; + function warn(message: string, data?: object): void; +} + +// utils/mapsequal + +export function mapsEqual(mapsA: Map, mapsB: Map): boolean; + +// utils/mix + +export function mix(baseClass: {new(): any}, ...mixins: any[]): void; + +// utils/nth + +export function nth(index: number, iterable: Iterable): T; + +// utils/objecttomap + +export function objectToMap(obj: T): Map; + +// utils/observablemixin + +export const ObservableMixin: Observable; + +export interface Observable extends Emitter { + bind(...bindProperties: string[]): BindChain; + decorate(methodName: string): void; + set(name: object): void; + set(name: string, value: any): void; + unbind(...unbindProperties: string[]): void; + + // Emitter + delegate(...events: string[]): EmitterMixinDelegateChain; + fire(eventOrInfo: string | EventInfo, ...args: any[]): any; + listenTo(emitter: Emitter, event: string, callback: Function, options?: {priority?: PriorityString | number }): void; + off(event: string, callback?: Function): void; + on(event: string, callback: Function, options?: {priority: PriorityString | number}): void; + once(event: string, callback: Function, options?: {priority: PriorityString | number}): void; + stopDelegating(event?: string, emitter?: Emitter): void; + stopListening(emitter?: Emitter, event?: string, callback?: Function): void; +} + +// utils/priorities + +export namespace priorities { + function get(priority: PriorityString | number): number; +} + +export type PriorityString = "highest" | "high" | "normal" | "low" | "lowest"; + +// utils/spy + +export function spy(): {(): void; called: boolean}; + +// utils/tomap + +export function toMap(data: Map): Map; +export function toMap(data: ReadonlyArray<[K, V]>): Map; +export function toMap(data: T): Map; + +// utils/translation-service + +export function add(language: string, translations: {[key: string]: string}): void; + +export function translate(language: string, translationKey: string): string; + +// TODO: CKEDITOR_TRANSLATIONS + +// utils/uid + +export function uid(): string; + +// utils/unicode + +export function isCombiningMark(character: string): boolean; + +export function isHighSurrogateHalf(character: string): boolean; + +export function isInsideCombinedSymbol(string: string, offset: number): boolean; + +export function isInsideSurrogatePair(string: string, offset: number): boolean; + +export function isLowSurrogateHalf(character: string): boolean; + +// utils/version + +// TODO: CKEDITOR_VERSION; diff --git a/types/ckeditor__ckeditor5-utils/tsconfig.json b/types/ckeditor__ckeditor5-utils/tsconfig.json new file mode 100644 index 0000000000..1fbda2fd6b --- /dev/null +++ b/types/ckeditor__ckeditor5-utils/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ckeditor__ckeditor5-utils-tests.ts" + ] +} diff --git a/types/ckeditor__ckeditor5-utils/tslint.json b/types/ckeditor__ckeditor5-utils/tslint.json new file mode 100644 index 0000000000..332951717c --- /dev/null +++ b/types/ckeditor__ckeditor5-utils/tslint.json @@ -0,0 +1,20 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "ban-types": { + "options": [ + ["Object", "Avoid using the `Object` type. Did you mean `object`?"], + ["Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?"], + ["Number", "Avoid using the `Number` type. Did you mean `number`?"], + ["String", "Avoid using the `String` type. Did you mean `string`?"], + ["Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?"] + ] + }, + "quotemark": [ + true, + "double", + "avoid-escape", + "avoid-template" + ] + } +}