eleva 1.0.0-alpha → 1.0.0-rc.10
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/LICENSE +1 -1
- package/README.md +554 -137
- package/dist/eleva-plugins.cjs.js +3397 -0
- package/dist/eleva-plugins.cjs.js.map +1 -0
- package/dist/eleva-plugins.esm.js +3392 -0
- package/dist/eleva-plugins.esm.js.map +1 -0
- package/dist/eleva-plugins.umd.js +3403 -0
- package/dist/eleva-plugins.umd.js.map +1 -0
- package/dist/eleva-plugins.umd.min.js +3 -0
- package/dist/eleva-plugins.umd.min.js.map +1 -0
- package/dist/eleva.cjs.js +1448 -0
- package/dist/eleva.cjs.js.map +1 -0
- package/dist/eleva.d.ts +1057 -80
- package/dist/eleva.esm.js +1230 -274
- package/dist/eleva.esm.js.map +1 -1
- package/dist/eleva.umd.js +1230 -274
- package/dist/eleva.umd.js.map +1 -1
- package/dist/eleva.umd.min.js +3 -0
- package/dist/eleva.umd.min.js.map +1 -0
- package/dist/plugins/attr.umd.js +231 -0
- package/dist/plugins/attr.umd.js.map +1 -0
- package/dist/plugins/attr.umd.min.js +3 -0
- package/dist/plugins/attr.umd.min.js.map +1 -0
- package/dist/plugins/props.umd.js +711 -0
- package/dist/plugins/props.umd.js.map +1 -0
- package/dist/plugins/props.umd.min.js +3 -0
- package/dist/plugins/props.umd.min.js.map +1 -0
- package/dist/plugins/router.umd.js +1807 -0
- package/dist/plugins/router.umd.js.map +1 -0
- package/dist/plugins/router.umd.min.js +3 -0
- package/dist/plugins/router.umd.min.js.map +1 -0
- package/dist/plugins/store.umd.js +684 -0
- package/dist/plugins/store.umd.js.map +1 -0
- package/dist/plugins/store.umd.min.js +3 -0
- package/dist/plugins/store.umd.min.js.map +1 -0
- package/package.json +240 -62
- package/src/core/Eleva.js +552 -145
- package/src/modules/Emitter.js +154 -18
- package/src/modules/Renderer.js +288 -86
- package/src/modules/Signal.js +132 -13
- package/src/modules/TemplateEngine.js +153 -27
- package/src/plugins/Attr.js +252 -0
- package/src/plugins/Props.js +590 -0
- package/src/plugins/Router.js +1919 -0
- package/src/plugins/Store.js +741 -0
- package/src/plugins/index.js +40 -0
- package/types/core/Eleva.d.ts +482 -48
- package/types/core/Eleva.d.ts.map +1 -1
- package/types/modules/Emitter.d.ts +151 -20
- package/types/modules/Emitter.d.ts.map +1 -1
- package/types/modules/Renderer.d.ts +151 -12
- package/types/modules/Renderer.d.ts.map +1 -1
- package/types/modules/Signal.d.ts +130 -16
- package/types/modules/Signal.d.ts.map +1 -1
- package/types/modules/TemplateEngine.d.ts +154 -14
- package/types/modules/TemplateEngine.d.ts.map +1 -1
- package/types/plugins/Attr.d.ts +28 -0
- package/types/plugins/Attr.d.ts.map +1 -0
- package/types/plugins/Props.d.ts +48 -0
- package/types/plugins/Props.d.ts.map +1 -0
- package/types/plugins/Router.d.ts +1000 -0
- package/types/plugins/Router.d.ts.map +1 -0
- package/types/plugins/Store.d.ts +86 -0
- package/types/plugins/Store.d.ts.map +1 -0
- package/types/plugins/index.d.ts +5 -0
- package/types/plugins/index.d.ts.map +1 -0
- package/dist/eleva.min.js +0 -2
- package/dist/eleva.min.js.map +0 -1
|
@@ -1,26 +1,166 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @typedef {Record<string, unknown>} TemplateData
|
|
3
|
+
* Data context for template interpolation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {string} TemplateString
|
|
7
|
+
* A string containing {{ expression }} interpolation markers
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {string} Expression
|
|
11
|
+
* A JavaScript expression to be evaluated in the data context
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {unknown} EvaluationResult
|
|
15
|
+
* The result of evaluating an expression (string, number, boolean, object, etc.)
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @class 🔒 TemplateEngine
|
|
19
|
+
* @classdesc A secure template engine that handles interpolation and dynamic attribute parsing.
|
|
20
|
+
* Provides a way to evaluate expressions in templates.
|
|
21
|
+
* All methods are static and can be called directly on the class.
|
|
22
|
+
*
|
|
23
|
+
* Template Syntax:
|
|
24
|
+
* - `{{ expression }}` - Interpolate any JavaScript expression
|
|
25
|
+
* - `{{ variable }}` - Access data properties directly
|
|
26
|
+
* - `{{ object.property }}` - Access nested properties
|
|
27
|
+
* - `{{ condition ? a : b }}` - Ternary expressions
|
|
28
|
+
* - `{{ func(arg) }}` - Call functions from data context
|
|
3
29
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Basic interpolation
|
|
32
|
+
* const template = "Hello, {{name}}!";
|
|
33
|
+
* const data = { name: "World" };
|
|
34
|
+
* const result = TemplateEngine.parse(template, data);
|
|
35
|
+
* // Result: "Hello, World!"
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Nested properties
|
|
39
|
+
* const template = "Welcome, {{user.name}}!";
|
|
40
|
+
* const data = { user: { name: "John" } };
|
|
41
|
+
* const result = TemplateEngine.parse(template, data);
|
|
42
|
+
* // Result: "Welcome, John!"
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Expressions
|
|
46
|
+
* const template = "Status: {{active ? 'Online' : 'Offline'}}";
|
|
47
|
+
* const data = { active: true };
|
|
48
|
+
* const result = TemplateEngine.parse(template, data);
|
|
49
|
+
* // Result: "Status: Online"
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // With Signal values
|
|
53
|
+
* const template = "Count: {{count.value}}";
|
|
54
|
+
* const data = { count: { value: 42 } };
|
|
55
|
+
* const result = TemplateEngine.parse(template, data);
|
|
56
|
+
* // Result: "Count: 42"
|
|
7
57
|
*/
|
|
8
58
|
export class TemplateEngine {
|
|
9
59
|
/**
|
|
10
|
-
*
|
|
60
|
+
* Regular expression for matching template expressions in the format {{ expression }}
|
|
61
|
+
* Matches: {{ anything }} with optional whitespace inside braces
|
|
11
62
|
*
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
63
|
+
* @static
|
|
64
|
+
* @private
|
|
65
|
+
* @type {RegExp}
|
|
15
66
|
*/
|
|
16
|
-
static
|
|
67
|
+
private static expressionPattern;
|
|
17
68
|
/**
|
|
18
|
-
*
|
|
69
|
+
* Parses a template string, replacing expressions with their evaluated values.
|
|
70
|
+
* Expressions are evaluated in the provided data context.
|
|
71
|
+
*
|
|
72
|
+
* @public
|
|
73
|
+
* @static
|
|
74
|
+
* @param {TemplateString|unknown} template - The template string to parse.
|
|
75
|
+
* @param {TemplateData} data - The data context for evaluating expressions.
|
|
76
|
+
* @returns {string} The parsed template with expressions replaced by their values.
|
|
19
77
|
*
|
|
20
|
-
* @
|
|
21
|
-
*
|
|
22
|
-
*
|
|
78
|
+
* @example
|
|
79
|
+
* // Simple variables
|
|
80
|
+
* TemplateEngine.parse("Hello, {{name}}!", { name: "World" });
|
|
81
|
+
* // Result: "Hello, World!"
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* // Nested properties
|
|
85
|
+
* TemplateEngine.parse("{{user.name}} is {{user.age}} years old", {
|
|
86
|
+
* user: { name: "John", age: 30 }
|
|
87
|
+
* });
|
|
88
|
+
* // Result: "John is 30 years old"
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* // Multiple expressions
|
|
92
|
+
* TemplateEngine.parse("{{greeting}}, {{name}}! You have {{count}} messages.", {
|
|
93
|
+
* greeting: "Hello",
|
|
94
|
+
* name: "User",
|
|
95
|
+
* count: 5
|
|
96
|
+
* });
|
|
97
|
+
* // Result: "Hello, User! You have 5 messages."
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* // With conditionals
|
|
101
|
+
* TemplateEngine.parse("Status: {{online ? 'Active' : 'Inactive'}}", {
|
|
102
|
+
* online: true
|
|
103
|
+
* });
|
|
104
|
+
* // Result: "Status: Active"
|
|
23
105
|
*/
|
|
24
|
-
static
|
|
106
|
+
public static parse(template: TemplateString | unknown, data: TemplateData): string;
|
|
107
|
+
/**
|
|
108
|
+
* Evaluates an expression in the context of the provided data object.
|
|
109
|
+
*
|
|
110
|
+
* Note: This does not provide a true sandbox and evaluated expressions may access global scope.
|
|
111
|
+
* The use of the `with` statement is necessary for expression evaluation but has security implications.
|
|
112
|
+
* Only use with trusted templates. User input should never be directly interpolated.
|
|
113
|
+
*
|
|
114
|
+
* @public
|
|
115
|
+
* @static
|
|
116
|
+
* @param {Expression|unknown} expression - The expression to evaluate.
|
|
117
|
+
* @param {TemplateData} data - The data context for evaluation.
|
|
118
|
+
* @returns {EvaluationResult} The result of the evaluation, or an empty string if evaluation fails.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Property access
|
|
122
|
+
* TemplateEngine.evaluate("user.name", { user: { name: "John" } });
|
|
123
|
+
* // Result: "John"
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* // Numeric values
|
|
127
|
+
* TemplateEngine.evaluate("user.age", { user: { age: 30 } });
|
|
128
|
+
* // Result: 30
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* // Expressions
|
|
132
|
+
* TemplateEngine.evaluate("items.length > 0", { items: [1, 2, 3] });
|
|
133
|
+
* // Result: true
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* // Function calls
|
|
137
|
+
* TemplateEngine.evaluate("formatDate(date)", {
|
|
138
|
+
* date: new Date(),
|
|
139
|
+
* formatDate: (d) => d.toISOString()
|
|
140
|
+
* });
|
|
141
|
+
* // Result: "2024-01-01T00:00:00.000Z"
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* // Failed evaluation returns empty string
|
|
145
|
+
* TemplateEngine.evaluate("nonexistent.property", {});
|
|
146
|
+
* // Result: ""
|
|
147
|
+
*/
|
|
148
|
+
public static evaluate(expression: Expression | unknown, data: TemplateData): EvaluationResult;
|
|
25
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Data context for template interpolation
|
|
152
|
+
*/
|
|
153
|
+
export type TemplateData = Record<string, unknown>;
|
|
154
|
+
/**
|
|
155
|
+
* A string containing {{ expression }} interpolation markers
|
|
156
|
+
*/
|
|
157
|
+
export type TemplateString = string;
|
|
158
|
+
/**
|
|
159
|
+
* A JavaScript expression to be evaluated in the data context
|
|
160
|
+
*/
|
|
161
|
+
export type Expression = string;
|
|
162
|
+
/**
|
|
163
|
+
* The result of evaluating an expression (string, number, boolean, object, etc.)
|
|
164
|
+
*/
|
|
165
|
+
export type EvaluationResult = unknown;
|
|
26
166
|
//# sourceMappingURL=TemplateEngine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEngine.d.ts","sourceRoot":"","sources":["../../src/modules/TemplateEngine.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TemplateEngine.d.ts","sourceRoot":"","sources":["../../src/modules/TemplateEngine.js"],"names":[],"mappings":"AAMA;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH;IACE;;;;;;;OAOG;IACH,iCAAkD;IAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,8BAhCW,cAAc,GAAC,OAAO,QACtB,YAAY,GACV,MAAM,CAmClB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,mCAhCW,UAAU,GAAC,OAAO,QAClB,YAAY,GACV,gBAAgB,CAqC5B;CACF;;;;2BArKY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;6BAKvB,MAAM;;;;yBAKN,MAAM;;;;+BAKN,OAAO"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export namespace AttrPlugin {
|
|
2
|
+
let name: string;
|
|
3
|
+
let version: string;
|
|
4
|
+
let description: string;
|
|
5
|
+
/**
|
|
6
|
+
* Installs the plugin into the Eleva instance
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} eleva - The Eleva instance
|
|
9
|
+
* @param {Object} options - Plugin configuration options
|
|
10
|
+
* @param {boolean} [options.enableAria=true] - Enable ARIA attribute handling
|
|
11
|
+
* @param {boolean} [options.enableData=true] - Enable data attribute handling
|
|
12
|
+
* @param {boolean} [options.enableBoolean=true] - Enable boolean attribute handling
|
|
13
|
+
* @param {boolean} [options.enableDynamic=true] - Enable dynamic property detection
|
|
14
|
+
*/
|
|
15
|
+
function install(eleva: Object, options?: {
|
|
16
|
+
enableAria?: boolean | undefined;
|
|
17
|
+
enableData?: boolean | undefined;
|
|
18
|
+
enableBoolean?: boolean | undefined;
|
|
19
|
+
enableDynamic?: boolean | undefined;
|
|
20
|
+
}): void;
|
|
21
|
+
/**
|
|
22
|
+
* Uninstalls the plugin from the Eleva instance
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} eleva - The Eleva instance
|
|
25
|
+
*/
|
|
26
|
+
function uninstall(eleva: Object): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=Attr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Attr.d.ts","sourceRoot":"","sources":["../../src/plugins/Attr.js"],"names":[],"mappings":";cAyCY,MAAM;iBAMN,MAAM;qBAMN,MAAM;IAIhB;;;;;;;;;OASG;IACH,wBAPW,MAAM,YAEd;QAA0B,UAAU;QACV,UAAU;QACV,aAAa;QACb,aAAa;KACzC,QAmKA;IAED;;;;OAIG;IACH,0BAFW,MAAM,QAgBhB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export namespace PropsPlugin {
|
|
2
|
+
let name: string;
|
|
3
|
+
let version: string;
|
|
4
|
+
let description: string;
|
|
5
|
+
/**
|
|
6
|
+
* Installs the plugin into the Eleva instance
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} eleva - The Eleva instance
|
|
9
|
+
* @param {Object} options - Plugin configuration options
|
|
10
|
+
* @param {boolean} [options.enableAutoParsing=true] - Enable automatic type detection and parsing
|
|
11
|
+
* @param {boolean} [options.enableReactivity=true] - Enable reactive prop updates using Eleva's signal system
|
|
12
|
+
* @param {Function} [options.onError=null] - Error handler function called when parsing fails
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Basic installation
|
|
16
|
+
* app.use(PropsPlugin);
|
|
17
|
+
*
|
|
18
|
+
* // Installation with custom options
|
|
19
|
+
* app.use(PropsPlugin, {
|
|
20
|
+
* enableAutoParsing: true,
|
|
21
|
+
* enableReactivity: false,
|
|
22
|
+
* onError: (error, value) => {
|
|
23
|
+
* console.error('Props parsing error:', error, value);
|
|
24
|
+
* }
|
|
25
|
+
* });
|
|
26
|
+
*/
|
|
27
|
+
function install(eleva: Object, options?: {
|
|
28
|
+
enableAutoParsing?: boolean | undefined;
|
|
29
|
+
enableReactivity?: boolean | undefined;
|
|
30
|
+
onError?: Function | undefined;
|
|
31
|
+
}): void;
|
|
32
|
+
/**
|
|
33
|
+
* Uninstalls the plugin from the Eleva instance
|
|
34
|
+
*
|
|
35
|
+
* @param {Object} eleva - The Eleva instance
|
|
36
|
+
*
|
|
37
|
+
* @description
|
|
38
|
+
* Restores the original Eleva methods and removes all plugin-specific
|
|
39
|
+
* functionality. This method should be called when the plugin is no
|
|
40
|
+
* longer needed.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Uninstall the plugin
|
|
44
|
+
* PropsPlugin.uninstall(app);
|
|
45
|
+
*/
|
|
46
|
+
function uninstall(eleva: Object): void;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=Props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Props.d.ts","sourceRoot":"","sources":["../../src/plugins/Props.js"],"names":[],"mappings":";cAuDY,MAAM;iBAMN,MAAM;qBAMN,MAAM;IAKhB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,wBAnBW,MAAM,YAEd;QAA0B,iBAAiB;QACjB,gBAAgB;QACf,OAAO;KAElC,QAodF;IAED;;;;;;;;;;;;;OAaG;IACH,0BAXW,MAAM,QAkChB"}
|