@benqoder/beam 0.4.0 → 0.4.2
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 +5 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +5 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -410,7 +410,7 @@ return ctx.drawer(render(<MyDrawer />), { position: 'left', size: 'medium' })
|
|
|
410
410
|
| `beam-watch-if` | Condition that must be true to trigger | `beam-watch-if="value.length >= 3"` |
|
|
411
411
|
| `beam-cast` | Cast input value: `number`, `integer`, `boolean`, `trim` | `beam-cast="number"` |
|
|
412
412
|
| `beam-loading-class` | Add class to input while request is in progress | `beam-loading-class="loading"` |
|
|
413
|
-
| `beam-keep` |
|
|
413
|
+
| `beam-keep` | Prevent element from being morphed during updates | `beam-keep` |
|
|
414
414
|
|
|
415
415
|
### Dirty Form Tracking
|
|
416
416
|
|
|
@@ -783,9 +783,9 @@ Add a class to the input while the request is in progress:
|
|
|
783
783
|
</style>
|
|
784
784
|
```
|
|
785
785
|
|
|
786
|
-
###
|
|
786
|
+
### Preventing Element Replacement
|
|
787
787
|
|
|
788
|
-
Use `beam-keep` to
|
|
788
|
+
Use `beam-keep` to prevent an element from being morphed/replaced during updates. This keeps the element exactly as-is, preserving its state (focus, value, etc.):
|
|
789
789
|
|
|
790
790
|
```html
|
|
791
791
|
<input
|
|
@@ -797,6 +797,8 @@ Use `beam-keep` to preserve focus and cursor position after the response morphs
|
|
|
797
797
|
/>
|
|
798
798
|
```
|
|
799
799
|
|
|
800
|
+
Since the input isn't replaced, focus and cursor position are naturally preserved.
|
|
801
|
+
|
|
800
802
|
### Auto-Save on Blur
|
|
801
803
|
|
|
802
804
|
Trigger action when the user leaves the field:
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,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,OAAO,CAAC,cAAc,CAAC,CAGlD;AAED,QAAA,MAAM,SAAS;;;;;;;;;sBAvqFO,OAAO,CAAC,cAAc,CAAC;CAirF5C,CAAA;AAGD,KAAK,YAAY,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,KAAK,OAAO,CAAC,cAAc,CAAC,CAAA;AAE/G,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,IAAI,EAAE,OAAO,SAAS,GAAG;YACvB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAA;SAC/B,CAAA;KACF;CACF"}
|
package/dist/client.js
CHANGED
|
@@ -174,7 +174,8 @@ function morph(target, html, options) {
|
|
|
174
174
|
Idiomorph.morph(target, html, {
|
|
175
175
|
morphStyle: 'innerHTML',
|
|
176
176
|
callbacks: {
|
|
177
|
-
// Skip morphing elements marked with beam-keep
|
|
177
|
+
// Skip morphing elements marked with beam-keep (preserves their current value)
|
|
178
|
+
// This only applies when both old and new DOM have a matching element
|
|
178
179
|
beforeNodeMorphed: (fromEl, toEl) => {
|
|
179
180
|
// Only handle Element nodes
|
|
180
181
|
if (!(fromEl instanceof Element))
|
|
@@ -196,14 +197,10 @@ function morph(target, html, options) {
|
|
|
196
197
|
}
|
|
197
198
|
}
|
|
198
199
|
return true;
|
|
199
|
-
},
|
|
200
|
-
// Prevent removal of beam-keep elements
|
|
201
|
-
beforeNodeRemoved: (node) => {
|
|
202
|
-
if (node instanceof Element && node.hasAttribute('beam-keep')) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
return true;
|
|
206
200
|
}
|
|
201
|
+
// Note: We intentionally do NOT prevent removal of beam-keep elements.
|
|
202
|
+
// If an element doesn't exist in the new DOM, it should be removed.
|
|
203
|
+
// beam-keep only preserves values during morphing, not during removal.
|
|
207
204
|
}
|
|
208
205
|
});
|
|
209
206
|
}
|
|
@@ -1840,9 +1837,6 @@ function setupInputWatcher(el) {
|
|
|
1840
1837
|
}
|
|
1841
1838
|
}
|
|
1842
1839
|
}
|
|
1843
|
-
// Only restore focus for "input" events, not "change" (blur) events
|
|
1844
|
-
const shouldRestoreFocus = htmlEl.hasAttribute('beam-keep') && eventType === 'input';
|
|
1845
|
-
const activeElement = document.activeElement;
|
|
1846
1840
|
// Add loading class if specified
|
|
1847
1841
|
if (loadingClass)
|
|
1848
1842
|
htmlEl.classList.add(loadingClass);
|
|
@@ -1891,19 +1885,6 @@ function setupInputWatcher(el) {
|
|
|
1891
1885
|
if (response.script) {
|
|
1892
1886
|
executeScript(response.script);
|
|
1893
1887
|
}
|
|
1894
|
-
// Restore focus if beam-keep is set and this was an input event (not change/blur)
|
|
1895
|
-
if (shouldRestoreFocus && activeElement instanceof HTMLElement) {
|
|
1896
|
-
const newEl = document.querySelector(`[name="${name}"]`);
|
|
1897
|
-
if (newEl && newEl !== activeElement) {
|
|
1898
|
-
newEl.focus();
|
|
1899
|
-
if (newEl instanceof HTMLInputElement || newEl instanceof HTMLTextAreaElement) {
|
|
1900
|
-
const cursorPos = activeElement.selectionStart;
|
|
1901
|
-
if (cursorPos !== null) {
|
|
1902
|
-
newEl.setSelectionRange(cursorPos, cursorPos);
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
1888
|
}
|
|
1908
1889
|
catch (err) {
|
|
1909
1890
|
console.error('Input watcher error:', err);
|