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.
Files changed (54) hide show
  1. package/.eslintrc.js +3 -2
  2. package/.github/workflows/lint.yaml +3 -1
  3. package/.prettierrc +1 -0
  4. package/babel.config.js +3 -0
  5. package/build/cjs/index.js +1 -1
  6. package/build/cjs/index.js.map +1 -1
  7. package/build/cjs/types/components/Cartesian.spec.d.ts +1 -0
  8. package/build/cjs/types/components/Mathbox.d.ts +7 -5
  9. package/build/cjs/types/components/MathboxNodeContext.d.ts +4 -0
  10. package/build/cjs/types/components/components.d.ts +261 -0
  11. package/build/cjs/types/components/hooks.d.ts +4 -0
  12. package/build/cjs/types/components/index.d.ts +2 -0
  13. package/build/cjs/types/components/types.d.ts +7 -0
  14. package/build/cjs/types/index.d.ts +1 -2
  15. package/build/cjs/types/stories/utils.d.ts +5 -0
  16. package/build/cjs/types/testSetup.d.ts +1 -0
  17. package/build/cjs/types/testUtils.d.ts +1 -0
  18. package/build/esm/index.js +15 -1
  19. package/build/esm/index.js.map +1 -1
  20. package/build/esm/types/components/Cartesian.spec.d.ts +1 -0
  21. package/build/esm/types/components/Mathbox.d.ts +7 -5
  22. package/build/esm/types/components/MathboxNodeContext.d.ts +4 -0
  23. package/build/esm/types/components/components.d.ts +261 -0
  24. package/build/esm/types/components/hooks.d.ts +4 -0
  25. package/build/esm/types/components/index.d.ts +2 -0
  26. package/build/esm/types/components/types.d.ts +7 -0
  27. package/build/esm/types/index.d.ts +1 -2
  28. package/build/esm/types/stories/utils.d.ts +5 -0
  29. package/build/esm/types/testSetup.d.ts +1 -0
  30. package/build/esm/types/testUtils.d.ts +1 -0
  31. package/build/index.d.ts +271 -5
  32. package/jest.config.js +12 -0
  33. package/mathbox-react-0.0.4.tgz +0 -0
  34. package/package.json +15 -6
  35. package/scratch.js +149 -0
  36. package/src/components/Cartesian.spec.tsx +101 -0
  37. package/src/components/Mathbox.tsx +50 -33
  38. package/src/components/MathboxNodeContext.ts +6 -0
  39. package/src/components/components.tsx +361 -0
  40. package/src/components/hooks.ts +51 -0
  41. package/src/components/index.ts +2 -0
  42. package/src/components/types.ts +9 -0
  43. package/src/index.ts +1 -3
  44. package/src/stories/Cartesian.stories.tsx +36 -0
  45. package/src/stories/Grid.stories.tsx +38 -0
  46. package/src/stories/Mathbox.stories.tsx +16 -0
  47. package/src/stories/Point.stories.tsx +68 -0
  48. package/src/stories/utils.tsx +31 -0
  49. package/src/testSetup.ts +3 -0
  50. package/src/testUtils.ts +46 -0
  51. package/tsconfig.base.json +0 -1
  52. package/tsconfig.json +1 -0
  53. package/src/components/Mathbox.stories.tsx +0 -28
  54. 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)
@@ -0,0 +1,3 @@
1
+ import { getMockContext } from "./testUtils"
2
+
3
+ HTMLCanvasElement.prototype.getContext = getMockContext
@@ -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
+ }
@@ -2,7 +2,6 @@
2
2
  "compilerOptions": {
3
3
  "esModuleInterop": true,
4
4
  "strict": true,
5
- "skipLibCheck": true,
6
5
  "jsx": "react",
7
6
  "module": "ESNext",
8
7
  "declaration": true,
package/tsconfig.json CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
2
  "extends": "./tsconfig.base.json",
3
+ "include": ["src/"],
3
4
  "exclude": ["src/**/*.test.tsx", "src/**/*.stories.tsx"]
4
5
  }
@@ -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
@@ -1,4 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- declare module "mathbox" {
3
- export const mathBox: any;
4
- }