@oscarpalmer/abydon 0.8.0 → 0.9.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/dist/fragment.mjs +21 -11
- package/dist/helpers/dom.mjs +4 -23
- package/dist/helpers/index.mjs +5 -5
- package/dist/index.js +317 -250
- package/dist/node/attribute/index.mjs +1 -9
- package/dist/node/attribute/value.mjs +27 -44
- package/dist/node/index.mjs +16 -7
- package/dist/node/value.mjs +41 -24
- package/package.json +5 -4
- package/src/fragment.ts +35 -13
- package/src/helpers/dom.ts +8 -36
- package/src/helpers/index.ts +4 -8
- package/src/models.ts +10 -3
- package/src/node/attribute/index.ts +13 -34
- package/src/node/attribute/value.ts +23 -50
- package/src/node/event.ts +2 -2
- package/src/node/index.ts +26 -10
- package/src/node/value.ts +68 -29
- package/types/helpers/dom.d.ts +3 -5
- package/types/helpers/index.d.ts +3 -3
- package/types/models.d.ts +8 -3
- package/types/node/attribute/index.d.ts +2 -3
- package/types/node/attribute/value.d.ts +2 -2
- package/types/node/event.d.ts +2 -2
- package/types/node/index.d.ts +2 -2
- package/types/node/value.d.ts +2 -1
package/dist/fragment.mjs
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
// src/fragment.ts
|
|
2
|
-
import {
|
|
2
|
+
import {html as html2} from "@oscarpalmer/toretto/html";
|
|
3
3
|
import {parse} from "./html";
|
|
4
4
|
import {mapNodes} from "./node";
|
|
5
5
|
|
|
6
6
|
class Fragment {
|
|
7
|
+
$fragment = true;
|
|
7
8
|
data;
|
|
8
9
|
constructor(strings, expressions) {
|
|
9
10
|
this.data = {
|
|
10
11
|
expressions,
|
|
11
12
|
strings,
|
|
12
|
-
|
|
13
|
+
items: [],
|
|
13
14
|
values: []
|
|
14
15
|
};
|
|
15
16
|
}
|
|
@@ -17,21 +18,30 @@ class Fragment {
|
|
|
17
18
|
element.append(...this.get());
|
|
18
19
|
}
|
|
19
20
|
get() {
|
|
20
|
-
if (this.data.
|
|
21
|
+
if (this.data.items.length === 0) {
|
|
21
22
|
const parsed = parse(this.data);
|
|
22
|
-
const templated =
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const templated = html2(parsed, {
|
|
24
|
+
sanitiseBooleanAttributes: false
|
|
25
|
+
});
|
|
26
|
+
this.data.items.splice(0, this.data.items.length, ...templated.map((node2) => ({
|
|
27
|
+
nodes: [node2]
|
|
28
|
+
})));
|
|
29
|
+
mapNodes(this.data, this.data.items.flatMap((item) => item.fragment?.get() ?? item.nodes));
|
|
25
30
|
}
|
|
26
|
-
return [
|
|
31
|
+
return [
|
|
32
|
+
...this.data.items.flatMap((item) => item.fragment?.get() ?? item.nodes)
|
|
33
|
+
];
|
|
27
34
|
}
|
|
28
35
|
remove() {
|
|
29
|
-
const { length } = this.data.
|
|
36
|
+
const { length } = this.data.items;
|
|
30
37
|
for (let index = 0;index < length; index += 1) {
|
|
31
|
-
const
|
|
32
|
-
|
|
38
|
+
const item = this.data.items[index];
|
|
39
|
+
item.fragment?.remove();
|
|
40
|
+
for (const node2 of item.nodes) {
|
|
41
|
+
node2.remove();
|
|
42
|
+
}
|
|
33
43
|
}
|
|
34
|
-
this.data.
|
|
44
|
+
this.data.items.splice(0, length);
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
export {
|
package/dist/helpers/dom.mjs
CHANGED
|
@@ -1,31 +1,14 @@
|
|
|
1
1
|
// src/helpers/dom.ts
|
|
2
2
|
import {getString} from "@oscarpalmer/atoms/string";
|
|
3
|
-
import {isFragment,
|
|
3
|
+
import {isFragment, isProperNode} from "./index";
|
|
4
4
|
function createNodes(value) {
|
|
5
|
-
if (isFragmentNode(value)) {
|
|
6
|
-
return [value];
|
|
7
|
-
}
|
|
8
5
|
if (isFragment(value)) {
|
|
9
6
|
return value.get();
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function createTemplate(html) {
|
|
14
|
-
const template = document.createElement("template");
|
|
15
|
-
template.innerHTML = html;
|
|
16
|
-
const cloned = template.content.cloneNode(true);
|
|
17
|
-
const scripts = [
|
|
18
|
-
...cloned instanceof Element ? cloned.querySelectorAll("script") : []
|
|
19
|
-
];
|
|
20
|
-
const { length } = scripts;
|
|
21
|
-
for (let index = 0;index < length; index += 1) {
|
|
22
|
-
scripts[index].remove();
|
|
8
|
+
if (isProperNode(value)) {
|
|
9
|
+
return [value];
|
|
23
10
|
}
|
|
24
|
-
|
|
25
|
-
return cloned;
|
|
26
|
-
}
|
|
27
|
-
function getNodes(node) {
|
|
28
|
-
return /^documentfragment$/i.test(node.constructor.name) ? [...node.childNodes] : [node];
|
|
11
|
+
return [new Text(getString(value))];
|
|
29
12
|
}
|
|
30
13
|
function replaceNodes(from, to) {
|
|
31
14
|
const { length } = from;
|
|
@@ -40,7 +23,5 @@ function replaceNodes(from, to) {
|
|
|
40
23
|
}
|
|
41
24
|
export {
|
|
42
25
|
replaceNodes,
|
|
43
|
-
getNodes,
|
|
44
|
-
createTemplate,
|
|
45
26
|
createNodes
|
|
46
27
|
};
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
function isFragment(value) {
|
|
3
3
|
return typeof value === "object" && value != null && "$fragment" in value && value.$fragment === true;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function isProperElement(value) {
|
|
6
6
|
return value instanceof HTMLElement || value instanceof SVGElement;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
return value instanceof
|
|
8
|
+
function isProperNode(value) {
|
|
9
|
+
return value instanceof CharacterData || value instanceof Element;
|
|
10
10
|
}
|
|
11
11
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
isProperNode,
|
|
13
|
+
isProperElement,
|
|
14
14
|
isFragment
|
|
15
15
|
};
|