mathbox-react 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js ADDED
@@ -0,0 +1,71 @@
1
+ module.exports = {
2
+ extends: [
3
+ "react-app",
4
+ "react-app/jest",
5
+ "airbnb",
6
+ "airbnb-typescript",
7
+ "prettier",
8
+ "eslint:recommended",
9
+ "plugin:react/recommended",
10
+ "plugin:@typescript-eslint/recommended",
11
+ "plugin:react-hooks/recommended",
12
+ ],
13
+ plugins: ["react", "@typescript-eslint", "prettier"],
14
+ rules: {
15
+ "import/no-extraneous-dependencies": [
16
+ "error",
17
+ {
18
+ devDependencies: ["**/*.stories.*"],
19
+ },
20
+ ],
21
+ "import/prefer-default-export": "off",
22
+ "max-classes-per-file": "off",
23
+ "react/destructuring-assignment": "off",
24
+ "react/function-component-definition": [
25
+ "error",
26
+ {
27
+ namedComponents: "arrow-function",
28
+ unnamedComponents: "arrow-function",
29
+ },
30
+ ],
31
+ "@typescript-eslint/no-unused-vars": [
32
+ "warn",
33
+ {
34
+ argsIgnorePattern: "^_",
35
+ varsIgnorePattern: "^_",
36
+ caughtErrorsIgnorePattern: "^_",
37
+ },
38
+ ],
39
+ "@typescript-eslint/naming-convention": [
40
+ "error",
41
+ {
42
+ selector: "variable",
43
+ format: ["camelCase", "PascalCase", "UPPER_CASE"],
44
+ filter: {
45
+ regex: "^_",
46
+ match: false,
47
+ },
48
+ },
49
+ ],
50
+ },
51
+ settings: {},
52
+ overrides: [
53
+ {
54
+ files: ["**/*.ts?(x)"],
55
+ rules: {
56
+ "react/prop-types": "off",
57
+ "react/require-default-props": "off",
58
+ "react/jsx-props-no-spreading": "off",
59
+ },
60
+ },
61
+ {
62
+ files: ["**/*.stories.*"],
63
+ rules: {
64
+ "import/no-anonymous-default-export": "off",
65
+ },
66
+ },
67
+ ],
68
+ parserOptions: {
69
+ project: "./tsconfig.base.json",
70
+ },
71
+ };
@@ -0,0 +1,18 @@
1
+ name: tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [main]
6
+
7
+ jobs:
8
+ linting:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - uses: actions/setup-node@v2
13
+ with:
14
+ node-version: "16"
15
+ cache: "npm"
16
+ cache-dependency-path: package-lock.json
17
+ - run: npm ci
18
+ - run: npm run lint
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
3
+ addons: [
4
+ "@storybook/addon-links",
5
+ "@storybook/addon-essentials",
6
+ "@storybook/addon-interactions",
7
+ ],
8
+ framework: "@storybook/react",
9
+ };
@@ -0,0 +1,11 @@
1
+ import "mathbox/build/mathbox.css";
2
+
3
+ export const parameters = {
4
+ actions: { argTypesRegex: "^on[A-Z].*" },
5
+ controls: {
6
+ matchers: {
7
+ color: /(background|color)$/i,
8
+ date: /Date$/,
9
+ },
10
+ },
11
+ };
package/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2022, Chris Chudzicki
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/package.json CHANGED
@@ -1,11 +1,51 @@
1
1
  {
2
2
  "name": "mathbox-react",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "React wrapper for Mathbox",
5
- "main": "index.js",
5
+ "license": "ISC",
6
+ "author": "Chris Chudzicki",
7
+ "main": "build/cjs/index.js",
8
+ "module": "build/esm/index.js",
6
9
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
10
+ "build": "rollup -c",
11
+ "build-storybook": "build-storybook",
12
+ "storybook": "start-storybook -p 6006",
13
+ "lint": "eslint \"src/**/*.{ts,tsx}\" --fix --max-warnings=0"
8
14
  },
9
- "author": "Chris Chudzicki",
10
- "license": "ISC"
15
+ "devDependencies": {
16
+ "@babel/core": "^7.17.5",
17
+ "@rollup/plugin-commonjs": "^21.0.1",
18
+ "@rollup/plugin-node-resolve": "^13.1.3",
19
+ "@rollup/plugin-typescript": "^8.3.0",
20
+ "@storybook/addon-actions": "^6.4.19",
21
+ "@storybook/addon-essentials": "^6.4.19",
22
+ "@storybook/addon-interactions": "^6.4.19",
23
+ "@storybook/addon-links": "^6.4.19",
24
+ "@storybook/react": "^6.4.19",
25
+ "@storybook/testing-library": "^0.0.9",
26
+ "@types/react": "^17.0.39",
27
+ "@types/three": "^0.137.0",
28
+ "babel-loader": "^8.2.3",
29
+ "eslint-config-airbnb": "^19.0.4",
30
+ "eslint-config-airbnb-typescript": "^16.1.0",
31
+ "eslint-config-prettier": "^8.3.0",
32
+ "eslint-config-react-app": "^7.0.0",
33
+ "eslint-import-resolver-typescript": "^2.5.0",
34
+ "eslint-plugin-prettier": "^4.0.0",
35
+ "mathbox": "^2.1.0",
36
+ "prettier": "^2.5.1",
37
+ "react": "^17.0.2",
38
+ "react-dom": "^17.0.2",
39
+ "rollup": "^2.67.3",
40
+ "rollup-plugin-dts": "^4.1.0",
41
+ "rollup-plugin-peer-deps-external": "^2.2.4",
42
+ "rollup-plugin-terser": "^7.0.2",
43
+ "three": "^0.137.5",
44
+ "typescript": "^4.5.5"
45
+ },
46
+ "peerDependencies": {
47
+ "mathbox": "^2.1.0",
48
+ "react": "^17.0.2",
49
+ "three": "^0.137.5"
50
+ }
11
51
  }
