@panphora/hyper-cms 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -40,6 +40,20 @@ cms.open({ rules: 'collection' })// a tag with data-rules-name~="collection"
40
40
  cms.open({ rules: { title: '.title' } }) // a literal rules object, passed by hand
41
41
  ```
42
42
 
43
+ ## Auto-open with `?cms=true`
44
+
45
+ Load any hypercms page with `?cms=true` in the URL and the CMS opens by itself once the DOM is ready — no trigger, no `cms.open()` call. The auto-open uses the host defaults (`document.body` as both `pageRoot` and `mountTo`), and it never double-mounts: if your page also calls `cms.open()`, the second open is a no-op.
46
+
47
+ When the user closes the CMS, hypercms rewrites the param to `cms=false` via `history.replaceState` (the param is kept, no reload), so refreshing or sharing the post-close URL does not auto-reopen:
48
+
49
+ ```
50
+ example.com/page?cms=true → CMS opens on load
51
+ → user closes
52
+ example.com/page?cms=false → refresh / share: stays closed
53
+ ```
54
+
55
+ The rewrite only touches the URL when `cms=true` is actually present; other params and the hash are preserved, and a page opened without a `cms` param never has one injected. Auto-open is ungated — it fires for every visitor, not just the page owner. (A non-owner's edits stay local to their DOM; in a hyperclayjs app the save path shows its "changes are local only" notice.)
56
+
43
57
  ## Hard requirement: `window.hyperclay.Mutation`
44
58
 
45
59
  hypercms uses [`hyperclayjs`'s Mutation utility](https://github.com/panphora/hyperclayjs/blob/main/src/utilities/mutation.js) as its page-change backend. It's a singleton that already understands `save-ignore`, `save-freeze`, `save-remove`, and `mutations-ignore`, which lets hypercms ignore its own DOM activity without per-event bookkeeping.
@@ -156,10 +170,19 @@ cms.api.removeItem(itemPath) // drop an item by index
156
170
  | `mountTo` | `document.body` | Where the shell DOM mounts. Can be a descendant of pageRoot. |
157
171
  | `side` | `'right'` | `'right'` or `'left'`. |
158
172
  | `overlay` | `false` | If true, sidebar covers the page; if false, page content gets a padding offset. |
159
- | `showSaveButton` | `false` | Renders a Save button in the shell footer; clicking dispatches `hcms:save`. |
173
+ | `showSaveButton` | `false` | Renders a Save button in the shell footer. The button carries the `trigger-save` attribute: in hyperclayjs apps the host save system handles the click (with a "changes are local only" notice for non-owners). Standalone hosts delegate it themselves — see below. |
160
174
  | `onChange(data, info)` | none | Per-commit callback. |
161
175
  | `onError(err)` | none | Per-commit error callback. |
162
- | `onSave(data)` | none | Save-button callback. |
176
+
177
+ Standalone `[trigger-save]` handling (no hyperclayjs on the page):
178
+
179
+ ```js
180
+ document.addEventListener('click', (e) => {
181
+ if (e.target.closest('[trigger-save]')) {
182
+ persistSomehow(document.documentElement.outerHTML) // or cms.api.getData()
183
+ }
184
+ })
185
+ ```
163
186
 
164
187
  ### Path syntax
165
188
 
@@ -174,10 +197,9 @@ All events dispatch on the shell root and bubble through the document.
174
197
  | `hcms:open` | `{ pageRoot }` | After mount, before first interaction. |
175
198
  | `hcms:change` | `{ data, path, structural }` | Per successful commit. `structural` is true for add/remove/reorder. |
176
199
  | `hcms:error` | `{ error, attemptedData }` | When apply throws (shape mismatch, missing template, etc.). |
177
- | `hcms:save` | `{ data }` | Save button clicked. |
178
200
  | `hcms:close` | `null` | Before teardown. |
179
201
 
180
- `hcms:change` and `hcms:save` are cancelable.
202
+ `hcms:change` is cancelable.
181
203
 
182
204
  ## Lifecycle
183
205