clay.js
  1. ClayJS
  2. Reference
  3. API
  4. Edit mode

Edit mode

Who may edit a page, and the five places clayjs looks to decide, in order.

Who may edit a page, and the places clayjs looks to decide, in order.

Resolution order#

Saving requires edit mode, and permission alone does not start it. On the platforms, permission is automatic: hyperclay.com grants it with a cookie when you’re the owner, and Hyperclay Local and HTML Clay grant it for local files with a save token. Even then the document opens in view mode. The person enters edit with the Edit switch the menu plugin draws, with ⌘⇧E (Ctrl+Shift+E), or through clay.setMode("edit"). Who may edit (clay.canEdit) is decided in this order:

PrioritySource
1?editmode=true / ?editmode=false in the URL
2<html viewonly>: the page never saves itself (a tool that renders runtime state)
3window.clayEditMode set before clay.js loads
4A save token the host put on the root element
5The platform’s owner cookie

The host’s own answer, document.writable in /_/meta, is the last word on clay.canEdit. Whether this tab starts editing is a separate question, decided once: a reload receipt the tab left for itself, then ?editmode=true, then window.clayEditMode = true or <html opens-in="edit">. Otherwise it starts in view. See how the mode is decided.

The save token sits above the owner cookie because it is the stronger claim: the host issued it for this document, while a cookie is ambient. A sandboxed document cannot read a cookie at all.

Arm it yourself#

Serving files from your own server? Arm it yourself:

HTML
<script>window.clayEditMode = true</script>
<script src="https://clayjs.com/v1/clay.js"></script>

window.clayEditMode = true grants permission and starts the tab in edit, for everyone who loads the page. Set it only in the copy your server sends to someone allowed to edit. To grant permission and still open in view, have the host put a save token on <html> instead.

Edit mode is client-side behavior. Whether a save is accepted is always the server’s decision.