From 600b4f4e8590d1ac7fb6fd37fca07e9e0297bad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=93=E8=80=90=E7=89=B9?= Date: Tue, 23 Oct 2018 05:32:53 +0800 Subject: [PATCH] Update omi.d.ts --- packages/omi/src/omi.d.ts | 220 ++++++++++++++++++++++++++++---------- 1 file changed, 164 insertions(+), 56 deletions(-) diff --git a/packages/omi/src/omi.d.ts b/packages/omi/src/omi.d.ts index eb1b59786..f68d30dfd 100644 --- a/packages/omi/src/omi.d.ts +++ b/packages/omi/src/omi.d.ts @@ -4,12 +4,11 @@ export as namespace Omi; declare namespace Omi { type Key = string | number; type Ref = (instance: T) => void; - type ComponentChild = JSX.Element | string | number | null; - type ComponentChildren = ComponentChild[]; + type ComponentChild = VNode | object | string | number | boolean | null; + type ComponentChildren = ComponentChild[] | ComponentChild; interface Attributes { key?: string | number | any; - jsx?: boolean; } interface ClassAttributes extends Attributes { @@ -23,31 +22,6 @@ declare namespace Omi { }; } - interface WeElement { - install?(): void; - installed?(): void; - uninstall?(): void; - beforeUpdate?(): void; - afterUpdate?(): void; - } - - abstract class WeElement { - constructor(); - - static props?: Array | object; - static data?: object; - - data: object; - props: object; - host: HTMLElement; - - css?(): void; - update(): void; - fire?(name: string, data?: object): void; - - abstract render(props?: object, data?: object): void; - } - /** * Define the contract for a virtual node in omi. * @@ -55,64 +29,104 @@ declare namespace Omi { * of child {VNode}s and a key. The key is used by omi for * internal purposes. */ - interface VNode

{ + interface VNode

{ nodeName: string; attributes: P; children: Array | string>; key?: Key | null; } + type RenderableProps = Readonly< + P & Attributes & { children?: ComponentChildren; ref?: Ref } + >; + + interface WeElement { + install?(): void; + installed?(): void; + uninstall?(): void; + beforeUpdate?(): void; + afterUpdate?(): void; + } + + abstract class WeElement

{ + constructor(); + + // Allow static members to reference class type parameters + // https://github.com/Microsoft/TypeScript/issues/24018 + static props: object; + static data: object; + + props: RenderableProps

; + data: D; + host: HTMLElement; + + css(): void; + update(): void; + fire(name: string, data?: object): void; + + // Abstract methods don't infer argument types + // https://github.com/Microsoft/TypeScript/issues/14887 + abstract render(props: RenderableProps

, data: D): void; + } + function h

( node: string, params: Attributes & P | null, - ...children: (ComponentChild | ComponentChildren)[] + ...children: ComponentChildren[] ): VNode; function h( node: string, params: JSX.HTMLAttributes & JSX.SVGAttributes & Record | null, - ...children: (ComponentChild | ComponentChildren)[] + ...children: ComponentChildren[] ): VNode; - function render( - vnode: JSX, - parent: string | Element | Document, - store?: object - ): void; - function define(name: string, ctor: HTMLElement): void; - function tag(name: string, pure?: boolean): void; - function cloneElement(element: JSX.Element, props: any): JSX.Element; + function render(vnode: ComponentChild, parent: string | Element | Document | ShadowRoot | DocumentFragment, store?: object): void; + + function define(name: string, ctor: any): void; + function tag(name: string, pure?: boolean): (ctor: any) => void; var options: { vnode?: (vnode: VNode) => void; + event?: (event: Event) => Event; }; } + +type Defaultize = + // Distribute over unions + Props extends any + ? // Make any properties included in Default optional + & Partial>> + // Include the remaining properties from Props + & Pick> + : never; + declare global { namespace JSX { - interface Element extends Omi.VNode {} + interface Element extends Omi.VNode { + } + + interface ElementClass extends Omi.WeElement { + } interface ElementAttributesProperty { props: any; } + interface ElementChildrenAttribute { + children: any; + } + + type LibraryManagedAttributes = + Component extends { defaultProps: infer Defaults } + ? Defaultize + : Props; + interface SVGAttributes extends HTMLAttributes { accentHeight?: number | string; accumulate?: "none" | "sum"; additive?: "replace" | "sum"; - alignmentBaseline?: - | "auto" - | "baseline" - | "before-edge" - | "text-before-edge" - | "middle" - | "central" - | "after-edge" - | "text-after-edge" - | "ideographic" - | "alphabetic" - | "hanging" - | "mathematical" - | "inherit"; + alignmentBaseline?: "auto" | "baseline" | "before-edge" | "text-before-edge" | "middle" | "central" | "after-edge" | "text-after-edge" | "ideographic" | "alphabetic" | "hanging" | "mathematical" | "inherit"; allowReorder?: "no" | "yes"; alphabetic?: number | string; amplitude?: number | string; @@ -370,102 +384,193 @@ declare global { type AnimationEventHandler = EventHandler; type TransitionEventHandler = EventHandler; type GenericEventHandler = EventHandler; + type PointerEventHandler = EventHandler; interface DOMAttributes extends Omi.OmiDOMAttributes { // Image Events onLoad?: GenericEventHandler; + onError?: GenericEventHandler; + onLoadCapture?: GenericEventHandler; // Clipboard Events onCopy?: ClipboardEventHandler; + onCopyCapture?: ClipboardEventHandler; onCut?: ClipboardEventHandler; + onCutCapture?: ClipboardEventHandler; onPaste?: ClipboardEventHandler; + onPasteCapture?: ClipboardEventHandler; // Composition Events onCompositionEnd?: CompositionEventHandler; + onCompositionEndCapture?: CompositionEventHandler; onCompositionStart?: CompositionEventHandler; + onCompositionStartCapture?: CompositionEventHandler; onCompositionUpdate?: CompositionEventHandler; + onCompositionUpdateCapture?: CompositionEventHandler; // Focus Events onFocus?: FocusEventHandler; + onFocusCapture?: FocusEventHandler; onBlur?: FocusEventHandler; + onBlurCapture?: FocusEventHandler; // Form Events onChange?: GenericEventHandler; + onChangeCapture?: GenericEventHandler; onInput?: GenericEventHandler; + onInputCapture?: GenericEventHandler; onSearch?: GenericEventHandler; + onSearchCapture?: GenericEventHandler; onSubmit?: GenericEventHandler; + onSubmitCapture?: GenericEventHandler; // Keyboard Events onKeyDown?: KeyboardEventHandler; + onKeyDownCapture?: KeyboardEventHandler; onKeyPress?: KeyboardEventHandler; + onKeyPressCapture?: KeyboardEventHandler; onKeyUp?: KeyboardEventHandler; + onKeyUpCapture?: KeyboardEventHandler; // Media Events onAbort?: GenericEventHandler; + onAbortCapture?: GenericEventHandler; onCanPlay?: GenericEventHandler; + onCanPlayCapture?: GenericEventHandler; onCanPlayThrough?: GenericEventHandler; + onCanPlayThroughCapture?: GenericEventHandler; onDurationChange?: GenericEventHandler; + onDurationChangeCapture?: GenericEventHandler; onEmptied?: GenericEventHandler; + onEmptiedCapture?: GenericEventHandler; onEncrypted?: GenericEventHandler; + onEncryptedCapture?: GenericEventHandler; onEnded?: GenericEventHandler; + onEndedCapture?: GenericEventHandler; onLoadedData?: GenericEventHandler; + onLoadedDataCapture?: GenericEventHandler; onLoadedMetadata?: GenericEventHandler; + onLoadedMetadataCapture?: GenericEventHandler; onLoadStart?: GenericEventHandler; + onLoadStartCapture?: GenericEventHandler; onPause?: GenericEventHandler; + onPauseCapture?: GenericEventHandler; onPlay?: GenericEventHandler; + onPlayCapture?: GenericEventHandler; onPlaying?: GenericEventHandler; + onPlayingCapture?: GenericEventHandler; onProgress?: GenericEventHandler; + onProgressCapture?: GenericEventHandler; onRateChange?: GenericEventHandler; + onRateChangeCapture?: GenericEventHandler; onSeeked?: GenericEventHandler; + onSeekedCapture?: GenericEventHandler; onSeeking?: GenericEventHandler; + onSeekingCapture?: GenericEventHandler; onStalled?: GenericEventHandler; + onStalledCapture?: GenericEventHandler; onSuspend?: GenericEventHandler; + onSuspendCapture?: GenericEventHandler; onTimeUpdate?: GenericEventHandler; + onTimeUpdateCapture?: GenericEventHandler; onVolumeChange?: GenericEventHandler; + onVolumeChangeCapture?: GenericEventHandler; onWaiting?: GenericEventHandler; + onWaitingCapture?: GenericEventHandler; // MouseEvents onClick?: MouseEventHandler; + onClickCapture?: MouseEventHandler; onContextMenu?: MouseEventHandler; + onContextMenuCapture?: MouseEventHandler; onDblClick?: MouseEventHandler; + onDblClickCapture?: MouseEventHandler; onDrag?: DragEventHandler; + onDragCapture?: DragEventHandler; onDragEnd?: DragEventHandler; + onDragEndCapture?: DragEventHandler; onDragEnter?: DragEventHandler; + onDragEnterCapture?: DragEventHandler; onDragExit?: DragEventHandler; + onDragExitCapture?: DragEventHandler; onDragLeave?: DragEventHandler; + onDragLeaveCapture?: DragEventHandler; onDragOver?: DragEventHandler; + onDragOverCapture?: DragEventHandler; onDragStart?: DragEventHandler; + onDragStartCapture?: DragEventHandler; onDrop?: DragEventHandler; + onDropCapture?: DragEventHandler; onMouseDown?: MouseEventHandler; + onMouseDownCapture?: MouseEventHandler; onMouseEnter?: MouseEventHandler; + onMouseEnterCapture?: MouseEventHandler; onMouseLeave?: MouseEventHandler; + onMouseLeaveCapture?: MouseEventHandler; onMouseMove?: MouseEventHandler; + onMouseMoveCapture?: MouseEventHandler; onMouseOut?: MouseEventHandler; + onMouseOutCapture?: MouseEventHandler; onMouseOver?: MouseEventHandler; + onMouseOverCapture?: MouseEventHandler; onMouseUp?: MouseEventHandler; + onMouseUpCapture?: MouseEventHandler; // Selection Events onSelect?: GenericEventHandler; + onSelectCapture?: GenericEventHandler; // Touch Events onTouchCancel?: TouchEventHandler; + onTouchCancelCapture?: TouchEventHandler; onTouchEnd?: TouchEventHandler; + onTouchEndCapture?: TouchEventHandler; onTouchMove?: TouchEventHandler; + onTouchMoveCapture?: TouchEventHandler; onTouchStart?: TouchEventHandler; + onTouchStartCapture?: TouchEventHandler; + + // Pointer Events + onPointerOver?: PointerEventHandler; + onPointerOverCapture?: PointerEventHandler; + onPointerEnter?: PointerEventHandler; + onPointerEnterCapture?: PointerEventHandler; + onPointerDown?: PointerEventHandler; + onPointerDownCapture?: PointerEventHandler; + onPointerMove?: PointerEventHandler; + onPointerMoveCapture?: PointerEventHandler; + onPointerUp?: PointerEventHandler; + onPointerUpCapture?: PointerEventHandler; + onPointerCancel?: PointerEventHandler; + onPointerCancelCapture?: PointerEventHandler; + onPointerOut?: PointerEventHandler; + onPointerOutCapture?: PointerEventHandler; + onPointerLeave?: PointerEventHandler; + onPointerLeaveCapture?: PointerEventHandler; + onGotPointerCapture?: PointerEventHandler; + onGotPointerCaptureCapture?: PointerEventHandler; + onLostPointerCapture?: PointerEventHandler; + onLostPointerCaptureCapture?: PointerEventHandler; // UI Events onScroll?: UIEventHandler; + onScrollCapture?: UIEventHandler; // Wheel Events onWheel?: WheelEventHandler; + onWheelCapture?: WheelEventHandler; // Animation Events onAnimationStart?: AnimationEventHandler; + onAnimationStartCapture?: AnimationEventHandler; onAnimationEnd?: AnimationEventHandler; + onAnimationEndCapture?: AnimationEventHandler; onAnimationIteration?: AnimationEventHandler; + onAnimationIterationCapture?: AnimationEventHandler; // Transition Events onTransitionEnd?: TransitionEventHandler; + onTransitionEndCapture?: TransitionEventHandler; } interface HTMLAttributes extends Omi.ClassAttributes, DOMAttributes { @@ -495,6 +600,7 @@ declare global { contentEditable?: boolean; contextMenu?: string; controls?: boolean; + controlsList?: string; coords?: string; crossOrigin?: string; data?: string; @@ -552,6 +658,7 @@ declare global { optimum?: number; pattern?: string; placeholder?: string; + playsInline?: boolean; poster?: string; preload?: string; radioGroup?: string; @@ -572,7 +679,7 @@ declare global { sizes?: string; slot?: string; span?: number; - spellCheck?: boolean; + spellcheck?: boolean; src?: string; srcset?: string; srcDoc?: string; @@ -715,7 +822,7 @@ declare global { track: HTMLAttributes; u: HTMLAttributes; ul: HTMLAttributes; - var: HTMLAttributes; + "var": HTMLAttributes; video: HTMLAttributes; wbr: HTMLAttributes; @@ -762,6 +869,7 @@ declare global { text: SVGAttributes; tspan: SVGAttributes; use: SVGAttributes; + [tagName: string]: any; } } }