-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
137 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include {{ name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>hec.js :: Plugins</title> | ||
<script type="module" defer src="./lazy.js"></script> | ||
|
||
</head> | ||
<body hidden> | ||
|
||
<div>The parts will lazy load...</div> | ||
|
||
<div data-lazy> | ||
<div>Inline 1 {{ name }}</div> | ||
</div> | ||
|
||
<div hidden data-lazy> | ||
<div>Inline 2 {{ name }}</div> | ||
|
||
<div hidden> | ||
<div>Inline 3 {{ name }}</div> | ||
|
||
<div hidden> | ||
Inline 4 {{ name }} | ||
</div> | ||
|
||
<my-test data-lazy></my-test> | ||
|
||
<div data-lazy data-include="include.html"></div> | ||
</div> | ||
|
||
<div data-lazy data-include="include.html"></div> | ||
</div> | ||
|
||
<div hidden data-lazy data-include="include.html"></div> | ||
<my-test hidden data-lazy></my-test> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { component, signal, templateByNode, templateByString } from '../../lib/index.js'; | ||
|
||
const p = { | ||
name: 'Lazy...' | ||
} | ||
|
||
const lazy = async () => { | ||
let i = 1; | ||
|
||
for (const lazy of document.querySelectorAll('[hidden]')) { | ||
await new Promise(r => setTimeout(r, 1000)); | ||
|
||
p.name += ` -> ${i++}`; | ||
|
||
lazy.removeAttribute('hidden'); | ||
} | ||
|
||
} | ||
|
||
lazy(); | ||
|
||
templateByNode(document.body, p); | ||
|
||
component('my-test', {}, () => templateByString(new Date().toJSON())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { notifyVisible } from '../notify/visible.js'; | ||
import { templateByNode } from '../template.js'; | ||
|
||
const loaded = new WeakSet(); | ||
|
||
/** | ||
* @type { import("../plugins.js").Plugin } | ||
*/ | ||
export const dataLazyPlugin = { | ||
select: '[data-lazy]', | ||
|
||
run: (node, props, stopTemplate) => { | ||
|
||
if (loaded.has(node) || !node.childNodes.length) { | ||
return; | ||
} | ||
|
||
loaded.add(node); | ||
|
||
const hidden = node.closest('[hidden]'); | ||
|
||
const execute = () => { | ||
for (const child of node.childNodes) { | ||
templateByNode(child, props); | ||
} | ||
} | ||
|
||
if (hidden) { | ||
notifyVisible(node, hidden).then(execute); | ||
stopTemplate(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ const joinsRoutes = (node) => { | |
} | ||
} | ||
|
||
return route | ||
return route.replaceAll(/\/+/g, '/'); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters