Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultCapabilities() []string
- func Mount(cfg MountConfig) render.HTML
- func UIHostOption() uihost.Option
- type DiffConfig
- type EditorConfig
- type MountConfig
- type Option
- func WithCapabilities(caps ...string) Option
- func WithDemoPage() Option
- func WithDevGrantAll() Option
- func WithDiff(original, modified, language string) Option
- func WithEditorConfig(cfg EditorConfig) Option
- func WithFontSize(px int) Option
- func WithLanguage(lang string) Option
- func WithMinimap() Option
- func WithReadOnly() Option
- func WithSaveHandler(fn func(ctx context.Context, req SaveRequest) error) Option
- func WithTheme(theme string) Option
- func WithWordWrap() Option
- func WithWorkers() Option
- func WithoutLineNumbers() Option
- type Plugin
- type SaveRequest
Constants ¶
const ( Name = "monaco" Version = "0.1.0-phase0" RoutePrefix = "/__gofastr/plugin/monaco" EditorHTMLURL = RoutePrefix + "/editor.html" EditorJSURL = RoutePrefix + "/editor.js" EditorCSSURL = RoutePrefix + "/editor.css" AdapterScriptURL = RoutePrefix + "/adapter.js" // ConfigScriptURL is a tiny host-page script that publishes this plugin // instance's EditorConfig (set via Go options) as a global the adapter // merges into the manifest config it registers with the platform broker. // It is served non-framed (host-page) and is static per plugin instance. ConfigScriptURL = RoutePrefix + "/config.js" SaveURL = RoutePrefix + "/save" DemoURL = "/monaco" SchemaVersion = "monaco-v1" )
Identity and route constants. Both this plugin and host/adapter.js hard-code these exactly. The demo lives at /monaco (mirrors mermaid's /mermaid) so multiple plugins co-mount without colliding on "/".
Variables ¶
var ErrConflict = errors.New("monaco: save conflict")
ErrConflict is the sentinel a WithSaveHandler hook returns to signal that the save lost an optimistic-concurrency check — the stored document changed under the editor since it loaded. handleSave maps it to HTTP 409 (E_CONFLICT) rather than the generic 500 (E_SAVE), which is the one status the host adapter relays back to the frame as a distinct saveResult so the editor can keep the doc dirty and warn the user instead of silently dropping their edits. Wrap it (fmt.Errorf("...: %w", monaco.ErrConflict)) to add context; handleSave uses errors.Is.
Functions ¶
func DefaultCapabilities ¶
func DefaultCapabilities() []string
DefaultCapabilities is the grant set advertised to the editor. Monaco has no upload path -- only document read/write + theme:read (same as mermaid).
func Mount ¶
func Mount(cfg MountConfig) render.HTML
Mount renders the mount marker div plus the two hidden inputs the host adapter syncs on docChanged (code + language). It wraps the platform pluginhost.MountMarker and adds the monaco-specific data-fui-plugin-for attribute naming the code + language hidden fields. Drop it into a form. All interpolated values are HTML-escaped via render.Escape inside MountMarker.
func UIHostOption ¶
UIHostOption injects the platform broker, this plugin's config script, and this plugin's adapter (in that order — the adapter reads the config global the config script publishes, and registers with the broker the former defines).
Types ¶
type DiffConfig ¶
type DiffConfig struct {
Original string `json:"original"`
Modified string `json:"modified"`
Language string `json:"language,omitempty"`
}
DiffConfig selects the diff-editor mount. When present (non-nil) the frame mounts monaco.editor.createDiffEditor instead of the normal editor.
type EditorConfig ¶
type EditorConfig struct {
Language string `json:"language"`
Theme string `json:"theme"` // "light" | "dark" | "auto"
ReadOnly bool `json:"readOnly"`
Minimap bool `json:"minimap"`
WordWrap bool `json:"wordWrap"`
LineNumbers bool `json:"lineNumbers"`
FontSize int `json:"fontSize"`
Workers bool `json:"workers"`
Diff *DiffConfig `json:"diff,omitempty"`
}
EditorConfig is the editor configuration bridged to the frame via init.config (through config.js + the adapter's manifest config). Every field is always serialized (no omitempty) so the frame always receives a complete config and never has to guess a default. The With* options above set individual slots.
type MountConfig ¶
type MountConfig struct {
DocID string
CodeField string // hidden input name for the code text (default "code")
LanguageField string // hidden input name for the language (default "language")
MinHeight string
Doc string // optional initial {code, language} JSON, server-rendered for reload round-trip
}
MountConfig configures Mount.
type Option ¶
type Option func(*Plugin)
func WithCapabilities ¶
WithCapabilities overrides the grant set advertised to the editor. Default: DefaultCapabilities.
func WithDemoPage ¶
func WithDemoPage() Option
WithDemoPage registers the self-contained themed demo page at DemoURL.
func WithDevGrantAll ¶
func WithDevGrantAll() Option
WithDevGrantAll bypasses the auth.HasScope gate on save so the demo / tests run without standing up auth. Default OFF (enforcing).
func WithDiff ¶
WithDiff mounts the diff editor by default, showing original to modified. language defaults to the EditorConfig language when DiffConfig.Language is empty. WithDiff supersedes the normal editor mount for this plugin instance.
func WithEditorConfig ¶
func WithEditorConfig(cfg EditorConfig) Option
WithEditorConfig replaces the full default EditorConfig. Use the field- specific options above for ergonomics; this is the escape hatch.
func WithFontSize ¶
WithFontSize sets the editor font size in pixels.
func WithLanguage ¶
WithLanguage sets the default editor language (e.g. "go", "javascript").
func WithMinimap ¶
func WithMinimap() Option
WithMinimap enables the minimap by default (off by default).
func WithSaveHandler ¶
func WithSaveHandler(fn func(ctx context.Context, req SaveRequest) error) Option
WithSaveHandler overrides the persistence hook. The default stores the canonical {code, language} doc in an in-memory map keyed by DocID.
func WithTheme ¶
WithTheme sets the default theme strategy: "light", "dark", or "auto" (the frame follows the bridged host scheme). Default "auto".
func WithWordWrap ¶
func WithWordWrap() Option
WithWordWrap enables word wrap by default (off by default).
func WithWorkers ¶
func WithWorkers() Option
WithWorkers OPTS IN to Monaco web workers (language services: richer TS/JS completions, diagnostics, formatting). OFF by default: under the opaque- origin sandbox (sandbox="allow-scripts" WITHOUT allow-same-origin) a worker loaded from a same-origin URL or a blob:/data: URL is restricted, so the editor boots worker-free by default and degrades gracefully (the monarch tokenizer that drives syntax highlighting runs on the main thread). When opted in, the frame attempts a worker and falls back to worker-free if the sandbox refuses it.
func WithoutLineNumbers ¶
func WithoutLineNumbers() Option
WithoutLineNumbers hides the line-number gutter (shown by default).
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin is the Monaco code-editor plugin. It implements framework.Plugin and mirrors the mermaid plugin's shape (opaque-origin sandboxed iframe, protocol v1 over postMessage, go:embed'd frame bundle, capability gate, save handler).
func New ¶
New constructs a Plugin. The platform manifest is built and Validate()'d here so a bad isolation/sandbox config aborts construction rather than silently de-opaquing the frame at runtime.
func (*Plugin) Capabilities ¶
func (*Plugin) DefaultConfig ¶
func (p *Plugin) DefaultConfig() EditorConfig
DefaultConfig returns the editor-config defaults this plugin instance will advertise (set via the With* options). The frame receives these through init.config and applies them on mount.
func (*Plugin) LoadDoc ¶
LoadDoc returns the last-saved canonical {code, language} JSON for docID from the in-memory default store. ok is false when the doc has never been saved. The returned docJSON is the canonical interchange blob (schema monaco-v1).
func (*Plugin) Manifest ¶
func (p *Plugin) Manifest() pluginhost.Manifest