mathbox-react 0.0.10 → 0.0.12

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 (61) hide show
  1. package/build/cjs/{types/components → components}/ContainedMathbox.d.ts +0 -0
  2. package/build/cjs/{types/components → components}/Mathbox.d.ts +0 -0
  3. package/build/cjs/components/MathboxNodeContext.d.ts +4 -0
  4. package/build/cjs/{types/components → components}/components.d.ts +6 -1
  5. package/build/cjs/{types/components → components}/index.d.ts +0 -0
  6. package/build/{esm/types → cjs}/components/types.d.ts +2 -2
  7. package/build/cjs/{types/components → components}/util.d.ts +1 -1
  8. package/build/cjs/{types/index.d.ts → index.d.ts} +0 -0
  9. package/build/cjs/index.js +1 -24
  10. package/build/cjs/index.js.map +1 -1
  11. package/build/cjs/{types/testSetup.d.ts → testSetup.d.ts} +0 -0
  12. package/build/cjs/{types/testUtils.d.ts → testUtils.d.ts} +0 -0
  13. package/build/esm/{types/components → components}/ContainedMathbox.d.ts +0 -0
  14. package/build/esm/{types/components → components}/Mathbox.d.ts +0 -0
  15. package/build/esm/components/MathboxNodeContext.d.ts +4 -0
  16. package/build/esm/{types/components → components}/components.d.ts +6 -1
  17. package/build/esm/{types/components → components}/index.d.ts +0 -0
  18. package/build/{cjs/types → esm}/components/types.d.ts +2 -2
  19. package/build/esm/{types/components → components}/util.d.ts +1 -1
  20. package/build/esm/{types/index.d.ts → index.d.ts} +0 -0
  21. package/build/esm/index.js +1 -24
  22. package/build/esm/index.js.map +1 -1
  23. package/build/esm/{types/testSetup.d.ts → testSetup.d.ts} +0 -0
  24. package/build/esm/{types/testUtils.d.ts → testUtils.d.ts} +0 -0
  25. package/build/index.d.ts +8 -3
  26. package/package.json +40 -45
  27. package/.eslintrc.js +0 -72
  28. package/.github/workflows/lint.yaml +0 -20
  29. package/.prettierrc +0 -1
  30. package/.storybook/main.js +0 -9
  31. package/.storybook/preview.js +0 -11
  32. package/LICENSE +0 -29
  33. package/README.md +0 -6
  34. package/babel.config.js +0 -3
  35. package/build/cjs/types/components/MathboxNodeContext.d.ts +0 -4
  36. package/build/cjs/types/components/components.spec.d.ts +0 -1
  37. package/build/cjs/types/stories/utils.d.ts +0 -5
  38. package/build/esm/types/components/MathboxNodeContext.d.ts +0 -4
  39. package/build/esm/types/components/components.spec.d.ts +0 -1
  40. package/build/esm/types/stories/utils.d.ts +0 -5
  41. package/jest.config.js +0 -12
  42. package/rollup.config.js +0 -38
  43. package/scratch.js +0 -149
  44. package/src/components/ContainedMathbox.tsx +0 -38
  45. package/src/components/Mathbox.tsx +0 -63
  46. package/src/components/MathboxNodeContext.ts +0 -6
  47. package/src/components/components.spec.tsx +0 -276
  48. package/src/components/components.tsx +0 -419
  49. package/src/components/index.ts +0 -3
  50. package/src/components/types.ts +0 -9
  51. package/src/components/util.ts +0 -106
  52. package/src/index.ts +0 -1
  53. package/src/stories/Cartesian.stories.tsx +0 -36
  54. package/src/stories/Grid.stories.tsx +0 -38
  55. package/src/stories/Mathbox.stories.tsx +0 -16
  56. package/src/stories/Point.stories.tsx +0 -68
  57. package/src/stories/utils.tsx +0 -33
  58. package/src/testSetup.ts +0 -3
  59. package/src/testUtils.ts +0 -46
  60. package/tsconfig.base.json +0 -17
  61. package/tsconfig.json +0 -5
