kolibril13 / ipymafs

Interactive math react components in jupyter
4 stars 0 forks source link

Interactive elements do not work #1

Closed kolibril13 closed 1 year ago

kolibril13 commented 1 year ago

When going to the https://code.esm.sh/ playground, static mafs components load just fine:

Copy pasting this css content https://unpkg.com/mafs@0.16.0/core.css and this react code (based on https://mafs.dev/guides/display/lines)

import React from "https://esm.sh/react"
import { Mafs, Line, Coordinates, useMovablePoint } from "https://esm.sh/mafs"

export default function SimplePoint() {
  const point1 = useMovablePoint([-2, -1])
  const point2 = useMovablePoint([2, 1])

  return (
    <Mafs viewBox={{ x: [-2, 2], y: [-1, 1] }}>
      <Coordinates.Cartesian />
      <Line.Segment
        point1={point1.point}
        point2={point2.point}
      />
    </Mafs>
  )
}

works fine!

However, when I add {point1.element} to the react component like this:

<Mafs viewBox={{ x: [-2, 2], y: [-1, 1] }}>
      <Coordinates.Cartesian />
      <Line.Segment
        point1={point1.point}
        point2={point2.point}
      />
    {point1.element}
    </Mafs>

I get the error:

[Error] TypeError: Object.entries requires that input parameter not be null or undefined
stevenpetryk commented 1 year ago

Not entirely sure what's happening, but it seems like the exact same issue that is occurring with Snowpack, so it might be something wrong on ESM.sh's end: https://github.com/pmndrs/use-gesture/issues/451

stevenpetryk commented 1 year ago

Here's the line of code that is failing in use-gesture, it should be debuggable from there (I will take a stab at it but also noting this down for reference).

kolibril13 commented 1 year ago

Hey Steven, Thanks a lot for your time and your motivation to dig into this,
I really appreciate your efforts! Bringing the ease of python with the speed of react together might have some interesting usecases in math education šŸŒŸ

kolibril13 commented 1 year ago

Fixed via vite rewrite -> https://github.com/manzt/anywidget/issues/185 šŸŽ‰