Edge: Lua widgets now require using widget.new

For those on the Edge builds and using Lua to build widgets (tables returning markdown, html etc.): you now need to wrap these tables in widget.new, see: https://silverbullet.md/Space%20Lua#Widgets

What you get in return for this breaking change, is the ability to attach event handlers, so you can now build a custom button widget like so:

```space-lua
function myButton(text)
  return widget.new {
    html = "<button>" .. text .. "</button>",
    events = {
      click = function()
        editor.flashNotification("Clicked " .. text)
      end
    }
  }
end
```

${myButton("Button 1")}
${myButton("Button 2")}
3 Likes

Great!
I think, this again opens great possibilities!

Might come to a solution for my Idea here:

Already tried this out and I’m able to generate an input field, which fires an event on change of the inputtext.
However, I could not figure out, yet, how to get to the text I put in…

Looks like I miss a puzzle piece again :slight_smile:

My Example:

```space-lua
function myInputField(text)
  return widget.new {
    html = text .."<input type=\"text\">",
    events = {
      change = function()
        editor.flashNotification("changed " .. text)
      end
    }
  }
end

${myInputField("Input here: ")}

image

The event function doesn’t happen to receive any arguments (at this moment)?

It should receive the event object, but not sure I even tested it. Just print the first argument to check.

Not sure, if I made it right, but all I can see as argument is:
{name = change, data = {isTrusted = true}}

Tested this way:

```space-lua
function myInputField(text)
  print(events)
  return widget.new {
    html = text .."<input type=\"text\" id=\"1234\" name=\"JustName\" placeholder=\"input here\"   >",
    events = {
      change = function(myArgs)
        print("CHANGE: " .. myArgs)
      end
      ,
      input = function(myArgs)
      print("INPUT: " .. myArgs)
      end
    }
  }
end

I see in the logs:
[Lua] INPUT: {name = input, data = {isTrusted = true}}
[Lua] CHANGE: {name = change, data = {isTrusted = true}}

I’ll dig into the widget sourcecode later on, maybe I understand what to add (but I don’t think so, to be honest :wink: )

Ok so this suggests you do indeed get the event object (the isTrusted thing is part of the event), but the javascript → Lua table mapping may not be including all useful event data. I’d have to see how to handle this in a more useful way.