From 8c9aefbcaf1243b844f03ba4b23823f2a54a06b5 Mon Sep 17 00:00:00 2001 From: Brian Zinn Date: Sat, 30 May 2020 17:09:41 -0700 Subject: [PATCH] Remove `react-spring` (and 14 other unused dependencies). #69 --- package.json | 72 +-------- src/plugins/react-babylon-spring/animated.ts | 84 ----------- .../react-babylon-spring/customProps.ts | 137 ------------------ src/plugins/react-babylon-spring/index.ts | 21 --- src/react-babylonjs.ts | 3 +- stories/babylonjs/GUI/gui.stories.js | 1 - stories/babylonjs/Hooks/more-hooks.stories.js | 1 - test/react-babylonjs.test.ts | 14 -- 8 files changed, 8 insertions(+), 325 deletions(-) delete mode 100644 src/plugins/react-babylon-spring/animated.ts delete mode 100644 src/plugins/react-babylon-spring/customProps.ts delete mode 100644 src/plugins/react-babylon-spring/index.ts delete mode 100644 test/react-babylonjs.test.ts diff --git a/package.json b/package.json index 691375d8..384eb4cc 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "react-babylonjs", - "version": "2.2.0", - "description": "React for BabylonJS", + "version": "2.2.1", + "description": "React for Babylon.js", "homepage": "https://brianzinn.github.io/react-babylonjs/", "keywords": [ "3d", "webgl", "react", - "babylonjs", + "babylon", + "babylon.js", "@babylonjs", "react-reconciler" ], @@ -26,56 +27,20 @@ "node": ">=6.0.0" }, "scripts": { - "lint": "tslint -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", + "lint": "tslint -t codeFrame 'src/**/*.ts'", "prebuild": "rimraf dist", "build": "cross-env NODE_ENV=production rollup -c", "start": "tsc-watch --onSuccess \"rollup -c\"", - "test": "jest", - "test:watch": "jest --watch", - "test:prod": "npm run lint && npm run test -- --coverage --no-cache", "deploy-docs": "ts-node tools/gh-pages-publish", - "report-coverage": "cat ./coverage/lcov.info | coveralls", "storybook": "start-storybook -p 6006 -s ./storyboard-site", "build-storybook": "build-storybook -o storybook-static -s ./storyboard-site", "generate-code": "ts-node -P tsconfig.generate.json tools/generate-code" }, "lint-staged": { - "{src,test}/**/*.ts": [ + "src/**/*.ts": [ "prettier --write --no-semi --print-width 160" ] }, - "config": { - "commitizen": { - "path": "node_modules/cz-conventional-changelog" - }, - "validate-commit-msg": { - "types": "conventional-commit-types", - "helpMessage": "Use \"npm run commit\" instead, we use conventional-changelog format :) (https://github.com/commitizen/cz-cli)" - } - }, - "jest": { - "transform": { - ".(ts|tsx)": "/node_modules/ts-jest/preprocessor.js" - }, - "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$", - "moduleFileExtensions": [ - "ts", - "tsx", - "js" - ], - "coveragePathIgnorePatterns": [ - "/node_modules/", - "/test/" - ], - "coverageThreshold": { - "global": { - "branches": 90, - "functions": 95, - "lines": 95, - "statements": 95 - } - } - }, "devDependencies": { "@babel/core": "^7.9.0", "@babel/plugin-proposal-class-properties": "^7.5.5", @@ -85,10 +50,6 @@ "@babylonjs/loaders": "^4.1.0", "@babylonjs/procedural-textures": "^4.1.0", "@inlet/react-pixi": "^1.2.8", - "@react-spring/addons": "^9.0.0-beta.33", - "@react-spring/animated": "^9.0.0-beta.33", - "@react-spring/core": "9.0.0-beta.30", - "@react-spring/shared": "^9.0.0-beta.33", "@rollup/plugin-json": "^4.0.2", "@rollup/plugin-typescript": "^4.0.0", "@storybook/addon-actions": "^5.3.17", @@ -100,7 +61,6 @@ "@storybook/react": "^5.3.17", "@storybook/source-loader": "^5.3.17", "@storybook/theming": "^5.3.17", - "@types/jest": "^23.3.12", "@types/lodash.camelcase": "^4.3.6", "@types/node": "^8.0.0", "@types/pixi.js": "^5.0.0", @@ -109,34 +69,22 @@ "babel-loader": "^8.1.0", "cannon": "^0.6.2", "chroma-js": "^2.1.0", - "colors": "^1.3.3", - "commitizen": "^3.0.5", - "coveralls": "^3.0.2", "cross-env": "^7.0.0", - "cz-conventional-changelog": "^2.1.0", "earcut": "^2.2.2", - "fbjs": "^1.0.0", "gsap": "^2.1.3", - "husky": "^1.3.1", - "jest": "^23.6.0", "lint-staged": "^8.1.0", "lodash.camelcase": "^4.3.0", "pixi-projection": "^0.3.11", "pixi.js": "^5.2.1", "prettier": "^1.15.3", - "prompt": "^1.0.0", "react": "^16.13.1", "react-dom": "^16.13.1", "react-reconciler": "^0.25.1", - "replace-in-file": "^3.4.3", "rimraf": "^2.6.1", "rollup": "^2.0.6", "rollup-plugin-terser": "^5.3.0", "rollup-plugin-typescript2": "^0.26.0", - "semantic-release": "^15.13.3", - "shallow-equal-object": "^1.1.1", "storybook": "^5.3.17", - "ts-jest": "^23.10.5", "ts-morph": "^4.0.1", "ts-node": "^7.0.1", "tsc-watch": "^1.0.31", @@ -144,19 +92,13 @@ "tslint": "^5.12.1", "tslint-config-prettier": "^1.17.0", "tslint-config-standard": "^8.0.1", - "typedoc": "^0.14.1", - "typescript": "3.8.2", - "validate-commit-msg": "^2.14.0" + "typescript": "3.8.2" }, "peerDependencies": { "@babylonjs/core": "4.x", "@babylonjs/gui": "4.x", "@babylonjs/inspector": "4.x", "@babylonjs/loaders": "4.x", - "@react-spring/addons": "9.x", - "@react-spring/animated": "9.x", - "@react-spring/core": "9.x", - "@react-spring/shared": "9.x", "react": "16.x", "react-dom": "16.x", "react-reconciler": "0.x" diff --git a/src/plugins/react-babylon-spring/animated.ts b/src/plugins/react-babylon-spring/animated.ts deleted file mode 100644 index 67c2de46..00000000 --- a/src/plugins/react-babylon-spring/animated.ts +++ /dev/null @@ -1,84 +0,0 @@ -import {extendAnimated, withAnimated} from '@react-spring/animated' -import {CSSProperties, ForwardRefExoticComponent} from 'react' -import { - AssignableKeys, - ComponentPropsWithRef, - ElementType, - SpringValue, -} from '@react-spring/shared'; -import {intrinsicClassMap} from "../../generatedCode"; - -// TODO: Support type-checking for `animated` props -type BabylonComponents = { [key: string]: ElementType } - -const elements = Object.keys(intrinsicClassMap); - -/** - * TODO: Check the purpose of these types - */ -type CreateAnimated = ( - wrappedComponent: T -) => AnimatedComponent - -// Extend animated with all the available Babylon elements -export const animated: CreateAnimated & BabylonComponents = extendAnimated( - withAnimated, - [...elements], - true -) - -export {animated as a} - -/** The type of an `animated()` component */ -export type AnimatedComponent = ForwardRefExoticComponent>> - -/** The props of an `animated()` component */ -export type AnimatedProps = { - [P in keyof Props]: (P extends 'ref' | 'key' - ? Props[P] - : AnimatedProp) -} - -// The animated prop value of a React element -type AnimatedProp = [T, T] extends [infer T, infer DT] - ? [DT] extends [never] - ? never - : DT extends void - ? undefined - : DT extends object - ? [AssignableKeys] extends [never] - ? DT extends ReadonlyArray - ? AnimatedStyles
- : DT - : AnimatedStyle - : DT | AnimatedLeaf - : never - -// An animated array of style objects -type AnimatedStyles> = { - [P in keyof T]: [T[P]] extends [infer DT] - ? DT extends object - ? [AssignableKeys] extends [never] - ? DT extends ReadonlyArray - ? AnimatedStyles
- : DT - : { [P in keyof DT]: AnimatedProp } - : DT - : never -} - -// An animated object of style attributes -type AnimatedStyle = [T, T] extends [infer T, infer DT] - ? DT extends void - ? undefined - : [DT] extends [never] - ? never - : DT extends object - ? { [P in keyof DT]: AnimatedStyle } - : DT | AnimatedLeaf - : never - -// An animated value that is not an object -type AnimatedLeaf = [T] extends [object] - ? never - : SpringValue> diff --git a/src/plugins/react-babylon-spring/customProps.ts b/src/plugins/react-babylon-spring/customProps.ts deleted file mode 100644 index 6dd2c917..00000000 --- a/src/plugins/react-babylon-spring/customProps.ts +++ /dev/null @@ -1,137 +0,0 @@ -import { - ICustomPropsHandler, - PropChangeType, - PropertyUpdateProcessResult -} from "../../PropsHandler"; -import {Color3, Color4, Vector3} from "@babylonjs/core"; - -function parseRgbaString(rgba: string): number[] { - const arr: string[] = rgba.replace(/[^\d,]/g, '').split(','); - return arr.map(num => parseInt(num, 10) / 255); -} - -const Key = 'react-babylon-spring'; - -export class CustomColor3StringHandler implements ICustomPropsHandler { - get name() { - return `${Key}:Color3String` - } - - public propChangeType: string = PropChangeType.Color3; - - accept(newProp: string): boolean { - return typeof (newProp) === 'string'; - } - - process(oldProp: string, newProp: string): PropertyUpdateProcessResult { - if (oldProp !== newProp) { - return { - processed: true, - value: Color3.FromArray(parseRgbaString(newProp)) - }; - } - - return {processed: false, value: null}; - } -} - -export class CustomColor3ArrayHandler implements ICustomPropsHandler { - get name() { - return `${Key}:Color3Array` - } - - public propChangeType: string = PropChangeType.Color3; - - accept(newProp: []): boolean { - return Array.isArray(newProp); - } - - process(oldProp: number[], newProp: number[]): PropertyUpdateProcessResult { - if (oldProp === undefined || oldProp.length !== newProp.length) { - // console.log(`found diff length (${oldProp?.length}/${newProp?.length}) Color3Array new? ${oldProp === undefined}`) - return { - processed: true, - value: Color3.FromArray(newProp) - }; - } - - for (let i = 0; i < oldProp.length; i++) { - if (oldProp[i] !== newProp[i]) { - // console.log('found diff value Color3Array') - return { - processed: true, - value: Color3.FromArray(newProp) - }; - } - } - - return {processed: false, value: null}; - } -} - -export class CustomColor4StringHandler implements ICustomPropsHandler { - - get name() { - return `${Key}:Color4String` - } - - public propChangeType: string = PropChangeType.Color4; - - accept(newProp: string): boolean { - return typeof (newProp) === 'string'; - } - - process(oldProp: string, newProp: string): PropertyUpdateProcessResult { - if (oldProp !== newProp) { - // console.log('found diff Color4String') - return { - processed: true, - value: Color4.FromArray(parseRgbaString(newProp)) - }; - } - - return {processed: false, value: null}; - } -} - - -export class CustomVector3ArrayHandler implements ICustomPropsHandler { - get name() { - return `${Key}:Vector3Array` - } - - public propChangeType: string = PropChangeType.Vector3; - - accept(newProp: []): boolean { - return Array.isArray(newProp); - } - - process(oldProp: number[], newProp: number[]): PropertyUpdateProcessResult { - if (oldProp === undefined || oldProp.length !== newProp.length) { - // console.log(`found diff length (${oldProp?.length}/${newProp?.length}) Color3Array new? ${oldProp === undefined}`) - return { - processed: true, - value: Vector3.FromArray(newProp) - }; - } - - for (let i = 0; i < oldProp.length; i++) { - if (oldProp[i] !== newProp[i]) { - return { - processed: true, - value: Vector3.FromArray(newProp) - }; - } - } - - return {processed: false, value: null}; - } -} - -// May be useful to include where they can be ES6 loaded via side-effect. -// ie: import 'react-babylonjs/plugins/handlers' -// CustomPropsHandler.RegisterPropsHandler(new CustomColor3StringHandler()); -// CustomPropsHandler.RegisterPropsHandler(new CustomColor3ArrayHandler()); -// CustomPropsHandler.RegisterPropsHandler(new CustomColor4StringHandler()); -// CustomPropsHandler.RegisterPropsHandler(new CustomVector3ArrayHandler()); - diff --git a/src/plugins/react-babylon-spring/index.ts b/src/plugins/react-babylon-spring/index.ts deleted file mode 100644 index aa80eb39..00000000 --- a/src/plugins/react-babylon-spring/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -import {Globals} from '@react-spring/core'; -import {createStringInterpolator} from '@react-spring/shared/stringInterpolation'; -import {applyInitialPropsToInstance} from "../../UpdateInstance"; -import './customProps'; - -Globals.assign({ - defaultElement: 'transformNode', - // todo: frameLoop can use runRenderLoop - applyAnimatedValues: (node, props) => { - /** - * used for update props - * initialization don't enter here - */ - applyInitialPropsToInstance(node, props) - }, - createStringInterpolator, -}); - -export * from './animated'; -export * from './customProps'; -export * from '@react-spring/core'; diff --git a/src/react-babylonjs.ts b/src/react-babylonjs.ts index c3063364..ef114586 100644 --- a/src/react-babylonjs.ts +++ b/src/react-babylonjs.ts @@ -3,10 +3,9 @@ export * from "./generatedProps"; export * from "./hooks"; export * from "./customComponents"; // TODO: Except for Skybox - these should not be exported. they are internal. export * from "./PropsHandler"; +export { applyInitialPropsToInstance } from './UpdateInstance'; // Imported by react-babylonjs-spring export { default as Engine, withBabylonJS, BabylonJSContext, useBabylonEngine, useBabylonCanvas } from "./Engine"; export { default as Scene, withScene, WithSceneContext, SceneContext, SceneEventArgs, useBabylonScene } from "./Scene"; export { HostWithEvents } from "./customHosts"; - -export * from './plugins/react-babylon-spring'; diff --git a/stories/babylonjs/GUI/gui.stories.js b/stories/babylonjs/GUI/gui.stories.js index 583f97c3..f2fa7abc 100644 --- a/stories/babylonjs/GUI/gui.stories.js +++ b/stories/babylonjs/GUI/gui.stories.js @@ -1,5 +1,4 @@ import React, { useRef, useCallback } from 'react' -import {storiesOf} from '@storybook/react' import '@babylonjs/inspector' import {Engine, Scene} from '../../../dist/react-babylonjs' import {Vector3} from '@babylonjs/core/Maths/math' diff --git a/stories/babylonjs/Hooks/more-hooks.stories.js b/stories/babylonjs/Hooks/more-hooks.stories.js index ccbe204c..ba675819 100644 --- a/stories/babylonjs/Hooks/more-hooks.stories.js +++ b/stories/babylonjs/Hooks/more-hooks.stories.js @@ -1,5 +1,4 @@ import React from 'react'; -import { storiesOf } from '@storybook/react' import { Engine, Scene, useBabylonEngine, useBabylonCanvas, useBabylonScene } from '../../../dist/react-babylonjs' import { Vector3 } from '@babylonjs/core' diff --git a/test/react-babylonjs.test.ts b/test/react-babylonjs.test.ts deleted file mode 100644 index 69ba7500..00000000 --- a/test/react-babylonjs.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -import DummyClass from "../src/react-babylonjs" - -/** - * Dummy test - */ -describe("Dummy test", () => { - it("works if true is truthy", () => { - expect(true).toBeTruthy() - }) - - it("DummyClass is instantiable", () => { - expect(new DummyClass()).toBeInstanceOf(DummyClass) - }) -})