@reidelsaltres/pureper 0.1.71 → 0.1.73
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/out/foundation/PHTMLParser.d.ts +2 -0
- package/out/foundation/PHTMLParser.d.ts.map +1 -1
- package/out/foundation/PHTMLParser.js +53 -28
- package/out/foundation/PHTMLParser.js.map +1 -1
- package/out/foundation/TripletDecorator.d.ts +1 -8
- package/out/foundation/TripletDecorator.d.ts.map +1 -1
- package/out/foundation/TripletDecorator.js +0 -10
- package/out/foundation/TripletDecorator.js.map +1 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js.map +1 -1
- package/package.json +1 -1
- package/src/foundation/PHTMLParser.ts +64 -37
- package/src/foundation/TripletDecorator.ts +1 -15
- package/src/index.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PHTMLParser.d.ts","sourceRoot":"","sources":["../../src/foundation/PHTMLParser.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,OAAO,OAAO,WAAW;
|
|
1
|
+
{"version":3,"file":"PHTMLParser.d.ts","sourceRoot":"","sources":["../../src/foundation/PHTMLParser.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,OAAO,OAAO,WAAW;IAG5B,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAcnC,OAAO,CAAC,aAAa;IA4CrB,OAAO,CAAC,MAAM,CAAC,KAAK,CAKlB;IACK,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IAExC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAQ/C,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG;IAWxE,OAAO,CAAC,cAAc;IAMf,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM;CAWrE"}
|
|
@@ -7,39 +7,62 @@ class PHTMLParserRule {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
export default class PHTMLParser {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
// Extracts a balanced block starting from position `start` in `content`.
|
|
11
|
+
// Returns { block, end } where `block` is the content inside braces and `end` is the position after closing brace.
|
|
12
|
+
static extractBalancedBlock(content, start) {
|
|
13
|
+
if (content[start] !== '{')
|
|
14
|
+
return null;
|
|
15
|
+
let depth = 1;
|
|
16
|
+
let i = start + 1;
|
|
17
|
+
while (i < content.length && depth > 0) {
|
|
18
|
+
if (content[i] === '{')
|
|
19
|
+
depth++;
|
|
20
|
+
else if (content[i] === '}')
|
|
21
|
+
depth--;
|
|
22
|
+
i++;
|
|
23
|
+
}
|
|
24
|
+
if (depth !== 0)
|
|
25
|
+
return null;
|
|
26
|
+
return { block: content.slice(start + 1, i - 1), end: i };
|
|
27
|
+
}
|
|
28
|
+
// Parses @for constructs with proper nesting support using brace counting.
|
|
29
|
+
parseForLoops(content, scope) {
|
|
30
|
+
const forPattern = /@for\s*\(([A-Za-z0-9_$]+)\s+in\s+([A-Za-z0-9_$.]+)\s*\)\s*\{/g;
|
|
31
|
+
let result = '';
|
|
32
|
+
let lastIndex = 0;
|
|
33
|
+
let match;
|
|
34
|
+
while ((match = forPattern.exec(content)) !== null) {
|
|
35
|
+
// Append text before this @for
|
|
36
|
+
result += content.slice(lastIndex, match.index);
|
|
37
|
+
const iterVar = match[1];
|
|
38
|
+
const iterableExpr = match[2];
|
|
39
|
+
const blockStart = match.index + match[0].length - 1; // position of '{'
|
|
40
|
+
const extracted = PHTMLParser.extractBalancedBlock(content, blockStart);
|
|
41
|
+
if (!extracted) {
|
|
42
|
+
// Unbalanced braces, just append the match as-is and continue
|
|
43
|
+
result += match[0];
|
|
44
|
+
lastIndex = match.index + match[0].length;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const inner = extracted.block;
|
|
48
|
+
lastIndex = extracted.end;
|
|
49
|
+
forPattern.lastIndex = lastIndex; // Update regex position
|
|
50
|
+
const resolved = this.resolveExpression(iterableExpr, scope);
|
|
18
51
|
const arr = Array.isArray(resolved) ? resolved : [];
|
|
19
52
|
const resultParts = [];
|
|
20
|
-
let i = 0;
|
|
21
53
|
for (const item of arr) {
|
|
22
54
|
const fullScope = Object.assign({}, scope, { [iterVar]: item });
|
|
23
|
-
// parse inner block for
|
|
24
|
-
|
|
25
|
-
// normalize whitespace: remove leading/trailing whitespace lines and
|
|
26
|
-
if (i === 0) {
|
|
27
|
-
t = t.trim();
|
|
28
|
-
t = " " + t;
|
|
29
|
-
}
|
|
30
|
-
t = t.split(/\n/)
|
|
31
|
-
//.map(line => line.trim())
|
|
32
|
-
.filter(line => line.length > 0)
|
|
33
|
-
.toString();
|
|
34
|
-
//.join('\n');
|
|
55
|
+
// Recursively parse inner block (handles nested @for and other rules)
|
|
56
|
+
const t = this.parse(inner, fullScope);
|
|
35
57
|
resultParts.push(t);
|
|
36
|
-
i++;
|
|
37
58
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
59
|
+
result += resultParts.join('\n');
|
|
60
|
+
}
|
|
61
|
+
// Append remaining content after last match
|
|
62
|
+
result += content.slice(lastIndex);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
static rules = [
|
|
43
66
|
new PHTMLParserRule(/@\(\(([\s\S]+?)\)\)/g, (parser, m, scope) => parser.stringifyValue(parser.resolveExpression(m[1], scope))),
|
|
44
67
|
new PHTMLParserRule(/@\(([\s\S]+?)\)/g, (parser, m, scope) => parser.stringifyValue(parser.resolveExpression(m[1], scope))),
|
|
45
68
|
];
|
|
@@ -70,7 +93,9 @@ export default class PHTMLParser {
|
|
|
70
93
|
return String(val);
|
|
71
94
|
}
|
|
72
95
|
parse(content, scope) {
|
|
73
|
-
|
|
96
|
+
// First, parse @for loops with proper nesting support
|
|
97
|
+
let working = this.parseForLoops(content, scope);
|
|
98
|
+
// Then apply other rules
|
|
74
99
|
for (const rule of PHTMLParser.rules) {
|
|
75
100
|
working = working.replace(rule.pattern, (...args) => rule.replacer(this, args, scope));
|
|
76
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PHTMLParser.js","sourceRoot":"","sources":["../../src/foundation/PHTMLParser.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe;IACV,OAAO,CAAS;IAEhB,QAAQ,CAAkF;IAEjG,YAAY,OAAe,EAAE,QAAyF;QAClH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAED,MAAM,CAAC,OAAO,OAAO,WAAW;
|
|
1
|
+
{"version":3,"file":"PHTMLParser.js","sourceRoot":"","sources":["../../src/foundation/PHTMLParser.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe;IACV,OAAO,CAAS;IAEhB,QAAQ,CAAkF;IAEjG,YAAY,OAAe,EAAE,QAAyF;QAClH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAED,MAAM,CAAC,OAAO,OAAO,WAAW;IAC5B,yEAAyE;IACzE,mHAAmH;IAC3G,MAAM,CAAC,oBAAoB,CAAC,OAAe,EAAE,KAAa;QAC9D,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QACxC,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;QAClB,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;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AC,OAAO,EAAE,KAAK,CAAC,CAAC;QAEjD,yBAAyB;QACzB,KAAK,MAAM,IAAI,IAAI,WAAW,CAAC,KAAK,EAAE,CAAC;YACnC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAClC,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAW,EAAE,KAAK,CAAC,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC"}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import UniHtml from "./component_api/UniHtml.js";
|
|
3
|
-
export declare function getRegisteredTriplets(): Array<{
|
|
4
|
-
triplet: Triplet<UniHtml>;
|
|
5
|
-
type: "router" | "markup";
|
|
6
|
-
name: string;
|
|
7
|
-
}>;
|
|
8
|
-
export declare function initializeAllTriplets(): Promise<void>;
|
|
1
|
+
import { AccessType } from "./Triplet.js";
|
|
9
2
|
export declare function ReComponent(html?: string, css?: string, js?: string, access?: AccessType, name?: string): (ctor: Function) => void;
|
|
10
3
|
export declare function RePage(html?: string, css?: string, js?: string, access?: AccessType, path?: string): (ctor: Function) => void;
|
|
11
4
|
//# sourceMappingURL=TripletDecorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TripletDecorator.d.ts","sourceRoot":"","sources":["../../src/foundation/TripletDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"TripletDecorator.d.ts","sourceRoot":"","sources":["../../src/foundation/TripletDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkB,MAAM,cAAc,CAAA;AAEzD,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,IAC7F,MAAM,QAAQ,UAQzB;AACD,wBAAgB,MAAM,CAAC,IAAI,CAAC,EAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,IACxF,MAAM,QAAQ,UAQzB"}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { AccessType, TripletBuilder } from "./Triplet.js";
|
|
2
|
-
// Реестр всех триплетов, созданных через декораторы
|
|
3
|
-
const tripletRegistry = [];
|
|
4
|
-
export function getRegisteredTriplets() {
|
|
5
|
-
return tripletRegistry;
|
|
6
|
-
}
|
|
7
|
-
export async function initializeAllTriplets() {
|
|
8
|
-
await Promise.all(tripletRegistry.map(entry => entry.triplet.init()));
|
|
9
|
-
}
|
|
10
2
|
export function ReComponent(html, css, js, access, name) {
|
|
11
3
|
return (ctor) => {
|
|
12
4
|
const triplet = TripletBuilder.create(html, css, js)
|
|
13
5
|
.withUni(ctor)
|
|
14
6
|
.withAccess(access ?? AccessType.BOTH)
|
|
15
7
|
.build();
|
|
16
|
-
tripletRegistry.push({ triplet, type: "markup", name: name });
|
|
17
8
|
triplet.register("markup", name);
|
|
18
9
|
};
|
|
19
10
|
}
|
|
@@ -23,7 +14,6 @@ export function RePage(html, css, js, access, path) {
|
|
|
23
14
|
.withUni(ctor)
|
|
24
15
|
.withAccess(access ?? AccessType.BOTH)
|
|
25
16
|
.build();
|
|
26
|
-
tripletRegistry.push({ triplet, type: "router", name: path });
|
|
27
17
|
triplet.register("router", path);
|
|
28
18
|
};
|
|
29
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TripletDecorator.js","sourceRoot":"","sources":["../../src/foundation/TripletDecorator.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"TripletDecorator.js","sourceRoot":"","sources":["../../src/foundation/TripletDecorator.ts"],"names":[],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OAAO,IAAI,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAE3D,cAAc,2CAA2C,CAAC;AAE1D,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAE,WAAW,EAAG,MAAM,EAAC,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAIhF,cAAc,uBAAuB,CAAC"}
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAE3D,cAAc,2CAA2C,CAAC;AAE1D,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAE3D,cAAc,2CAA2C,CAAC;AAE1D,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAE,WAAW,EAAG,MAAM,EAAC,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAIhF,cAAc,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -10,43 +10,67 @@ class PHTMLParserRule {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export default class PHTMLParser {
|
|
13
|
+
// Extracts a balanced block starting from position `start` in `content`.
|
|
14
|
+
// Returns { block, end } where `block` is the content inside braces and `end` is the position after closing brace.
|
|
15
|
+
private static extractBalancedBlock(content: string, start: number): { block: string; end: number } | null {
|
|
16
|
+
if (content[start] !== '{') return null;
|
|
17
|
+
let depth = 1;
|
|
18
|
+
let i = start + 1;
|
|
19
|
+
while (i < content.length && depth > 0) {
|
|
20
|
+
if (content[i] === '{') depth++;
|
|
21
|
+
else if (content[i] === '}') depth--;
|
|
22
|
+
i++;
|
|
23
|
+
}
|
|
24
|
+
if (depth !== 0) return null;
|
|
25
|
+
return { block: content.slice(start + 1, i - 1), end: i };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Parses @for constructs with proper nesting support using brace counting.
|
|
29
|
+
private parseForLoops(content: string, scope?: Record<string, any>): string {
|
|
30
|
+
const forPattern = /@for\s*\(([A-Za-z0-9_$]+)\s+in\s+([A-Za-z0-9_$.]+)\s*\)\s*\{/g;
|
|
31
|
+
let result = '';
|
|
32
|
+
let lastIndex = 0;
|
|
33
|
+
let match: RegExpExecArray | null;
|
|
34
|
+
|
|
35
|
+
while ((match = forPattern.exec(content)) !== null) {
|
|
36
|
+
// Append text before this @for
|
|
37
|
+
result += content.slice(lastIndex, match.index);
|
|
38
|
+
|
|
39
|
+
const iterVar = match[1];
|
|
40
|
+
const iterableExpr = match[2];
|
|
41
|
+
const blockStart = match.index + match[0].length - 1; // position of '{'
|
|
42
|
+
|
|
43
|
+
const extracted = PHTMLParser.extractBalancedBlock(content, blockStart);
|
|
44
|
+
if (!extracted) {
|
|
45
|
+
// Unbalanced braces, just append the match as-is and continue
|
|
46
|
+
result += match[0];
|
|
47
|
+
lastIndex = match.index + match[0].length;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const inner = extracted.block;
|
|
52
|
+
lastIndex = extracted.end;
|
|
53
|
+
forPattern.lastIndex = lastIndex; // Update regex position
|
|
54
|
+
|
|
55
|
+
const resolved = this.resolveExpression(iterableExpr, scope);
|
|
56
|
+
const arr = Array.isArray(resolved) ? resolved : [];
|
|
57
|
+
|
|
58
|
+
const resultParts: string[] = [];
|
|
59
|
+
for (const item of arr) {
|
|
60
|
+
const fullScope = Object.assign({}, scope, { [iterVar]: item });
|
|
61
|
+
// Recursively parse inner block (handles nested @for and other rules)
|
|
62
|
+
const t = this.parse(inner, fullScope);
|
|
63
|
+
resultParts.push(t);
|
|
64
|
+
}
|
|
65
|
+
result += resultParts.join('\n');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Append remaining content after last match
|
|
69
|
+
result += content.slice(lastIndex);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
13
73
|
private static rules: PHTMLParserRule[] = [
|
|
14
|
-
// Rule: for-loops like @for (item in items) { ... }
|
|
15
|
-
new PHTMLParserRule(/@for\s*\(([A-Za-z0-9_$]+)\s+in\s+([A-Za-z0-9_$.]+)\s*\)\s*\{([\s\S]*?)\}/g,
|
|
16
|
-
(parser, m, scope) => {
|
|
17
|
-
// m[1] = iteration variable name, m[2] = iterable expression, m[3] = inner block
|
|
18
|
-
const iterVar = m[1];
|
|
19
|
-
const iterableExpr = m[2];
|
|
20
|
-
const inner = m[3];
|
|
21
|
-
|
|
22
|
-
const resolved = parser.resolveExpression(iterableExpr, scope);
|
|
23
|
-
const arr = Array.isArray(resolved) ? resolved : [];
|
|
24
|
-
|
|
25
|
-
const resultParts: string[] = [];
|
|
26
|
-
let i = 0;
|
|
27
|
-
for (const item of arr) {
|
|
28
|
-
const fullScope = Object.assign({}, scope, { [iterVar]: item });
|
|
29
|
-
// parse inner block for this item
|
|
30
|
-
let t = parser.parse(inner, fullScope);
|
|
31
|
-
// normalize whitespace: remove leading/trailing whitespace lines and
|
|
32
|
-
if (i === 0) {
|
|
33
|
-
t = t.trim();
|
|
34
|
-
t = " " + t;
|
|
35
|
-
}
|
|
36
|
-
t = t.split(/\n/)
|
|
37
|
-
//.map(line => line.trim())
|
|
38
|
-
.filter(line => line.length > 0)
|
|
39
|
-
.toString();
|
|
40
|
-
//.join('\n');
|
|
41
|
-
resultParts.push(t);
|
|
42
|
-
i++;
|
|
43
|
-
}
|
|
44
|
-
// join each item's rendered chunk with a single newline so output is compact
|
|
45
|
-
return resultParts.join('\n');
|
|
46
|
-
|
|
47
|
-
// Parse inner block for each element in the iterable using a local scope
|
|
48
|
-
//return arr.map((el) => parser.parse(inner, Object.assign({}, scope, { [iterVar]: el }))).join('');
|
|
49
|
-
}),
|
|
50
74
|
new PHTMLParserRule(/@\(\(([\s\S]+?)\)\)/g, (parser, m, scope) =>
|
|
51
75
|
parser.stringifyValue(parser.resolveExpression(m[1], scope))),
|
|
52
76
|
new PHTMLParserRule(/@\(([\s\S]+?)\)/g, (parser, m, scope) =>
|
|
@@ -80,7 +104,10 @@ export default class PHTMLParser {
|
|
|
80
104
|
}
|
|
81
105
|
|
|
82
106
|
public parse(content: string, scope?: Record<string, any>): string {
|
|
83
|
-
|
|
107
|
+
// First, parse @for loops with proper nesting support
|
|
108
|
+
let working = this.parseForLoops(content, scope);
|
|
109
|
+
|
|
110
|
+
// Then apply other rules
|
|
84
111
|
for (const rule of PHTMLParser.rules) {
|
|
85
112
|
working = working.replace(rule.pattern,
|
|
86
113
|
(...args) => rule.replacer(this, args as any, scope));
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import UniHtml from "./component_api/UniHtml.js"
|
|
3
|
-
|
|
4
|
-
// Реестр всех триплетов, созданных через декораторы
|
|
5
|
-
const tripletRegistry: Array<{ triplet: Triplet<UniHtml>, type: "router" | "markup", name: string }> = [];
|
|
6
|
-
|
|
7
|
-
export function getRegisteredTriplets(): Array<{ triplet: Triplet<UniHtml>, type: "router" | "markup", name: string }> {
|
|
8
|
-
return tripletRegistry;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function initializeAllTriplets(): Promise<void> {
|
|
12
|
-
await Promise.all(tripletRegistry.map(entry => entry.triplet.init()));
|
|
13
|
-
}
|
|
1
|
+
import { AccessType, TripletBuilder } from "./Triplet.js"
|
|
14
2
|
|
|
15
3
|
export function ReComponent(html? : string, css?: string, js?: string, access?: AccessType, name?: string) {
|
|
16
4
|
return (ctor: Function) => {
|
|
@@ -19,7 +7,6 @@ export function ReComponent(html? : string, css?: string, js?: string, access?:
|
|
|
19
7
|
.withAccess(access ?? AccessType.BOTH)
|
|
20
8
|
.build();
|
|
21
9
|
|
|
22
|
-
tripletRegistry.push({ triplet, type: "markup", name: name! });
|
|
23
10
|
triplet.register("markup", name)
|
|
24
11
|
}
|
|
25
12
|
}
|
|
@@ -30,7 +17,6 @@ export function RePage(html? : string, css?: string, js?: string, access?: Acces
|
|
|
30
17
|
.withAccess(access ?? AccessType.BOTH)
|
|
31
18
|
.build();
|
|
32
19
|
|
|
33
|
-
tripletRegistry.push({ triplet, type: "router", name: path! });
|
|
34
20
|
triplet.register("router", path)
|
|
35
21
|
}
|
|
36
22
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { default as Page } from './foundation/component_api/Page.js';
|
|
|
10
10
|
export { default as Component } from './foundation/component_api/Component.js';
|
|
11
11
|
|
|
12
12
|
export { default as Triplet, TripletBuilder, AccessType } from './foundation/Triplet.js';
|
|
13
|
-
export { ReComponent, RePage
|
|
13
|
+
export { ReComponent , RePage} from './foundation/TripletDecorator.js';
|
|
14
14
|
|
|
15
15
|
export { default as Fetcher } from './foundation/Fetcher.js';
|
|
16
16
|
|