tareqimbasher / NetPad

A cross-platform C# editor and playground.
MIT License
1.12k stars 60 forks source link

[Project request] HTML controls as individual project #133

Closed sdcb closed 3 months ago

sdcb commented 8 months ago

Noticed this project have HTML controls inside like LINQPad that already works in browser instead of just client app, I'm thinking of it for a long time, .NET don't have some easy to use framework like gradio in python, I'm eager to find a component like gradio that make .NET controls code easy to share to the websites, like this:

Textbox input = new();
Button btn = new("DoWork");
Util.HorizontalRun(gaps: true, controls: [input, btn]).Dump();
TextArea output = new().Dump();
btn.Click += delegate { output.Text = MySuperCoolFunction(input.Text); };

app.Start("http://+:5000");

gradio demo: https://www.gradio.app/

sdcb commented 8 months ago

My fault, it's still in roadmap, so can skip this one currently: image

tareqimbasher commented 8 months ago

You're right, NetPad uses an internal library code-named O2HTML, an HTML serialization lib that I wrote to power NetPad's Dump(). It will be published as its own OSS package.

O2HTML offers a slimmed down version of a virtual DOM that allows you to build HTML DOM structures in C# using a Fluent API. NetPad will be getting a feature update soon to be able to access this API and .Dump() DOM structures to the output pane.

image

(The API is not final, I'd like it to be more concise but its working for me so far :grinning:)

This initial version will not include the ability to attach event handlers to elements and execute your code when they fire, its just rendering the HTML controls and supports basic JavaScript event handlers. Ability to embed JavaScript script tags into the your DOM structures is also planned.


Finally, the ability to start an ASP.NET web app is coming too:

Peek 2023-11-29 05-29

sdcb commented 8 months ago

I'm seeking a library that can easily interact with frontend/backend, like gradio

tareqimbasher commented 7 months ago

In .NET that library would be Blazor components. Blazor support is planned (see #109) and should fill that use case as I understood from your code and the demo on gradio's website, although it won't always be as concise as what they're offering. Alas, offering a new rendering framework for .NET will be outside the scope of this project, least of which because it requires brighter minds than myself 😄

tareqimbasher commented 3 months ago

@sdcb new v0.7.0 release has experimental HTML rendering support.