@limetech/lime-elements 39.12.4 → 39.12.5
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/CHANGELOG.md +7 -0
- package/dist/cjs/limel-markdown.cjs.entry.js +813 -2
- package/dist/collection/components/markdown/markdown.js +3 -2
- package/dist/collection/components/markdown/morph-dom.js +29 -0
- package/dist/esm/limel-markdown.entry.js +813 -2
- package/dist/lime-elements/lime-elements.esm.js +1 -1
- package/dist/lime-elements/p-537df672.entry.js +1 -0
- package/dist/types/components/markdown/morph-dom.d.ts +12 -0
- package/package.json +2 -1
- package/dist/lime-elements/p-73623bb5.entry.js +0 -1
|
@@ -3,6 +3,7 @@ import { markdownToHTML } from "./markdown-parser";
|
|
|
3
3
|
import { globalConfig } from "../../global/config";
|
|
4
4
|
import { ImageIntersectionObserver } from "./image-intersection-observer";
|
|
5
5
|
import { hydrateCustomElements } from "./hydrate-custom-elements";
|
|
6
|
+
import { morphChildren } from "./morph-dom";
|
|
6
7
|
import { DEFAULT_MARKDOWN_WHITELIST } from "./default-whitelist";
|
|
7
8
|
/**
|
|
8
9
|
* The Markdown component receives markdown syntax
|
|
@@ -95,7 +96,7 @@ export class Markdown {
|
|
|
95
96
|
lazyLoadImages: this.lazyLoadImages,
|
|
96
97
|
removeEmptyParagraphs: this.removeEmptyParagraphs,
|
|
97
98
|
});
|
|
98
|
-
this.rootElement
|
|
99
|
+
morphChildren(this.rootElement, html);
|
|
99
100
|
// Hydration parses JSON attribute values (e.g. link='{"href":"..."}')
|
|
100
101
|
// into JS properties. URL sanitization happens here because
|
|
101
102
|
// rehype-sanitize can't inspect values inside JSON strings.
|
|
@@ -119,7 +120,7 @@ export class Markdown {
|
|
|
119
120
|
this.cleanupImageIntersectionObserver();
|
|
120
121
|
}
|
|
121
122
|
render() {
|
|
122
|
-
return (h(Host, { key: '
|
|
123
|
+
return (h(Host, { key: '9d88a42e047b6701215699ab5459af3275e51693' }, h("div", { key: '83a5801839318bf47eeacbf53e320e4628559bfa', id: "markdown", ref: (el) => (this.rootElement = el) })));
|
|
123
124
|
}
|
|
124
125
|
setupImageIntersectionObserver() {
|
|
125
126
|
if (this.lazyLoadImages) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import morphdom from "morphdom";
|
|
2
|
+
/**
|
|
3
|
+
* Morph the children of `container` to match the given HTML string.
|
|
4
|
+
*
|
|
5
|
+
* Uses morphdom to diff the existing DOM against the new HTML and apply
|
|
6
|
+
* only the minimum changes. This preserves existing DOM nodes (including
|
|
7
|
+
* custom elements with internal state) that haven't changed.
|
|
8
|
+
*
|
|
9
|
+
* @param container - The parent element whose children should be morphed.
|
|
10
|
+
* @param html - The new HTML content for the container's children.
|
|
11
|
+
*/
|
|
12
|
+
export function morphChildren(container, html = '') {
|
|
13
|
+
// morphdom's second argument must be a single root element. We wrap
|
|
14
|
+
// the new HTML in a <div> purely to satisfy that requirement — the
|
|
15
|
+
// tag name doesn't matter because childrenOnly makes morphdom skip
|
|
16
|
+
// the root and only diff the children. The container element itself
|
|
17
|
+
// is never compared or replaced, so it can be any element type.
|
|
18
|
+
try {
|
|
19
|
+
morphdom(container, `<div>${html}</div>`, {
|
|
20
|
+
childrenOnly: true,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
// Fall back to innerHTML so that content is at least visible,
|
|
25
|
+
// even though custom elements will be destroyed and recreated.
|
|
26
|
+
console.warn('morphdom failed, falling back to innerHTML:', error);
|
|
27
|
+
container.innerHTML = html;
|
|
28
|
+
}
|
|
29
|
+
}
|