chocola 1.3.1 → 1.3.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.
Binary file
@@ -23,14 +23,31 @@ export function processComponentElement(
23
23
  const tagName = element.tagName.toLowerCase();
24
24
  const compName = tagName + ".js";
25
25
  const ctx = extractContextFromElement(element);
26
+ const srcInnerHtml = element.innerHTML;
26
27
 
27
28
  const instance = loadedComponents.get(compName);
28
29
  if (!instance || instance === undefined) return false;
29
30
 
30
31
  if (instance && instance.body) {
31
32
  let body = instance.body;
32
- body = body.replace(/\{ctx\.(\w+)\}/g, (_, key) => ctx[key] || "");
33
+ body = body.replace(
34
+ /(?<!\b(?:if|del-if)=)\{ctx\.(\w+)\}/g,
35
+ (_, key) => ctx[key] || ""
36
+ );
33
37
  const fragment = JSDOM.fragment(body);
38
+ const children = Array.from(fragment.querySelectorAll("*"));
39
+ children.forEach(child => {
40
+ if (child.hasAttribute("if")) {
41
+ const expr = child.getAttribute("if").slice(1, -1);
42
+ const fn = new Function("ctx", `if (${expr} === true) {return true} else {return ${expr} === '{true}'}`);
43
+ if (!fn(ctx)) child.style.display = "none";
44
+ }
45
+ if (child.hasAttribute("del-if")) {
46
+ const expr = child.getAttribute("del-if").slice(1, -1);
47
+ const fn = new Function("ctx", `if (${expr} === true) {return true} else {return ${expr} === '{true}'}`);
48
+ if (!fn(ctx)) child.remove();
49
+ }
50
+ });
34
51
  const firstChild = fragment.firstChild;
35
52
 
36
53
  if (firstChild && firstChild.nodeType === 1) {
@@ -72,7 +89,14 @@ export function processComponentElement(
72
89
  runtimeChunks.push(`${letter}RUNTIME(document.querySelector('[chid="${compId}"]'), ${JSON.stringify(ctx)});`);
73
90
  }
74
91
  }
92
+
93
+ const slotFragment = JSDOM.fragment(srcInnerHtml);
94
+ Array.from(fragment.querySelectorAll("slot")).forEach(slot => {
95
+ slot.replaceWith(slotFragment);
96
+ });
97
+
75
98
  element.replaceWith(fragment);
99
+
76
100
  return true;
77
101
  }
78
102
 
package/package.json CHANGED
@@ -1,41 +1,41 @@
1
- {
2
- "name": "chocola",
3
- "version": "1.3.1",
4
- "description": "The sweetest way to build reactive web apps",
5
- "keywords": [
6
- "web",
7
- "app",
8
- "pipeline",
9
- "framework",
10
- "gui",
11
- "components",
12
- "ui"
13
- ],
14
- "homepage": "https://github.com/sad-gabi/chocola#readme",
15
- "bugs": {
16
- "url": "https://github.com/sad-gabi/chocola/issues"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/sad-gabi/chocola.git"
21
- },
22
- "license": "MIT",
23
- "author": "SadGabi",
24
- "type": "module",
25
- "main": "index.js",
26
- "scripts": {
27
- "test": "echo \"Error: no test specified\" && exit 1"
28
- },
29
- "exports": {
30
- ".": "./index.js",
31
- "./types": "./types/index.js"
32
- },
33
- "dependencies": {
34
- "chalk": "^5.6.2",
35
- "js-beautify": "^1.15.4",
36
- "jsdom": "^27.4.0"
37
- },
38
- "devDependencies": {
39
- "js-beautify": "^1.15.4"
40
- }
41
- }
1
+ {
2
+ "name": "chocola",
3
+ "version": "1.3.2",
4
+ "description": "The sweetest way to build reactive web apps",
5
+ "keywords": [
6
+ "web",
7
+ "app",
8
+ "pipeline",
9
+ "framework",
10
+ "gui",
11
+ "components",
12
+ "ui"
13
+ ],
14
+ "homepage": "https://github.com/sad-gabi/chocola#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/sad-gabi/chocola/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/sad-gabi/chocola.git"
21
+ },
22
+ "license": "MIT",
23
+ "author": "SadGabi",
24
+ "type": "module",
25
+ "main": "index.js",
26
+ "scripts": {
27
+ "test": "echo \"Error: no test specified\" && exit 1"
28
+ },
29
+ "exports": {
30
+ ".": "./index.js",
31
+ "./types": "./types/index.js"
32
+ },
33
+ "dependencies": {
34
+ "chalk": "^5.6.2",
35
+ "js-beautify": "^1.15.4",
36
+ "jsdom": "^27.4.0"
37
+ },
38
+ "devDependencies": {
39
+ "js-beautify": "^1.15.4"
40
+ }
41
+ }