Merge pull request #30370 from overflowapp/master

Add type definition flowdoc
This commit is contained in:
Armando Aguirre
2018-11-08 11:29:57 -08:00
committed by GitHub
4 changed files with 253 additions and 0 deletions
+103
View File
@@ -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
};
+121
View File
@@ -0,0 +1,121 @@
// Type definitions for flowdoc 1.0
// Project: https://github.com/overflowapp/Flow
// Definitions by: Stefan Mansson <https://github.com/animify>
// 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;
}
+23
View File
@@ -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"
]
}
+6
View File
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"no-const-enum": false
}
}