diff --git a/build.gradle b/build.gradle --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,8 @@ typescript { jsx = "react" jsxFactory = "createElement" moduleResolution = "node" + // dojo-typings are sick + skipLibCheck = true // traceResolution = true // baseUrl = "./" // paths = [ "*": [ "$projectDir/src/typings/*" ] ] @@ -30,7 +32,7 @@ typescript { configureTsMain { compilerOptions { - types = ["requirejs"] + types = ["requirejs", "dojo-typings"] } } diff --git a/license b/license new file mode 100644 --- /dev/null +++ b/license @@ -0,0 +1,22 @@ +Copyright 2017-2019 Implab team + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json --- a/package-lock.json +++ b/package-lock.json @@ -45,14 +45,6 @@ "integrity": "sha512-f5dXGzOJycyzSMdaXVhiBhauL4dYydXwVpavfQ1mVCaGjR56a9QfklXObUxlIY9bGTmCPHEEZ04I16BZ/8w5ww==", "dev": true }, - "@types/dijit": { - "version": "file:src/typings/dijit", - "dev": true - }, - "@types/dojo": { - "version": "file:src/typings/dojo", - "dev": true - }, "@types/requirejs": { "version": "2.1.31", "resolved": "https://registry.npmjs.org/@types/requirejs/-/requirejs-2.1.31.tgz", @@ -307,6 +299,15 @@ "integrity": "sha512-DUiXyoLK6vMF5BPr/qiMLTxDMfiM9qlzN1jxfDsVfuvB/CwhYpNxA/M4mbqKN8PCVGLmccXBJbfmFJPP5+zmzw==", "dev": true }, + "dojo-typings": { + "version": "1.11.9", + "resolved": "https://registry.npmjs.org/dojo-typings/-/dojo-typings-1.11.9.tgz", + "integrity": "sha512-mh8w+Mau2Y1QfTEszEAdO7j6ycNhYxF/Ing6nAk1eUg6NxjeT0viVHjICMd9sU3U463vM2G+KfBBK5grk3/Mlw==", + "dev": true, + "requires": { + "@types/chai": "^4.0.4" + } + }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", diff --git a/package.json b/package.json --- a/package.json +++ b/package.json @@ -8,7 +8,12 @@ "typescript", "widgets" ], - "repository": "", + "author": "Implab team", + "license": "BSD-2-Clause", + "repository": "https://hg.code.sf.net/p/implabjs/djx", + "publishConfig": { + "access": "public" + }, "peerDependencies": { "dojo": "1.16.0", "@implab/core-amd": "^1.3.2" @@ -24,7 +29,6 @@ "@types/yaml": "1.2.0", "chai": "4.2.0", "@types/chai": "4.1.3", - "@types/dojo": "./src/typings/dojo", - "@types/dijit": "./src/typings/dijit" + "dojo-typings": "~1.11.9" } } diff --git a/readme.md b/readme.md new file mode 100644 --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +# @implab/djx + +TODO \ No newline at end of file diff --git a/src/main/ts/declare.ts b/src/main/ts/declare.ts --- a/src/main/ts/declare.ts +++ b/src/main/ts/declare.ts @@ -1,7 +1,9 @@ import declare = require("dojo/_base/declare"); import { each } from "@implab/core-amd/safe"; import { Constructor } from "@implab/core-amd/interfaces"; -import { DeclareConstructor } from "dojo/_base/declare"; +// import { DeclareConstructor } from "dojo/_base/declare"; + +type DeclareConstructor = dojo._base.DeclareConstructor; export interface AbstractConstructor { prototype: T; diff --git a/src/main/ts/djx.ts b/src/main/ts/djx.ts new file mode 100644 --- /dev/null +++ b/src/main/ts/djx.ts @@ -0,0 +1,33 @@ +import { Constructor } from "@implab/core-amd/interfaces"; +import { HtmlElementContext } from "./djx/HtmlElementContext"; +import { WidgetContext } from "./djx/WidgetContext"; +import { isWidgetConstructor, BuildContext } from "./djx/traits"; + +export function createElement(elementType: string | T, ...args: any[]): BuildContext { + if (typeof elementType === "string") { + const ctx = new HtmlElementContext(elementType); + if (args) + args.forEach(x => ctx.visitNext(x)); + + return ctx; + } else if (isWidgetConstructor(elementType)) { + const ctx = new WidgetContext(elementType); + if (args) + args.forEach(x => ctx.visitNext(x)); + + return ctx; + } else { + throw new Error(`The element type '${elementType}' is unsupported`); + } +} + +export interface EventDetails { + detail: T; +} + +export interface EventSelector { + selectorTarget: HTMLElement; + target: HTMLElement; +} + +export type DojoMouseEvent = MouseEvent & EventSelector & EventDetails; diff --git a/src/main/ts/djx/DjxWidgetBase.ts b/src/main/ts/djx/DjxWidgetBase.ts --- a/src/main/ts/djx/DjxWidgetBase.ts +++ b/src/main/ts/djx/DjxWidgetBase.ts @@ -3,7 +3,8 @@ import _WidgetBase = require("dijit/_Wid import _AttachMixin = require("dijit/_AttachMixin"); import { BuildContext, isNode } from "./traits"; import registry = require("dijit/registry"); -import { Handle } from "dojo/interfaces"; +// import { Handle } from "dojo/interfaces"; +type Handle = dojo.Handle; @djclass export abstract class DjxWidgetBase extends djbase(_WidgetBase, _AttachMixin) { diff --git a/src/main/ts/djx/traits.ts b/src/main/ts/djx/traits.ts --- a/src/main/ts/djx/traits.ts +++ b/src/main/ts/djx/traits.ts @@ -1,5 +1,7 @@ import _WidgetBase = require("dijit/_WidgetBase"); -import { _WidgetBaseConstructor } from "dijit/_WidgetBase"; + +type _WidgetBaseConstructor = typeof _WidgetBase; + export interface BuildContext { getDomElement(): HTMLElement; diff --git a/src/main/tsconfig.json b/src/main/tsconfig.json --- a/src/main/tsconfig.json +++ b/src/main/tsconfig.json @@ -3,7 +3,7 @@ "compilerOptions": { "rootDir": "ts", "types": [ - "requirejs" + "requirejs", "dojo-typings" ] } } \ No newline at end of file diff --git a/src/tsconfig.json b/src/tsconfig.json --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -6,6 +6,7 @@ "types": [], "experimentalDecorators": true, "jsxFactory": "createElement", + "skipLibCheck": true, "jsx": "react", "lib": ["es5", "es2015.promise", "es2015.symbol", "es2015.iterable", "dom", "scripthost"] }