From 8739c165232c4a52e30c97ca2c8075711a6fd26d Mon Sep 17 00:00:00 2001 From: Stefan Mansson Date: Thu, 8 Nov 2018 11:44:35 +0200 Subject: [PATCH] Add flowdoc type definitions --- types/flowdoc/flowdoc-tests.ts | 103 ++++++++++++++++++++++++++++ types/flowdoc/index.d.ts | 121 +++++++++++++++++++++++++++++++++ types/flowdoc/tsconfig.json | 23 +++++++ types/flowdoc/tslint.json | 6 ++ 4 files changed, 253 insertions(+) create mode 100644 types/flowdoc/flowdoc-tests.ts create mode 100644 types/flowdoc/index.d.ts create mode 100644 types/flowdoc/tsconfig.json create mode 100644 types/flowdoc/tslint.json diff --git a/types/flowdoc/flowdoc-tests.ts b/types/flowdoc/flowdoc-tests.ts new file mode 100644 index 0000000000..04b765f65c --- /dev/null +++ b/types/flowdoc/flowdoc-tests.ts @@ -0,0 +1,103 @@ +const flowFile: Flow.File = { + document: { + id: 'cjo45613k00002a5p9gj6nr3b', + name: 'Basic Document', + type: Flow.Type.Document, + children: [ + { + id: 'cjo456d2700002a5p80zudiut', + name: 'Page 1', + type: Flow.Type.Page, + backgroundColor: { + r: 0, + g: 0, + b: 0, + a: 1, + }, + children: [ + { + id: 'cjo45mq7500002a5p8n8u1bfz', + name: 'Sign in', + type: Flow.Type.Screen, + source: { + fileName: 'sign-in.png', + dirPath: './assets', + }, + children: [], + size: { + h: 700, + w: 1152, + }, + position: { + x: 200, + y: 128, + }, + }, + { + id: 'cjo45oi8700002a5pmpnxhfny', + name: 'Sign up', + type: Flow.Type.Screen, + source: { + fileName: 'sign-up.png', + dirPath: './assets', + }, + children: [], + size: { + h: 700, + w: 1152, + }, + position: { + x: 1452, + y: 128, + }, + }, + ], + }, + ], + }, + settings: { + grid: [40, 40], + }, + schemaVersion: 1, +}; + +flowFile.settings = {}; +flowFile.schemaVersion = 1; + +const document: Flow.Document = flowFile.document; +document.type = Flow.Type.Document; + +const page: Flow.Page = document.children[0]; +page.type = Flow.Type.Page; +page.backgroundColor = { + r: 255, + g: 255, + b: 255, + a: 1 +}; + +const hotspot: Flow.Layer = { + id: 'cjo5mezgg00003g5winhxc8o0', + name: 'Layer', + type: Flow.Type.Hotspot, + position: { + x: 390, + y: 390, + }, + size: { + h: 42, + w: 370, + }, + connections: [{ + nodeID: 'cjo45mq7500002a5p8n8u1bfz', + }], +}; +hotspot.type = Flow.Type.Hotspot; + +const screen = page.children[0] as Flow.Screen; +screen.type = Flow.Type.Screen; +screen.children.push(hotspot); +screen.position = { + x: 0, + y: 0 +}; diff --git a/types/flowdoc/index.d.ts b/types/flowdoc/index.d.ts new file mode 100644 index 0000000000..9e39a24384 --- /dev/null +++ b/types/flowdoc/index.d.ts @@ -0,0 +1,121 @@ +// Type definitions for flowdoc 1.0 +// Project: https://github.com/overflowapp/Flow +// Definitions by: Stefan Mansson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +declare namespace Flow { + interface File { + document: Document; + settings: Settings; + schemaVersion: SchemaVersion; + } + + interface Document { + id: string; + name: string; + type: Type.Document; + children: Page[]; + } + + interface Page extends Node { + type: Type.Page; + children: Array<(Screen | Image | Rectangle | Ellipse | Diamond)>; + backgroundColor: Color; + startNodeID?: string; + } + + interface Screen extends Graphic { + type: Type.Screen; + children: Layer[]; + connections?: Connection[]; + } + + interface Image extends Graphic { + type: Type.Image; + connections?: Connection[]; + } + + interface Rectangle extends Shape { + type: Type.Rectangle; + } + + interface Ellipse extends Shape { + type: Type.Ellipse; + } + + interface Diamond extends Shape { + type: Type.Diamond; + } + + interface Layer extends Node { + type: Type.Layer | Type.Hotspot; + position: Point; + size: Size; + connections?: Connection[]; + } + + interface Connection { + nodeID: string; + } + + interface Settings { + grid?: [number, number]; + } + + interface Color { + r: number; + g: number; + b: number; + a: number; + } + + interface FileAsset { + fileName: string; + dirPath: string; + } + + type URLAsset = string; + + interface Point { + x: number; + y: number; + } + + interface Size { + h: number; + w: number; + } + + const enum Type { + Document = 'DOCUMENT', + Page = 'PAGE', + Screen = 'SCREEN', + Image = 'IMAGE', + Rectangle = 'RECT', + Ellipse = 'ELLIPSE', + Diamond = 'DIAMOND', + Hotspot = 'HOTSPOT', + Layer = 'LAYER', + } + + type SchemaVersion = 1; +} + +interface Node { + id: string; + name: string; + type: Flow.Type; +} + +interface Shape extends Node { + position: Flow.Point; + size: Flow.Size; + connections?: Flow.Connection[]; +} + +interface Graphic extends Node { + position: Flow.Point; + size: Flow.Size; + source: Flow.FileAsset | Flow.URLAsset; +} diff --git a/types/flowdoc/tsconfig.json b/types/flowdoc/tsconfig.json new file mode 100644 index 0000000000..a35d4c4c58 --- /dev/null +++ b/types/flowdoc/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "flowdoc-tests.ts" + ] +} diff --git a/types/flowdoc/tslint.json b/types/flowdoc/tslint.json new file mode 100644 index 0000000000..3224b40b8b --- /dev/null +++ b/types/flowdoc/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-const-enum": false + } +}