Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
giabao committed Apr 22, 2019
1 parent 733405c commit 4bf1c5d
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"main": "./bundles/index.umd.js",
"module": "./esm5/index.js",
"es2015": "./esm2015/index.js",
"typings": "./types/index.d.ts",
"typings": "./types/types.d.ts",
"dependencies": {
"core-js": "^3.0.1",
"tslib": "^1.9.3"
Expand Down
8 changes: 6 additions & 2 deletions scripts/tsc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {writeFileSync} from "fs";
import {writeFileSync, copyFileSync} from "fs";
import {resolve} from "path";
import {srcDir, modules} from "./util";
import {srcDir, modules, distDir} from "./util";
import {spawnSync} from "child_process";

function writeTsConfig(name: string, es: boolean) {
Expand Down Expand Up @@ -47,6 +47,10 @@ function main() {
const success = tsc(es);
if (!success) break;
}

modules.forEach(m => {
copyFileSync(resolve(srcDir, m, 'types.d.ts'), resolve(distDir, m, 'types/types.d.ts'));
});
}

// usage: node [options] scripts/tsc.js [tsc arguments]
Expand Down
2 changes: 1 addition & 1 deletion scripts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {join, resolve} from "path";
import {readdirSync, statSync} from "fs";

export const projectRoot = resolve(__dirname, '..');

export const srcDir = resolve(projectRoot, 'src');
export const distDir = resolve(projectRoot, 'dist');

//['core', 'classapplier',..]
export const modules = readdirSync(srcDir)
Expand Down
14 changes: 14 additions & 0 deletions src/classapplier/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// this file will be copy to dist/<module>/index.d.ts when running scripts/tsc.ts
import * as rangy from "rangy2";
export * from "./index";
import * as m from "./index";

declare module "rangy2" {
type ClassApplier = m.ClassApplier;
const ClassApplier: typeof m.ClassApplier;

type CssClassApplier = m.ClassApplier;
const CssClassApplier: typeof m.ClassApplier;

const createClassApplier: typeof m.createClassApplier;
}
6 changes: 0 additions & 6 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@ export function shim(win?) {
shimCreateRange(win);
shimGetSelection(win);
}

import * as Rangy from ".";
export type RangyStatic = typeof Rangy;
declare global {
const rangy: RangyStatic;
}
4 changes: 4 additions & 0 deletions src/core/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// this file will be copy to dist/<module>/index.d.ts when running scripts/tsc.ts
export * from "./index";

export as namespace rangy;
3 changes: 2 additions & 1 deletion src/highlighter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
import * as api from "rangy2";
import {WrappedRange, WrappedSelection, dom, RangyRangeEx} from "rangy2";
import {ClassApplier} from "../classapplier";
const getBody = dom.getBody;

// const module = new Module("Highlighter", ["ClassApplier"]);
Expand Down Expand Up @@ -245,7 +246,7 @@ export class Highlighter {
this.doc = doc || document;
this.converter = getConverter(type);
}
addClassApplier(classApplier) {
addClassApplier(classApplier: ClassApplier) {
this.classAppliers[classApplier.className] = classApplier;
}

Expand Down
11 changes: 11 additions & 0 deletions src/highlighter/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// this file will be copy to dist/<module>/index.d.ts when running scripts/tsc.ts
import * as rangy from "rangy2";
export * from "./index";
import * as m from "./index";

declare module "rangy2" {
const registerHighlighterType: typeof m.registerHighlighterType;
const createHighlighter: typeof m.createHighlighter;
type Highlighter = m.Highlighter;
const Highlighter: typeof m.Highlighter;
}
14 changes: 14 additions & 0 deletions src/selectionsaverestore/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as rangy from "rangy2";
export * from "./index";
import * as m from "./index";

declare module "rangy2" {
const saveRange: typeof m.saveRange;
const restoreRange: typeof m.restoreRange;
const saveRanges: typeof m.saveRanges;
const saveSelection: typeof m.saveSelection;
const restoreRanges: typeof m.restoreRanges;
const restoreSelection: typeof m.restoreSelection;
const removeMarkerElement: typeof m.removeMarkerElement;
const removeMarkers: typeof m.removeMarkers;
}
19 changes: 19 additions & 0 deletions src/serializer/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// this file will be copy to dist/<module>/index.d.ts when running scripts/tsc.ts
import * as rangy from "rangy2";
export * from "./index";
import * as m from "./index";

declare module "rangy2" {
const nodeToInfoString: typeof m.nodeToInfoString;
const getElementChecksum: typeof m.getElementChecksum;
const serializePosition: typeof m.serializePosition;
const deserializePosition: typeof m.deserializePosition;
const serializeRange: typeof m.serializeRange;
const deserializeRange: typeof m.deserializeRange;
const canDeserializeRange: typeof m.canDeserializeRange;
const serializeSelection: typeof m.serializeSelection;
const deserializeSelection: typeof m.deserializeSelection;
const canDeserializeSelection: typeof m.canDeserializeSelection;
const restoreSelectionFromCookie: typeof m.restoreSelectionFromCookie;
const saveSelectionCookie: typeof m.saveSelectionCookie;
}
7 changes: 7 additions & 0 deletions src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,10 @@ export function selectNodeContents(node) {
}

// TODO: simple selection save/restore

// // for d.ts typescript export purpose only
// import * as _rangy from ".";
// declare global {
// type RangyUtilModule = typeof _rangy;
// interface Rangy extends RangyUtilModule{}
// }
7 changes: 7 additions & 0 deletions src/util/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// this file will be copy to dist/<module>/index.d.ts when running scripts/tsc.ts
import * as rangy from "rangy2";
export * from "./index";
import * as m from "./index";

declare module "rangy2" {
}
2 changes: 2 additions & 0 deletions test/core/dom.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as rangy from "rangy2";

QUnit.module("Range");

function createTestNodes(parentNode, limit, copies) {
Expand Down
1 change: 1 addition & 0 deletions test/core/feature.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as rangy from "rangy2";
import Bowser from "bowser";

const browser = Bowser.getParser(window.navigator.userAgent);
Expand Down
4 changes: 2 additions & 2 deletions test/core/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="dom.test.js"></script>
<script src="range.test.js"></script>
<!--<script src="dom.test.js"></script>-->
<!--<script src="range.test.js"></script>-->
<script src="selection.test.js"></script>
<!-- Next line for Acid3 tests -->
<script type="text/javascript">document.write('<iframe src="empty.html" id="selectors"><\/iframe>');</script>
Expand Down
1 change: 1 addition & 0 deletions test/core/range.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as rangy from "rangy2";
import {DomRange, RangyRange, DOMException, WrappedRange} from "rangy2";

import "../qunit-ex";
Expand Down
9 changes: 9 additions & 0 deletions test/core/selection.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as rangy from "rangy2";
import {RangyRangeEx, WrappedSelection} from "rangy2";

var hasNativeGetSelection = "getSelection" in window;
Expand Down Expand Up @@ -587,6 +588,7 @@ function testSelectionAndRangeCreators(wins, winName,
t.assertFalse(sel.refresh(true));

sel.nativeSelection.selectAllChildren(nodes.div);
t.equal(iframeWin.length, 1);
t.assertTrue(sel.refresh(true));
t.assertFalse(sel.refresh(true));

Expand Down Expand Up @@ -778,6 +780,13 @@ QUnit.module("getIframeSelection test");
});

var iframeEl;
/*
window.addEventListener("load", function() {
// Do it in an iframe
iframeEl = document.getElementById("selectors");
iframeWin[0] = iframeEl.contentWindow;
});
*/
window.addEventListener("load", function() {
// Do it in an iframe
iframeEl = document.body.appendChild(document.createElement("iframe"));
Expand Down
23 changes: 14 additions & 9 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@
"stripInternal": true,
"baseUrl": ".",
"paths": {
"rangy2": ["../src/core"],
"rangy-classapplier": ["../src/classapplier"],
"rangy-highlighter": ["../src/highlighter"],
"rangy-selectionsaverestore": ["../src/selectionsaverestore"],
"rangy-serializer": ["../src/serializer"],
"rangy-util": ["../src/util"]
"rangy2": ["../dist/core"],
"rangy-classapplier": ["../dist/classapplier"],
"rangy-highlighter": ["../dist/highlighter"],
"rangy-selectionsaverestore": ["../dist/selectionsaverestore"],
"rangy-serializer": ["../dist/serializer"],
"rangy-util": ["../dist/util"]
}
},
"references": [
{ "path": "../src" }
]
// "references": [
// { "path": "../src/core"},
// { "path": "../src/classapplier"},
// { "path": "../src/highlighter"},
// { "path": "../src/selectionsaverestore"},
// { "path": "../src/serializer"},
// { "path": "../src/util"}
// ]
// "include": ["./**/*.ts"]
}

0 comments on commit 4bf1c5d

Please sign in to comment.