@@ -0,0 +1,38 @@
1
+ import resolve from "@rollup/plugin-node-resolve";
2
+ import commonjs from "@rollup/plugin-commonjs";
3
+ import typescript from "@rollup/plugin-typescript";
4
+ import dts from "rollup-plugin-dts";
5
+ import { terser } from "rollup-plugin-terser";
6
+ import peerDepsExternal from "rollup-plugin-peer-deps-external";
7
+ import packageJson from "./package.json";
8
+
9
+ export default [
10
+ {
11
+ input: "src/index.ts",
12
+ output: [
13
+ {
14
+ file: packageJson.main,
15
+ format: "cjs",
16
+ sourcemap: true,
17
+ },
18
+ {
19
+ file: packageJson.module,
20
+ format: "esm",
21
+ sourcemap: true,
22
+ },
23
+ ],
24
+ plugins: [
25
+ peerDepsExternal(),
26
+ resolve(),
27
+ commonjs(),
28
+ typescript({ tsconfig: "./tsconfig.json" }),
29
+ terser(),
30
+ ],
31
+ external: ["react", "react-dom", "styled-components"],
32
+ },
33
+ {
34
+ input: "build/esm/types/index.d.ts",
35
+ output: [{ file: "build/index.d.ts", format: "esm" }],
36
+ plugins: [dts()],
37
+ },
38
+ ];
@@ -0,0 +1,28 @@
1
+ import React, { useRef, useState, useEffect } from 'react';
2
+ import { Story, Meta } from '@storybook/react';
3
+
4
+ import Mathbox from './Mathbox';
5
+
6
+ export default {
7
+ title: 'Mathbox',
8
+ component: Mathbox,
9
+ argTypes: {
10
+ },
11
+ } as Meta<typeof Mathbox>;
12
+
13
+ const Template: Story<React.ComponentProps<typeof Mathbox>> = () => {
14
+ const container = useRef<HTMLDivElement>(null);
15
+ const [_isMounted, setIsMounted] = useState(false)
16
+ useEffect(() => {
17
+ setIsMounted(true)
18
+ return () => setIsMounted(false)
19
+ }, [])
20
+ return (
21
+ <div ref={container} style={{ height: 450 }}>
22
+ {container.current &&
23
+ <Mathbox element={container.current} />}
24
+ </div>
25
+ )
26
+ };
27
+
28
+ export const HelloWorld = Template.bind({});
@@ -0,0 +1,41 @@
1
+ import { useEffect } from 'react'
2
+ import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
3
+ import { Color } from "three/src/math/Color";
4
+ import * as MB from 'mathbox'
5
+
6
+ type Props = {
7
+ element: HTMLElement
8
+ }
9
+
10
+ const Mathbox = (props: Props) => {
11
+ useEffect(() => {
12
+ const mathbox = MB.mathBox({
13
+ plugins: ["core", "controls", "cursor"],
14
+ controls: {
15
+ klass: OrbitControls,
16
+ },
17
+ element: props.element,
18
+ });
19
+
20
+ mathbox.three.camera.position.set(1, 1, 2);
21
+ mathbox.three.renderer.setClearColor(new Color(0xffffff), 1.0);
22
+
23
+ const view = mathbox.cartesian({
24
+ range: [
25
+ [-2, 2],
26
+ [-1, 1],
27
+ [-1, 1],
28
+ ],
29
+ scale: [2, 1, 1],
30
+ });
31
+ view.grid({
32
+ divideX: 20,
33
+ width: 5,
34
+ opacity: 0.3,
35
+ });
36
+
37
+ }, [props.element])
38
+ return null
39
+ }
40
+
41
+ export default Mathbox
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ import Mathbox from "./components/Mathbox";
2
+
3
+ export { Mathbox };
package/src/types.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ declare module "mathbox" {
3
+ export const mathBox: any;
4
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "esModuleInterop": true,
4
+ "strict": true,
5
+ "skipLibCheck": true,
6
+ "jsx": "react",
7
+ "module": "ESNext",
8
+ "declaration": true,
9
+ "declarationDir": "types",
10
+ "sourceMap": true,
11
+ "outDir": "build",
12
+ "moduleResolution": "node",
13
+ "emitDeclarationOnly": true,
14
+ "allowSyntheticDefaultImports": true,
15
+ "forceConsistentCasingInFileNames": true
16
+ },
17
+ "exclude": ["dist", "node_modules"]
18
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+ "exclude": ["src/**/*.test.tsx", "src/**/*.stories.tsx"]
4
+ }