diff --git a/README.md b/README.md index d3e6c0e27c..ab2080714b 100644 --- a/README.md +++ b/README.md @@ -55,18 +55,23 @@ Before you share your improvement with the world, use it yourself. #### Test editing an exiting package To add new features you can use [module augmentation](http://www.typescriptlang.org/docs/handbook/declaration-merging.html). -You can also directly edit the types in `node_modules/@types/foo/index.d.ts`, -or copy them from there and paste inside of `declarations.d.ts` and follow the steps below. +You can also directly edit the types in `node_modules/@types/foo/index.d.ts`, or copy them from there and follow the steps below. #### Test a new package -* Add a new file `declarations.d.ts` to your project. -* Add it to the compilation, through `"includes"` or `"files"` in your [tsconfig](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html), -or through a `/// ` declaration in your code. -* Inside `declarations.d.ts`, write `declare module "foo" { }`, then write the module declaration inside. -* Test that your code works. -* *Then*, once you've tested your definitions, make a PR contributing the definition. +Add to your `tsconfig.json`: + +```json +"baseUrl": "types", +"typeRoots": ["types"], +``` + +(You can also use `src/types`.) +Create `types/foo/index.d.ts` containing declarations for the module "foo". +You should now be able import from `"foo"` in your code and it will route to the new type definition. +Then build *and* run the code to make sure your type definition actually corresponds to what happens at runtime. +Once you've tested your definitions with real code, make a PR contributing the definition by copying `types/foo` to `DefinitelyTyped/foo` and adding a `tsconfig.json` and `foo-tests.ts`. ### Make a pull request diff --git a/math3d/math3d.d.ts b/math3d/math3d.d.ts new file mode 100644 index 0000000000..4d89db48ac --- /dev/null +++ b/math3d/math3d.d.ts @@ -0,0 +1,170 @@ +// Type definitions for math3.d.ts +// Project: https://github.com/adragonite/math3d +// Definitions by: Laszlo Jakab +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "math3d" { + export class Vector3 { + constructor(x?: number, y?: number, z?: number); + + public static back: Vector3; + public static down: Vector3; + public static forward: Vector3; + public static left: Vector3; + public static one: Vector3; + public static right: Vector3; + public static up: Vector3; + public static zero: Vector3; + public static dimension: number; + public static FromVector4: (vector4: Vector4) => Vector3; + + public homogeneous: Vector4; + public magnitude: number; + public values: number[]; + public vector4: Vector4; + public x: number; + public y: number; + public z: number; + + public add(vector3: Vector3): Vector3; + public average(vector3: Vector3): Vector3; + public cross(vector3: Vector3): Vector3; + public distanceTo(vector3: Vector3): number; + public dot(vector3: Vector3): number; + public equals(vector3: Vector3): boolean; + public mulScalar(scalar: Number): Vector3; + public negate(): Vector3; + public normalize(): Vector3; + public scale(vector3: Vector3): Vector3; + public sub(vector3: Vector3): Vector3; + public toString(): string; + } + + export class Vector4 { + constructor(x?: number, y?: number, z?: number, w?: number); + + public static one: Vector4; + public static zero: Vector4; + public static dimension: number; + + public magnitude: number; + public values: number[]; + public x: number; + public y: number; + public z: number; + public w: number; + + public add(vector4: Vector4): Vector4; + public distanceTo(vector4: Vector4): number; + public dot(vector4: Vector4): number; + public equals(vector4: Vector4): boolean; + public mulScalar(scalar: Number): Vector4; + public negate(): Vector4; + public normalize(): Vector3; + public sub(vector4: Vector4): Vector3; + public toString(): string; + } + + export class Quaternion { + constructor(x?: number, y?: number, z?: number, w?: number); + public static Euler(x?: number, y?: number, z?: number): Quaternion; + public static AngleAxis(axis: Vector3, angle: number): Quaternion; + + public static identity: Quaternion; + public static zero: Quaternion; + + public angleAxis: { axis: Vector3, angle: number }; + public eulerAngles: { x: number, y: number, z: number }; + public x: number; + public y: number; + public z: number; + public w: number; + + public angleTo(quaternion: Quaternion): number; + public conjugate(): Quaternion; + public distanceTo(quaternion: Quaternion): number; + public dot(quaternion: Quaternion): number; + public equals(quaternion: Quaternion): boolean; + public inverse(): Quaternion; + public mul(quaternion: Quaternion): Quaternion; + public mulVector3(vector3: Vector3): Vector3; + public toString(): string; + } + + export class Matrix4x4 { + constructor(data: number[]); + + public static FlipMatrix(flipX: boolean, flipY: boolean, flipZ: boolean): Matrix4x4; + public static ScaleMatrix(scale: number | Vector3): Matrix4x4; + public static RotationMatrix(quaternion: Quaternion): Matrix4x4; + public static TranslationMatrix(translation: Vector3): Matrix4x4; + public static TRS(translation: Vector3, rotation: Quaternion, scale: number | Vector3): Matrix4x4; + public static LocalToWorldMatrix(position: Vector3, rotation: Quaternion, scale: number | Vector3): Matrix4x4; + public static WorldToLocalMatrix(position: Vector3, rotation: Quaternion, scale: number | Vector3): Matrix4x4; + + public static identity: Matrix4x4; + public static zero: Matrix4x4; + + public columns: number[][]; + public m11: number; + public m12: number; + public m13: number; + public m14: number; + public m21: number; + public m22: number; + public m23: number; + public m24: number; + public m31: number; + public m32: number; + public m33: number; + public m34: number; + public m41: number; + public m42: number; + public m43: number; + public m44: number; + public rows: number[][]; + public size: { rows: number, columns: number }; + public values: number[]; + + public determinant(): number + public inverse(): Matrix4x4; + public negate(): Matrix4x4; + public transpose(): Matrix4x4; + public add(matrix4x4: Matrix4x4): Matrix4x4; + public sub(matrix4x4: Matrix4x4): Matrix4x4; + public mul(matrix4x4: Matrix4x4): Matrix4x4; + public mulScalar(scalar: Number): Matrix4x4; + public mulVector3(vector3: Vector3): Vector3; + } + + export class Transform { + constructor(position?: Vector3, rotation?: Quaternion); + + public forward: Vector3; + public localPosition: Vector3; + public localRotation: Quaternion; + public localToWorldMatrix: Matrix4x4; + public name: string; + public parent: Transform; + public position: Vector3; + public right: Vector3; + public root: Transform; + public rotation: Vector3; + public up: Vector3; + public worldToLocalMatrix: Matrix4x4; + + public addChild(child: Transform): void; + public inverseTransformPosition(position: Vector3): Vector3; + public removeChild(child: Transform): void; + public transformPosition(position: Vector3): Vector3; + public translate(translation: Vector3, relativeTo?: Transform.Space): Transform; + public rotate(x: number, y: number, z: number, relativeTo?: Transform.Space): Transform; + } + + export module Transform { + export enum Space { + Self, + World + } + } +} diff --git a/plugapi/plugapi-tests.ts b/plugapi/plugapi-tests.ts new file mode 100644 index 0000000000..279a5b659d --- /dev/null +++ b/plugapi/plugapi-tests.ts @@ -0,0 +1,35 @@ +/// + +import * as PlugAPI from "plugapi"; + +new PlugAPI({ + email: "", + password: "" +}, function (err, bot) { + if (!err) { + const ROOM = "roomslug"; + bot.connect(ROOM); // The part after https://plug.dj + + bot.on(PlugAPI.events.ROOM_JOIN, function (room) { + console.log("Joined " + room); + }); + + bot.on("chat", function (data) { + if (data.type == "emote") { + console.log(data.from + data.message); + } else { + console.log(data.from + "> " + data.message); + } + }); + + bot.on("error", function () { + bot.connect(ROOM); + }); + + bot.deleteAllChat = false; + bot.multiLine = true; + bot.multiLineLimit = 5; + } else { + console.log("Error initializing plugAPI: " + err); + } +}); \ No newline at end of file diff --git a/plugapi/plugapi.d.ts b/plugapi/plugapi.d.ts new file mode 100644 index 0000000000..90351ac53a --- /dev/null +++ b/plugapi/plugapi.d.ts @@ -0,0 +1,420 @@ +// Type definitions for plugapi +// Project: https://www.npmjs.com/package/plugapi +// Definitions by: Brice Theurillat +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "plugapi" { + interface PlugLogin { + email: string; + password: string; + } + + interface Notification { + action: string; + id: number; + timestamp: string; + value: string; + } + + interface RawChatMessage { + cid: string; + message: string; + sub: number; + uid: number; + un: string; + } + + interface Media { + author: string; + format: number; + image: string; + cid: string; + duration: number; + title: string; + id: number; + } + + interface Score { + positive: number; + listeners: number; + grabs: number; + negative: number; + skipped: number; + } + + interface LastPlay { + dj: User.DJ; + media: Media; + score: Score; + } + + interface FollowJoinData { + r: number; + un: string; + id: string; + } + + interface LogObject { + log: () => void; + } + + namespace User { + interface Default { + username: string; + language: string; + avatarID: string; + } + + interface Extended extends Default { + status: number; + fans: number; + listenerPoints: number; + id: string; + curatorPoints: number; + djPoints: number; + } + + interface Update extends Extended { + dateJoined: string; + } + + interface Room extends Default { + sub: number; + level: number; + joined: string; + id: number; + badge: string; + role: number; + gRole: number; + slug: string; + } + + interface User extends Room { + silver: boolean; + guest: boolean; + } + + interface DJ extends Room { + blurp: any; + grab: boolean; + status: number; + vote: number; + } + + interface Audience extends DJ { + ignores: any[]; + notifications: Notification[]; + pp: number; + pw: number; + xp: number; + } + } + + namespace Enum { + interface RoomRole { + NONE: number; + RESIDENTDJ: number; + BOUNCER: number; + MANAGER: number; + COHOST: number; + HOST: number; + } + + interface GlobalRole { + NONE: number; + VOLUNTEER: number; + AMBASSADOR: number; + LEADER: number; + ADMIN: number; + } + + interface Status { + OFFLINE: number; + ONLINE: number; + } + + interface Ban { + HOUR: "h"; + DAY: "d"; + PERMA: "f"; + } + + interface BanReason { + SPAMMING_TROLLING: number; + VERBAL_ABUSE: number; + OFFENSIVE_MEDIA: number; + INAPPROPRIATE_GENRE: number; + NEGATIVE_ATTITUDE: number; + } + + interface Mute { + SHORT: "s"; + MEDIUM: "m"; + LONG: "l"; + } + + interface MuteReason { + VIOLATING_COMMUNITY_RULES: number; + VERBAL_ABUSE: number; + SPAMMING_TROLLING: number; + OFFENSIVE_LANGUAGE: number; + NEGATIVE_ATTITUDE: number; + } + + interface Events { + ADVANCE: "advance"; + BAN: "ban"; + BOOTH_LOCKED: "boothLocked"; + CHAT: "chat"; + CHAT_COMMAND: "command"; + CHAT_DELETE: "chatDelete"; + CHAT_LEVEL_UPDATE: "roomMinChatLevelUpdate"; + COMMAND: "command"; + DJ_LIST_CYCLE: "djListCycle"; + DJ_LIST_UPDATE: "djListUpdate"; + DJ_LIST_LOCKED: "djListLocked"; + EARN: "earn"; + FOLLOW_JOIN: "followJoin"; + FLOOD_CHAT: "floodChat"; + FRIEND_REQUEST: "friendRequest"; + GIFTED: "gifted"; + GRAB: "grab"; + KILL_SESSION: "killSession"; + MAINT_MODE: "plugMaintenance"; + MAINT_MODE_ALERT: "plugMaintenanceAlert"; + MODERATE_ADD_DJ: "modAddDJ"; + MODERATE_ADD_WAITLIST: "modAddWaitList"; + MODERATE_AMBASSADOR: "modAmbassador"; + MODERATE_BAN: "modBan"; + MODERATE_MOVE_DJ: "modMoveDJ"; + MODERATE_MUTE: "modMute"; + MODERATE_REMOVE_DJ: "modRemoveDJ"; + MODERATE_REMOVE_WAITLIST: "modRemoveWaitList"; + MODERATE_SKIP: "modSkip"; + MODERATE_STAFF: "modStaff"; + NOTIFY: "notify"; + PDJ_MESSAGE: "pdjMessage"; + PDJ_UPDATE: "pdjUpdate"; + PING: "ping"; + PLAYLIST_CYCLE: "playlistCycle"; + REQUEST_DURATION: "requestDuration"; + REQUEST_DURATION_RETRY: "requestDurationRetry"; + ROOM_CHANGE: "roomChanged"; + ROOM_DESCRIPTION_UPDATE: "roomDescriptionUpdate"; + ROOM_JOIN: "roomJoin"; + ROOM_NAME_UPDATE: "roomNameUpdate"; + ROOM_VOTE_SKIP: "roomVoteSkip"; + ROOM_WELCOME_UPDATE: "roomWelcomeUpdate"; + SESSION_CLOSE: "sessionClose"; + SKIP: "skip"; + STROBE_TOGGLE: "strobeToggle"; + USER_COUNTER_UPDATE: "userCounterUpdate"; + USER_FOLLOW: "userFollow"; + USER_JOIN: "userJoin"; + USER_LEAVE: "userLeave"; + USER_UPDATE: "userUpdate"; + VOTE: "vote"; + } + } + + namespace Event { + interface BoothCycle { + moderator: string; + cycle: boolean; + } + + interface BoothLocked { + m: string; + c: boolean; + ml: string; + f: boolean; + } + + interface Chat { + raw: RawChatMessage; + id: string; + from: User.User; + message: string; + mentions: Array; + muted: boolean; + type: string; + } + + interface ChatDelete { + mi: number; + chatID: string; + } + + type Grab = number; + + interface Advance { + media: Media; + startTime: string; + historyID: string; + djs: User.DJ[]; + currentDJ: User.DJ; + playlistID: number; + lastPlay: LastPlay; + } + + interface DJListUpdate { + djs: User.DJ[]; + remove: string; + } + + interface Emote { + fromID: string; + message: string; + from: string; + type: string; + chatID: string; + } + + interface FollowJoin { + data: FollowJoinData; + type: string; + } + + interface ModAddDJ { + moderator: string; + username: string; + } + + interface ModBan { + moderator: string; + username: string; + duration: number; + ref: string; + reason: string; + } + + interface ModMoveDJ { + moderator: string; + index: number; + old: number; + userID: string; + } + + interface ModRemoveDJ { + moderator: string; + username: string; + userID: string; + } + + interface ModSkip { + mi: number; + m: string; + } + + interface RoomMinChatLevelUpdate { + level: number; + id: number; + user: User.User; + } + + type RoomJoin = string; + + type UserJoin = User.User; + + type UserLeave = User.User; + + interface UserUpdate { + username: string; + status: number; + fans: number; + listenerPoints: number; + dateJoined: string; + language: string; + avatarID: string; + id: string; + curatorPoints: number; + djPoints: number; + } + + interface Vote { + i: number; + v: number; + } + + interface Command extends Event.Chat { + command: string; + args: string[]; + respond: Function; + respondTimeout: Function; + havePermission: Function; + isFrom: Function; + } + } + + interface PlugAPIInstance { + deleteAllChat: boolean; + multiLine: boolean; + multiLineLimit: number; + + connect(room: string): void; + changeDJCycle(enabled: boolean, callback?: () => void): boolean; + changeRoom(room: string, callback?: () => void): void; + close(): void; + getAdmins(): User.Extended[]; + getAmbassadors(): User.Extended[]; + getAudience(): User.Audience[]; + getDJ(): User.DJ; + getDJs(): User.DJ[]; + getHost(): User.Extended; + getMedia(): Media; + getRoomScore(): Score; + getSelf(): User.Audience; + getStaff(): User.Extended[]; + getTimeElapsed(): number; + getTimeRemaining(): number; + getUser(userID: number): User.DJ; + getUsers(): User.DJ[]; + getWaitList(): User.Extended; + getWaitListPosition(userID: number): number; + havePermission(userID: number, permission: number, global?: boolean): boolean; + joinBooth(callback?: () => void): boolean; + leaveBooth(callback?: () => void): boolean; + selfSkip(callback?: () => void): boolean; + sendChat(msg: string, timeout?: number): void; + setLogger(logObject: LogObject): boolean; + + on(event: "boothCycle", callback: (data: Event.BoothCycle) => void): void; + on(event: "boothLocked", callback: (data: Event.BoothLocked) => void): void; + on(event: "chat", callback: (data: Event.Chat) => void): void; + on(event: "chatDelete", callback: (data: Event.ChatDelete) => void): void; + on(event: "grab", callback: (data: Event.Grab) => void): void; + on(event: "advance", callback: (data: Event.Advance) => void): void; + on(event: "djListUpdate", callback: (data: Event.DJListUpdate) => void): void; + on(event: "emote", callback: (data: Event.Emote) => void): void; + on(event: "followJoin", callback: (data: Event.FollowJoin) => void): void; + on(event: "modAddDJ", callback: (data: Event.ModAddDJ) => void): void; + on(event: "modBan", callback: (data: Event.ModBan) => void): void; + on(event: "modMoveDJ", callback: (data: Event.ModMoveDJ) => void): void; + on(event: "modRemoveDJ", callback: (data: Event.ModRemoveDJ) => void): void; + on(event: "modSkip", callback: (data: Event.ModSkip) => void): void; + on(event: "roomMinChatLevelUpdate", callback: (data: Event.RoomMinChatLevelUpdate) => void): void; + on(event: "roomJoin", callback: (data: Event.RoomJoin) => void): void; + on(event: "userJoin", callback: (data: Event.UserJoin) => void): void; + on(event: "userLeave", callback: (data: Event.UserLeave) => void): void; + on(event: "userUpdate", callback: (data: Event.UserUpdate) => void): void; + on(event: "vote", callback: (data: Event.Vote) => void): void; + on(event: "command", callback: (data: Event.Command) => void): void; + on(event: string, callback: (data: any) => void): void; + } + + interface PlugAPIStatic { + new (login: PlugLogin, callback?: (error: Error, bot: PlugAPIInstance) => void): PlugAPIInstance; + new (login: PlugLogin, callback?: (bot: PlugAPIInstance) => void): PlugAPIInstance; + ROOM_ROLE: Enum.RoomRole; + GLOBAL_ROLES: Enum.GlobalRole; + STATUS: Enum.Status; + BAN: Enum.Ban; + BAN_REASON: Enum.BanReason; + MUTE: Enum.Mute; + MUTE_REASON: Enum.MuteReason; + events: Enum.Events; + } + + var PlugAPI: PlugAPIStatic; + export = PlugAPI; +} \ No newline at end of file diff --git a/random-seed/random-seed-tests.ts b/random-seed/random-seed-tests.ts new file mode 100644 index 0000000000..de49c65e45 --- /dev/null +++ b/random-seed/random-seed-tests.ts @@ -0,0 +1,18 @@ +/// +import { RandomSeed, create } from "random-seed"; + +// these generators produce different numbers +let rand1: RandomSeed = create(); // method 1 + +// these generators will produce +// the same sequence of numbers +let seed = 'My Secret String Value'; +let rand2 = create(seed); + +// API +rand1.addEntropy(); +rand1.random(); +rand1.range(100); +rand1.intBetween(0, 10); +rand1.floatBetween(0, 1); +rand1.seed("new seed"); diff --git a/random-seed/random-seed.d.ts b/random-seed/random-seed.d.ts new file mode 100644 index 0000000000..2dcb02d1e6 --- /dev/null +++ b/random-seed/random-seed.d.ts @@ -0,0 +1,28 @@ +// Type definitions for random-seed 0.3.0 +// Project: https://github.com/skratchdot/random-seed/ +// Definitions by: Endel Dreyer +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "random-seed" { + + export interface RandomSeed { + range (range: number): number; + random (): number; + floatBetween (min: number, max: number): number; + intBetween (min: number, max: number): number; + + string (count: number): string; + seed (seed: string): void; + + cleanString (inStr: string): string; + hashString (inStr: string): string; + + addEntropy (...args: any[]): void; + initState (): void; + + done (): void; + } + + export function create (seed?: string): RandomSeed; + +} diff --git a/react-dnd/react-dnd-decorator-tests.ts b/react-dnd/react-dnd-decorator-tests.ts deleted file mode 100644 index 1d7c4b8d18..0000000000 --- a/react-dnd/react-dnd-decorator-tests.ts +++ /dev/null @@ -1,313 +0,0 @@ -/// -/// -/// -"use strict"; - -// Test adapted from the ReactDnD chess game tutorial: -// http://gaearon.github.io/react-dnd/docs-tutorial.html - -import React = require("react"); -import ReactDnd = require("react-dnd"); - -var r = React.DOM; - -import DragSource = ReactDnd.DragSource; -import DropTarget = ReactDnd.DropTarget; -import DragLayer = ReactDnd.DragLayer; -import DragDropContext = ReactDnd.DragDropContext; -import HTML5Backend, { getEmptyImage, NativeTypes } from "react-dnd-html5-backend"; -import TestBackend from "react-dnd-test-backend"; - -// Game Component -// ---------------------------------------------------------------------- - -namespace Game { - var knightPosition = [0, 0]; - var observer: any = null; - - function emitChange() { - observer(knightPosition); - } - - export function observe(o: any) { - if (observer) { - throw new Error("Multiple observers not implemented."); - } - - observer = o; - emitChange(); - } - - export function moveKnight(toX: number, toY: number) { - knightPosition = [toX, toY]; - emitChange(); - } - - export function canMoveKnight(toX: number, toY: number) { - const x = knightPosition[0]; - const y = knightPosition[1]; - const dx = toX - x; - const dy = toY - y; - - return (Math.abs(dx) === 2 && Math.abs(dy) === 1) || - (Math.abs(dx) === 1 && Math.abs(dy) === 2); - } -} - -var ItemTypes = { - KNIGHT: "knight" -}; - -// Knight Component -// ---------------------------------------------------------------------- - -namespace Knight { - interface KnightP extends React.Props { - connectDragSource: ReactDnd.ConnectDragSource; - connectDragPreview: ReactDnd.ConnectDragPreview; - isDragging: boolean; - } - - var knightSource: ReactDnd.DragSourceSpec = { - beginDrag: (props) => { - return {}; - } - }; - - function knightCollect(connect: ReactDnd.DragSourceConnector, monitor: ReactDnd.DragSourceMonitor) { - return { - connectDragSource: connect.dragSource(), - connectDragPreview: connect.dragPreview(), - isDragging: monitor.isDragging() - }; - } - - @DragSource(ItemTypes.KNIGHT, knightSource, knightCollect) - export class Knight extends React.Component { - static defaultProps: KnightP; - - static create = React.createFactory(Knight); - - componentDidMount() { - var img = getEmptyImage(); - img.onload = () => this.props.connectDragPreview(img); - } - - render() { - return this.props.connectDragSource( - r.div({ - style: { - opacity: this.props.isDragging ? 0.5 : 1, - fontSize: 25, - fontWeight: 'bold', - cursor: 'move' - } - }, "♘") - ); - } - } - - export var create = React.createFactory(Knight); -} - -// Square Component -// ---------------------------------------------------------------------- - -namespace Square { - interface SquareP extends React.Props { - black: boolean; - } - - export class Square extends React.Component { - render() { - var fill = this.props.black ? 'black' : 'white'; - return r.div({ - style: { - backgroundColor: fill - } - }) - } - } - - export var create = React.createFactory(Square); -} - -// BoardSquare Component -// ---------------------------------------------------------------------- - -namespace BoardSquare { - interface BoardSquareP extends React.Props { - x: number; - y: number; - connectDropTarget?: ReactDnd.ConnectDropTarget; - isOver?: boolean; - canDrop?: boolean; - } - - var boardSquareTarget: ReactDnd.DropTargetSpec = { - canDrop: (props) => Game.canMoveKnight(props.x, props.y), - drop: (props) => Game.moveKnight(props.x, props.y) - }; - - function boardSquareCollect(connect: ReactDnd.DropTargetConnector, monitor: ReactDnd.DropTargetMonitor) { - return { - connectDropTarget: connect.dropTarget(), - isOver: monitor.isOver(), - canDrop: monitor.canDrop() - }; - } - - @DropTarget(ItemTypes.KNIGHT, boardSquareTarget, boardSquareCollect) - @DropTarget(NativeTypes.FILE, boardSquareTarget, boardSquareCollect) - export class BoardSquare extends React.Component { - static defaultProps: BoardSquareP; - - private _renderOverlay = (color: string) => { - return r.div({ - style: { - position: 'absolute', - top: 0, - left: 0, - height: '100%', - width: '100%', - zIndex: 1, - opacity: 0.5, - backgroundColor: color - } - }); - }; - - render() { - var black = (this.props.x + this.props.y) % 2 === 1; - var isOver = this.props.isOver; - var canDrop = this.props.canDrop; - - return this.props.connectDropTarget( - r.div({ - style: { - position: 'relative', - width: '100%', - height: '100%' - }, - children: [ - Square.create({ - black: black - }), - isOver && !canDrop ? this._renderOverlay('red') : null, - !isOver && canDrop ? this._renderOverlay('yellow') : null, - isOver && canDrop ? this._renderOverlay('green') : null - ] - }) - ); - } - } - - export var create = React.createFactory(BoardSquare); -} - -// Custom Drag Layer Component -// ---------------------------------------------------------------------- -namespace CustomDragLayer { - interface CustomDragLayerP extends React.Props { - isDragging?: boolean; - item?: Object; - } - - function dragLayerCollect(monitor: ReactDnd.DragLayerMonitor) { - return { - isDragging: monitor.isDragging(), - item: monitor.getItem(), - }; - } - - @DragLayer(dragLayerCollect) - export class CustomDragLayer extends React.Component { - render() { - return r.div(null, this.props.isDragging ? this.props.item : null); - } - } - - export var create = React.createFactory(CustomDragLayer); -} - -// Board Component -// ---------------------------------------------------------------------- - -namespace Board { - interface BoardP extends React.Props { - knightPosition: number[]; - } - - export class Board extends React.Component { - private _renderPiece = (x: number, y: number) => { - var knightX = this.props.knightPosition[0]; - var knightY = this.props.knightPosition[1]; - return x === knightX && y === knightY ? - Knight.create() : - null; - }; - - private _renderSquare = (i: number) => { - var x = i % 8; - var y = Math.floor(i / 8); - - return r.div({ - key: i, - style: { - width: '12.5%', - height: '12.5%' - } - }, BoardSquare.create({ - x: x, - y: y - }, this._renderPiece(x, y))); - }; - - render() { - var squares: React.ReactHTMLElement[] = []; - for (let i = 0; i < 64; i++) { - squares.push(this._renderSquare(i)); - } - - return r.div({ - children: [ - CustomDragLayer.create(), - r.div({ - style: { - width: '100%', - height: '100%', - display: 'flex', - flexWrap: 'wrap' - }, - children: squares - }) - ] - }); - } - } - - @DragDropContext(HTML5Backend) - export class BoardWithHTML5Backend extends Board { - - } - - @DragDropContext(TestBackend) - export class BoardWithTestBackend extends Board { - - } - - export var createWithHTMLBackend = React.createFactory(BoardWithHTML5Backend); - export var createWithTestBackend = React.createFactory(BoardWithTestBackend); -} - -// Render the Board Component -// ---------------------------------------------------------------------- - -Board.createWithHTMLBackend({ - knightPosition: [0, 0] -}); - - -Board.createWithTestBackend({ - knightPosition: [0, 0] -}); diff --git a/react-dnd/react-dnd.d.ts b/react-dnd/react-dnd.d.ts index 37f065ec48..000cd04ee2 100644 --- a/react-dnd/react-dnd.d.ts +++ b/react-dnd/react-dnd.d.ts @@ -11,13 +11,13 @@ declare module __ReactDnd { // Decorated React Components // ---------------------------------------------------------------------- - interface ContextComponent extends React.Component { + class ContextComponent extends React.Component { getDecoratedComponentInstance(): React.Component; // Note: getManager is not yet documented on the React DnD docs. getManager(): any; } - interface DndComponent extends React.Component { + class DndComponent extends React.Component { getDecoratedComponentInstance(): React.Component; getHandlerId(): Identifier; } @@ -40,23 +40,23 @@ declare module __ReactDnd { spec: DragSourceSpec

