rename vdomclient to waveapp

This commit is contained in:
sawka
2024-11-14 13:29:57 -08:00
parent cb928db233
commit e41d771ae2
9 changed files with 62 additions and 68 deletions
+1 -1
View File
@@ -192,7 +192,7 @@ type CanvasUpdaterProps struct {
CanvasRef *vdom.VDomRef
}
var CanvasUpdater = vdomclient.DefineComponent[CanvasUpdaterProps](
var CanvasUpdater = waveapp.DefineComponent[CanvasUpdaterProps](
Client, "CanvasUpdater",
func(ctx context.Context, props CanvasUpdaterProps) any {
particles, setParticles := vdom.UseState(ctx, initParticles(10))
+8 -8
View File
@@ -10,7 +10,7 @@ import (
"strings"
"github.com/wavetermdev/waveterm/pkg/vdom"
"github.com/wavetermdev/waveterm/pkg/vdom/vdomclient"
"github.com/wavetermdev/waveterm/pkg/waveapp"
)
//go:embed style.css
@@ -19,7 +19,7 @@ var styleCSS []byte
// Command-line args (accessible in components)
var galleryPath string
var GalleryClient *vdomclient.Client = vdomclient.MakeClient(vdomclient.AppOpts{
var AppClient *waveapp.Client = waveapp.MakeClient(waveapp.AppOpts{
CloseOnCtrlC: true,
GlobalStyles: styleCSS,
})
@@ -42,7 +42,7 @@ type ImageViewProps struct {
HasPrev bool `json:"hasPrev"`
}
var ImageView = vdomclient.DefineComponent[ImageViewProps](GalleryClient, "ImageView",
var ImageView = waveapp.DefineComponent[ImageViewProps](AppClient, "ImageView",
func(ctx context.Context, props ImageViewProps) any {
return vdom.E("div",
vdom.Class("image-view"),
@@ -77,7 +77,7 @@ var ImageView = vdomclient.DefineComponent[ImageViewProps](GalleryClient, "Image
},
)
var App = vdomclient.DefineComponent(GalleryClient, "App",
var App = waveapp.DefineComponent(AppClient, "App",
func(ctx context.Context, _ any) any {
// Get images from the provided path
images, err := scanDirectory(galleryPath)
@@ -198,7 +198,7 @@ func scanDirectory(root string) ([]ImageInfo, error) {
}
func main() {
GalleryClient.RegisterDefaultFlags()
AppClient.RegisterDefaultFlags()
flag.Parse()
if flag.NArg() != 1 {
fmt.Fprintf(os.Stderr, "Usage: gallery [flags] <path>\n")
@@ -206,7 +206,7 @@ func main() {
os.Exit(1)
}
galleryPath = flag.Arg(0)
GalleryClient.RegisterFilePrefixHandler("/img/", func(path string) (*vdomclient.FileHandlerOption, error) {
AppClient.RegisterFilePrefixHandler("/img/", func(path string) (*waveapp.FileHandlerOption, error) {
imgPath := strings.TrimPrefix(path, "/img/")
fullPath := filepath.Join(galleryPath, imgPath)
@@ -227,10 +227,10 @@ func main() {
return nil, err
}
return &vdomclient.FileHandlerOption{
return &waveapp.FileHandlerOption{
Data: data,
ETag: etag,
}, nil
})
GalleryClient.RunMain()
AppClient.RunMain()
}
+3 -3
View File
@@ -11,13 +11,13 @@ import (
"strings"
"github.com/wavetermdev/waveterm/pkg/vdom"
"github.com/wavetermdev/waveterm/pkg/vdom/vdomclient"
"github.com/wavetermdev/waveterm/pkg/waveapp"
)
//go:embed style.css
var styleCSS []byte
var AppClient = vdomclient.MakeClient(vdomclient.AppOpts{
var AppClient = waveapp.MakeClient(waveapp.AppOpts{
CloseOnCtrlC: true,
GlobalStyles: styleCSS,
})
@@ -46,7 +46,7 @@ func calculateStats(points []DataPoint) (count int, avg float64) {
return count, sum / float64(count)
}
var App = vdomclient.DefineComponent(AppClient, "App",
var App = waveapp.DefineComponent(AppClient, "App",
func(ctx context.Context, _ any) any {
// State for our data points and update counter
points, _, setPointsFn := vdom.UseStateWithFn(ctx, []DataPoint{})
+6 -6
View File
@@ -9,10 +9,10 @@ import (
"time"
"github.com/wavetermdev/waveterm/pkg/vdom"
"github.com/wavetermdev/waveterm/pkg/vdom/vdomclient"
"github.com/wavetermdev/waveterm/pkg/waveapp"
)
var ParticleVDomClient *vdomclient.Client = vdomclient.MakeClient(vdomclient.AppOpts{
var AppClient *waveapp.Client = waveapp.MakeClient(waveapp.AppOpts{
CloseOnCtrlC: true,
})
@@ -28,7 +28,7 @@ type CanvasUpdaterProps struct {
CanvasRef *vdom.VDomRef
}
var CanvasUpdaterParticles = vdomclient.DefineComponent[CanvasUpdaterProps](ParticleVDomClient, "CanvasUpdaterParticles",
var CanvasUpdaterParticles = waveapp.DefineComponent[CanvasUpdaterProps](AppClient, "CanvasUpdaterParticles",
func(ctx context.Context, props CanvasUpdaterProps) any {
particles, setParticles := vdom.UseState(ctx, initParticles(10))
lastRenderTs := vdom.UseRef(ctx, int64(0))
@@ -76,7 +76,7 @@ var CanvasUpdaterParticles = vdomclient.DefineComponent[CanvasUpdaterProps](Part
// Trigger re-render based on tickNum, not particles
go func() {
time.Sleep(60 * time.Millisecond)
ParticleVDomClient.SendAsyncInitiation()
AppClient.SendAsyncInitiation()
}()
return nil
@@ -129,7 +129,7 @@ func updateParticles(particles []Particle) []Particle {
return particles
}
var App = vdomclient.DefineComponent[struct{}](ParticleVDomClient, "App",
var App = waveapp.DefineComponent[struct{}](AppClient, "App",
func(ctx context.Context, _ struct{}) any {
canvasRef := vdom.UseVDomRef(ctx)
return vdom.E("div",
@@ -144,5 +144,5 @@ var App = vdomclient.DefineComponent[struct{}](ParticleVDomClient, "App",
)
func main() {
ParticleVDomClient.RunMain()
AppClient.RunMain()
}
+11 -11
View File
@@ -7,13 +7,13 @@ import (
"time"
"github.com/wavetermdev/waveterm/pkg/vdom"
"github.com/wavetermdev/waveterm/pkg/vdom/vdomclient"
"github.com/wavetermdev/waveterm/pkg/waveapp"
)
//go:embed style.css
var styleCSS []byte
var PomodoroVDomClient *vdomclient.Client = vdomclient.MakeClient(vdomclient.AppOpts{
var AppClient *waveapp.Client = waveapp.MakeClient(waveapp.AppOpts{
CloseOnCtrlC: true,
GlobalStyles: styleCSS,
})
@@ -50,7 +50,7 @@ type TimerState struct {
isActive bool // Track if the timer goroutine is running
}
var TimerDisplay = vdomclient.DefineComponent[TimerDisplayProps](PomodoroVDomClient, "TimerDisplay",
var TimerDisplay = waveapp.DefineComponent[TimerDisplayProps](AppClient, "TimerDisplay",
func(ctx context.Context, props TimerDisplayProps) any {
return vdom.E("div",
vdom.Class("timer-display"),
@@ -66,7 +66,7 @@ var TimerDisplay = vdomclient.DefineComponent[TimerDisplayProps](PomodoroVDomCli
},
)
var ControlButtons = vdomclient.DefineComponent[ControlButtonsProps](PomodoroVDomClient, "ControlButtons",
var ControlButtons = waveapp.DefineComponent[ControlButtonsProps](AppClient, "ControlButtons",
func(ctx context.Context, props ControlButtonsProps) any {
return vdom.E("div",
vdom.Class("control-buttons"),
@@ -104,7 +104,7 @@ var ControlButtons = vdomclient.DefineComponent[ControlButtonsProps](PomodoroVDo
},
)
var App = vdomclient.DefineComponent[struct{}](PomodoroVDomClient, "App",
var App = waveapp.DefineComponent[struct{}](AppClient, "App",
func(ctx context.Context, _ struct{}) any {
isRunning, setIsRunning := vdom.UseState(ctx, false)
minutes, setMinutes := vdom.UseState(ctx, WorkMode.Duration)
@@ -158,7 +158,7 @@ var App = vdomclient.DefineComponent[struct{}](PomodoroVDomClient, "App",
setSeconds(0)
setIsComplete(true)
stopTimer()
PomodoroVDomClient.SendAsyncInitiation()
AppClient.SendAsyncInitiation()
return
}
@@ -169,7 +169,7 @@ var App = vdomclient.DefineComponent[struct{}](PomodoroVDomClient, "App",
if m != minutes || s != seconds {
setMinutes(m)
setSeconds(s)
PomodoroVDomClient.SendAsyncInitiation()
AppClient.SendAsyncInitiation()
}
}
}
@@ -179,7 +179,7 @@ var App = vdomclient.DefineComponent[struct{}](PomodoroVDomClient, "App",
pauseTimer := func() {
stopTimer()
setIsRunning(false)
PomodoroVDomClient.SendAsyncInitiation()
AppClient.SendAsyncInitiation()
}
resetTimer := func() {
@@ -192,7 +192,7 @@ var App = vdomclient.DefineComponent[struct{}](PomodoroVDomClient, "App",
setMinutes(BreakMode.Duration)
}
setSeconds(0)
PomodoroVDomClient.SendAsyncInitiation()
AppClient.SendAsyncInitiation()
}
changeMode := func(duration int) {
@@ -206,7 +206,7 @@ var App = vdomclient.DefineComponent[struct{}](PomodoroVDomClient, "App",
} else {
setMode(BreakMode.Name)
}
PomodoroVDomClient.SendAsyncInitiation()
AppClient.SendAsyncInitiation()
}
// Cleanup on unmount
@@ -239,5 +239,5 @@ var App = vdomclient.DefineComponent[struct{}](PomodoroVDomClient, "App",
)
func main() {
PomodoroVDomClient.RunMain()
AppClient.RunMain()
}
+13 -13
View File
@@ -19,13 +19,13 @@ The VDOM client should be created as a global variable using AppOpts:
```go
// Create client at package level
var AppClient *vdomclient.Client = vdomclient.MakeClient(vdomclient.AppOpts{
var AppClient *waveapp.Client = waveapp.MakeClient(waveapp.AppOpts{
CloseOnCtrlC: true,
GlobalStyles: styleCSS,
})
// Components are registered with the client
var MyComponent = vdomclient.DefineComponent[MyProps](AppClient, "MyComponent",
var MyComponent = waveapp.DefineComponent[MyProps](AppClient, "MyComponent",
func(ctx context.Context, props MyProps) any {
// component logic
},
@@ -183,7 +183,7 @@ Embed and provide them through AppOpts:
//go:embed style.css
var styleCSS []byte
var AppClient *vdomclient.Client = vdomclient.MakeClient(vdomclient.AppOpts{
var AppClient *waveapp.Client = waveapp.MakeClient(waveapp.AppOpts{
CloseOnCtrlC: true,
GlobalStyles: styleCSS,
})
@@ -199,7 +199,7 @@ type TodoItemProps struct {
OnToggle func() `json:"onToggle"`
}
var TodoItem = vdomclient.DefineComponent[TodoItemProps](AppClient, "TodoItem",
var TodoItem = waveapp.DefineComponent[TodoItemProps](AppClient, "TodoItem",
func(ctx context.Context, props TodoItemProps) any {
return vdom.E("div",
vdom.P("className", "todo-item"),
@@ -391,7 +391,7 @@ type TimerState struct {
isActive bool
}
var TodoApp = vdomclient.DefineComponent[struct{}](AppClient, "TodoApp",
var TodoApp = waveapp.DefineComponent[struct{}](AppClient, "TodoApp",
func(ctx context.Context, _ struct{}) any {
// Local state for UI updates
count, setCount := vdom.UseState(ctx, 0)
@@ -471,13 +471,13 @@ The VDOM system can serve files to components. Any URL starting with `vdom://` w
```go
// Register handlers for files (in the main func)
AppClient.RegisterFileHandler("/logo.png", vdomclient.FileHandlerOption{
AppClient.RegisterFileHandler("/logo.png", waveapp.FileHandlerOption{
FilePath: "./assets/logo.png",
})
// returning nil will produce a 404, path will be the full path, including the prefix
AppClient.RegisterFilePrefixHandler("/img/", func(path string) (*vdomclient.FileHandlerOption, error) {
return &vdomclient.FileHandlerOption{Data: data, MimeType: "image/png"}
AppClient.RegisterFilePrefixHandler("/img/", func(path string) (*waveapp.FileHandlerOption, error) {
return &waveapp.FileHandlerOption{Data: data, MimeType: "image/png"}
})
// Use in components with vdom:// prefix
@@ -522,7 +522,7 @@ import (
"fmt"
"os"
"github.com/wavetermdev/waveterm/pkg/vdom"
"github.com/wavetermdev/waveterm/pkg/vdom/vdomclient"
"github.com/wavetermdev/waveterm/pkg/waveapp"
)
//go:embed style.css
@@ -532,13 +532,13 @@ var styleCSS []byte
var myPath string
var verbose = flag.Bool("v", false, "verbose output")
var AppClient = vdomclient.MakeClient(vdomclient.AppOpts{
var AppClient = waveapp.MakeClient(waveapp.AppOpts{
CloseOnCtrlC: true,
GlobalStyles: styleCSS,
})
// Root component must be named "App" (it takes no props)
var App = vdomclient.DefineComponent(AppClient, "App",
var App = waveapp.DefineComponent(AppClient, "App",
func(ctx context.Context, _ any) any {
count, setCount := vdom.UseState(ctx, 0)
return vdom.E("div", nil,
@@ -566,7 +566,7 @@ func main() {
myPath = flag.Arg(0)
// Optional: Add URL handlers
AppClient.RegisterFileHandler("/api/data", vdomclient.FileHandlerOption{...})
AppClient.RegisterFileHandler("/api/data", waveapp.FileHandlerOption{...})
AppClient.RegisterFilePrefixHandler("/img/", imageHandler)
// Run the app
@@ -597,7 +597,7 @@ type AppOpts struct {
- Props must be defined as Go structs with json tags
- Components take their props type directly: `func MyComponent(ctx context.Context, props MyProps) any`
- Use vdom.Props() when passing structured props to vdom.E()
- Always use vdomclient.DefineComponent with the client instance
- Always use waveapp.DefineComponent with the client instance
- Use PStyle for cleaner style property setting
- Call SendAsyncInitiation() after async state updates
- Provide keys when using ForEach() with lists
+10 -16
View File
@@ -9,7 +9,7 @@ import (
"log"
"github.com/wavetermdev/waveterm/pkg/vdom"
"github.com/wavetermdev/waveterm/pkg/vdom/vdomclient"
"github.com/wavetermdev/waveterm/pkg/waveapp"
"github.com/wavetermdev/waveterm/pkg/waveobj"
"github.com/wavetermdev/waveterm/pkg/wshrpc"
"github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
@@ -18,17 +18,11 @@ import (
//go:embed style.css
var styleCSS []byte
var HtmlVDomClient *vdomclient.Client = vdomclient.MakeClient(vdomclient.AppOpts{
var AppClient *waveapp.Client = waveapp.MakeClient(waveapp.AppOpts{
CloseOnCtrlC: true,
GlobalStyles: styleCSS,
})
func init() {
HtmlVDomClient.AddSetupFn(func() {
})
}
// Prop Types
type BgItemProps struct {
Bg string `json:"bg"`
@@ -46,7 +40,7 @@ type BgItem struct {
}
// Components
var Style = vdomclient.DefineComponent[struct{}](HtmlVDomClient, "Style",
var Style = waveapp.DefineComponent[struct{}](AppClient, "Style",
func(ctx context.Context, _ struct{}) any {
return vdom.E("wave:style",
vdom.P("src", "vdom:///style.css"),
@@ -54,7 +48,7 @@ var Style = vdomclient.DefineComponent[struct{}](HtmlVDomClient, "Style",
},
)
var BgItemTag = vdomclient.DefineComponent[BgItemProps](HtmlVDomClient, "BgItem",
var BgItemTag = waveapp.DefineComponent[BgItemProps](AppClient, "BgItem",
func(ctx context.Context, props BgItemProps) any {
return vdom.E("div",
vdom.Class("bg-item"),
@@ -71,16 +65,16 @@ var BgItemTag = vdomclient.DefineComponent[BgItemProps](HtmlVDomClient, "BgItem"
},
)
var BgList = vdomclient.DefineComponent[BgListProps](HtmlVDomClient, "BgList",
var BgList = waveapp.DefineComponent[BgListProps](AppClient, "BgList",
func(ctx context.Context, props BgListProps) any {
setBackground := func(bg string) func() {
return func() {
blockInfo, err := wshclient.BlockInfoCommand(HtmlVDomClient.RpcClient, HtmlVDomClient.RpcContext.BlockId, nil)
blockInfo, err := wshclient.BlockInfoCommand(AppClient.RpcClient, AppClient.RpcContext.BlockId, nil)
if err != nil {
log.Printf("error getting block info: %v\n", err)
return
}
err = wshclient.SetMetaCommand(HtmlVDomClient.RpcClient, wshrpc.CommandSetMetaData{
err = wshclient.SetMetaCommand(AppClient.RpcClient, wshrpc.CommandSetMetaData{
ORef: waveobj.ORef{OType: "tab", OID: blockInfo.TabId},
Meta: map[string]any{"bg": bg},
}, nil)
@@ -106,7 +100,7 @@ var BgList = vdomclient.DefineComponent[BgListProps](HtmlVDomClient, "BgList",
},
)
var App = vdomclient.DefineComponent[struct{}](HtmlVDomClient, "App",
var App = waveapp.DefineComponent[struct{}](AppClient, "App",
func(ctx context.Context, _ struct{}) any {
inputText, setInputText := vdom.UseState(ctx, "start")
@@ -156,8 +150,8 @@ var App = vdomclient.DefineComponent[struct{}](HtmlVDomClient, "App",
)
func main() {
HtmlVDomClient.RegisterFileHandler("/test.png", vdomclient.FileHandlerOption{
AppClient.RegisterFileHandler("/test.png", waveapp.FileHandlerOption{
FilePath: "~/Downloads/IMG_1939.png",
})
HtmlVDomClient.RunMain()
AppClient.RunMain()
}
+7 -7
View File
@@ -5,13 +5,13 @@ import (
_ "embed"
"github.com/wavetermdev/waveterm/pkg/vdom"
"github.com/wavetermdev/waveterm/pkg/vdom/vdomclient"
"github.com/wavetermdev/waveterm/pkg/waveapp"
)
//go:embed style.css
var styleCSS []byte
var TodoVDomClient *vdomclient.Client = vdomclient.MakeClient(vdomclient.AppOpts{
var AppClient *waveapp.Client = waveapp.MakeClient(waveapp.AppOpts{
CloseOnCtrlC: true,
GlobalStyles: styleCSS,
})
@@ -40,7 +40,7 @@ type InputFieldProps struct {
OnEnter func() `json:"onEnter"`
}
var InputField = vdomclient.DefineComponent[InputFieldProps](TodoVDomClient, "InputField",
var InputField = waveapp.DefineComponent[InputFieldProps](AppClient, "InputField",
func(ctx context.Context, props InputFieldProps) any {
keyDown := &vdom.VDomFunc{
Type: vdom.ObjectType_Func,
@@ -67,7 +67,7 @@ var InputField = vdomclient.DefineComponent[InputFieldProps](TodoVDomClient, "In
},
)
var TodoItem = vdomclient.DefineComponent(TodoVDomClient, "TodoItem",
var TodoItem = waveapp.DefineComponent(AppClient, "TodoItem",
func(ctx context.Context, props TodoItemProps) any {
return vdom.E("div",
vdom.Class("todo-item"),
@@ -91,7 +91,7 @@ var TodoItem = vdomclient.DefineComponent(TodoVDomClient, "TodoItem",
},
)
var TodoList = vdomclient.DefineComponent(TodoVDomClient, "TodoList",
var TodoList = waveapp.DefineComponent(AppClient, "TodoList",
func(ctx context.Context, props TodoListProps) any {
return vdom.E("div",
vdom.Class("todo-list"),
@@ -106,7 +106,7 @@ var TodoList = vdomclient.DefineComponent(TodoVDomClient, "TodoList",
},
)
var App = vdomclient.DefineComponent(TodoVDomClient, "App",
var App = waveapp.DefineComponent(AppClient, "App",
func(ctx context.Context, _ any) any {
// State using hooks
todos, setTodos := vdom.UseState(ctx, []Todo{
@@ -183,5 +183,5 @@ var App = vdomclient.DefineComponent(TodoVDomClient, "App",
)
func main() {
TodoVDomClient.RunMain()
AppClient.RunMain()
}
+3 -3
View File
@@ -9,13 +9,13 @@ import (
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/load"
"github.com/wavetermdev/waveterm/pkg/vdom"
"github.com/wavetermdev/waveterm/pkg/vdom/vdomclient"
"github.com/wavetermdev/waveterm/pkg/waveapp"
)
//go:embed style.css
var styleCSS []byte
var AppClient = vdomclient.MakeClient(vdomclient.AppOpts{
var AppClient = waveapp.MakeClient(waveapp.AppOpts{
CloseOnCtrlC: true,
GlobalStyles: styleCSS,
TargetToolbar: &vdom.VDomTargetToolbar{Toolbar: true, Height: "1.5em"},
@@ -26,7 +26,7 @@ type Metrics struct {
LoadAvg [3]float64
}
var App = vdomclient.DefineComponent(AppClient, "App",
var App = waveapp.DefineComponent(AppClient, "App",
func(ctx context.Context, _ any) any {
metrics, setMetrics := vdom.UseState(ctx, Metrics{})