editor

package
v1.1.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package editor ships the in-place editing script injected into pages viewed by logged-in editors, plus a vendored copy of TinyMCE 6.8.6 (the final MIT-licensed release; see tinymce/license.txt) that provides the WYSIWYG behavior for rich HTML regions. TinyMCE runs in inline mode, so content is edited directly in the page using the page's own styles, and everything is self-hosted from the module — no CDN, and no build step for consumers.

editor.js is generated: the source lives in src/ as ES modules and is bundled by the build tool in build/ (a nested Go module wrapping esbuild, so it never enters consumers' dependency graphs). After editing anything under src/, regenerate the committed artifact with `go generate ./editor` — or `go run -C editor/build . -watch` for a rebuild-on-save loop while developing.

The glue script's own chrome (toolbar, media picker) lives in Shadow DOM, isolated from host-page CSS. TinyMCE's floating UI uses tox- prefixed classes in the light DOM. TinyMCE loads lazily, only when an editor actually presses "Edit page".

Index

Constants

View Source
const PathPrefix = "/cms/editor/"

PathPrefix is the public route the editor assets are served under.

Variables

View Source
var Version = sync.OnceValue(func() string {
	h := sha256.New()
	err := fs.WalkDir(assets, ".", func(path string, d fs.DirEntry, err error) error {
		if err != nil || d.IsDir() {
			return err
		}
		body, err := assets.ReadFile(path)
		if err != nil {
			return err
		}

		fmt.Fprintf(h, "%s\x00%d\x00", path, len(body))
		h.Write(body)
		return nil
	})
	if err != nil {

		return "unversioned"
	}
	return hex.EncodeToString(h.Sum(nil))[:versionLen]
})

Version is a content address for the whole editor bundle — the script and every vendored TinyMCE file — and it appears in the URL those assets are served under.

It exists because the alternative does not work. Served at a fixed path with a max-age, the script is a mutable URL a browser was told it could keep: ship a fix and editors go on running the old one until their cache expires, with no symptom except behaviour that does not match the code. A hard refresh papers over it for whoever thinks to try one.

With the digest in the path, a changed bundle is a different URL that no cache has seen, so the new script is fetched the first time a page asks for it — and the old one can be marked immutable honestly, because it never changes.

Computed once, lazily: hashing half a megabyte of embedded assets is cheap but pointless in a process that never serves an edit render.

Functions

func Handler

func Handler() http.Handler

Handler serves the editor script and the vendored TinyMCE files. Mount it at PathPrefix.

Assets live under a version segment — /cms/editor/<version>/editor.js — and TinyMCE's own files sit beside the script under the same segment, so its runtime base URL carries the version too and a stale skin cannot outlive the script that loads it.

A request naming a *different* version is still served, from the current files, on a short cache. That address can only come from HTML minted by an older build — a page a browser cached, or one held by a CDN — and answering it with the working editor beats 404ing an editor who did nothing wrong.

func ScriptPath added in v0.9.0

func ScriptPath() string

ScriptPath is the versioned URL of the editor script, for the tag that loads it.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL