Permalink
Browse files

Export type definitions

  • Loading branch information...
cocopon committed Jan 9, 2019
1 parent 2383f5c commit 4d5dd5a1def0871536e0e7d76b6eff1b9f33a7e1
@@ -1,6 +1,7 @@
/docs/
/dist/
/docs/
/pages/
/test-require/dist/
/test/

*.tgz
@@ -6,6 +6,7 @@
"license": "MIT",
"homepage": "https://cocopon.github.com/tweakpane/",
"main": "dist/tweakpane.js",
"types": "dist/types/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/cocopon/tweakpane.git"
@@ -31,14 +32,15 @@
"doc:format": "run-p doc:format:*",
"doc:format:css": "prettier --parser scss --write 'src/doc/sass/**/*.scss'",
"doc:format:js": "prettier --parser typescript --write 'src/doc/js/**/*.ts'",
"doc:lint:js": "tslint --project tsconfig.json 'src/doc/js/**/*'",
"doc:lint:js": "tslint --project src/doc/tsconfig.json 'src/doc/js/**/*'",
"doc:server": "http-server ./docs",
"doc:test": "run-s doc:lint:js doc:checkFormat",
"doc:watch": "run-p doc:watch:*",
"doc:watch:css": "onchange 'src/doc/sass/**/*.scss' -- npm run doc:build:css",
"doc:watch:html": "onchange 'src/doc/template/**/*.html' -- npm run doc:build:html",
"doc:watch:js": "webpack --config webpack-doc.config.js --watch",
"main:build": "run-p main:build:*",
"main:build:dts": "tsc --project src/main/tsconfig-dts.json",
"main:build:dev": "webpack --mode development",
"main:build:prod": "webpack --mode production",
"main:checkFormat": "run-p main:checkFormat:*",
@@ -47,7 +49,7 @@
"main:format": "run-p main:format:*",
"main:format:css": "prettier --parser scss --write 'src/main/sass/**/*.scss'",
"main:format:js": "prettier --parser typescript --write 'src/main/js/**/*.ts'",
"main:lint:js": "tslint --project tsconfig.json 'src/main/js/**/*'",
"main:lint:js": "tslint --project src/main/tsconfig.json 'src/main/js/**/*'",
"main:prepare": "npm-run-all main:build --serial main:release:dist",
"main:release": "npm-run-all clean main:build --serial main:release:dist main:release:version main:release:zip",
"main:release:dist": "mkdir -p dist && cp docs/assets/tweakpane*.js dist",
@@ -56,9 +58,9 @@
"main:test": "run-s main:checkFormat main:lint:js main:test:js main:test:require",
"main:test:coverage": "nyc report --reporter=html --reporter=text --reporter=lcovonly --report-dir=test/coverage",
"main:test:coveralls": "nyc report --reporter=text-lcov | coveralls",
"main:test:js": "nyc --extension '.ts' --exclude '**/*-test.ts' mocha --require ts-node/register 'src/main/js/**/*-test.ts'",
"main:test:report": "nyc --extension '.ts' --exclude '**/*-test.ts' mocha --require ts-node/register --reporter mocha-junit-reporter --reporter-options mochaFile=./test/results/results.xml 'src/main/js/**/*-test.ts'",
"main:test:require": "npm run main:prepare && (cd test-require && npm run try)",
"main:test:js": "TS_NODE_PROJECT='src/main/tsconfig.json' nyc --extension '.ts' --exclude '**/*-test.ts' mocha --require ts-node/register 'src/main/js/**/*-test.ts'",
"main:test:report": "TS_NODE_PROJECT='src/main/tsconfig.json' nyc --extension '.ts' --exclude '**/*-test.ts' mocha --require ts-node/register --reporter mocha-junit-reporter --reporter-options mochaFile=./test/results/results.xml 'src/main/js/**/*-test.ts'",
"main:test:require": "npm run main:prepare && (cd test-require && npm install && npm run try)",
"main:watch": "webpack --mode development --watch"
},
"dependencies": {
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig-base.json"
}
@@ -45,7 +45,10 @@ export default class FolderApi {
params,
);
this.controller.uiControllerList.append(uc);
return new InputBindingApi(uc);
return new InputBindingApi<
InputBindingControllerCreators.InputtableInType,
InputBindingControllerCreators.InputtableOutType
>(uc);
}

public addMonitor(object: object, key: string, opt_params?: MonitorParams) {
@@ -56,7 +59,9 @@ export default class FolderApi {
params,
);
this.controller.uiControllerList.append(uc);
return new MonitorBindingApi(uc);
return new MonitorBindingApi<
MonitorBindingControllerCreators.MonitorableType
>(uc);
}

public addButton(params: ButtonParams): ButtonApi {
@@ -3,21 +3,14 @@ import {Handler} from '../misc/emitter';

type EventName = 'change';

export default class InputBindingApi<
In,
Out,
B extends InputBindingController<In, Out>
> {
public readonly controller: B;
export default class InputBindingApi<In, Out> {
public readonly controller: InputBindingController<In, Out>;

constructor(bindingController: B) {
constructor(bindingController: InputBindingController<In, Out>) {
this.controller = bindingController;
}

public on(
eventName: EventName,
handler: Handler,
): InputBindingApi<In, Out, B> {
public on(eventName: EventName, handler: Handler): InputBindingApi<In, Out> {
const emitter = this.controller.binding.value.emitter;
emitter.on(eventName, handler);
return this;
@@ -3,17 +3,14 @@ import {Handler} from '../misc/emitter';

type EventName = 'update';

export default class MonitorBindingApi<
In,
B extends MonitorBindingController<In>
> {
public readonly controller: B;
export default class MonitorBindingApi<In> {
public readonly controller: MonitorBindingController<In>;

constructor(bindingController: B) {
constructor(bindingController: MonitorBindingController<In>) {
this.controller = bindingController;
}

public on(eventName: EventName, handler: Handler): MonitorBindingApi<In, B> {
public on(eventName: EventName, handler: Handler): MonitorBindingApi<In> {
const emitter = this.controller.binding.value.emitter;
emitter.on(eventName, handler);
return this;
@@ -20,6 +20,7 @@ import {
FolderParams,
InputParams,
MonitorParams,
UiController,
} from '../controller/ui';
import {Handler} from '../misc/emitter';
import {PresetObject} from './preset';
@@ -65,7 +66,10 @@ export default class RootApi {
params,
);
this.controller.uiControllerList.append(uc);
return new InputBindingApi(uc);
return new InputBindingApi<
InputBindingControllerCreators.InputtableInType,
InputBindingControllerCreators.InputtableOutType
>(uc);
}

public addMonitor(object: object, key: string, opt_params?: MonitorParams) {
@@ -76,7 +80,9 @@ export default class RootApi {
params,
);
this.controller.uiControllerList.append(uc);
return new MonitorBindingApi(uc);
return new MonitorBindingApi<
MonitorBindingControllerCreators.MonitorableType
>(uc);
}

public addButton(params: ButtonParams): ButtonApi {
@@ -2,8 +2,10 @@ import * as BooleanConverter from '../../converter/boolean';
import * as NumberConverter from '../../converter/number';
import * as StringConverter from '../../converter/string';
import PaneError from '../../misc/pane-error';
import Color from '../../model/color';
import Target from '../../model/target';
import ColorParser from '../../parser/color';
import InputBindingController from '../input-binding';
import * as BooleanInputBindingControllerCreators from './boolean-input';
import * as ColorInputBindingControllerCreators from './color-input';
import * as NumberInputBindingControllerCreators from './number-input';
@@ -65,6 +67,9 @@ function normalizeParams<T1, T2>(
return p2;
}

export type InputtableInType = boolean | number | string | Color;
export type InputtableOutType = boolean | number | string;

export function create(
document: Document,
target: Target,
@@ -1,5 +1,6 @@
import PaneError from '../../misc/pane-error';
import Target from '../../model/target';
import MonitorBindingController from '../monitor-binding';
import * as BooleanMonitorBindingControllerCreators from './boolean-monitor';
import * as NumberMonitorBindingControllerCreators from './number-monitor';
import * as StringMonitorBindingControllerCreators from './string-monitor';
@@ -14,6 +15,8 @@ interface Params {
type?: string;
}

export type MonitorableType = boolean | number | string;

export function create(document: Document, target: Target, params: Params) {
const initialValue = target.read();

@@ -0,0 +1,8 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "../../dist/types"
}
}
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig-base.json"
}
File renamed without changes.
@@ -9,5 +9,9 @@ const PARAMS = {
const pane = new Tweakpane({
document: (new Jsdom('')).window.document,
});
pane.addInput(PARAMS, 'foo');
pane.addInput(PARAMS, 'foo', {
max: 1,
min: 0,
step: 1,
});
console.log(pane);
@@ -0,0 +1,15 @@
import {JSDOM} from 'jsdom';
import Tweakpane from 'tweakpane';

const PARAMS = {
foo: 1,
};
const pane = new Tweakpane({
document: (new JSDOM('')).window.document,
});
pane.addInput(PARAMS, 'foo', {
max: 1,
min: 0,
step: 1,
});
console.log(pane);
@@ -3,12 +3,18 @@
"version": "1.0.0",
"description": "",
"scripts": {
"try": "npm install && node index.js"
"try": " run-p try:js try:ts",
"try:js": "node index.js",
"try:ts": "ts-node index.ts"
},
"author": "cocopon",
"license": "MIT",
"devDependencies": {
"dependencies": {
"@types/jsdom": "^12.2.1",
"jsdom": "^13.1.0",
"tweakpane": "file:.."
"npm-run-all": "^4.1.5",
"ts-node": "^7.0.1",
"tweakpane": "file:..",
"typescript": "^3.2.2"
}
}
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"esModuleInterop": true,
"lib": [
"dom",
"es2015"
],
"outDir": "dist",
"strictNullChecks": true,
"target": "es5"
},
}
@@ -18,6 +18,9 @@ module.exports = (_env) => {
include: [Path.resolve(__dirname, 'src/doc/js/')],
exclude: /node_modules/,
loader: 'awesome-typescript-loader',
options: {
configFileName: 'src/doc/tsconfig.json',
},
},
],
},
@@ -29,6 +29,9 @@ module.exports = (_env, argv) => {
include: [Path.resolve(__dirname, 'src/main/js/')],
exclude: /node_modules/,
loader: 'awesome-typescript-loader',
options: {
configFileName: 'src/main/tsconfig.json',
},
}, {
test: /\.s?css$/,
include: [Path.resolve(__dirname, 'src/main/sass/')],

0 comments on commit 4d5dd5a

Please sign in to comment.