edgexpress 3.0.1 → 3.0.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.
Files changed (92) hide show
  1. package/eslint.config.cjs +6 -0
  2. package/examples/index.js +41 -0
  3. package/examples/views/components/layout/main.edge +26 -0
  4. package/examples/views/components/modal.edge +27 -0
  5. package/examples/views/home.edge +84 -0
  6. package/examples/views/partials/button.edge +1 -0
  7. package/examples/views/partials/home-footer.edge +49 -0
  8. package/examples/views/partials/home-header.edge +61 -0
  9. package/examples/views/welcome.edge +22 -0
  10. package/index.d.ts +7 -0
  11. package/package.json +3 -3
  12. package/src/cache_manager.d.ts +28 -0
  13. package/src/cache_manager.js +58 -0
  14. package/src/compiler.d.ts +73 -0
  15. package/src/compiler.js +319 -0
  16. package/src/component/props.d.ts +53 -0
  17. package/src/component/props.js +110 -0
  18. package/src/edge/globals.d.ts +5 -0
  19. package/src/edge/globals.js +95 -0
  20. package/src/edge/main.d.ts +192 -0
  21. package/src/edge/main.js +334 -0
  22. package/src/edge/renderer.d.ts +44 -0
  23. package/src/edge/renderer.js +85 -0
  24. package/src/edge/stacks.d.ts +22 -0
  25. package/src/edge/stacks.js +98 -0
  26. package/src/loader.d.ts +138 -0
  27. package/src/loader.js +347 -0
  28. package/src/migrate/globals.d.ts +1 -0
  29. package/src/migrate/globals.js +100 -0
  30. package/src/migrate/plugin.d.ts +2 -0
  31. package/src/migrate/plugin.js +58 -0
  32. package/src/migrate/props.d.ts +66 -0
  33. package/src/migrate/props.js +129 -0
  34. package/src/migrate/tags/layout.d.ts +6 -0
  35. package/src/migrate/tags/layout.js +25 -0
  36. package/src/migrate/tags/main.d.ts +4 -0
  37. package/src/migrate/tags/main.js +19 -0
  38. package/src/migrate/tags/section.d.ts +6 -0
  39. package/src/migrate/tags/section.js +23 -0
  40. package/src/migrate/tags/set.d.ts +26 -0
  41. package/src/migrate/tags/set.js +104 -0
  42. package/src/migrate/tags/super.d.ts +9 -0
  43. package/src/migrate/tags/super.js +31 -0
  44. package/src/plugins/supercharged.d.ts +4 -0
  45. package/src/plugins/supercharged.js +88 -0
  46. package/src/processor.d.ts +42 -0
  47. package/src/processor.js +86 -0
  48. package/src/tags/assign.d.ts +5 -0
  49. package/src/tags/assign.js +42 -0
  50. package/src/tags/component.d.ts +6 -0
  51. package/src/tags/component.js +299 -0
  52. package/src/tags/debugger.d.ts +5 -0
  53. package/src/tags/debugger.js +26 -0
  54. package/src/tags/each.d.ts +20 -0
  55. package/src/tags/each.js +185 -0
  56. package/src/tags/else.d.ts +2 -0
  57. package/src/tags/else.js +22 -0
  58. package/src/tags/else_if.d.ts +7 -0
  59. package/src/tags/else_if.js +39 -0
  60. package/src/tags/eval.d.ts +7 -0
  61. package/src/tags/eval.js +30 -0
  62. package/src/tags/if.d.ts +5 -0
  63. package/src/tags/if.js +45 -0
  64. package/src/tags/include.d.ts +27 -0
  65. package/src/tags/include.js +78 -0
  66. package/src/tags/include_if.d.ts +10 -0
  67. package/src/tags/include_if.js +61 -0
  68. package/src/tags/inject.d.ts +6 -0
  69. package/src/tags/inject.js +40 -0
  70. package/src/tags/let.d.ts +6 -0
  71. package/src/tags/let.js +69 -0
  72. package/src/tags/main.d.ts +18 -0
  73. package/src/tags/main.js +47 -0
  74. package/src/tags/new_error.d.ts +6 -0
  75. package/src/tags/new_error.js +47 -0
  76. package/src/tags/push_once_to.d.ts +13 -0
  77. package/src/tags/push_once_to.js +65 -0
  78. package/src/tags/push_to.d.ts +7 -0
  79. package/src/tags/push_to.js +62 -0
  80. package/src/tags/slot.d.ts +6 -0
  81. package/src/tags/slot.js +29 -0
  82. package/src/tags/stack.d.ts +5 -0
  83. package/src/tags/stack.js +38 -0
  84. package/src/tags/unless.d.ts +12 -0
  85. package/src/tags/unless.js +52 -0
  86. package/src/template.d.ts +127 -0
  87. package/src/template.js +203 -0
  88. package/src/types.d.ts +144 -0
  89. package/src/types.js +10 -0
  90. package/src/utils.d.ts +96 -0
  91. package/src/utils.js +297 -0
  92. package/tsconfig.json +16 -0
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ /*
3
+ * edge.js
4
+ *
5
+ * (c) Edge
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.migrate = void 0;
45
+ const Tags = __importStar(require("./tags/main.js"));
46
+ const globals_js_1 = require("./globals.js");
47
+ const migrate = (edge) => {
48
+ edge.compat = true;
49
+ edge.compiler.compat = true;
50
+ edge.asyncCompiler.compat = true;
51
+ Object.keys(globals_js_1.GLOBALS).forEach((name) => {
52
+ edge.global(name, globals_js_1.GLOBALS[name]);
53
+ });
54
+ Object.keys(Tags).forEach((name) => {
55
+ edge.registerTag(Tags[name]);
56
+ });
57
+ };
58
+ exports.migrate = migrate;
@@ -0,0 +1,66 @@
1
+ import { type ComponentProps } from '../component/props.js'
2
+ /**
3
+ * Class to ease interactions with component props
4
+ */
5
+ export declare class Props {
6
+ #private
7
+ /**
8
+ * Use ".next" property to migrate to newer
9
+ * api
10
+ */
11
+ next: ComponentProps
12
+ constructor(props: any)
13
+ /**
14
+ * Find if a key exists inside the props
15
+ */
16
+ has(key: string): boolean
17
+ /**
18
+ * Get value for a given key
19
+ */
20
+ get(key: string, defaultValue?: any): any
21
+ /**
22
+ * Returns all the props
23
+ */
24
+ all(): any
25
+ /**
26
+ * Validate prop value
27
+ */
28
+ validate(key: string, validateFn: (key: string, value?: any) => any): void
29
+ /**
30
+ * Return values for only the given keys
31
+ */
32
+ only(keys: string[]): any
33
+ /**
34
+ * Return values except the given keys
35
+ */
36
+ except(keys: string[]): any
37
+ /**
38
+ * Serialize all props to a string of HTML attributes
39
+ */
40
+ serialize(
41
+ mergeProps?: any,
42
+ prioritizeInline?: boolean
43
+ ): {
44
+ value: any
45
+ }
46
+ /**
47
+ * Serialize only the given keys to a string of HTML attributes
48
+ */
49
+ serializeOnly(
50
+ keys: string[],
51
+ mergeProps?: any,
52
+ prioritizeInline?: boolean
53
+ ): {
54
+ value: any
55
+ }
56
+ /**
57
+ * Serialize except the given keys to a string of HTML attributes
58
+ */
59
+ serializeExcept(
60
+ keys: string[],
61
+ mergeProps?: any,
62
+ prioritizeInline?: boolean
63
+ ): {
64
+ value: any
65
+ }
66
+ }
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ /*
3
+ * edge.js
4
+ *
5
+ * (c) EdgeJS
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.Props = void 0;
15
+ const lodash_1 = __importDefault(require("@poppinss/utils/lodash"));
16
+ const stringify_attributes_1 = __importDefault(require("stringify-attributes"));
17
+ const template_js_1 = require("../template.js");
18
+ const props_js_1 = require("../component/props.js");
19
+ /**
20
+ * Class to ease interactions with component props
21
+ */
22
+ class Props {
23
+ /**
24
+ * Use ".next" property to migrate to newer
25
+ * api
26
+ */
27
+ next;
28
+ constructor(props) {
29
+ // @ts-ignore
30
+ this[Symbol.for('options')] = { props };
31
+ Object.assign(this, props);
32
+ this.next = new props_js_1.ComponentProps(props);
33
+ }
34
+ /**
35
+ * Merges the className attribute with the class attribute
36
+ */
37
+ #mergeClassAttributes(props) {
38
+ if (props.className) {
39
+ if (!props.class) {
40
+ props.class = [];
41
+ }
42
+ /**
43
+ * Normalize class attribute to be an array
44
+ */
45
+ if (!Array.isArray(props.class)) {
46
+ props.class = [props.class];
47
+ }
48
+ props.class = props.class.concat(props.className);
49
+ props.className = false;
50
+ }
51
+ return props;
52
+ }
53
+ /**
54
+ * Find if a key exists inside the props
55
+ */
56
+ has(key) {
57
+ const value = this.get(key);
58
+ return value !== undefined && value !== null;
59
+ }
60
+ /**
61
+ * Get value for a given key
62
+ */
63
+ get(key, defaultValue) {
64
+ return lodash_1.default.get(this.all(), key, defaultValue);
65
+ }
66
+ /**
67
+ * Returns all the props
68
+ */
69
+ all() {
70
+ // @ts-ignore
71
+ return this[Symbol.for('options')].props;
72
+ }
73
+ /**
74
+ * Validate prop value
75
+ */
76
+ validate(key, validateFn) {
77
+ const value = this.get(key);
78
+ validateFn(key, value);
79
+ }
80
+ /**
81
+ * Return values for only the given keys
82
+ */
83
+ only(keys) {
84
+ return lodash_1.default.pick(this.all(), keys);
85
+ }
86
+ /**
87
+ * Return values except the given keys
88
+ */
89
+ except(keys) {
90
+ return lodash_1.default.omit(this.all(), keys);
91
+ }
92
+ /**
93
+ * Serialize all props to a string of HTML attributes
94
+ */
95
+ serialize(mergeProps, prioritizeInline = true) {
96
+ /**
97
+ * Prioritize user attributes when prioritizeInline=false
98
+ */
99
+ const attributes = prioritizeInline
100
+ ? lodash_1.default.merge({}, this.all(), mergeProps)
101
+ : lodash_1.default.merge({}, mergeProps, this.all());
102
+ return (0, template_js_1.htmlSafe)((0, stringify_attributes_1.default)(this.#mergeClassAttributes(attributes)));
103
+ }
104
+ /**
105
+ * Serialize only the given keys to a string of HTML attributes
106
+ */
107
+ serializeOnly(keys, mergeProps, prioritizeInline = true) {
108
+ /**
109
+ * Prioritize user attributes when prioritizeInline=false
110
+ */
111
+ const attributes = prioritizeInline
112
+ ? lodash_1.default.merge({}, this.only(keys), mergeProps)
113
+ : lodash_1.default.merge({}, mergeProps, this.only(keys));
114
+ return (0, template_js_1.htmlSafe)((0, stringify_attributes_1.default)(this.#mergeClassAttributes(attributes)));
115
+ }
116
+ /**
117
+ * Serialize except the given keys to a string of HTML attributes
118
+ */
119
+ serializeExcept(keys, mergeProps, prioritizeInline = true) {
120
+ /**
121
+ * Prioritize user attributes when prioritizeInline=false
122
+ */
123
+ const attributes = prioritizeInline
124
+ ? lodash_1.default.merge({}, this.except(keys), mergeProps)
125
+ : lodash_1.default.merge({}, mergeProps, this.except(keys));
126
+ return (0, template_js_1.htmlSafe)((0, stringify_attributes_1.default)(this.#mergeClassAttributes(attributes)));
127
+ }
128
+ }
129
+ exports.Props = Props;
@@ -0,0 +1,6 @@
1
+ import { type TagContract } from '../../types.js'
2
+ /**
3
+ * Layout tag is used to define parent layout for a given template. The layout
4
+ * must appear in the first line of the template itself.
5
+ */
6
+ export declare const layoutTag: TagContract
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /*
3
+ * edge.js
4
+ *
5
+ * (c) EdgeJS
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.layoutTag = void 0;
12
+ /**
13
+ * Layout tag is used to define parent layout for a given template. The layout
14
+ * must appear in the first line of the template itself.
15
+ */
16
+ exports.layoutTag = {
17
+ block: false,
18
+ seekable: true,
19
+ tagName: 'layout',
20
+ noNewLine: true,
21
+ compile() {
22
+ // The layouts are handled by the template itself. I am just a way to
23
+ // tell lexer to parse me as a block node
24
+ },
25
+ };
@@ -0,0 +1,4 @@
1
+ export { setTag as set } from './set.js'
2
+ export { superTag as super } from './super.js'
3
+ export { layoutTag as layout } from './layout.js'
4
+ export { sectionTag as section } from './section.js'
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /*
3
+ * edge.js
4
+ *
5
+ * (c) EdgeJS
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.section = exports.layout = exports.super = exports.set = void 0;
12
+ var set_js_1 = require("./set.js");
13
+ Object.defineProperty(exports, "set", { enumerable: true, get: function () { return set_js_1.setTag; } });
14
+ var super_js_1 = require("./super.js");
15
+ Object.defineProperty(exports, "super", { enumerable: true, get: function () { return super_js_1.superTag; } });
16
+ var layout_js_1 = require("./layout.js");
17
+ Object.defineProperty(exports, "layout", { enumerable: true, get: function () { return layout_js_1.layoutTag; } });
18
+ var section_js_1 = require("./section.js");
19
+ Object.defineProperty(exports, "section", { enumerable: true, get: function () { return section_js_1.sectionTag; } });
@@ -0,0 +1,6 @@
1
+ import { type TagContract } from '../../types.js'
2
+ /**
3
+ * Section tag is used to define the sections on a given template. Sections cannot be
4
+ * nested and must appear as top level children inside a component.
5
+ */
6
+ export declare const sectionTag: TagContract
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /*
3
+ * edge.js
4
+ *
5
+ * (c) EdgeJS
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.sectionTag = void 0;
12
+ /**
13
+ * Section tag is used to define the sections on a given template. Sections cannot be
14
+ * nested and must appear as top level children inside a component.
15
+ */
16
+ exports.sectionTag = {
17
+ block: true,
18
+ seekable: true,
19
+ tagName: 'section',
20
+ compile(parser, buffer, token) {
21
+ token.children.forEach((child) => parser.processToken(child, buffer));
22
+ },
23
+ };
@@ -0,0 +1,26 @@
1
+ import type lodash from '@poppinss/utils/lodash'
2
+ import { type TagContract } from '../../types.js'
3
+ declare module '../../template.js' {
4
+ interface Template {
5
+ setValue: (typeof lodash)['set']
6
+ }
7
+ }
8
+ /**
9
+ * The set tag is used to set runtime values within the template. The value
10
+ * is set inside the current scope of the template.
11
+ *
12
+ * ```edge
13
+ * @set('user.username', 'virk')
14
+ * <p> {{ user.username }} </p>
15
+ * ```
16
+ *
17
+ * Set it inside the each loop.
18
+ *
19
+ * ```edge
20
+ * @each(user in users)
21
+ * @set('age', user.age + 1)
22
+ * {{ age }}
23
+ * @endeach
24
+ * ```
25
+ */
26
+ export declare const setTag: TagContract
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /*
3
+ * edge.js
4
+ *
5
+ * (c) EdgeJS
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.setTag = void 0;
15
+ const edge_error_1 = require("edge-error");
16
+ const edge_parser_1 = require("edge-parser");
17
+ const lodash_1 = __importDefault(require("@poppinss/utils/lodash"));
18
+ const utils_js_1 = require("../../utils.js");
19
+ /**
20
+ * The set tag is used to set runtime values within the template. The value
21
+ * is set inside the current scope of the template.
22
+ *
23
+ * ```edge
24
+ * @set('user.username', 'virk')
25
+ * <p> {{ user.username }} </p>
26
+ * ```
27
+ *
28
+ * Set it inside the each loop.
29
+ *
30
+ * ```edge
31
+ * @each(user in users)
32
+ * @set('age', user.age + 1)
33
+ * {{ age }}
34
+ * @endeach
35
+ * ```
36
+ */
37
+ exports.setTag = {
38
+ block: false,
39
+ seekable: true,
40
+ tagName: 'set',
41
+ noNewLine: true,
42
+ /**
43
+ * Compiles else block node to Javascript else statement
44
+ */
45
+ compile(parser, buffer, token) {
46
+ const parsed = (0, utils_js_1.parseJsArg)(parser, token);
47
+ /**
48
+ * The set tag only accepts a sequence expression.
49
+ */
50
+ (0, utils_js_1.isSubsetOf)(parsed, [edge_parser_1.expressions.SequenceExpression], () => {
51
+ throw (0, utils_js_1.unallowedExpression)(`"${token.properties.jsArg}" is not a valid key-value pair for the @slot tag`, token.filename, parser.utils.getExpressionLoc(parsed));
52
+ });
53
+ /**
54
+ * Disallow less than 2 and more than 3 values for the sequence
55
+ * expression
56
+ */
57
+ if (parsed.expressions.length < 2 || parsed.expressions.length > 3) {
58
+ throw new edge_error_1.EdgeError('@set tag accepts a minimum of 2 or maximum or 3 arguments', 'E_INVALID_ARGUMENTS_COUNT', {
59
+ line: parsed.loc.start.line,
60
+ col: parsed.loc.start.column,
61
+ filename: token.filename,
62
+ });
63
+ }
64
+ /**
65
+ * Extract key-value and the collection (if any)
66
+ */
67
+ let collection;
68
+ let key;
69
+ let value;
70
+ if (parsed.expressions.length === 3) {
71
+ collection = parsed.expressions[0];
72
+ key = parsed.expressions[1];
73
+ value = parsed.expressions[2];
74
+ }
75
+ else {
76
+ key = parsed.expressions[0];
77
+ value = parsed.expressions[1];
78
+ }
79
+ /**
80
+ * Mutate the collection when defined
81
+ */
82
+ if (collection) {
83
+ buffer.writeExpression(`template.setValue(${parser.utils.stringify(collection)}, '${key.value}', ${parser.utils.stringify(value)})`, token.filename, token.loc.start.line);
84
+ return;
85
+ }
86
+ /**
87
+ * Write statement to mutate the key. If the variable has already been
88
+ * defined, then just update it's value.
89
+ *
90
+ * We do not allow re-declaring a variable as of now
91
+ */
92
+ const expression = parser.stack.has(key.value)
93
+ ? `${key.value} = ${parser.utils.stringify(value)}`
94
+ : `let ${key.value} = ${parser.utils.stringify(value)}`;
95
+ buffer.writeExpression(expression, token.filename, token.loc.start.line);
96
+ parser.stack.defineVariable(key.value);
97
+ },
98
+ /**
99
+ * Add methods to the template for running the loop
100
+ */
101
+ boot(template) {
102
+ template.macro('setValue', lodash_1.default.set);
103
+ },
104
+ };
@@ -0,0 +1,9 @@
1
+ import { type TagContract } from '../../types.js'
2
+ /**
3
+ * Super tag is used inside sections to inherit the parent section
4
+ * content.
5
+ *
6
+ * The implementation of super tag is handled by the compiler itself, but we need
7
+ * the tag to exists, so that the lexer can parse it as a tag.
8
+ */
9
+ export declare const superTag: TagContract
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /*
3
+ * edge.js
4
+ *
5
+ * (c) EdgeJS
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.superTag = void 0;
12
+ const edge_error_1 = require("edge-error");
13
+ /**
14
+ * Super tag is used inside sections to inherit the parent section
15
+ * content.
16
+ *
17
+ * The implementation of super tag is handled by the compiler itself, but we need
18
+ * the tag to exists, so that the lexer can parse it as a tag.
19
+ */
20
+ exports.superTag = {
21
+ block: false,
22
+ seekable: false,
23
+ tagName: 'super',
24
+ compile(_, __, token) {
25
+ throw new edge_error_1.EdgeError('@super tag must appear as top level tag inside the @section tag', 'E_ORPHAN_SUPER_TAG', {
26
+ line: token.loc.start.line,
27
+ col: token.loc.start.col,
28
+ filename: token.filename,
29
+ });
30
+ },
31
+ };
@@ -0,0 +1,4 @@
1
+ import { type PluginFn } from '../types.js'
2
+ export declare const pluginSuperCharged: PluginFn<{
3
+ recurring: boolean
4
+ }>
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ /*
3
+ * edge.js
4
+ *
5
+ * (c) EdgeJS
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.pluginSuperCharged = void 0;
12
+ /**
13
+ * Hooks into the compiler phase of Edge and converts
14
+ * tags to components.
15
+ *
16
+ * The components are discovered from the components directory
17
+ * inside every registered disk.
18
+ */
19
+ class SuperChargedComponents {
20
+ #edge;
21
+ #components = {};
22
+ constructor(edge) {
23
+ this.#edge = edge;
24
+ this.#claimTags();
25
+ this.#transformTags();
26
+ }
27
+ /**
28
+ * Refreshes the list of components
29
+ */
30
+ refreshComponents() {
31
+ this.#components = this.#edge.loader
32
+ .listComponents()
33
+ .reduce((result, { components }) => {
34
+ components.forEach((component) => {
35
+ result[component.tagName] = component.componentName;
36
+ });
37
+ return result;
38
+ }, {});
39
+ }
40
+ /**
41
+ * Registers hook to claim self processing of tags that
42
+ * are references to components
43
+ */
44
+ #claimTags() {
45
+ this.#edge.compiler.claimTag((name) => {
46
+ if (this.#components[name]) {
47
+ return { seekable: true, block: true };
48
+ }
49
+ return null;
50
+ });
51
+ this.#edge.asyncCompiler.claimTag((name) => {
52
+ if (this.#components[name]) {
53
+ return { seekable: true, block: true };
54
+ }
55
+ return null;
56
+ });
57
+ }
58
+ /**
59
+ * Transforms tags to component calls
60
+ */
61
+ #transformTags() {
62
+ this.#edge.processor.process('tag', ({ tag }) => {
63
+ const component = this.#components[tag.properties.name];
64
+ if (!component) {
65
+ return;
66
+ }
67
+ tag.properties.name = 'component';
68
+ if (tag.properties.jsArg.trim() === '') {
69
+ tag.properties.jsArg = `'${component}'`;
70
+ }
71
+ else {
72
+ tag.properties.jsArg = `'${component}',${tag.properties.jsArg}`;
73
+ }
74
+ });
75
+ }
76
+ }
77
+ /**
78
+ * The superCharged plugin converts components stored within the
79
+ * components directory of all the disk to Edge tags.
80
+ */
81
+ let superCharged;
82
+ const pluginSuperCharged = (edge, firstRun) => {
83
+ if (firstRun) {
84
+ superCharged = new SuperChargedComponents(edge);
85
+ }
86
+ superCharged.refreshComponents();
87
+ };
88
+ exports.pluginSuperCharged = pluginSuperCharged;
@@ -0,0 +1,42 @@
1
+ import type { Template } from './template.js'
2
+ import type { TagToken } from 'edge-lexer/types'
3
+ /**
4
+ * Exposes the API to register a set of handlers to process the
5
+ * templates output at different stages
6
+ */
7
+ export declare class Processor {
8
+ #private
9
+ /**
10
+ * Execute tag handler
11
+ */
12
+ executeTag(data: { tag: TagToken; path: string }): void
13
+ /**
14
+ * Execute raw handlers
15
+ */
16
+ executeRaw(data: { raw: string; path: string }): string
17
+ /**
18
+ * Execute compiled handlers
19
+ */
20
+ executeCompiled(data: { compiled: string; path: string }): string
21
+ /**
22
+ * Execute output handlers
23
+ */
24
+ executeOutput(data: { output: string; template: Template; state: Record<string, any> }): string
25
+ /**
26
+ * Define a processor function
27
+ */
28
+ process(event: 'raw', handler: (data: { raw: string; path: string }) => string | void): this
29
+ process(event: 'tag', handler: (data: { tag: TagToken; path: string }) => void): this
30
+ process(
31
+ event: 'compiled',
32
+ handler: (data: { compiled: string; path: string }) => string | void
33
+ ): this
34
+ process(
35
+ event: 'output',
36
+ handler: (data: {
37
+ output: string
38
+ template: Template
39
+ state: Record<string, any>
40
+ }) => string | void
41
+ ): this
42
+ }