@@ -1,9 +0,0 @@
1
- import type { ReactNode } from "react"
2
- import type { MathboxSelection, NodeType } from "mathbox"
3
- import React from "react"
4
-
5
- export type WithChildren<T> = {
6
- children?: ReactNode | ReactNode[]
7
- } & T
8
-
9
- export type MathboxRef<T extends NodeType> = React.Ref<MathboxSelection<T>>
@@ -1,106 +0,0 @@
1
- /* eslint-disable no-underscore-dangle */
2
- import { isEqual } from "lodash"
3
- import { useRef, useMemo } from "react"
4
- import { MathboxSelection, NodeType } from "mathbox"
5
-
6
- type WithPrivateUp = MathboxSelection & { _up?: WithPrivateUp }
7
-
8
- /**
9
- * Get root node given any node in Mathbox tree
10
- */
11
- const getRoot = (selection: MathboxSelection) => {
12
- let current = selection as WithPrivateUp
13
- while (current._up) {
14
- current = current._up
15
- }
16
- return current
17
- }
18
-
19
- export const isRootDestroyed = (selection: MathboxSelection) => {
20
- const root = getRoot(selection)
21
- return root.three === undefined
22
- }
23
-
24
- /**
25
- * Check that parent is actually the selection's parent.
26
- * The mathbox components occasionally render with a selection value whose
27
- * parent does not match the parent specified in MathboxContext.
28
- *
29
- * I believe this fundamentally this is happening because
30
- * - we store parent value in context...
31
- * - we update the context parent value using useEffect hooks..
32
- * - useEffect hooks are called children before parents.
33
- *
34
- * One wonders whether we really need to be using useEffect hooks for the
35
- * mathbox components, or if we can just put all the node creation/removal stuff
36
- * in a render function. Hooks seem nice for dependencies, but mathbox is pretty
37
- * smart about diffing out the actual changes.
38
- */
39
- export const isSelectionParent = (
40
- selection: MathboxSelection,
41
- parent: MathboxSelection
42
- ) => {
43
- const selectionParentNode = (selection as WithPrivateUp)._up?.[0]
44
- return selectionParentNode === parent[0]
45
- }
46
-
47
- const CAN_HAVE_CHILDREN = [
48
- "view",
49
- "cartesian",
50
- "cartesian4",
51
- "polar",
52
- "spherical",
53
- "stereographic",
54
- "stereographic4",
55
- "transform",
56
- "transform4",
57
- "vertex",
58
- "fragment",
59
- "layer",
60
- "mask",
61
- "group",
62
- "inherit",
63
- "root",
64
- "unit",
65
- "rtt",
66
- "clock",
67
- "now",
68
- "move",
69
- "present",
70
- "reveal",
71
- "slide",
72
- ] as const
73
-
74
- export type ParentNodeTypes = typeof CAN_HAVE_CHILDREN[number]
75
-
76
- export const canNodeHaveChildren = (type: NodeType) =>
77
- (CAN_HAVE_CHILDREN as readonly string[]).includes(type)
78
-
79
- export const capitalize = (s: string) => {
80
- if (!s) return ""
81
- return s[0].toLocaleUpperCase() + s.slice(1)
82
- }
83
-
84
- /**
85
- * Returns the same reference to `value` as long as the the given values are
86
- * deep equal.
87
- *
88
- * This is, in general, not a great idea. See
89
- * https://github.com/facebook/react/issues/14476#issuecomment-471199055
90
- *
91
- * This should work OK for mathbox options because the objects in question are
92
- * either shallow, or are deep equal at a fairly shallow level.
93
- * E.g., OrbitControls may not be a shall object, but if it's not, it will at
94
- * least be deep equal between renders.
95
- *
96
- * But should work OK for mathbox options.
97
- */
98
- export const useDeepCompareMemo = <T>(value: T, initial: T): T => {
99
- const oldValue = useRef<T>(initial)
100
- const memoOptions = useMemo(() => {
101
- if (isEqual(value, oldValue.current)) return oldValue.current
102
- oldValue.current = value
103
- return value
104
- }, [value])
105
- return memoOptions
106
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./components"
@@ -1,36 +0,0 @@
1
- import React from "react"
2
- import { Story, Meta } from "@storybook/react"
3
-
4
- import { CustomMathbox as Mathbox } from "./utils"
5
- import { Cartesian, Grid } from "../components/components"
6
-
7
- export default {
8
- title: "Cartesian",
9
- component: Cartesian,
10
- argTypes: {
11
- range: {
12
- type: "array",
13
- default: [
14
- [-1, 1],
15
- [-1, 1],
16
- [-1, 1],
17
- [-1, 1],
18
- ],
19
- },
20
- scale: {
21
- type: "array",
22
- default: [1, 1, 1],
23
- },
24
- },
25
- } as Meta<typeof Cartesian>
26
-
27
- const Template: Story<React.ComponentProps<typeof Cartesian>> = (args) => (
28
- <Mathbox containerStyle={{ height: 450 }}>
29
- <Cartesian {...args}>
30
- <Grid />
31
- </Cartesian>
32
- </Mathbox>
33
- )
34
-
35
- export const DefaultCartesian = Template.bind({})
36
- DefaultCartesian.args = {}
@@ -1,38 +0,0 @@
1
- import React from "react"
2
- import { Story, Meta } from "@storybook/react"
3
-
4
- import { CustomMathbox as Mathbox } from "./utils"
5
- import { Grid } from "../components"
6
-
7
- export default {
8
- title: "Grid",
9
- component: Grid,
10
- argTypes: {
11
- color: {
12
- type: "string",
13
- default: "rgb(128, 128, 128)",
14
- },
15
- axes: {
16
- type: "string",
17
- default: "xy",
18
- },
19
- },
20
- } as Meta<typeof Grid>
21
-
22
- const Template: Story<React.ComponentProps<typeof Grid>> = (args) => (
23
- <Mathbox containerStyle={{ height: 450 }}>
24
- <Grid {...args} />
25
- </Mathbox>
26
- )
27
-
28
- export const DefaultGrid = Template.bind({})
29
- DefaultGrid.args = {}
30
-
31
- export const GridXY = Template.bind({})
32
- GridXY.args = { axes: "xy" }
33
-
34
- export const GridYZ = Template.bind({})
35
- GridYZ.args = { axes: "yz" }
36
-
37
- export const GridZX = Template.bind({})
38
- GridZX.args = { axes: "zx" }
@@ -1,16 +0,0 @@
1
- import React from "react"
2
- import { Story, Meta } from "@storybook/react"
3
-
4
- import { ContainedMathbox } from "../components"
5
-
6
- export default {
7
- title: "Mathbox",
8
- component: ContainedMathbox,
9
- argTypes: {},
10
- } as Meta<typeof ContainedMathbox>
11
-
12
- const Template: Story<React.ComponentProps<typeof ContainedMathbox>> = () => (
13
- <ContainedMathbox />
14
- )
15
-
16
- export const HelloWorld = Template.bind({})
@@ -1,68 +0,0 @@
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 containerStyle={{ 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 = {}
@@ -1,33 +0,0 @@
1
- import React, { useMemo, useCallback } from "react"
2
- import { MathboxSelection } from "mathbox"
3
- import { OrbitControls } from "three/examples/jsm/controls/OrbitControls"
4
- import { ContainedMathbox } from "../components"
5
-
6
- type MathboxProps = React.ComponentProps<typeof ContainedMathbox>
7
-
8
- const storybookDefaultMathboxOptions = {
9
- plugins: ["core", "controls", "cursor"],
10
- controls: {
11
- klass: OrbitControls,
12
- },
13
- }
14
-
15
- export const CustomMathbox = (props: MathboxProps) => {
16
- const { options: overrides, ...others } = props
17
- const options = useMemo(
18
- () => ({
19
- ...storybookDefaultMathboxOptions,
20
- ...(overrides ?? {}),
21
- }),
22
- [overrides]
23
- )
24
- const setup = useCallback((mathbox: MathboxSelection<"root"> | null) => {
25
- if (mathbox === null) return
26
- mathbox.three.camera.position.set(1, 1, 2)
27
- }, [])
28
- return (
29
- <ContainedMathbox ref={setup} options={options} {...others}>
30
- {props.children}
31
- </ContainedMathbox>
32
- )
33
- }
package/src/testSetup.ts DELETED
@@ -1,3 +0,0 @@
1
- import { getMockContext } from "./testUtils"
2
-
3
- HTMLCanvasElement.prototype.getContext = getMockContext
package/src/testUtils.ts DELETED
@@ -1,46 +0,0 @@
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
- }
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "esModuleInterop": true,
4
- "strict": true,
5
- "jsx": "react",
6
- "module": "ESNext",
7
- "declaration": true,
8
- "declarationDir": "types",
9
- "sourceMap": true,
10
- "outDir": "build",
11
- "moduleResolution": "node",
12
- "emitDeclarationOnly": true,
13
- "allowSyntheticDefaultImports": true,
14
- "forceConsistentCasingInFileNames": true
15
- },
16
- "exclude": ["dist", "node_modules"]
17
- }
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "./tsconfig.base.json",
3
- "include": ["src/"],
4
- "exclude": ["src/**/*.test.tsx", "src/**/*.stories.tsx"]
5
- }