, collect: DragSourceCollector, options?: DndOptions

- ): | React.StatelessComponent

>(componentClass: C) => C & DndComponentClass

; + ): (componentClass: React.ComponentClass

| React.StatelessComponent

) => DndComponentClass

; export function DropTarget

( types: Identifier | Identifier[] | ((props: P) => Identifier | Identifier[]), spec: DropTargetSpec

, collect: DropTargetCollector, options?: DndOptions

- ): | React.StatelessComponent

>(componentClass: C) => C & DndComponentClass

; + ): (componentClass: React.ComponentClass

| React.StatelessComponent

) => DndComponentClass

; export function DragDropContext

( backend: Backend - ): | React.StatelessComponent

>(componentClass: C) => C & ContextComponentClass

; + ):

(componentClass: React.ComponentClass

| React.StatelessComponent

) => ContextComponentClass

; export function DragLayer

( collect: DragLayerCollector, options?: DndOptions

- ): | React.StatelessComponent

>(componentClass: C) => C & DndComponentClass

; + ): (componentClass: React.ComponentClass

| React.StatelessComponent

) => DndComponentClass

; type DragSourceCollector = (connect: DragSourceConnector, monitor: DragSourceMonitor) => Object; type DropTargetCollector = (connect: DropTargetConnector, monitor: DropTargetMonitor) => Object; diff --git a/react-native/react-native.d.ts b/react-native/react-native.d.ts index 4cc5d47449..713da055ec 100644 --- a/react-native/react-native.d.ts +++ b/react-native/react-native.d.ts @@ -7490,7 +7490,7 @@ declare namespace __React { key: string; } - export interface NavigationState extends NavigationRoute { + export interface NavigationState { index: number; routes: NavigationRoute[]; } diff --git a/rx/rx-lite.d.ts b/rx/rx-lite.d.ts index f159979204..ecaf1145d6 100644 --- a/rx/rx-lite.d.ts +++ b/rx/rx-lite.d.ts @@ -261,8 +261,8 @@ declare namespace Rx { mergeObservable(): Observable; // alias for mergeAll skipUntil(other: Observable): Observable; skipUntil(other: IPromise): Observable; - switch(): Observable; - switchLatest(): Observable; // alias for switch + switch(): T; + switchLatest(): T; // alias for switch takeUntil(other: Observable): Observable; takeUntil(other: IPromise): Observable; zip(second: Observable|IPromise): Observable<[T, T2]>;