Skip to content

Commit

Permalink
fix clean build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
giabao committed Apr 19, 2019
1 parent 6ea692d commit 0181b41
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 45 deletions.
48 changes: 36 additions & 12 deletions src/core/api.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
const UNDEF = "undefined";

// // TODO remove
// // Ensure rangy.rangePrototype and rangy.selectionPrototype are available immediately
// export class RangePrototype {}
// class SelectionPrototype {}

export const version = "%%build:version%%";
export const isBrowser = typeof window != UNDEF && typeof document != UNDEF;
if (!isBrowser) {
console.log("Rangy can only run in a browser");
}
export const features = {
implementsDomRange: true, // always support
implementsTextRange: false, // dont support IE < 9
htmlParsingConforms: true, // don't support IE 6, 7, Pre-Blink Opera
// Test for IE's crash (IE 6/7) or exception (IE >= 8) when a reference to garbage-collected text node is queried
// rangy2 don't support IE < 9. I have tested in browserstack.com with updated IE => not crash
export interface Features {
/** @deprecated always support */
implementsDomRange: true;
/** @deprecated always dont support IE < 9 */
implementsTextRange: false;
/** @deprecated always don't support IE 6, 7, Pre-Blink Opera */
htmlParsingConforms: true;
/** @deprecated
* Test for IE's crash (IE 6/7) or exception (IE >= 8) when a reference to garbage-collected text node is queried
* rangy2 don't support IE < 9. I have tested in browserstack.com with updated IE => not crash */
crashyTextNodes: false;
/** Always use window.getSelection */
implementsWinGetSelection: true;
/** document.selection should only be used for IE < 9 which rangy2 don't support */
implementsDocSelection: false;
selectionHasAnchorAndFocus?: boolean;
selectionHasExtend?: boolean;
selectionHasRangeCount?: boolean;
selectionSupportsMultipleRanges: false;
implementsControlRange: false;
}
export const features: Features = {
implementsDomRange: true,
implementsTextRange: false,
htmlParsingConforms: true,
crashyTextNodes: false,
implementsWinGetSelection: true,
implementsDocSelection: false,
selectionSupportsMultipleRanges: false,
implementsControlRange: false,
};
export const config = {
/** @deprecated all configs is const! */
export interface Config {
preferTextRange: false;
checkSelectionRanges: true;
}
/** @deprecated all configs is const! */
export const config: Config = {
preferTextRange: false,
checkSelectionRanges: true,
};
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 @@ -2,6 +2,7 @@ export {
rangeProperties,
RangeBase,
RangyRange,
RangyRangeEx,
rangesEqual,
getRangeDocument,
createPrototypeRange,
Expand Down
2 changes: 2 additions & 0 deletions src/core/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export {
// from ./domrange
RangeBase,
RangyRange,
RangyRangeEx,
rangesEqual,
getRangeDocument,
createPrototypeRange,
Expand All @@ -17,5 +18,6 @@ export {
isSelectionValid,
getSelection,
Selection,
WrappedSelection,
shimGetSelection
} from "./_";
45 changes: 16 additions & 29 deletions src/core/internal/wrappedselection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as util from "../util";
import {Constructor, isHostMethod} from "../util";

import * as dom from "../dom";
import {DomPosition, getDocument, getBody} from "../dom";
import {DomPosition, getDocument} from "../dom";

import {
DomRange, RangeBase, rangesEqual,
Expand All @@ -20,8 +20,6 @@ const module = new Module("WrappedSelection", ["DomRange", "WrappedRange"]);
// This module creates a selection object wrapper that conforms as closely as possible to the Selection specification
// in the HTML Editing spec (http://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#selections)
// /* build:replaceWith(api) */rangy/* build:replaceEnd */.createCoreModule("WrappedSelection", ["DomRange", "WrappedRange"], function(api, module) {
config.checkSelectionRanges = true;

var BOOLEAN = "boolean";
var NUMBER = "number";
var log = log4javascript.getLogger("rangy.WrappedSelection");
Expand Down Expand Up @@ -63,11 +61,6 @@ export function isSelectionValid() {
return true;
}

// features. Always use window.getSelection
const implementsWinGetSelection = true;
//features. document.selection should only be used for IE < 9 which rangy2 don't support
const implementsDocSelection = false;

var testSelection = getNativeSelection();

// In Firefox, the selection is null in an iframe with display: none. See issue #138.
Expand All @@ -77,23 +70,21 @@ const implementsDocSelection = false;
}

var testRange = createNativeRange(document);
var body = getBody(document);

// Obtaining a range from a selection
//features
const selectionHasAnchorAndFocus = util.areHostProperties(testSelection,
["anchorNode", "focusNode", "anchorOffset", "focusOffset"]);
const selectionHasAnchorAndFocus =
features.selectionHasAnchorAndFocus =
util.areHostProperties(testSelection, ["anchorNode", "focusNode", "anchorOffset", "focusOffset"]);

// Test for existence of native selection extend() method
//features
export const selectionHasExtend = isHostMethod(testSelection, "extend");
const selectionHasExtend =
features.selectionHasExtend =
isHostMethod(testSelection, "extend");

// Test if rangeCount exists
//features
const selectionHasRangeCount = (typeof testSelection.rangeCount == NUMBER);

//features
const selectionSupportsMultipleRanges = false;
const selectionHasRangeCount =
features.selectionHasRangeCount =
(typeof testSelection.rangeCount == NUMBER);

const addRangeBackwardToNative = selectionHasExtend
? function(nativeSelection, range) {
Expand All @@ -105,10 +96,6 @@ const addRangeBackwardToNative = selectionHasExtend
}
: null;

// ControlRanges
//features
const implementsControlRange = false;

// Selection collapsedness
let selectionIsCollapsed =
selectionHasAnchorAndFocus
Expand Down Expand Up @@ -279,7 +266,7 @@ export class WrappedSelBase {
readonly anchorOffset: number;
isCollapsed: boolean;

constructor(public nativeSelection: Selection, public win) {
constructor(public nativeSelection: Selection, public win: Window) {
//@deprecated the old rangy2 constructor form: (nativeSelection, docSelection: null, win)
if (arguments.length == 3) {
this.win = arguments[2];
Expand All @@ -288,6 +275,7 @@ export class WrappedSelBase {
}
}

// TODO
function createWrappedSelection<TBase extends Constructor<WrappedSelBase>>(Base: TBase) {
function addRangeBackward(sel, range) {
addRangeBackwardToNative(sel.nativeSelection, range);
Expand All @@ -299,7 +287,7 @@ function createWrappedSelection<TBase extends Constructor<WrappedSelBase>>(Base:
addRangeBackward(this, range);
} else {
var previousRangeCount;
if (selectionSupportsMultipleRanges) {
if (features.selectionSupportsMultipleRanges) {
previousRangeCount = this.rangeCount;
} else {
this.removeAllRanges();
Expand Down Expand Up @@ -647,12 +635,11 @@ function createWrappedSelection<TBase extends Constructor<WrappedSelBase>>(Base:
}
}

const WrappedSelection = createWrappedSelection(WrappedSelBase);
// export type WrappedSelection = InstanceType<typeof WrappedSelection>;
// export interface WrappedSelection extends InstanceType<typeof WrappedSelection>{};
export const WrappedSelection = createWrappedSelection(WrappedSelBase);
export interface WrappedSelection extends InstanceType<typeof WrappedSelection>{}
//alias
export const Selection = WrappedSelection;
export interface Selection extends InstanceType<typeof WrappedSelection>{};
export interface Selection extends WrappedSelection{}

export function shimGetSelection(win?) {
if(!win) win = window;
Expand Down
4 changes: 2 additions & 2 deletions src/highlighter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Build date: %%build:date%%
*/
import * as api from "rangy2";
import {WrappedRange, WrappedSelection, dom} from "rangy2";
import {WrappedRange, WrappedSelection, dom, RangyRangeEx} from "rangy2";
const getBody = dom.getBody;

// const module = new Module("Highlighter", ["ClassApplier"]);
Expand All @@ -35,7 +35,7 @@ type ConverterCreator = () => Converter;
interface Converter {
type?: string;

rangeToCharacterRange(range: RangyRange, containerNode?: Node): CharacterRange;
rangeToCharacterRange(range: RangyRangeEx, containerNode?: Node): CharacterRange;

characterRangeToRange(doc: Document | Window | HTMLIFrameElement,
characterRange: CharacterRange,
Expand Down
4 changes: 2 additions & 2 deletions src/selectionsaverestore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import * as api from "rangy2";
import {Module, dom, selectionHasExtend} from "rangy2";
import {Module, dom, features} from "rangy2";

const removeNode = dom.removeNode;

Expand Down Expand Up @@ -194,7 +194,7 @@ export function restoreSelection(savedSelection, preserveDirection) {
var sel = api.getSelection(savedSelection.win);
var ranges = restoreRanges(rangeInfos), rangeCount = rangeInfos.length;

if (rangeCount == 1 && preserveDirection && selectionHasExtend && rangeInfos[0].backward) {
if (rangeCount == 1 && preserveDirection && features.selectionHasExtend && rangeInfos[0].backward) {
sel.removeAllRanges();
sel.addRange(ranges[0], true);
} else {
Expand Down

0 comments on commit 0181b41

Please sign in to comment.