Skip to content

Commit

Permalink
add types & simplify WrappedSelection
Browse files Browse the repository at this point in the history
  • Loading branch information
giabao committed Apr 19, 2019
1 parent ff0fdce commit 8399c46
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 109 deletions.
2 changes: 1 addition & 1 deletion src/core/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export function isWindow(obj): obj is Window {
function isIframe(o): o is HTMLIFrameElement {
return o.nodeType == 1 && o.tagName.toLowerCase() == "iframe"
}
export function getContentDocument(obj: Document | HTMLIFrameElement| Window, module: Module, methodName): Document {
export function getContentDocument(obj: Document | HTMLIFrameElement| Window, module: Module, methodName: string): Document {
var doc;

if (!obj) {
Expand Down
1 change: 1 addition & 0 deletions src/core/internal/domrange/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export {
getRangeDocument,
createPrototypeRange,
DomRange,
RangeIterator,
createRangyRange
} from "./_";
2 changes: 1 addition & 1 deletion src/core/internal/domrange/part1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ export function createDomRangeP1<TBase extends Constructor<RangeP2 & RangeBase>>

// in rangy1, this method is implement in wrappedselection.js
// TODO declare in RangeP1Ex
select(direction?) {
select(this: RangyRangeEx, direction?): void {
getSelection( this.getDocument() ).setSingleRange(this, direction);
}
}
Expand Down
28 changes: 10 additions & 18 deletions src/core/internal/domrange/part2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,6 @@ function createDomRangeP2<TBase extends Constructor<RangeBase>>(Base: TBase, bou

/*----------------------------------------------------------------------------------------------------------------*/

/** TODO remove comment
* @requires call `Object.assign(R, comparisonConstants)` after call this function:
* `class R extends createPrototypeRange(..`
* or
* `const R = createPrototypeRange(..`
*/
export function createPrototypeRange<T extends RangeBase, TBase extends Constructor<T>>(
Base: TBase, boundaryUpdater: BoundaryUpdater
): Constructor<RangyRangeEx & T> & TBase & ComparisonConstants {
Expand All @@ -375,25 +369,23 @@ export function createPrototypeRange<T extends RangeBase, TBase extends Construc
return Object.assign(R12, comparisonConstants);
}

// TODO remove comment
// we need this const to bypass TS2506: 'DomRange' is referenced directly or indirectly in it own base expression
// export const _DomRange = createPrototypeRange(RangeBase, updateBoundaries);
// export type DomRange = InstanceType<typeof DomRange>;
export class DomRange extends createPrototypeRange(DomRangeBase, updateBoundaries) {
static inspect = rangeInspect;
static toHtml = rangeToHtml;
static getRangeDocument = getRangeDocument;
static rangesEqual = rangesEqual;
static rangeProperties = rangeProperties;
/** @deprecated use rangy.RangeIterator (umd) or better directly:
* `import {RangeIterator} from "rangy2"` */
static RangeIterator = RangeIterator;
/** @deprecated please replace by:
* `class C extends createPrototypeRange(..){..} Object.assign(C, comparisonConstants)` */
static copyComparisonConstants = copyComparisonConstants;
/** @deprecated use rangy.createPrototypeRange (umd) or better directly:
* `import {createPrototypeRange} from "rangy2"` */
static createPrototypeRange = createPrototypeRange;
}

// @deprecated pls directly import & use the exported member of this module
Object.assign(DomRange, {
rangeProperties,
RangeIterator,
copyComparisonConstants,
createPrototypeRange,
});

export function createRangyRange(doc?) {
doc = getContentDocument(doc, module, "createRangyRange");
return new DomRange(doc);
Expand Down
3 changes: 2 additions & 1 deletion src/core/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export {
getNativeSelection,
isSelectionValid,
getSelection,
Selection,
WrappedSelection,
WrappedSelection as Selection, //alias
RangeIterator,
shimGetSelection
} from "./_";
4 changes: 2 additions & 2 deletions src/core/internal/wrappedrange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export class WrappedRange extends createPrototypeRange(RangeBase, updateNativeRa
updateRangeProperties(this);
};

private static createBeforeAfterNodeSetter(name) {
return function(node) {
private static createBeforeAfterNodeSetter(name: string) {
return function(node: Node): void {
this.nativeRange[name](node);
updateRangeProperties(this);
};
Expand Down
Loading

0 comments on commit 8399c46

Please sign in to comment.