coralite 0.24.0 → 0.26.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/bin/coralite.js +2 -0
- package/dist/lib/coralite.d.ts +27 -18
- package/dist/lib/coralite.d.ts.map +1 -1
- package/dist/lib/index.js +131 -41
- package/dist/lib/index.js.map +2 -2
- package/dist/lib/parse.d.ts +12 -9
- package/dist/lib/parse.d.ts.map +1 -1
- package/dist/lib/plugin.d.ts +1 -1
- package/dist/lib/plugin.d.ts.map +1 -1
- package/dist/lib/script-manager.d.ts.map +1 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/plugins/refs.js +1 -1
- package/dist/types/core.d.ts +9 -0
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/document.d.ts +14 -2
- package/dist/types/document.d.ts.map +1 -1
- package/dist/types/dom.d.ts +8 -0
- package/dist/types/dom.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/plugin.d.ts +57 -18
- package/dist/types/plugin.d.ts.map +1 -1
- package/package.json +1 -1
package/bin/coralite.js
CHANGED
|
@@ -21,6 +21,7 @@ program
|
|
|
21
21
|
.requiredOption('-o, --output <path>', 'Output directory for the generated site')
|
|
22
22
|
.option('-m, --mode <mode>', 'Build mode: "development" or "production"', 'production')
|
|
23
23
|
.option('-i, --ignore-attribute <key=value...>', 'Ignore elements by attribute name value pair', [])
|
|
24
|
+
.option('-s, --skip-render-attribute <key...>', 'Parse elements but exclude them from final render output', [])
|
|
24
25
|
.option('-d, --dry-run', 'Run in dry-run mode')
|
|
25
26
|
|
|
26
27
|
program.parse(process.argv)
|
|
@@ -49,6 +50,7 @@ const coraliteOptions = {
|
|
|
49
50
|
templates: options.templates,
|
|
50
51
|
pages,
|
|
51
52
|
ignoreByAttribute,
|
|
53
|
+
skipRenderByAttribute: options.skipRenderAttribute,
|
|
52
54
|
mode: options.mode,
|
|
53
55
|
plugins: []
|
|
54
56
|
}
|
package/dist/lib/coralite.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* CoraliteCollectionItem,
|
|
10
10
|
* CoraliteDocumentRoot,
|
|
11
11
|
* CoraliteCollectionEventSet,
|
|
12
|
-
*
|
|
12
|
+
* Attribute,
|
|
13
13
|
* CoraliteDocumentResult,
|
|
14
14
|
* CoraliteValues,
|
|
15
15
|
* InstanceContext} from '../types/index.js'
|
|
@@ -26,22 +26,25 @@
|
|
|
26
26
|
* @param {CoralitePluginInstance[]} [options.plugins=[]]
|
|
27
27
|
* @param {string} options.pages - The path to the directory containing pages that will be rendered using the provided templates.
|
|
28
28
|
* @param {string} [options.mode='production'] - Build mode: "development" or "production"
|
|
29
|
-
* @param {
|
|
29
|
+
* @param {Attribute[]} [options.ignoreByAttribute] - Elements to ignore with attribute name value pair
|
|
30
|
+
* @param {string[]} [options.skipRenderByAttribute] - Element attributes to parse but exclude from final render output
|
|
30
31
|
* @example
|
|
31
32
|
* const coralite = new Coralite({
|
|
32
33
|
* templates: './path/to/templates',
|
|
33
34
|
* pages: './path/to/pages',
|
|
34
35
|
* mode: 'development',
|
|
35
36
|
* plugins: [myPlugin],
|
|
36
|
-
* ignoreByAttribute: [{ name: 'data-ignore', value: 'true' }]
|
|
37
|
+
* ignoreByAttribute: [{ name: 'data-ignore', value: 'true' }],
|
|
38
|
+
* skipRenderByAttribute: ['data-skip-render']
|
|
37
39
|
* });
|
|
38
40
|
*/
|
|
39
|
-
export function Coralite({ templates, pages, plugins, ignoreByAttribute, mode }: {
|
|
41
|
+
export function Coralite({ templates, pages, plugins, ignoreByAttribute, skipRenderByAttribute, mode }: {
|
|
40
42
|
templates: string;
|
|
41
43
|
plugins?: CoralitePluginInstance[];
|
|
42
44
|
pages: string;
|
|
43
45
|
mode?: string;
|
|
44
|
-
ignoreByAttribute?:
|
|
46
|
+
ignoreByAttribute?: Attribute[];
|
|
47
|
+
skipRenderByAttribute?: string[];
|
|
45
48
|
}): void;
|
|
46
49
|
export class Coralite {
|
|
47
50
|
/**
|
|
@@ -55,7 +58,7 @@ export class Coralite {
|
|
|
55
58
|
* CoraliteCollectionItem,
|
|
56
59
|
* CoraliteDocumentRoot,
|
|
57
60
|
* CoraliteCollectionEventSet,
|
|
58
|
-
*
|
|
61
|
+
* Attribute,
|
|
59
62
|
* CoraliteDocumentResult,
|
|
60
63
|
* CoraliteValues,
|
|
61
64
|
* InstanceContext} from '../types/index.js'
|
|
@@ -72,28 +75,32 @@ export class Coralite {
|
|
|
72
75
|
* @param {CoralitePluginInstance[]} [options.plugins=[]]
|
|
73
76
|
* @param {string} options.pages - The path to the directory containing pages that will be rendered using the provided templates.
|
|
74
77
|
* @param {string} [options.mode='production'] - Build mode: "development" or "production"
|
|
75
|
-
* @param {
|
|
78
|
+
* @param {Attribute[]} [options.ignoreByAttribute] - Elements to ignore with attribute name value pair
|
|
79
|
+
* @param {string[]} [options.skipRenderByAttribute] - Element attributes to parse but exclude from final render output
|
|
76
80
|
* @example
|
|
77
81
|
* const coralite = new Coralite({
|
|
78
82
|
* templates: './path/to/templates',
|
|
79
83
|
* pages: './path/to/pages',
|
|
80
84
|
* mode: 'development',
|
|
81
85
|
* plugins: [myPlugin],
|
|
82
|
-
* ignoreByAttribute: [{ name: 'data-ignore', value: 'true' }]
|
|
86
|
+
* ignoreByAttribute: [{ name: 'data-ignore', value: 'true' }],
|
|
87
|
+
* skipRenderByAttribute: ['data-skip-render']
|
|
83
88
|
* });
|
|
84
89
|
*/
|
|
85
|
-
constructor({ templates, pages, plugins, ignoreByAttribute, mode }: {
|
|
90
|
+
constructor({ templates, pages, plugins, ignoreByAttribute, skipRenderByAttribute, mode }: {
|
|
86
91
|
templates: string;
|
|
87
92
|
plugins?: CoralitePluginInstance[];
|
|
88
93
|
pages: string;
|
|
89
94
|
mode?: string;
|
|
90
|
-
ignoreByAttribute?:
|
|
95
|
+
ignoreByAttribute?: Attribute[];
|
|
96
|
+
skipRenderByAttribute?: string[];
|
|
91
97
|
});
|
|
92
98
|
options: {
|
|
93
99
|
templates: string;
|
|
94
100
|
pages: string;
|
|
95
101
|
plugins: CoralitePluginInstance[];
|
|
96
|
-
ignoreByAttribute: import("../types/document.js").
|
|
102
|
+
ignoreByAttribute: import("../types/document.js").Attribute[];
|
|
103
|
+
skipRenderByAttribute: string[];
|
|
97
104
|
mode: string;
|
|
98
105
|
path: {
|
|
99
106
|
templates: string;
|
|
@@ -111,8 +118,10 @@ export class Coralite {
|
|
|
111
118
|
onTemplateSet: any[];
|
|
112
119
|
onTemplateUpdate: any[];
|
|
113
120
|
onTemplateDelete: any[];
|
|
121
|
+
onBeforePageRender: any[];
|
|
114
122
|
onAfterPageRender: any[];
|
|
115
|
-
|
|
123
|
+
onBeforeBuild: any[];
|
|
124
|
+
onAfterBuild: any[];
|
|
116
125
|
};
|
|
117
126
|
};
|
|
118
127
|
_scriptManager: ScriptManager;
|
|
@@ -132,7 +141,7 @@ export class Coralite {
|
|
|
132
141
|
templates: string;
|
|
133
142
|
pages: string;
|
|
134
143
|
};
|
|
135
|
-
excludeByAttribute: import("../types/document.js").
|
|
144
|
+
excludeByAttribute: import("../types/document.js").Attribute[];
|
|
136
145
|
templates: CoraliteCollection;
|
|
137
146
|
pages: CoraliteCollection;
|
|
138
147
|
};
|
|
@@ -558,25 +567,25 @@ export class Coralite {
|
|
|
558
567
|
*
|
|
559
568
|
* @internal
|
|
560
569
|
*
|
|
561
|
-
* @param {'onPageSet'|'onPageUpdate'|'onPageDelete'|'onTemplateSet'|'onTemplateUpdate'|'onTemplateDelete'|'onAfterPageRender'|'
|
|
570
|
+
* @param {'onPageSet'|'onPageUpdate'|'onPageDelete'|'onTemplateSet'|'onTemplateUpdate'|'onTemplateDelete'|'onBeforePageRender'|'onAfterPageRender'|'onBeforeBuild'|'onAfterBuild'} name - The name of the hook to trigger.
|
|
562
571
|
* @param {T} data - Data to pass to each callback function.
|
|
563
572
|
* @return {Promise<Array<T>>} A promise that resolves to an array of results from all callbacks.
|
|
564
573
|
*/
|
|
565
|
-
_triggerPluginHook<T extends unknown>(name: "onPageSet" | "onPageUpdate" | "onPageDelete" | "onTemplateSet" | "onTemplateUpdate" | "onTemplateDelete" | "onAfterPageRender" | "
|
|
574
|
+
_triggerPluginHook<T extends unknown>(name: "onPageSet" | "onPageUpdate" | "onPageDelete" | "onTemplateSet" | "onTemplateUpdate" | "onTemplateDelete" | "onBeforePageRender" | "onAfterPageRender" | "onBeforeBuild" | "onAfterBuild", data: T): Promise<Array<T>>;
|
|
566
575
|
/**
|
|
567
576
|
* Registers a callback function under the specified hook name.
|
|
568
577
|
*
|
|
569
578
|
* @internal
|
|
570
579
|
*
|
|
571
|
-
* @param {'onPageSet'|'onPageUpdate'|'onPageDelete'|'onTemplateSet'|'onTemplateUpdate'|'onTemplateDelete'|'onAfterPageRender'|'
|
|
580
|
+
* @param {'onPageSet'|'onPageUpdate'|'onPageDelete'|'onTemplateSet'|'onTemplateUpdate'|'onTemplateDelete'|'onBeforePageRender'|'onAfterPageRender'|'onBeforeBuild'|'onAfterBuild'} name - The name of the hook to register the callback with.
|
|
572
581
|
* @param {Function} callback - The callback function to be executed when the hook is triggered.
|
|
573
582
|
*/
|
|
574
|
-
_addPluginHook(name: "onPageSet" | "onPageUpdate" | "onPageDelete" | "onTemplateSet" | "onTemplateUpdate" | "onTemplateDelete" | "onAfterPageRender" | "
|
|
583
|
+
_addPluginHook(name: "onPageSet" | "onPageUpdate" | "onPageDelete" | "onTemplateSet" | "onTemplateUpdate" | "onTemplateDelete" | "onBeforePageRender" | "onAfterPageRender" | "onBeforeBuild" | "onAfterBuild", callback: Function): void;
|
|
575
584
|
}
|
|
576
585
|
export default Coralite;
|
|
577
586
|
export type BuildPageHandler = (result: CoraliteResult) => Promise<any> | any;
|
|
578
587
|
import type { CoralitePluginInstance } from '../types/plugin.js';
|
|
579
|
-
import type {
|
|
588
|
+
import type { Attribute } from '../types/index.js';
|
|
580
589
|
import type { CoraliteCollectionItem } from '../types/index.js';
|
|
581
590
|
import { ScriptManager } from './script-manager.js';
|
|
582
591
|
import { parseHTML } from './parse.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coralite.d.ts","sourceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;GAEG;AAEH
|
|
1
|
+
{"version":3,"file":"coralite.d.ts","sourceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;GAEG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wGAhBG;IAAwB,SAAS,EAAzB,MAAM;IAC6B,OAAO,GAA1C,sBAAsB,EAAE;IACR,KAAK,EAArB,MAAM;IACW,IAAI,GAArB,MAAM;IACgB,iBAAiB,GAAvC,SAAS,EAAE;IACQ,qBAAqB,GAAxC,MAAM,EAAE;CAChB,QA+KF;;IA/MD;;;;;;;;;;;;;;;;;OAiBG;IAEH;;OAEG;IAEH;;;;;;;;;;;;;;;;;;OAkBG;IACH,2FAhBG;QAAwB,SAAS,EAAzB,MAAM;QAC6B,OAAO,GAA1C,sBAAsB,EAAE;QACR,KAAK,EAArB,MAAM;QACW,IAAI,GAArB,MAAM;QACgB,iBAAiB,GAAvC,SAAS,EAAE;QACQ,qBAAqB,GAAxC,MAAM,EAAE;KAChB,EA+KF;IA1IC;;;;;;;;;;;MAQC;IAED,oDAAoD;IACpD,eADW,GAAG,CAAC,MAAM,EAAE,sBAAsB,EAAE,CAAC,CAClB;IAG9B;;;;;;;;;;;;;;MAcC;IAGD,8BAAyC;IAGzC;;;;;;;;8BAi2BS,oBAAoB,GAAG,eAAe,GAAG,eAAe,EAAE,YAC1D,oBAAoB,KAClB,MAAM;;;;;;;;;;;;MAl1BhB;IAyFH;;;OAGG;IACH,cAFa,OAAO,CAAC,IAAI,CAAC,CAyPzB;IAtPC,8BAwCE;IAaF;;OAEG;IACH;;MAA6C;I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;;;OAUG;IACH,mBAVsB,CAAC,wBAMZ,WAAW,GAAC,cAAc,GAAC,cAAc,GAAC,eAAe,GAAC,kBAAkB,GAAC,kBAAkB,GAAC,oBAAoB,GAAC,mBAAmB,GAAC,eAAe,GAAC,cAAc,QACvK,CAAC,GACA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAc5B;IAED;;;;;;;OAOG;IACH,qBAHW,WAAW,GAAC,cAAc,GAAC,cAAc,GAAC,eAAe,GAAC,kBAAkB,GAAC,kBAAkB,GAAC,oBAAoB,GAAC,mBAAmB,GAAC,eAAe,GAAC,cAAc,4BAajL;;;wCAriCU,cAAc,KACZ,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG;4CAztBY,oBAAoB;+BAFrC,mBAAmB;4CAAnB,mBAAmB;8BA9Bf,qBAAqB;0BAFmB,YAAY;4BAAZ,YAAY;6BADxC,WAAW;4BAAX,WAAW;8BACiB,YAAY;+BAAZ,YAAY;0CAgCxD,mBAAmB;qCAAnB,mBAAmB;0CAMN,gBAAgB;+BAxBxB,iBAAiB;oCAkBtB,mBAAmB;0CAAnB,mBAAmB;qCAAnB,mBAAmB;sCAAnB,mBAAmB;oCAAnB,mBAAmB"}
|
package/dist/lib/index.js
CHANGED
|
@@ -6136,12 +6136,14 @@ function cloneDocumentInstance(originalDocument) {
|
|
|
6136
6136
|
const newRoot = cloneNode(nodeMap, originalDocument.root, null);
|
|
6137
6137
|
const newCustomElements = originalDocument.customElements.map((el) => nodeMap.get(el));
|
|
6138
6138
|
const newTempElements = originalDocument.tempElements ? originalDocument.tempElements.map((el) => nodeMap.get(el)) : [];
|
|
6139
|
+
const newSkipRenderElements = originalDocument.skipRenderElements ? originalDocument.skipRenderElements.map((el) => nodeMap.get(el)) : [];
|
|
6139
6140
|
return {
|
|
6140
6141
|
...originalDocument,
|
|
6141
6142
|
values: { ...originalDocument.values },
|
|
6142
6143
|
root: newRoot,
|
|
6143
6144
|
customElements: newCustomElements,
|
|
6144
|
-
tempElements: newTempElements
|
|
6145
|
+
tempElements: newTempElements,
|
|
6146
|
+
skipRenderElements: newSkipRenderElements
|
|
6145
6147
|
};
|
|
6146
6148
|
}
|
|
6147
6149
|
function findAndExtractScript(code) {
|
|
@@ -8766,7 +8768,7 @@ function isValidCustomElementName(name, maxLength = 100) {
|
|
|
8766
8768
|
}
|
|
8767
8769
|
|
|
8768
8770
|
// lib/parse.js
|
|
8769
|
-
function parseHTML(string, ignoreByAttribute) {
|
|
8771
|
+
function parseHTML(string, ignoreByAttribute, skipRenderByAttribute) {
|
|
8770
8772
|
const root = createCoraliteDocument({
|
|
8771
8773
|
type: "root",
|
|
8772
8774
|
children: []
|
|
@@ -8774,6 +8776,7 @@ function parseHTML(string, ignoreByAttribute) {
|
|
|
8774
8776
|
const stack = [root];
|
|
8775
8777
|
const customElements = [];
|
|
8776
8778
|
const tempElements = [];
|
|
8779
|
+
const skipRenderElements = [];
|
|
8777
8780
|
const ignoreAttributeMap = getIgnoreAttributeMap(ignoreByAttribute);
|
|
8778
8781
|
const parser = new Parser3({
|
|
8779
8782
|
onprocessinginstruction(name, data2) {
|
|
@@ -8792,6 +8795,14 @@ function parseHTML(string, ignoreByAttribute) {
|
|
|
8792
8795
|
parent,
|
|
8793
8796
|
ignoreByAttribute: ignoreAttributeMap
|
|
8794
8797
|
});
|
|
8798
|
+
if (skipRenderByAttribute && skipRenderByAttribute.length > 0) {
|
|
8799
|
+
for (let i = 0; i < skipRenderByAttribute.length; i++) {
|
|
8800
|
+
if (Object.prototype.hasOwnProperty.call(attributes, skipRenderByAttribute[i])) {
|
|
8801
|
+
element.skipRender = true;
|
|
8802
|
+
break;
|
|
8803
|
+
}
|
|
8804
|
+
}
|
|
8805
|
+
}
|
|
8795
8806
|
if (element.slots) {
|
|
8796
8807
|
customElements.push(element);
|
|
8797
8808
|
}
|
|
@@ -8803,8 +8814,12 @@ function parseHTML(string, ignoreByAttribute) {
|
|
|
8803
8814
|
},
|
|
8804
8815
|
onclosetag() {
|
|
8805
8816
|
const element = stack[stack.length - 1];
|
|
8806
|
-
if (element.type === "tag"
|
|
8807
|
-
|
|
8817
|
+
if (element.type === "tag") {
|
|
8818
|
+
if (element.remove) {
|
|
8819
|
+
tempElements.push(element.parent.children[element.parent.children.length - 1]);
|
|
8820
|
+
} else if (element.skipRender) {
|
|
8821
|
+
skipRenderElements.push(element.parent.children[element.parent.children.length - 1]);
|
|
8822
|
+
}
|
|
8808
8823
|
}
|
|
8809
8824
|
stack.pop();
|
|
8810
8825
|
},
|
|
@@ -8823,7 +8838,8 @@ function parseHTML(string, ignoreByAttribute) {
|
|
|
8823
8838
|
return {
|
|
8824
8839
|
root,
|
|
8825
8840
|
customElements,
|
|
8826
|
-
tempElements
|
|
8841
|
+
tempElements,
|
|
8842
|
+
skipRenderElements
|
|
8827
8843
|
};
|
|
8828
8844
|
}
|
|
8829
8845
|
function sortSlottedChildren(elements) {
|
|
@@ -8843,7 +8859,7 @@ function sortSlottedChildren(elements) {
|
|
|
8843
8859
|
}
|
|
8844
8860
|
}
|
|
8845
8861
|
}
|
|
8846
|
-
function parseModule(string, { ignoreByAttribute }) {
|
|
8862
|
+
function parseModule(string, { ignoreByAttribute, skipRenderByAttribute }) {
|
|
8847
8863
|
const root = createCoraliteDocument({
|
|
8848
8864
|
type: "root",
|
|
8849
8865
|
children: []
|
|
@@ -8872,6 +8888,14 @@ function parseModule(string, { ignoreByAttribute }) {
|
|
|
8872
8888
|
parent,
|
|
8873
8889
|
ignoreByAttribute: ignoreAttributeMap
|
|
8874
8890
|
});
|
|
8891
|
+
if (skipRenderByAttribute && skipRenderByAttribute.length > 0) {
|
|
8892
|
+
for (let i = 0; i < skipRenderByAttribute.length; i++) {
|
|
8893
|
+
if (Object.prototype.hasOwnProperty.call(attributes, skipRenderByAttribute[i])) {
|
|
8894
|
+
element.skipRender = true;
|
|
8895
|
+
break;
|
|
8896
|
+
}
|
|
8897
|
+
}
|
|
8898
|
+
}
|
|
8875
8899
|
if (element.slots) {
|
|
8876
8900
|
customElements.push(element);
|
|
8877
8901
|
}
|
|
@@ -9218,10 +9242,7 @@ function ScriptManager() {
|
|
|
9218
9242
|
this.scriptModules = [];
|
|
9219
9243
|
}
|
|
9220
9244
|
ScriptManager.prototype.use = async function(plugin) {
|
|
9221
|
-
if (plugin && typeof plugin.setup === "function") {
|
|
9222
|
-
plugin.setup(this);
|
|
9223
|
-
}
|
|
9224
|
-
if (plugin && typeof plugin !== "function" && (plugin.helpers || plugin.imports)) {
|
|
9245
|
+
if (plugin && typeof plugin !== "function" && (plugin.helpers || plugin.imports || typeof plugin.setup === "function")) {
|
|
9225
9246
|
this.scriptModules.push(plugin);
|
|
9226
9247
|
}
|
|
9227
9248
|
this.plugins.push(plugin);
|
|
@@ -9266,11 +9287,11 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
9266
9287
|
const entryCodeParts = [];
|
|
9267
9288
|
const moduleNamespace = "coralite-script-module:";
|
|
9268
9289
|
for (let i = 0; i < this.scriptModules.length; i++) {
|
|
9269
|
-
entryCodeParts.push(`import
|
|
9290
|
+
entryCodeParts.push(`import { helpers as helpers_${i}, runSetup as runSetup_${i} } from "${moduleNamespace}${i}";
|
|
9270
9291
|
`);
|
|
9271
9292
|
}
|
|
9272
9293
|
const helperParts = [
|
|
9273
|
-
...this.scriptModules.map((_, i) => `...
|
|
9294
|
+
...this.scriptModules.map((_, i) => `...helpers_${i}`),
|
|
9274
9295
|
this.getHelpersContent()
|
|
9275
9296
|
].filter(Boolean).join(",\n");
|
|
9276
9297
|
entryCodeParts.push(`const coraliteTemplateScriptHelpers = {
|
|
@@ -9284,6 +9305,23 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
9284
9305
|
}
|
|
9285
9306
|
return helpers
|
|
9286
9307
|
}
|
|
9308
|
+
`);
|
|
9309
|
+
entryCodeParts.push(`const getSetups = async (context) => {
|
|
9310
|
+
const values = {};
|
|
9311
|
+
const results = await Promise.all([
|
|
9312
|
+
${this.scriptModules.map((_, i) => `runSetup_${i}(context)`).join(",\n ")}
|
|
9313
|
+
]);
|
|
9314
|
+
for (const res of results) {
|
|
9315
|
+
if (res && typeof res === 'object') {
|
|
9316
|
+
Object.assign(values, res);
|
|
9317
|
+
}
|
|
9318
|
+
}
|
|
9319
|
+
return values;
|
|
9320
|
+
}
|
|
9321
|
+
`);
|
|
9322
|
+
entryCodeParts.push(`const globalContext = {};
|
|
9323
|
+
`);
|
|
9324
|
+
entryCodeParts.push(`const globalSetupValuesPromise = getSetups(globalContext);
|
|
9287
9325
|
`);
|
|
9288
9326
|
const instanceValues = Object.entries(instances);
|
|
9289
9327
|
const processedTemplates = {};
|
|
@@ -9332,10 +9370,12 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
9332
9370
|
};
|
|
9333
9371
|
entryCodeParts.push(";(async() => {\n");
|
|
9334
9372
|
entryCodeParts.push("const context = " + serialize(context) + ";\n");
|
|
9335
|
-
entryCodeParts.push("const helpers = getHelpers(context);\n");
|
|
9336
9373
|
entryCodeParts.push(`const imports = coraliteComponentImports["${context.templateId}"] || {};
|
|
9337
9374
|
`);
|
|
9338
9375
|
entryCodeParts.push("context.imports = imports;\n");
|
|
9376
|
+
entryCodeParts.push("const setupValues = await globalSetupValuesPromise;\n");
|
|
9377
|
+
entryCodeParts.push("context.values = { ...context.values, ...setupValues };\n");
|
|
9378
|
+
entryCodeParts.push("const helpers = getHelpers(context);\n");
|
|
9339
9379
|
entryCodeParts.push("context.helpers = helpers;\n");
|
|
9340
9380
|
entryCodeParts.push(`
|
|
9341
9381
|
// Instance: ${instanceId}
|
|
@@ -9355,7 +9395,8 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
9355
9395
|
treeShaking: true,
|
|
9356
9396
|
sourcemap: mode === "production" ? false : "inline",
|
|
9357
9397
|
minify: mode === "production",
|
|
9358
|
-
format: "
|
|
9398
|
+
format: "esm",
|
|
9399
|
+
external: ["http://*", "https://*"],
|
|
9359
9400
|
sourceRoot: pathToFileURL(process.cwd()).href,
|
|
9360
9401
|
plugins: [
|
|
9361
9402
|
{
|
|
@@ -9487,7 +9528,19 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
9487
9528
|
contents += importsObjContent + "\n";
|
|
9488
9529
|
const configContent = module.config ? `const pluginConfig = ${JSON.stringify(module.config)};` : "const pluginConfig = {};";
|
|
9489
9530
|
contents += configContent + "\n";
|
|
9490
|
-
|
|
9531
|
+
const setupFn = module.setup ? normalizeFunction(module.setup) : "null";
|
|
9532
|
+
contents += `export const runSetup = async (context) => {
|
|
9533
|
+
const setup = ${setupFn};
|
|
9534
|
+
if (!setup) return {};
|
|
9535
|
+
const ctx = {
|
|
9536
|
+
imports: pluginImports,
|
|
9537
|
+
config: pluginConfig,
|
|
9538
|
+
...context
|
|
9539
|
+
};
|
|
9540
|
+
return await setup(ctx);
|
|
9541
|
+
};
|
|
9542
|
+
`;
|
|
9543
|
+
contents += "export const helpers = {\n";
|
|
9491
9544
|
if (module.helpers) {
|
|
9492
9545
|
for (const key in module.helpers) {
|
|
9493
9546
|
if (Object.hasOwn(module.helpers, key)) {
|
|
@@ -9503,7 +9556,6 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
9503
9556
|
}
|
|
9504
9557
|
}
|
|
9505
9558
|
contents += "};\n";
|
|
9506
|
-
contents += "export default helpers;";
|
|
9507
9559
|
return {
|
|
9508
9560
|
contents,
|
|
9509
9561
|
loader: "js",
|
|
@@ -9702,7 +9754,7 @@ var defineComponent = createPlugin({
|
|
|
9702
9754
|
// plugins/refs.js
|
|
9703
9755
|
var refsPlugin = createPlugin({
|
|
9704
9756
|
name: "refs",
|
|
9705
|
-
|
|
9757
|
+
client: {
|
|
9706
9758
|
helpers: {
|
|
9707
9759
|
/**
|
|
9708
9760
|
* Creates a ref resolver function that maps IDs to DOM elements.
|
|
@@ -9843,6 +9895,7 @@ function Coralite({
|
|
|
9843
9895
|
pages,
|
|
9844
9896
|
plugins,
|
|
9845
9897
|
ignoreByAttribute,
|
|
9898
|
+
skipRenderByAttribute,
|
|
9846
9899
|
mode = "production"
|
|
9847
9900
|
}) {
|
|
9848
9901
|
if (!templates && typeof templates !== "string") {
|
|
@@ -9863,6 +9916,7 @@ function Coralite({
|
|
|
9863
9916
|
pages,
|
|
9864
9917
|
plugins,
|
|
9865
9918
|
ignoreByAttribute,
|
|
9919
|
+
skipRenderByAttribute,
|
|
9866
9920
|
mode,
|
|
9867
9921
|
path: path2
|
|
9868
9922
|
};
|
|
@@ -9876,8 +9930,10 @@ function Coralite({
|
|
|
9876
9930
|
onTemplateSet: [],
|
|
9877
9931
|
onTemplateUpdate: [],
|
|
9878
9932
|
onTemplateDelete: [],
|
|
9933
|
+
onBeforePageRender: [],
|
|
9879
9934
|
onAfterPageRender: [],
|
|
9880
|
-
|
|
9935
|
+
onBeforeBuild: [],
|
|
9936
|
+
onAfterBuild: []
|
|
9881
9937
|
}
|
|
9882
9938
|
};
|
|
9883
9939
|
this._scriptManager = new ScriptManager();
|
|
@@ -9933,14 +9989,20 @@ function Coralite({
|
|
|
9933
9989
|
if (plugin.onTemplateUpdate) {
|
|
9934
9990
|
this._addPluginHook("onTemplateUpdate", plugin.onTemplateUpdate);
|
|
9935
9991
|
}
|
|
9992
|
+
if (plugin.onBeforePageRender) {
|
|
9993
|
+
this._addPluginHook("onBeforePageRender", plugin.onBeforePageRender);
|
|
9994
|
+
}
|
|
9936
9995
|
if (plugin.onAfterPageRender) {
|
|
9937
9996
|
this._addPluginHook("onAfterPageRender", plugin.onAfterPageRender);
|
|
9938
9997
|
}
|
|
9939
|
-
if (plugin.
|
|
9940
|
-
this._addPluginHook("
|
|
9998
|
+
if (plugin.onBeforeBuild) {
|
|
9999
|
+
this._addPluginHook("onBeforeBuild", plugin.onBeforeBuild);
|
|
10000
|
+
}
|
|
10001
|
+
if (plugin.onAfterBuild) {
|
|
10002
|
+
this._addPluginHook("onAfterBuild", plugin.onAfterBuild);
|
|
9941
10003
|
}
|
|
9942
|
-
if (plugin.
|
|
9943
|
-
this._scriptManager.use(plugin.
|
|
10004
|
+
if (plugin.client) {
|
|
10005
|
+
this._scriptManager.use(plugin.client);
|
|
9944
10006
|
}
|
|
9945
10007
|
}
|
|
9946
10008
|
source.contextModules.defineComponent = source.context.plugins.defineComponent;
|
|
@@ -10003,7 +10065,7 @@ Coralite.prototype.initialise = async function() {
|
|
|
10003
10065
|
this._pageCustomElements = pageCustomElements;
|
|
10004
10066
|
this._childCustomElements = childCustomElements;
|
|
10005
10067
|
const onFileSet = async (data2) => {
|
|
10006
|
-
const elements = parseHTML(data2.content, this.options.ignoreByAttribute);
|
|
10068
|
+
const elements = parseHTML(data2.content, this.options.ignoreByAttribute, this.options.skipRenderByAttribute);
|
|
10007
10069
|
for (let i = 0; i < elements.customElements.length; i++) {
|
|
10008
10070
|
const customElement = elements.customElements[i];
|
|
10009
10071
|
const name = customElement.name;
|
|
@@ -10056,7 +10118,8 @@ Coralite.prototype.initialise = async function() {
|
|
|
10056
10118
|
path: data2.path,
|
|
10057
10119
|
root: elements.root,
|
|
10058
10120
|
customElements: elements.customElements,
|
|
10059
|
-
tempElements: elements.tempElements
|
|
10121
|
+
tempElements: elements.tempElements,
|
|
10122
|
+
skipRenderElements: elements.skipRenderElements
|
|
10060
10123
|
}
|
|
10061
10124
|
};
|
|
10062
10125
|
};
|
|
@@ -10183,6 +10246,11 @@ Coralite.prototype._generatePages = async function* (path2, values = {}) {
|
|
|
10183
10246
|
Object.assign(document2.values, values);
|
|
10184
10247
|
const renderContext = this._createRenderContext(buildId);
|
|
10185
10248
|
renderContext.mode = this.options.mode;
|
|
10249
|
+
await this._triggerPluginHook("onBeforePageRender", {
|
|
10250
|
+
document: document2,
|
|
10251
|
+
values,
|
|
10252
|
+
renderContext
|
|
10253
|
+
});
|
|
10186
10254
|
if (document2.tempElements) {
|
|
10187
10255
|
for (const element of document2.tempElements) {
|
|
10188
10256
|
if (element.parent && element.parent.children) {
|
|
@@ -10305,6 +10373,15 @@ ${css}
|
|
|
10305
10373
|
}));
|
|
10306
10374
|
bodyElement.children.push(scriptElement);
|
|
10307
10375
|
}
|
|
10376
|
+
if (document2.skipRenderElements) {
|
|
10377
|
+
for (const element of document2.skipRenderElements) {
|
|
10378
|
+
if (element.parent && element.parent.children) {
|
|
10379
|
+
element.parent.children = element.parent.children.filter(
|
|
10380
|
+
(child) => child !== element
|
|
10381
|
+
);
|
|
10382
|
+
}
|
|
10383
|
+
}
|
|
10384
|
+
}
|
|
10308
10385
|
let rawHTML = "";
|
|
10309
10386
|
rawHTML = this.transform(document2.root);
|
|
10310
10387
|
yield {
|
|
@@ -10331,6 +10408,13 @@ Coralite.prototype.build = async function(...args) {
|
|
|
10331
10408
|
options = args[1];
|
|
10332
10409
|
callback = args[2];
|
|
10333
10410
|
}
|
|
10411
|
+
if (!options) {
|
|
10412
|
+
options = {};
|
|
10413
|
+
}
|
|
10414
|
+
await this._triggerPluginHook("onBeforeBuild", {
|
|
10415
|
+
path: path2,
|
|
10416
|
+
options
|
|
10417
|
+
});
|
|
10334
10418
|
const signal = options?.signal;
|
|
10335
10419
|
const maxConcurrent = options?.maxConcurrent || availableParallelism();
|
|
10336
10420
|
const variables = options?.variables;
|
|
@@ -10400,7 +10484,7 @@ Coralite.prototype.build = async function(...args) {
|
|
|
10400
10484
|
throw finalError;
|
|
10401
10485
|
} finally {
|
|
10402
10486
|
const duration = performance.now() - startTime;
|
|
10403
|
-
await this._triggerPluginHook("
|
|
10487
|
+
await this._triggerPluginHook("onAfterBuild", {
|
|
10404
10488
|
results,
|
|
10405
10489
|
error: buildError,
|
|
10406
10490
|
duration
|
|
@@ -11041,9 +11125,11 @@ function createPlugin({
|
|
|
11041
11125
|
onTemplateSet,
|
|
11042
11126
|
onTemplateUpdate,
|
|
11043
11127
|
onTemplateDelete,
|
|
11128
|
+
onBeforePageRender,
|
|
11044
11129
|
onAfterPageRender,
|
|
11045
|
-
|
|
11046
|
-
|
|
11130
|
+
onBeforeBuild,
|
|
11131
|
+
onAfterBuild,
|
|
11132
|
+
client,
|
|
11047
11133
|
server
|
|
11048
11134
|
}) {
|
|
11049
11135
|
validateNonEmptyString(name, "name");
|
|
@@ -11054,32 +11140,34 @@ function createPlugin({
|
|
|
11054
11140
|
validateOptionalFunction(onTemplateSet, "onTemplateSet");
|
|
11055
11141
|
validateOptionalFunction(onTemplateUpdate, "onTemplateUpdate");
|
|
11056
11142
|
validateOptionalFunction(onTemplateDelete, "onTemplateDelete");
|
|
11143
|
+
validateOptionalFunction(onBeforePageRender, "onBeforePageRender");
|
|
11057
11144
|
validateOptionalFunction(onAfterPageRender, "onAfterPageRender");
|
|
11058
|
-
validateOptionalFunction(
|
|
11145
|
+
validateOptionalFunction(onBeforeBuild, "onBeforeBuild");
|
|
11146
|
+
validateOptionalFunction(onAfterBuild, "onAfterBuild");
|
|
11059
11147
|
validateOptionalFunction(server, "server");
|
|
11060
11148
|
validateStringArray(templates, "templates");
|
|
11061
|
-
if (
|
|
11062
|
-
if (typeof
|
|
11149
|
+
if (client != null) {
|
|
11150
|
+
if (typeof client !== "object") {
|
|
11063
11151
|
throw new Error(
|
|
11064
|
-
`Coralite plugin validation failed: "
|
|
11152
|
+
`Coralite plugin validation failed: "client" must be an object, received ${typeof client}`
|
|
11065
11153
|
);
|
|
11066
11154
|
}
|
|
11067
|
-
if (
|
|
11155
|
+
if (client.setup != null && typeof client.setup !== "function") {
|
|
11068
11156
|
throw new Error(
|
|
11069
|
-
`Coralite plugin validation failed: "
|
|
11157
|
+
`Coralite plugin validation failed: "client.setup" must be a function, received ${typeof client.setup}`
|
|
11070
11158
|
);
|
|
11071
11159
|
}
|
|
11072
|
-
if (
|
|
11160
|
+
if (client.helpers != null && typeof client.helpers !== "object") {
|
|
11073
11161
|
throw new Error(
|
|
11074
|
-
`Coralite plugin validation failed: "
|
|
11162
|
+
`Coralite plugin validation failed: "client.helpers" must be an object, received ${typeof client.helpers}`
|
|
11075
11163
|
);
|
|
11076
11164
|
}
|
|
11077
|
-
if (
|
|
11078
|
-
validateImportArray(
|
|
11165
|
+
if (client.imports != null) {
|
|
11166
|
+
validateImportArray(client.imports, "client.imports");
|
|
11079
11167
|
}
|
|
11080
|
-
if (
|
|
11168
|
+
if (client.config != null && typeof client.config !== "object") {
|
|
11081
11169
|
throw new Error(
|
|
11082
|
-
`Coralite plugin validation failed: "
|
|
11170
|
+
`Coralite plugin validation failed: "client.config" must be an object, received ${typeof client.config}`
|
|
11083
11171
|
);
|
|
11084
11172
|
}
|
|
11085
11173
|
}
|
|
@@ -11106,9 +11194,11 @@ function createPlugin({
|
|
|
11106
11194
|
onTemplateSet,
|
|
11107
11195
|
onTemplateUpdate,
|
|
11108
11196
|
onTemplateDelete,
|
|
11197
|
+
onBeforePageRender,
|
|
11109
11198
|
onAfterPageRender,
|
|
11110
|
-
|
|
11111
|
-
|
|
11199
|
+
onBeforeBuild,
|
|
11200
|
+
onAfterBuild,
|
|
11201
|
+
client,
|
|
11112
11202
|
server
|
|
11113
11203
|
};
|
|
11114
11204
|
}
|