From da9251d117b85bb1902641662fffa1e5129b8fb2 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:46:04 -0500 Subject: [PATCH 01/14] add types entry to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 974aa55..0a2d7cb 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.14.1", "description": "Perform virtual DOM updates based on changes to a data model.", "main": "lib/index.js", + "types": "types/etch.d.ts", "scripts": { "test": "npm run standard && npm run mocha", "mocha": "electron-mocha test --renderer --recursive --require @babel/register", From 6fdfa60a7e13a4d311cd59475739575db3974fb6 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:46:10 -0500 Subject: [PATCH 02/14] install typescript for dev --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a2d7cb..4f0b6f5 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "estraverse-fb": "^1.3.2", "mocha": "^8.1.3", "random-seed": "^0.3.0", - "standard": "^8.5.0" + "standard": "^8.5.0", + "typescript": "^4.0.3" }, "standard": { "parser": "babel-eslint", From f285d5bb56d082c208848899bc43789469b42140 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:50:24 -0500 Subject: [PATCH 03/14] Etch class props --- types/etch-element.d.ts | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 types/etch-element.d.ts diff --git a/types/etch-element.d.ts b/types/etch-element.d.ts new file mode 100644 index 0000000..04ae46c --- /dev/null +++ b/types/etch-element.d.ts @@ -0,0 +1,3 @@ +/** Etch class props */ +type Props = object + From 35623805d348d8a5ace82b43f7b81a88ef832b4d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:50:42 -0500 Subject: [PATCH 04/14] Etch element extra props --- types/etch-element.d.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/types/etch-element.d.ts b/types/etch-element.d.ts index 04ae46c..bb3af00 100644 --- a/types/etch-element.d.ts +++ b/types/etch-element.d.ts @@ -1,3 +1,18 @@ /** Etch class props */ type Props = object +/** Etch element extra props */ +interface EtchExtraProps { + ref?: string + className?: string + on?: { + click?: (e: MouseEvent) => any + [name: string]: ((e: any) => any) | undefined + } + dataset?: { + [propName: string]: string | number | null + } + innerHTML?: string + innerText?: string + key?: any +} From 14ddafd5cdeabb7ae639e1c7f3a7e575c4542a8a Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:50:56 -0500 Subject: [PATCH 05/14] Etch HTML element --- types/etch-element.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/types/etch-element.d.ts b/types/etch-element.d.ts index bb3af00..ee4834e 100644 --- a/types/etch-element.d.ts +++ b/types/etch-element.d.ts @@ -16,3 +16,11 @@ interface EtchExtraProps { innerText?: string key?: any } + +/** Etch HTML element */ +export interface EtchHTMLElement { + tag: Tag + props: HTMLElementTagNameMap[Tag] & EtchExtraProps & Props + children: ChildSpec + ambiguous: Array +} From 7dc8099fdcd7e9c2e0e12fa496c1bfa8406cb78c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:51:07 -0500 Subject: [PATCH 06/14] Etch SVG element --- types/etch-element.d.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/etch-element.d.ts b/types/etch-element.d.ts index ee4834e..6d58243 100644 --- a/types/etch-element.d.ts +++ b/types/etch-element.d.ts @@ -24,3 +24,12 @@ export interface EtchHTMLElement { children: ChildSpec ambiguous: Array } + +/** Etch SVG element */ +export interface EtchSVGElement { + tag: Tag + props: SVGElementTagNameMap[Tag] & EtchExtraProps & Props + children?: ChildSpec + ambiguous: Array +} + From e6731979507b69b65b676563782d50aba14b016e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:51:18 -0500 Subject: [PATCH 07/14] Etch element's tag --- types/etch-element.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/etch-element.d.ts b/types/etch-element.d.ts index 6d58243..a37a68e 100644 --- a/types/etch-element.d.ts +++ b/types/etch-element.d.ts @@ -33,3 +33,7 @@ export interface EtchSVGElement { ambiguous: Array } + +/** Etch element's tag */ +type TagSpec = string | ElementClassConstructor | keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap + From cc34edbdd9e526b59773d182587111b9c97d8595 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:51:28 -0500 Subject: [PATCH 08/14] General Etch element --- types/etch-element.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/types/etch-element.d.ts b/types/etch-element.d.ts index a37a68e..0681ca4 100644 --- a/types/etch-element.d.ts +++ b/types/etch-element.d.ts @@ -37,3 +37,10 @@ export interface EtchSVGElement { /** Etch element's tag */ type TagSpec = string | ElementClassConstructor | keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap +/** General Etch element */ +export interface EtchElement { + tag: Tag + props: EtchExtraProps & Props + children?: ChildSpec + ambiguous: Array +} From 0d431194798a5bc051121d05f4df8d05b844adc0 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:51:38 -0500 Subject: [PATCH 09/14] Etch JSX Element --- types/etch-element.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/types/etch-element.d.ts b/types/etch-element.d.ts index 0681ca4..c1a4af6 100644 --- a/types/etch-element.d.ts +++ b/types/etch-element.d.ts @@ -44,3 +44,10 @@ export interface EtchElement { children?: ChildSpec ambiguous: Array } + +/** Etch JSX Element */ +type EtchJSXElement = + | EtchHTMLElement + | EtchSVGElement + | EtchElement + | {text: string | number} From 0db98387c98d6dd2e0462dc41bb3cbd0514b7014 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:53:11 -0500 Subject: [PATCH 10/14] type of etch elements' children Co-Authored-By: Nikolay Yakimov --- types/etch-element.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/etch-element.d.ts b/types/etch-element.d.ts index c1a4af6..29ac946 100644 --- a/types/etch-element.d.ts +++ b/types/etch-element.d.ts @@ -51,3 +51,8 @@ type EtchJSXElement = | EtchSVGElement | EtchElement | {text: string | number} + +type SingleOrArray = T | T[] +/** type of etch elements' children */ +type ChildSpec = SingleOrArray + From 8c361d18cc1a8d9bb9a59d54bd87ef10fdb57edd Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:53:18 -0500 Subject: [PATCH 11/14] ElementClassConstructor Co-Authored-By: Nikolay Yakimov --- types/etch-element.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/types/etch-element.d.ts b/types/etch-element.d.ts index 29ac946..6e0bc03 100644 --- a/types/etch-element.d.ts +++ b/types/etch-element.d.ts @@ -56,3 +56,6 @@ type SingleOrArray = T | T[] /** type of etch elements' children */ type ChildSpec = SingleOrArray + +type ElementClassConstructor = new (props: T["props"], children: EtchJSXElement[]) => T + From d92745c873bdb2730f2e195c853fb936664cd25d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 07:53:31 -0500 Subject: [PATCH 12/14] JSX Co-Authored-By: Nikolay Yakimov --- types/etch-element.d.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/types/etch-element.d.ts b/types/etch-element.d.ts index 6e0bc03..0a4ce93 100644 --- a/types/etch-element.d.ts +++ b/types/etch-element.d.ts @@ -59,3 +59,16 @@ type ChildSpec = SingleOrArray type ElementClassConstructor = new (props: T["props"], children: EtchJSXElement[]) => T +export declare namespace JSX { + type Element = EtchJSXElement + type IntrinsicElements = EtchJSXElement + class ElementClass { + public props: Props + constructor(props: Props, children?: EtchJSXElement[]) + public render?(): EtchJSXElement + public update(props: Props, children?: EtchJSXElement[]): Promise + } + interface ElementAttributesProperty { + props: Props // specify the property name to use + } +} From d1fffc1657b674aa1107a207b45d556e2a09365e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 08:05:57 -0500 Subject: [PATCH 13/14] dom function --- types/dom.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 types/dom.d.ts diff --git a/types/dom.d.ts b/types/dom.d.ts new file mode 100644 index 0000000..e963c5c --- /dev/null +++ b/types/dom.d.ts @@ -0,0 +1,6 @@ +import {JSX, EtchJSXElement, EtchExtraProps, Props, ChildSpec, TagSpec, ElementClassConstructor} from "./etch-element" + +export function dom(tag: T, props?: HTMLElementTagNameMap[T] & EtchExtraProps & Props, ...children: ChildSpec[]): EtchJSXElement +export function dom(tag: T, props?: SVGElementTagNameMap[T] & EtchExtraProps & Props, ...children: ChildSpec[]): EtchJSXElement +export function dom( tag: ElementClassConstructor, props: T["props"],...children: ChildSpec[]): EtchJSXElement +export function dom(tag: string, props?: EtchExtraProps & Props, ...children: ChildSpec[]): EtchJSXElement From bbfa43fa435d51541f4d1c95c8cdf24e0474ff77 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sun, 27 Sep 2020 08:06:29 -0500 Subject: [PATCH 14/14] etch other functions Co-Authored-By: Nikolay Yakimov --- types/etch.d.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 types/etch.d.ts diff --git a/types/etch.d.ts b/types/etch.d.ts new file mode 100644 index 0000000..ab54a62 --- /dev/null +++ b/types/etch.d.ts @@ -0,0 +1,12 @@ +export * from "./etch-element" +export * from "./dom" +import {EtchJSXElement} from "./etch-element" + +export function destroy(component: any, removeNode?: boolean): Promise +export function destroySync(component: any, removeNode: any): void +export function getScheduler(): any +export function initialize(component: any): void +export function render(virtualNode: EtchJSXElement, options?: any): Node +export function setScheduler(customScheduler: any): void +export function update(component: any, replaceNode?: boolean): Promise +export function updateSync(component: any, replaceNode?: boolean): void