mathbox-react 0.0.11-rc → 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.
- package/build/cjs/components/components.d.ts +2 -2
- package/build/cjs/components/types.d.ts +2 -2
- package/build/cjs/components/util.d.ts +1 -1
- package/build/cjs/index.js +1 -1
- package/build/cjs/index.js.map +1 -1
- package/build/esm/components/components.d.ts +2 -2
- package/build/esm/components/types.d.ts +2 -2
- package/build/esm/components/util.d.ts +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/index.d.ts +4 -4
- package/package.json +12 -17
- package/.eslintrc.js +0 -72
- package/.github/renovate.json +0 -13
- package/.github/workflows/lint.yaml +0 -20
- package/.prettierrc +0 -1
- package/.storybook/main.js +0 -9
- package/.storybook/preview.js +0 -11
- package/LICENSE +0 -29
- package/README.md +0 -6
- package/babel.config.js +0 -3
- package/build/cjs/components/components.spec.d.ts +0 -1
- package/build/cjs/stories/utils.d.ts +0 -5
- package/build/esm/components/components.spec.d.ts +0 -1
- package/build/esm/stories/utils.d.ts +0 -5
- package/jest.config.js +0 -12
- package/rollup.config.js +0 -38
- package/src/components/ContainedMathbox.tsx +0 -38
- package/src/components/Mathbox.tsx +0 -63
- package/src/components/MathboxNodeContext.ts +0 -6
- package/src/components/components.spec.tsx +0 -311
- package/src/components/components.tsx +0 -443
- package/src/components/index.ts +0 -3
- package/src/components/types.ts +0 -9
- package/src/components/util.ts +0 -106
- package/src/index.ts +0 -1
- package/src/stories/Cartesian.stories.tsx +0 -36
- package/src/stories/Grid.stories.tsx +0 -38
- package/src/stories/Mathbox.stories.tsx +0 -16
- package/src/stories/Point.stories.tsx +0 -75
- package/src/stories/utils.tsx +0 -33
- package/src/testSetup.ts +0 -3
- package/src/testUtils.ts +0 -46
- package/tsconfig.base.json +0 -17
- package/tsconfig.json +0 -5
|
@@ -1,443 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
forwardRef,
|
|
3
|
-
useRef,
|
|
4
|
-
useContext,
|
|
5
|
-
useEffect,
|
|
6
|
-
useReducer,
|
|
7
|
-
useImperativeHandle,
|
|
8
|
-
} from "react"
|
|
9
|
-
import { Props, NodeType, MathboxSelection } from "mathbox"
|
|
10
|
-
import MathboxAPIContext from "./MathboxNodeContext"
|
|
11
|
-
import { WithChildren } from "./types"
|
|
12
|
-
import {
|
|
13
|
-
isRootDestroyed,
|
|
14
|
-
isSelectionParent,
|
|
15
|
-
canNodeHaveChildren,
|
|
16
|
-
ParentNodeTypes,
|
|
17
|
-
capitalize,
|
|
18
|
-
} from "./util"
|
|
19
|
-
|
|
20
|
-
type LiveProps<P> = {
|
|
21
|
-
[K in keyof P]: (t: number, dt: number) => P[K]
|
|
22
|
-
}
|
|
23
|
-
type MathboxComponent<T extends NodeType> = React.ForwardRefExoticComponent<
|
|
24
|
-
(T extends ParentNodeTypes ? WithChildren<Props[T]> : Props[T]) &
|
|
25
|
-
React.RefAttributes<MathboxSelection<T>> & {
|
|
26
|
-
liveProps?: LiveProps<Props[T]>
|
|
27
|
-
}
|
|
28
|
-
>
|
|
29
|
-
|
|
30
|
-
const mathboxComponentFactory = <T extends NodeType>(
|
|
31
|
-
type: T
|
|
32
|
-
): MathboxComponent<T> => {
|
|
33
|
-
const canHaveChildren = canNodeHaveChildren(type)
|
|
34
|
-
const componentName = capitalize(type)
|
|
35
|
-
const Comp = (
|
|
36
|
-
props: WithChildren<Props[T]> & { liveProps?: LiveProps<Props[T]> },
|
|
37
|
-
ref: React.Ref<MathboxSelection<T> | null>
|
|
38
|
-
) => {
|
|
39
|
-
const [_ignored, forceUpdate] = useReducer((x) => x + 1, 0)
|
|
40
|
-
const parent = useContext(MathboxAPIContext)
|
|
41
|
-
const selection = useRef<MathboxSelection<T> | null>(null)
|
|
42
|
-
const prevLiveProps = useRef<LiveProps<Props[T]> | undefined>(undefined)
|
|
43
|
-
useEffect(
|
|
44
|
-
() => () => {
|
|
45
|
-
if (selection.current) {
|
|
46
|
-
selection.current.remove()
|
|
47
|
-
selection.current = null
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
[]
|
|
51
|
-
)
|
|
52
|
-
useImperativeHandle(ref, () => selection.current)
|
|
53
|
-
|
|
54
|
-
const { children, liveProps, ...others } = props
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (!parent) return
|
|
57
|
-
if (isRootDestroyed(parent)) {
|
|
58
|
-
forceUpdate()
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
if (selection.current) {
|
|
62
|
-
if (!isSelectionParent(selection.current, parent)) {
|
|
63
|
-
selection.current.remove()
|
|
64
|
-
selection.current = null
|
|
65
|
-
forceUpdate()
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (!selection.current) {
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
70
|
-
// @ts-expect-error
|
|
71
|
-
selection.current = parent[type](others, liveProps)
|
|
72
|
-
forceUpdate()
|
|
73
|
-
} else {
|
|
74
|
-
/**
|
|
75
|
-
* If liveProps have changed, remove all the old liveProps.
|
|
76
|
-
* (The same prop cannot be re-assigned live without being un-assigned
|
|
77
|
-
* first.)
|
|
78
|
-
*
|
|
79
|
-
* We could unbind just the ones that have changed, but simpler to
|
|
80
|
-
* unbind them all.
|
|
81
|
-
*/
|
|
82
|
-
if (prevLiveProps.current && liveProps !== prevLiveProps.current) {
|
|
83
|
-
Object.keys(prevLiveProps.current).forEach((key) => {
|
|
84
|
-
// @ts-expect-error this is not in ts yet
|
|
85
|
-
selection.current.unbind(key)
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
if (liveProps && liveProps !== prevLiveProps.current) {
|
|
89
|
-
selection.current.bind(liveProps)
|
|
90
|
-
}
|
|
91
|
-
selection.current.set(others)
|
|
92
|
-
}
|
|
93
|
-
prevLiveProps.current = liveProps
|
|
94
|
-
}, [parent, others, liveProps])
|
|
95
|
-
if (!canHaveChildren) {
|
|
96
|
-
if (props.children) {
|
|
97
|
-
throw new Error(`Component <${componentName} /> cannot have children.`)
|
|
98
|
-
}
|
|
99
|
-
return null
|
|
100
|
-
}
|
|
101
|
-
return (
|
|
102
|
-
<MathboxAPIContext.Provider value={selection.current}>
|
|
103
|
-
{props.children}
|
|
104
|
-
</MathboxAPIContext.Provider>
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* The line below gives a TS error without explicit any.
|
|
109
|
-
* But if you replace each generic T above with a specific instance, e.g.,
|
|
110
|
-
* 'cartesian', there is no error.
|
|
111
|
-
*
|
|
112
|
-
* So an alternative without "any" would be be to copy the definition of Comp
|
|
113
|
-
* with all ~64 different node types.
|
|
114
|
-
*
|
|
115
|
-
* I'm not 100% sure why there's a ts error here, but the above indicates to
|
|
116
|
-
* me that this is actually type-safe. And I do not want that much copy pasta.
|
|
117
|
-
* So instead, use the any and put explicit return type on the factory.
|
|
118
|
-
*/
|
|
119
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
-
return forwardRef(Comp) as any
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Component wrapper for mathbox [`area`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#dataarea).
|
|
125
|
-
*/
|
|
126
|
-
export const Area = mathboxComponentFactory("area")
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Component wrapper for mathbox [`array`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#dataarray).
|
|
130
|
-
*/
|
|
131
|
-
const MBArray = mathboxComponentFactory("array")
|
|
132
|
-
|
|
133
|
-
export { MBArray as Array }
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Component wrapper for mathbox [`axis`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawaxis).
|
|
137
|
-
*/
|
|
138
|
-
export const Axis = mathboxComponentFactory("axis")
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Component wrapper for mathbox [`camera`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#cameracamera).
|
|
142
|
-
*/
|
|
143
|
-
export const Camera = mathboxComponentFactory("camera")
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Component wrapper for mathbox [`cartesian`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewcartesian).
|
|
147
|
-
*/
|
|
148
|
-
export const Cartesian = mathboxComponentFactory("cartesian")
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Component wrapper for mathbox [`cartesian4`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewcartesian4).
|
|
152
|
-
*/
|
|
153
|
-
export const Cartesian4 = mathboxComponentFactory("cartesian4")
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Component wrapper for mathbox [`clamp`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorclamp).
|
|
157
|
-
*/
|
|
158
|
-
export const Clamp = mathboxComponentFactory("clamp")
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Component wrapper for mathbox [`clock`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#timeclock).
|
|
162
|
-
*/
|
|
163
|
-
export const Clock = mathboxComponentFactory("clock")
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Component wrapper for mathbox [`compose`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#rttcompose).
|
|
167
|
-
*/
|
|
168
|
-
export const Compose = mathboxComponentFactory("compose")
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Component wrapper for mathbox [`dom`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#overlaydom).
|
|
172
|
-
*/
|
|
173
|
-
export const Dom = mathboxComponentFactory("dom")
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Component wrapper for mathbox [`face`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawface).
|
|
177
|
-
*/
|
|
178
|
-
export const Face = mathboxComponentFactory("face")
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Component wrapper for mathbox [`format`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#textformat).
|
|
182
|
-
*/
|
|
183
|
-
export const Format = mathboxComponentFactory("format")
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Component wrapper for mathbox [`fragment`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformfragment).
|
|
187
|
-
*/
|
|
188
|
-
export const Fragment = mathboxComponentFactory("fragment")
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Component wrapper for mathbox [`grid`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawgrid).
|
|
192
|
-
*/
|
|
193
|
-
export const Grid = mathboxComponentFactory("grid")
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Component wrapper for mathbox [`group`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#basegroup).
|
|
197
|
-
*/
|
|
198
|
-
export const Group = mathboxComponentFactory("group")
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Component wrapper for mathbox [`grow`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorgrow).
|
|
202
|
-
*/
|
|
203
|
-
export const Grow = mathboxComponentFactory("grow")
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Component wrapper for mathbox [`html`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#overlayhtml).
|
|
207
|
-
*/
|
|
208
|
-
export const Html = mathboxComponentFactory("html")
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Component wrapper for mathbox [`inherit`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#baseinherit).
|
|
212
|
-
*/
|
|
213
|
-
export const Inherit = mathboxComponentFactory("inherit")
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Component wrapper for mathbox [`interval`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#datainterval).
|
|
217
|
-
*/
|
|
218
|
-
export const Interval = mathboxComponentFactory("interval")
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Component wrapper for mathbox [`join`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorjoin).
|
|
222
|
-
*/
|
|
223
|
-
export const Join = mathboxComponentFactory("join")
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Component wrapper for mathbox [`label`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#textlabel).
|
|
227
|
-
*/
|
|
228
|
-
export const Label = mathboxComponentFactory("label")
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Component wrapper for mathbox [`layer`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformlayer).
|
|
232
|
-
*/
|
|
233
|
-
export const Layer = mathboxComponentFactory("layer")
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Component wrapper for mathbox [`lerp`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorlerp).
|
|
237
|
-
*/
|
|
238
|
-
export const Lerp = mathboxComponentFactory("lerp")
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Component wrapper for mathbox [`line`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawline).
|
|
242
|
-
*/
|
|
243
|
-
export const Line = mathboxComponentFactory("line")
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Component wrapper for mathbox [`mask`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformmask).
|
|
247
|
-
*/
|
|
248
|
-
export const Mask = mathboxComponentFactory("mask")
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Component wrapper for mathbox [`matrix`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#datamatrix).
|
|
252
|
-
*/
|
|
253
|
-
export const Matrix = mathboxComponentFactory("matrix")
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Component wrapper for mathbox [`memo`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatormemo).
|
|
257
|
-
*/
|
|
258
|
-
export const Memo = mathboxComponentFactory("memo")
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Component wrapper for mathbox [`move`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentmove).
|
|
262
|
-
*/
|
|
263
|
-
export const Move = mathboxComponentFactory("move")
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Component wrapper for mathbox [`now`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#timenow).
|
|
267
|
-
*/
|
|
268
|
-
export const Now = mathboxComponentFactory("now")
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Component wrapper for mathbox [`play`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentplay).
|
|
272
|
-
*/
|
|
273
|
-
export const Play = mathboxComponentFactory("play")
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Component wrapper for mathbox [`point`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawpoint).
|
|
277
|
-
*/
|
|
278
|
-
export const Point = mathboxComponentFactory("point")
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Component wrapper for mathbox [`polar`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewpolar).
|
|
282
|
-
*/
|
|
283
|
-
export const Polar = mathboxComponentFactory("polar")
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Component wrapper for mathbox [`present`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentpresent).
|
|
287
|
-
*/
|
|
288
|
-
export const Present = mathboxComponentFactory("present")
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Component wrapper for mathbox [`readback`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorreadback).
|
|
292
|
-
*/
|
|
293
|
-
export const Readback = mathboxComponentFactory("readback")
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Component wrapper for mathbox [`repeat`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorrepeat).
|
|
297
|
-
*/
|
|
298
|
-
export const Repeat = mathboxComponentFactory("repeat")
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Component wrapper for mathbox [`resample`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorresample).
|
|
302
|
-
*/
|
|
303
|
-
export const Resample = mathboxComponentFactory("resample")
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Component wrapper for mathbox [`retext`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#textretext).
|
|
307
|
-
*/
|
|
308
|
-
export const Retext = mathboxComponentFactory("retext")
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Component wrapper for mathbox [`reveal`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentreveal).
|
|
312
|
-
*/
|
|
313
|
-
export const Reveal = mathboxComponentFactory("reveal")
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Component wrapper for mathbox [`rtt`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#rttrtt).
|
|
317
|
-
*/
|
|
318
|
-
export const Rtt = mathboxComponentFactory("rtt")
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Component wrapper for mathbox [`scale`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#datascale).
|
|
322
|
-
*/
|
|
323
|
-
export const Scale = mathboxComponentFactory("scale")
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Component wrapper for mathbox [`shader`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#shadershader).
|
|
327
|
-
*/
|
|
328
|
-
export const Shader = mathboxComponentFactory("shader")
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Component wrapper for mathbox [`slice`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorslice).
|
|
332
|
-
*/
|
|
333
|
-
export const Slice = mathboxComponentFactory("slice")
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Component wrapper for mathbox [`slide`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentslide).
|
|
337
|
-
*/
|
|
338
|
-
export const Slide = mathboxComponentFactory("slide")
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Component wrapper for mathbox [`spherical`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewspherical).
|
|
342
|
-
*/
|
|
343
|
-
export const Spherical = mathboxComponentFactory("spherical")
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Component wrapper for mathbox [`split`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorsplit).
|
|
347
|
-
*/
|
|
348
|
-
export const Split = mathboxComponentFactory("split")
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Component wrapper for mathbox [`spread`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorspread).
|
|
352
|
-
*/
|
|
353
|
-
export const Spread = mathboxComponentFactory("spread")
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Component wrapper for mathbox [`step`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentstep).
|
|
357
|
-
*/
|
|
358
|
-
export const Step = mathboxComponentFactory("step")
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Component wrapper for mathbox [`stereographic`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewstereographic).
|
|
362
|
-
*/
|
|
363
|
-
export const Stereographic = mathboxComponentFactory("stereographic")
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Component wrapper for mathbox [`stereographic4`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewstereographic4).
|
|
367
|
-
*/
|
|
368
|
-
export const Stereographic4 = mathboxComponentFactory("stereographic4")
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Component wrapper for mathbox [`strip`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawstrip).
|
|
372
|
-
*/
|
|
373
|
-
export const Strip = mathboxComponentFactory("strip")
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Component wrapper for mathbox [`subdivide`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorsubdivide).
|
|
377
|
-
*/
|
|
378
|
-
export const Subdivide = mathboxComponentFactory("subdivide")
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Component wrapper for mathbox [`surface`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawsurface).
|
|
382
|
-
*/
|
|
383
|
-
export const Surface = mathboxComponentFactory("surface")
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* Component wrapper for mathbox [`swizzle`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorswizzle).
|
|
387
|
-
*/
|
|
388
|
-
export const Swizzle = mathboxComponentFactory("swizzle")
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Component wrapper for mathbox [`text`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#texttext).
|
|
392
|
-
*/
|
|
393
|
-
export const Text = mathboxComponentFactory("text")
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Component wrapper for mathbox [`ticks`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawticks).
|
|
397
|
-
*/
|
|
398
|
-
export const Ticks = mathboxComponentFactory("ticks")
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Component wrapper for mathbox [`transform`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformtransform).
|
|
402
|
-
*/
|
|
403
|
-
export const Transform = mathboxComponentFactory("transform")
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Component wrapper for mathbox [`transform4`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformtransform4).
|
|
407
|
-
*/
|
|
408
|
-
export const Transform4 = mathboxComponentFactory("transform4")
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* Component wrapper for mathbox [`transpose`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatortranspose).
|
|
412
|
-
*/
|
|
413
|
-
export const Transpose = mathboxComponentFactory("transpose")
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Component wrapper for mathbox [`unit`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#baseunit).
|
|
417
|
-
*/
|
|
418
|
-
export const Unit = mathboxComponentFactory("unit")
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Component wrapper for mathbox [`vector`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawvector).
|
|
422
|
-
*/
|
|
423
|
-
export const Vector = mathboxComponentFactory("vector")
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Component wrapper for mathbox [`vertex`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformvertex).
|
|
427
|
-
*/
|
|
428
|
-
export const Vertex = mathboxComponentFactory("vertex")
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Component wrapper for mathbox [`view`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewview).
|
|
432
|
-
*/
|
|
433
|
-
export const View = mathboxComponentFactory("view")
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* Component wrapper for mathbox [`volume`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#datavolume).
|
|
437
|
-
*/
|
|
438
|
-
export const Volume = mathboxComponentFactory("volume")
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Component wrapper for mathbox [`voxel`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#datavoxel).
|
|
442
|
-
*/
|
|
443
|
-
export const Voxel = mathboxComponentFactory("voxel")
|
package/src/components/index.ts
DELETED
package/src/components/types.ts
DELETED
|
@@ -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>>
|
package/src/components/util.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
|
-
import isEqual from "lodash/isEqual"
|
|
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({})
|