From bd4a357c6582936a77d262ed7e6a60448b9d6aaa Mon Sep 17 00:00:00 2001 From: Andrew Sun Date: Mon, 26 Feb 2018 17:51:22 -0500 Subject: [PATCH] Cleanup --- packages/inferno/src/JSX.ts | 3838 ++++++++++++++++++ packages/inferno/src/core/component.ts | 3 - packages/inferno/src/core/implementation.ts | 1 - packages/inferno/src/index.ts | 3843 +------------------ 4 files changed, 3839 insertions(+), 3846 deletions(-) create mode 100644 packages/inferno/src/JSX.ts diff --git a/packages/inferno/src/JSX.ts b/packages/inferno/src/JSX.ts new file mode 100644 index 000000000..394586e09 --- /dev/null +++ b/packages/inferno/src/JSX.ts @@ -0,0 +1,3838 @@ +import { Component, ComponentClass, StatelessComponent, InfernoChildren, SFC, VNode } from "inferno"; + +declare global { + // Based on Type definitions for React 16.0 + // Project: http://facebook.github.io/react/ + // Definitions by: Asana + // AssureSign + // Microsoft + // John Reilly + // Benoit Benezech + // Patricio Zavolinsky + // Digiguru + // Eric Anderson + // Albert Kurniawan + // Tanguy Krotoff + // Dovydas Navickas + // Stéphane Goetz + // Rich Seviora + // Josh Rutherford + // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + // TypeScript Version: 2.6 + + /// + + type NativeAnimationEvent = AnimationEvent; + type NativeClipboardEvent = ClipboardEvent; + type NativeCompositionEvent = CompositionEvent; + type NativeDragEvent = DragEvent; + type NativeFocusEvent = FocusEvent; + type NativeKeyboardEvent = KeyboardEvent; + type NativeMouseEvent = MouseEvent; + type NativeTouchEvent = TouchEvent; + type NativeTransitionEvent = TransitionEvent; + type NativeUIEvent = UIEvent; + type NativeWheelEvent = WheelEvent; + +// tslint:disable-next-line:export-just-namespace +// export = InfernoJSX; +// export as namespace InfernoJSX; + + namespace _InfernoJSX { + // + // React Elements + // ---------------------------------------------------------------------- + + type InfernoJSXType

= string | ComponentType

; + type ComponentType

= ComponentClass

| StatelessComponent

; + + type Key = string | number; + type Ref = { bivarianceHack(instance: T | null): any }["bivarianceHack"]; + + // tslint:disable-next-line:interface-over-type-literal + type ComponentState = {}; + + interface Attributes { + key?: Key; + } + + interface ClassAttributes extends Attributes { + ref?: Ref; + } + + interface InfernoJSXElement

extends VNode

{ + // type: string | ComponentClass

| SFC

; + // props: P; + // key: Key | null; + } + + interface SFCElement

extends InfernoJSXElement

{ + type: SFC

; + } + + // type CElement> = ComponentElement; + // interface ComponentElement> extends InfernoJSXElement

{ + // type: ComponentClass

; + // // ref?: Ref; + // ref: Ref

; + // } + + // string fallback for custom web-components + interface DOMElement

| SVGAttributes, T extends Element> extends InfernoJSXElement

{ + type: string; + ref: Ref; + } + + // ReactHTML for ReactHTMLElement + // tslint:disable-next-line:no-empty-interface + interface InfernoHTMLElement extends DetailedInfernoHTMLElement, T> { + } + + interface DetailedInfernoHTMLElement

, T extends HTMLElement> extends DOMElement { + type: keyof InfernoHTML; + } + + // ReactSVG for ReactSVGElement + interface InfernoSVGElement extends DOMElement, SVGElement> { + type: keyof InfernoSVG; + } + + interface InfernoJSXPortal { + key: Key | null; + children: InfernoJSXNode; + } + + // + // Factories + // ---------------------------------------------------------------------- + + type Factory

= (props?: Attributes & P, ...children: InfernoJSXNode[]) => InfernoJSXElement

; + + type SFCFactory

= (props?: Attributes & P, ...children: InfernoJSXNode[]) => SFCElement

; + + // type ComponentFactory> = + // (props?: ClassAttributes & P, ...children: InfernoJSXNode[]) => CElement; + + // type CFactory> = ComponentFactory; + // type ClassicFactory

= CFactory>; + + type DOMFactory

, T extends Element> = + (props?: ClassAttributes & P | null, ...children: InfernoJSXNode[]) => DOMElement; + + // tslint:disable-next-line:no-empty-interface + interface HTMLFactory extends DetailedHTMLFactory, T> { + } + + interface DetailedHTMLFactory

, T extends HTMLElement> extends DOMFactory { + (props?: ClassAttributes & P | null, ...children: InfernoJSXNode[]): DetailedInfernoHTMLElement; + } + + interface SVGFactory extends DOMFactory, SVGElement> { + (props?: ClassAttributes & SVGAttributes | null, ...children: InfernoJSXNode[]): InfernoSVGElement; + } + + // + // React Nodes + // http://facebook.github.io/react/docs/glossary.html + // ---------------------------------------------------------------------- + + type InfernoJSXText = string | number; + type InfernoJSXChild = InfernoJSXElement | InfernoJSXText; + + // Should be Array but type aliases cannot be recursive + // type InfernoJSXFragment = {} | Array; + type InfernoJSXNode = InfernoChildren; + + // + // Top Level API + // ---------------------------------------------------------------------- + + // DOM Elements + // function createFactory( + // type: keyof InfernoHTML): HTMLFactory; + // function createFactory( + // type: keyof InfernoSVG): SVGFactory; + // function createFactory

, T extends Element>( + // type: string): DOMFactory; + + // Custom components + // function createFactory

(type: SFC

): SFCFactory

; + // function createFactory

( + // type: ClassType, ClassicComponentClass

>): CFactory>; + // function createFactory, C extends ComponentClass

>( + // type: ClassType): CFactory; + // function createFactory

(type: ComponentClass

): Factory

; + + // DOM Elements + // TODO: generalize this to everything in `keyof ReactHTML`, not just "input" + // function createElement( + // type: "input", + // props?: InputHTMLAttributes & ClassAttributes | null, + // ...children: InfernoJSXNode[]): DetailedInfernoHTMLElement, HTMLInputElement>; + // function createElement

, T extends HTMLElement>( + // type: keyof InfernoHTML, + // props?: ClassAttributes & P | null, + // ...children: InfernoJSXNode[]): DetailedInfernoHTMLElement; + // function createElement

, T extends SVGElement>( + // type: keyof InfernoSVG, + // props?: ClassAttributes & P | null, + // ...children: InfernoJSXNode[]): InfernoSVGElement; + // function createElement

, T extends Element>( + // type: string, + // props?: ClassAttributes & P | null, + // ...children: InfernoJSXNode[]): DOMElement; + + // Custom components + // function createElement

( + // type: SFC

, + // props?: Attributes & P | null, + // ...children: InfernoJSXNode[]): SFCElement

; + // function createElement

( + // type: ClassType, ClassicComponentClass

>, + // props?: ClassAttributes> & P | null, + // ...children: InfernoJSXNode[]): CElement>; + // function createElement, C extends ComponentClass

>( + // type: ClassType, + // props?: ClassAttributes & P | null, + // ...children: InfernoJSXNode[]): CElement; + // function createElement

( + // type: SFC

| ComponentClass

| string, + // props?: Attributes & P | null, + // ...children: InfernoJSXNode[]): InfernoJSXElement

; + + // DOM Elements + // ReactHTMLElement + // function cloneElement

, T extends HTMLElement>( + // element: DetailedInfernoHTMLElement, + // props?: P, + // ...children: InfernoJSXNode[]): DetailedInfernoHTMLElement; + // // ReactHTMLElement, less specific + // function cloneElement

, T extends HTMLElement>( + // element: InfernoHTMLElement, + // props?: P, + // ...children: InfernoJSXNode[]): InfernoHTMLElement; + // // SVGElement + // function cloneElement

, T extends SVGElement>( + // element: InfernoSVGElement, + // props?: P, + // ...children: InfernoJSXNode[]): InfernoSVGElement; + // // DOM Element (has to be the last, because type checking stops at first overload that fits) + // function cloneElement

, T extends Element>( + // element: DOMElement, + // props?: DOMAttributes & P, + // ...children: InfernoJSXNode[]): DOMElement; + + // // Custom components + // function cloneElement

( + // element: SFCElement

, + // props?: Q, // should be Q & Attributes, but then Q is inferred as {} + // ...children: InfernoJSXNode[]): SFCElement

; + // function cloneElement

>( + // element: CElement, + // props?: Q, // should be Q & ClassAttributes + // ...children: InfernoJSXNode[]): CElement; + // function cloneElement

( + // element: InfernoJSXElement

, + // props?: Q, // should be Q & Attributes + // ...children: InfernoJSXNode[]): InfernoJSXElement

; + + // function isValidElement

(object: {} | null | undefined): object is InfernoJSXElement

; + + // const Children: ReactChildren; + // const Fragment: ComponentType; + // const version: string; + + // + // Component API + // ---------------------------------------------------------------------- + + type InfernoJSXInstance = Component | Element; + + // Base component for plain JS classes + // tslint:disable-next-line:no-empty-interface + // interface Component

extends ComponentLifecycle { } + + // class PureComponent

extends Component { } + + // interface ClassicComponent

extends Component { + // replaceState(nextState: S, callback?: () => void): void; + // isMounted(): boolean; + // getInitialState?(): S; + // } + + // interface ChildContextProvider { + // getChildContext(): CC; + // } + + // + // Class Interfaces + // ---------------------------------------------------------------------- + + // interface ClassicComponentClass

extends ComponentClass

{ + // new (props: P, context?: any): ClassicComponent; + // getDefaultProps?(): P; + // } + + /** + * We use an intersection type to infer multiple type parameters from + * a single argument, which is useful for many top-level API defs. + * See https://github.com/Microsoft/TypeScript/issues/7234 for more info. + */ + type ClassType, C extends ComponentClass

> = + C & + (new (props?: P, context?: any) => T) & + (new (props?: P, context?: any) => { props: P }); + + // + // Component Specs and Lifecycle + // ---------------------------------------------------------------------- + + // interface Mixin extends ComponentLifecycle { + // mixins?: Array>; + // statics?: { + // [key: string]: any; + // }; + // + // displayName?: string; + // propTypes?: ValidationMap; + // contextTypes?: ValidationMap; + // childContextTypes?: ValidationMap; + // + // getDefaultProps?(): P; + // getInitialState?(): S; + // } + + // interface ComponentSpec extends Mixin { + // render(): InfernoJSXNode; + // + // [propertyName: string]: any; + // } + + // + // Event System + // ---------------------------------------------------------------------- + + interface SyntheticEvent { + bubbles: boolean; + /** + * A reference to the element on which the event listener is registered. + */ + currentTarget: EventTarget & T; + cancelable: boolean; + defaultPrevented: boolean; + eventPhase: number; + isTrusted: boolean; + nativeEvent: Event; + + preventDefault(): void; + + isDefaultPrevented(): boolean; + + stopPropagation(): void; + + isPropagationStopped(): boolean; + + persist(): void; + + // If you thought this should be `EventTarget & T`, see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/12239 + /** + * A reference to the element from which the event was originally dispatched. + * This might be a child element to the element on which the event listener is registered. + * + * @see currentTarget + */ + target: EventTarget; + timeStamp: number; + type: string; + } + + interface ClipboardEvent extends SyntheticEvent { + clipboardData: DataTransfer; + nativeEvent: NativeClipboardEvent; + } + + interface CompositionEvent extends SyntheticEvent { + data: string; + nativeEvent: NativeCompositionEvent; + } + + interface DragEvent extends MouseEvent { + dataTransfer: DataTransfer; + nativeEvent: NativeDragEvent; + } + + interface FocusEvent extends SyntheticEvent { + nativeEvent: NativeFocusEvent; + relatedTarget: EventTarget; + } + + // tslint:disable-next-line:no-empty-interface + interface FormEvent extends SyntheticEvent { + } + + interface InvalidEvent extends SyntheticEvent { + target: EventTarget & T; + } + + interface ChangeEvent extends SyntheticEvent { + target: EventTarget & T; + } + + interface KeyboardEvent extends SyntheticEvent { + altKey: boolean; + charCode: number; + ctrlKey: boolean; + + /** + * See [DOM Level 3 Events spec](https://www.w3.org/TR/uievents-key/#keys-modifier). for a list of valid (case-sensitive) arguments to this method. + */ + getModifierState(key: string): boolean; + + /** + * See the [DOM Level 3 Events spec](https://www.w3.org/TR/uievents-key/#named-key-attribute-values). for possible values + */ + key: string; + keyCode: number; + locale: string; + location: number; + metaKey: boolean; + nativeEvent: NativeKeyboardEvent; + repeat: boolean; + shiftKey: boolean; + which: number; + } + + interface MouseEvent extends SyntheticEvent { + altKey: boolean; + button: number; + buttons: number; + clientX: number; + clientY: number; + ctrlKey: boolean; + + /** + * See [DOM Level 3 Events spec](https://www.w3.org/TR/uievents-key/#keys-modifier). for a list of valid (case-sensitive) arguments to this method. + */ + getModifierState(key: string): boolean; + + metaKey: boolean; + nativeEvent: NativeMouseEvent; + pageX: number; + pageY: number; + relatedTarget: EventTarget; + screenX: number; + screenY: number; + shiftKey: boolean; + } + + interface TouchEvent extends SyntheticEvent { + altKey: boolean; + changedTouches: TouchList; + ctrlKey: boolean; + + /** + * See [DOM Level 3 Events spec](https://www.w3.org/TR/uievents-key/#keys-modifier). for a list of valid (case-sensitive) arguments to this method. + */ + getModifierState(key: string): boolean; + + metaKey: boolean; + nativeEvent: NativeTouchEvent; + shiftKey: boolean; + targetTouches: TouchList; + touches: TouchList; + } + + interface UIEvent extends SyntheticEvent { + detail: number; + nativeEvent: NativeUIEvent; + view: AbstractView; + } + + interface WheelEvent extends MouseEvent { + deltaMode: number; + deltaX: number; + deltaY: number; + deltaZ: number; + nativeEvent: NativeWheelEvent; + } + + interface AnimationEvent extends SyntheticEvent { + animationName: string; + elapsedTime: number; + nativeEvent: NativeAnimationEvent; + pseudoElement: string; + } + + interface TransitionEvent extends SyntheticEvent { + elapsedTime: number; + nativeEvent: NativeTransitionEvent; + propertyName: string; + pseudoElement: string; + } + + // + // Event Handler Types + // ---------------------------------------------------------------------- + + type EventHandler> = { bivarianceHack(event: E): void }["bivarianceHack"]; + + type InfernoEventHandler = EventHandler>; + + type ClipboardEventHandler = EventHandler>; + type CompositionEventHandler = EventHandler>; + type DragEventHandler = EventHandler>; + type FocusEventHandler = EventHandler>; + type FormEventHandler = EventHandler>; + type ChangeEventHandler = EventHandler>; + type KeyboardEventHandler = EventHandler>; + type MouseEventHandler = EventHandler>; + type TouchEventHandler = EventHandler>; + type UIEventHandler = EventHandler>; + type WheelEventHandler = EventHandler>; + type AnimationEventHandler = EventHandler>; + type TransitionEventHandler = EventHandler>; + + // + // Props / DOM Attributes + // ---------------------------------------------------------------------- + + /** + * @deprecated. This was used to allow clients to pass `ref` and `key` + * to `createElement`, which is no longer necessary due to intersection + * types. If you need to declare a props object before passing it to + * `createElement` or a factory, use `ClassAttributes`: + * + * ```ts + * var b: Button | null; + * var props: ButtonProps & ClassAttributes