mathbox-react 0.0.4 → 0.0.5-dev
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 +3 -2
- package/.github/workflows/lint.yaml +3 -1
- package/.prettierrc +1 -0
- package/babel.config.js +3 -0
- package/build/cjs/index.js +1 -1
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/types/components/Cartesian.spec.d.ts +1 -0
- package/build/cjs/types/components/Mathbox.d.ts +7 -5
- package/build/cjs/types/components/MathboxNodeContext.d.ts +4 -0
- package/build/cjs/types/components/components.d.ts +261 -0
- package/build/cjs/types/components/hooks.d.ts +4 -0
- package/build/cjs/types/components/index.d.ts +2 -0
- package/build/cjs/types/components/types.d.ts +7 -0
- package/build/cjs/types/index.d.ts +1 -2
- package/build/cjs/types/stories/utils.d.ts +5 -0
- package/build/cjs/types/testSetup.d.ts +1 -0
- package/build/cjs/types/testUtils.d.ts +1 -0
- package/build/esm/index.js +15 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/types/components/Cartesian.spec.d.ts +1 -0
- package/build/esm/types/components/Mathbox.d.ts +7 -5
- package/build/esm/types/components/MathboxNodeContext.d.ts +4 -0
- package/build/esm/types/components/components.d.ts +261 -0
- package/build/esm/types/components/hooks.d.ts +4 -0
- package/build/esm/types/components/index.d.ts +2 -0
- package/build/esm/types/components/types.d.ts +7 -0
- package/build/esm/types/index.d.ts +1 -2
- package/build/esm/types/stories/utils.d.ts +5 -0
- package/build/esm/types/testSetup.d.ts +1 -0
- package/build/esm/types/testUtils.d.ts +1 -0
- package/build/index.d.ts +271 -5
- package/jest.config.js +12 -0
- package/mathbox-react-0.0.4.tgz +0 -0
- package/package.json +15 -6
- package/scratch.js +149 -0
- package/src/components/Cartesian.spec.tsx +101 -0
- package/src/components/Mathbox.tsx +50 -33
- package/src/components/MathboxNodeContext.ts +6 -0
- package/src/components/components.tsx +361 -0
- package/src/components/hooks.ts +51 -0
- package/src/components/index.ts +2 -0
- package/src/components/types.ts +9 -0
- package/src/index.ts +1 -3
- package/src/stories/Cartesian.stories.tsx +36 -0
- package/src/stories/Grid.stories.tsx +38 -0
- package/src/stories/Mathbox.stories.tsx +16 -0
- package/src/stories/Point.stories.tsx +68 -0
- package/src/stories/utils.tsx +31 -0
- package/src/testSetup.ts +3 -0
- package/src/testUtils.ts +46 -0
- package/tsconfig.base.json +0 -1
- package/tsconfig.json +1 -0
- package/src/components/Mathbox.stories.tsx +0 -28
- package/src/types.d.ts +0 -4
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React, { useState } from "react"
|
|
2
|
+
import { Story, Meta } from "@storybook/react"
|
|
3
|
+
import { MathboxSelection } from "mathbox"
|
|
4
|
+
import { CustomMathbox as Mathbox } from "./utils"
|
|
5
|
+
import { Cartesian, Grid, Point, Array as MBArray } from "../components"
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: "Point",
|
|
9
|
+
component: Point,
|
|
10
|
+
argTypes: {
|
|
11
|
+
color: {
|
|
12
|
+
type: "string",
|
|
13
|
+
default: "rgb(128, 128, 128)",
|
|
14
|
+
},
|
|
15
|
+
opacity: {
|
|
16
|
+
type: "number",
|
|
17
|
+
default: 1,
|
|
18
|
+
},
|
|
19
|
+
points: {
|
|
20
|
+
type: "array",
|
|
21
|
+
default: [[1, 1, 1]],
|
|
22
|
+
},
|
|
23
|
+
size: {
|
|
24
|
+
type: "number",
|
|
25
|
+
default: 4,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
} as Meta<typeof Grid>
|
|
29
|
+
|
|
30
|
+
const Template: Story<React.ComponentProps<typeof Point>> = (args) => {
|
|
31
|
+
const { points, ...otherArgs } = args
|
|
32
|
+
const [data, setData] = useState<MathboxSelection<"array">>()
|
|
33
|
+
return (
|
|
34
|
+
<Mathbox style={{ height: 450 }}>
|
|
35
|
+
<Cartesian
|
|
36
|
+
range={[
|
|
37
|
+
[-5, 5],
|
|
38
|
+
[-5, 5],
|
|
39
|
+
[-5, 5],
|
|
40
|
+
]}
|
|
41
|
+
>
|
|
42
|
+
<Grid axes="xy" />
|
|
43
|
+
<Grid axes="xz" />
|
|
44
|
+
<MBArray
|
|
45
|
+
ref={setData}
|
|
46
|
+
items={1}
|
|
47
|
+
channels={3}
|
|
48
|
+
data={[
|
|
49
|
+
[1, 1, 2],
|
|
50
|
+
[1, 1, 3],
|
|
51
|
+
]}
|
|
52
|
+
/>
|
|
53
|
+
<MBArray
|
|
54
|
+
items={1}
|
|
55
|
+
channels={3}
|
|
56
|
+
data={[
|
|
57
|
+
[1, 1, -2],
|
|
58
|
+
[1, 1, -3],
|
|
59
|
+
]}
|
|
60
|
+
/>
|
|
61
|
+
<Point points={data} {...otherArgs} />
|
|
62
|
+
</Cartesian>
|
|
63
|
+
</Mathbox>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const DefaultPoint = Template.bind({})
|
|
68
|
+
DefaultPoint.args = {}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React, { forwardRef, useMemo } from "react"
|
|
2
|
+
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls"
|
|
3
|
+
import { Mathbox } from "../components"
|
|
4
|
+
|
|
5
|
+
type MathboxProps = React.ComponentProps<typeof Mathbox>
|
|
6
|
+
type MathboxRef = React.ComponentRef<typeof Mathbox>
|
|
7
|
+
|
|
8
|
+
const storybookDefaultMathboxOptions = {
|
|
9
|
+
plugins: ["core", "controls", "cursor"],
|
|
10
|
+
controls: {
|
|
11
|
+
klass: OrbitControls,
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const CustomMathboxF = (props: MathboxProps, ref: React.Ref<MathboxRef>) => {
|
|
16
|
+
const { options: overrides, ...divProps } = props
|
|
17
|
+
const options = useMemo(
|
|
18
|
+
() => ({
|
|
19
|
+
...storybookDefaultMathboxOptions,
|
|
20
|
+
...(props.options ?? {}),
|
|
21
|
+
}),
|
|
22
|
+
[props.options]
|
|
23
|
+
)
|
|
24
|
+
return (
|
|
25
|
+
<Mathbox options={options} {...divProps} ref={ref}>
|
|
26
|
+
{props.children}
|
|
27
|
+
</Mathbox>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const CustomMathbox = forwardRef(CustomMathboxF)
|
package/src/testSetup.ts
ADDED
package/src/testUtils.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
type Automock = any
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A mock that uses proxies to create properties as they are accessed. Supports
|
|
6
|
+
* function calls and toPrimitive.
|
|
7
|
+
*
|
|
8
|
+
* @param specifics Allows specifying specific values for properties. If a prop
|
|
9
|
+
* exists on `specifics`, then that value will be used when the property is
|
|
10
|
+
* accessed on automock.
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
const getAutomock = <T extends Record<string | symbol, unknown>>(
|
|
14
|
+
specifics?: T
|
|
15
|
+
): Automock => {
|
|
16
|
+
const autmockSeed = jest.fn()
|
|
17
|
+
const handler = {
|
|
18
|
+
get(target: Automock, prop: string | symbol) {
|
|
19
|
+
if (prop === Symbol.toPrimitive) {
|
|
20
|
+
return () => `Automock: ${JSON.stringify(specifics)}`
|
|
21
|
+
}
|
|
22
|
+
if (specifics && Reflect.has(specifics, prop)) {
|
|
23
|
+
const value = Reflect.get(specifics, prop)
|
|
24
|
+
return value
|
|
25
|
+
}
|
|
26
|
+
if (!Reflect.has(target, prop)) {
|
|
27
|
+
Reflect.set(target, prop, getAutomock())
|
|
28
|
+
}
|
|
29
|
+
return Reflect.get(target, prop)
|
|
30
|
+
},
|
|
31
|
+
apply() {
|
|
32
|
+
return getAutomock()
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
return new Proxy(autmockSeed, handler)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const getMockContext = () => {
|
|
39
|
+
const mockContext = getAutomock({
|
|
40
|
+
getParameter: jest.fn((name) => {
|
|
41
|
+
if (name === mockContext.VERSION) return "Fake version!"
|
|
42
|
+
return getAutomock()
|
|
43
|
+
}),
|
|
44
|
+
})
|
|
45
|
+
return mockContext
|
|
46
|
+
}
|
package/tsconfig.base.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,28 +0,0 @@
|
|
|
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({});
|
package/src/types.d.ts
DELETED