Imports rewritten to the extracted plugin SDK module (P2 of the proto-first plugin SDK program); block/core require dropped. Wasm build + check-safety verified. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"io/fs"
|
|
"net/http"
|
|
|
|
"git.dev.alexdunmow.com/block/pluginsdk/blocks"
|
|
"git.dev.alexdunmow.com/block/pluginsdk/templates"
|
|
)
|
|
|
|
//go:embed all:web/dist/assets
|
|
var distAssets embed.FS
|
|
|
|
//go:embed plugin.mod
|
|
var pluginModBytes []byte
|
|
|
|
// Register is the plugin entry point that registers the Smart Block.
|
|
// Returns an error if registration fails.
|
|
func Register(tr templates.TemplateRegistry, br blocks.BlockRegistry) error {
|
|
// Register the Smart Block
|
|
br.Register(SmartBlockMeta, SmartBlockFunc)
|
|
return nil
|
|
}
|
|
|
|
// SmartBlockMeta defines the Smart Block metadata
|
|
var SmartBlockMeta = blocks.BlockMeta{
|
|
Key: "smart",
|
|
Title: "Smart Block",
|
|
Description: "AI-powered block that generates custom content structures from natural language prompts",
|
|
Source: "smartblock",
|
|
EditorJS: "remoteEntry.js",
|
|
}
|
|
|
|
// AssetsHandler serves static assets including the Module Federation remote entry.
|
|
// This is called by the plugin loader to mount assets at /api/plugins/smartblock/
|
|
func AssetsHandler() http.Handler {
|
|
// Create a sub-filesystem pointing to web/dist/assets
|
|
subFS, err := fs.Sub(distAssets, "web/dist/assets")
|
|
if err != nil {
|
|
// Fallback to 404 handler if embed fails
|
|
return http.NotFoundHandler()
|
|
}
|
|
|
|
return http.FileServer(http.FS(subFS))
|
|
}
|