hyperclayjs 1.23.1 → 1.24.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
@@ -79,6 +79,7 @@ import 'hyperclayjs/presets/standard.js';
79
79
  | input-helpers | 3.9KB | [prevent-enter], [autosize] for textareas |
80
80
  | movable | 2.5KB | Free-positioning drag with [movable] and [movable-handle], edit mode only |
81
81
  | onaftersave | 1KB | [onaftersave] attribute - run JS when save status changes |
82
+ | save-freeze | 1.9KB | [save-freeze] attribute - freeze element innerHTML for saves, live DOM changes freely |
82
83
  | sortable | 3.4KB | Drag-drop sorting with [sortable], lazy-loads ~118KB Sortable.js in edit mode |
83
84
 
84
85
  ### UI Components (User interface elements)
@@ -96,7 +97,7 @@ import 'hyperclayjs/presets/standard.js';
96
97
  | cache-bust | 0.6KB | Cache-bust href/src attributes |
97
98
  | cookie | 1.4KB | Cookie management (often auto-included) |
98
99
  | debounce | 0.4KB | Function debouncing |
99
- | mutation | 13.7KB | DOM mutation observation (often auto-included) |
100
+ | mutation | 13.8KB | DOM mutation observation (often auto-included) |
100
101
  | nearest | 3.4KB | Find nearest elements (often auto-included) |
101
102
  | throttle | 0.8KB | Function throttling |
102
103
 
@@ -143,7 +144,7 @@ Standard feature set for most use cases
143
144
 
144
145
  **Modules:** `save-core`, `snapshot`, `save-system`, `unsaved-warning`, `edit-mode-helpers`, `persist`, `option-visibility`, `event-attrs`, `dom-helpers`, `toast`, `save-toast`, `export-to-window`, `view-mode-excludes-edit-modules`
145
146
 
146
- ### Everything (~217.6KB)
147
+ ### Everything (~219.6KB)
147
148
  All available features
148
149
 
149
150
  Includes all available modules across all categories.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperclayjs",
3
- "version": "1.23.1",
3
+ "version": "1.24.0",
4
4
  "description": "Modular JavaScript library for building interactive malleable HTML files with Hyperclay",
5
5
  "type": "module",
6
6
  "main": "src/hyperclay.js",
@@ -0,0 +1,69 @@
1
+ /**
2
+ * [save-freeze] Custom Attribute
3
+ *
4
+ * Freezes an element's innerHTML for save purposes.
5
+ * The live DOM can change freely, but the saved HTML always
6
+ * contains the original content captured when the element first appeared.
7
+ *
8
+ * Usage:
9
+ * <div save-freeze>Content that JS will modify at runtime</div>
10
+ *
11
+ * The original innerHTML is captured:
12
+ * - On page load, for all existing [save-freeze] elements
13
+ * - On DOM insertion, for dynamically added [save-freeze] elements
14
+ *
15
+ * At save time, the clone's innerHTML is replaced with the stored original.
16
+ * Changes inside [save-freeze] elements do not trigger autosave dirty checks.
17
+ */
18
+
19
+ import { onPrepareForSave } from "../core/snapshot.js";
20
+ import { isEditMode } from "../core/isAdminOfCurrentResource.js";
21
+
22
+ const originals = new WeakMap();
23
+
24
+ function capture(el) {
25
+ if (!originals.has(el)) {
26
+ originals.set(el, el.innerHTML);
27
+ }
28
+ }
29
+
30
+ function captureAll() {
31
+ for (const el of document.querySelectorAll('[save-freeze]')) {
32
+ capture(el);
33
+ }
34
+ }
35
+
36
+ function init() {
37
+ if (!isEditMode) return;
38
+
39
+ captureAll();
40
+
41
+ const observer = new MutationObserver(mutations => {
42
+ for (const m of mutations) {
43
+ for (const node of m.addedNodes) {
44
+ if (node.nodeType !== 1) continue;
45
+ if (node.hasAttribute?.('save-freeze')) capture(node);
46
+ for (const el of node.querySelectorAll?.('[save-freeze]') || []) {
47
+ capture(el);
48
+ }
49
+ }
50
+ }
51
+ });
52
+ observer.observe(document.documentElement, { childList: true, subtree: true });
53
+
54
+ onPrepareForSave(clone => {
55
+ const liveElements = document.querySelectorAll('[save-freeze]');
56
+ const cloneElements = clone.querySelectorAll('[save-freeze]');
57
+
58
+ for (let i = 0; i < cloneElements.length; i++) {
59
+ const liveEl = liveElements[i];
60
+ if (liveEl && originals.has(liveEl)) {
61
+ cloneElements[i].innerHTML = originals.get(liveEl);
62
+ }
63
+ }
64
+ });
65
+ }
66
+
67
+ init();
68
+
69
+ export default init;
package/src/hyperclay.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * DO NOT EDIT THIS FILE DIRECTLY — it is generated from build/hyperclay.template.js
3
3
  *
4
- * HyperclayJS v1.23.1 - Minimal Browser-Native Loader
4
+ * HyperclayJS v1.24.0 - Minimal Browser-Native Loader
5
5
  *
6
6
  * Modules auto-init when imported (no separate init call needed).
7
7
  * Include `export-to-window` feature to export to window.hyperclay.
@@ -44,6 +44,7 @@ const MODULE_PATHS = {
44
44
  "dom-helpers": "./custom-attributes/domHelpers.js",
45
45
  "input-helpers": "./custom-attributes/inputHelpers.js",
46
46
  "onaftersave": "./custom-attributes/onaftersave.js",
47
+ "save-freeze": "./custom-attributes/saveFreeze.js",
47
48
  "dialogs": "./ui/prompts.js",
48
49
  "toast": "./ui/toast.js",
49
50
  "toast-hyperclay": "./ui/toast-hyperclay.js",
@@ -124,6 +125,7 @@ const PRESETS = {
124
125
  "dom-helpers",
125
126
  "input-helpers",
126
127
  "onaftersave",
128
+ "save-freeze",
127
129
  "dialogs",
128
130
  "toast",
129
131
  "the-modal",
@@ -168,6 +170,7 @@ const PRESETS = {
168
170
  "dom-helpers",
169
171
  "input-helpers",
170
172
  "onaftersave",
173
+ "save-freeze",
171
174
  "dialogs",
172
175
  "toast",
173
176
  "the-modal",
@@ -208,6 +211,7 @@ const EDIT_MODE_ONLY = new Set([
208
211
  "sortable",
209
212
  "movable",
210
213
  "onaftersave",
214
+ "save-freeze",
211
215
  "cache-bust",
212
216
  "hyper-morph",
213
217
  "file-upload",
@@ -204,7 +204,8 @@ const Mutation = {
204
204
  while (element && element.nodeType === 1) {
205
205
  if (element.hasAttribute?.('mutations-ignore') ||
206
206
  element.hasAttribute?.('save-remove') ||
207
- element.hasAttribute?.('save-ignore')) {
207
+ element.hasAttribute?.('save-ignore') ||
208
+ element.hasAttribute?.('save-freeze')) {
208
209
  return true;
209
210
  }
210
211
  element = element.parentElement;