coralite 0.31.7 → 0.32.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/dist/lib/coralite.d.ts +1 -1
- package/dist/lib/coralite.d.ts.map +1 -1
- package/dist/lib/index.js +196 -79
- package/dist/lib/index.js.map +3 -3
- package/dist/lib/script-manager.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +6 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/metadata.d.ts.map +1 -1
- package/dist/plugins/metadata.js +61 -42
- package/dist/plugins/testing.d.ts +4 -0
- package/dist/plugins/testing.d.ts.map +1 -0
- package/dist/plugins/testing.js +29 -0
- package/dist/types/core.d.ts +5 -5
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/plugin.d.ts +1 -1
- package/dist/types/plugin.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/lib/coralite.d.ts
CHANGED
|
@@ -554,7 +554,7 @@ export class Coralite {
|
|
|
554
554
|
/**
|
|
555
555
|
* @template {Object} T
|
|
556
556
|
*
|
|
557
|
-
* Executes all plugin callbacks registered under the specified hook name.
|
|
557
|
+
* Executes all plugin callbacks registered under the specified hook name sequentially.
|
|
558
558
|
*
|
|
559
559
|
* @internal
|
|
560
560
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coralite.d.ts","sourceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,2IAXW,cAAc,
|
|
1
|
+
{"version":3,"file":"coralite.d.ts","sourceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,2IAXW,cAAc,QAsMxB;;IA9ND;;;;;;;;;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OAAO,CAAC,GAAG,CAAC,GAAG,GAAG;oCA5tCN,mBAAmB;4CAAnB,mBAAmB;8BA/Bd,qBAAqB;6BAHT,WAAW;4BAAX,WAAW;+BACiB,YAAY;2CAiCzD,mBAAmB;qCAAnB,mBAAmB;0CAIL,gBAAgB;+BAvBxB,iBAAiB;oCAmBvB,mBAAmB;uCAAnB,mBAAmB;0CAAnB,mBAAmB;qCAAnB,mBAAmB;oCAAnB,mBAAmB"}
|
package/dist/lib/index.js
CHANGED
|
@@ -6808,6 +6808,23 @@ function findAndExtractScript(code) {
|
|
|
6808
6808
|
});
|
|
6809
6809
|
return result;
|
|
6810
6810
|
}
|
|
6811
|
+
function extractGlobals(code) {
|
|
6812
|
+
try {
|
|
6813
|
+
const ast = parse3(code, {
|
|
6814
|
+
ecmaVersion: "latest",
|
|
6815
|
+
sourceType: "module"
|
|
6816
|
+
});
|
|
6817
|
+
const globals = /* @__PURE__ */ new Set();
|
|
6818
|
+
simple(ast, {
|
|
6819
|
+
Identifier(node) {
|
|
6820
|
+
globals.add(node.name);
|
|
6821
|
+
}
|
|
6822
|
+
});
|
|
6823
|
+
return [...globals];
|
|
6824
|
+
} catch (err) {
|
|
6825
|
+
return [];
|
|
6826
|
+
}
|
|
6827
|
+
}
|
|
6811
6828
|
|
|
6812
6829
|
// lib/html.js
|
|
6813
6830
|
import { dirname, extname, join } from "node:path";
|
|
@@ -9484,9 +9501,9 @@ ScriptManager.prototype.use = async function(plugin) {
|
|
|
9484
9501
|
};
|
|
9485
9502
|
ScriptManager.prototype.getHelpersContent = function() {
|
|
9486
9503
|
let helpers = "";
|
|
9487
|
-
for (const key of Object.
|
|
9504
|
+
for (const [key, value] of Object.entries(this.helpers)) {
|
|
9488
9505
|
helpers += `"${key}": async (globalContext) => {
|
|
9489
|
-
const phase1 = ${
|
|
9506
|
+
const phase1 = ${value};
|
|
9490
9507
|
const phase2 = await phase1(globalContext);
|
|
9491
9508
|
return (localContext) => phase2(localContext);
|
|
9492
9509
|
},`;
|
|
@@ -9499,9 +9516,9 @@ ScriptManager.prototype.addHelper = async function(name, method) {
|
|
|
9499
9516
|
};
|
|
9500
9517
|
ScriptManager.prototype.getHelpers = function() {
|
|
9501
9518
|
let helpers = "";
|
|
9502
|
-
for (const key of Object.
|
|
9519
|
+
for (const [key, value] of Object.entries(this.helpers)) {
|
|
9503
9520
|
helpers += `"${key}": async (globalContext) => {
|
|
9504
|
-
const phase1 = ${
|
|
9521
|
+
const phase1 = ${value};
|
|
9505
9522
|
const phase2 = await phase1(globalContext);
|
|
9506
9523
|
return (localContext) => phase2(localContext);
|
|
9507
9524
|
},`;
|
|
@@ -9665,7 +9682,7 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
9665
9682
|
}
|
|
9666
9683
|
} else if (fnData.script && fnData.script.components && fnData.script.components.length > 0) {
|
|
9667
9684
|
processedComponent[componentId] = true;
|
|
9668
|
-
} else if (
|
|
9685
|
+
} else if (hasObjectKeys(fnData.defaultValues)) {
|
|
9669
9686
|
processedComponent[componentId] = true;
|
|
9670
9687
|
}
|
|
9671
9688
|
}
|
|
@@ -9727,7 +9744,7 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
9727
9744
|
}
|
|
9728
9745
|
entryCodeParts.push("};\n");
|
|
9729
9746
|
const domSerializerPath = fileURLToPath(import.meta.resolve("dom-serializer"));
|
|
9730
|
-
entryCodeParts.push(`import render from
|
|
9747
|
+
entryCodeParts.push(`import render from ${JSON.stringify(domSerializerPath)};
|
|
9731
9748
|
`);
|
|
9732
9749
|
entryCodeParts.push("\nexport { getHelpers, getSetups, render };\n");
|
|
9733
9750
|
const entryPoints = {
|
|
@@ -9870,7 +9887,7 @@ export default {
|
|
|
9870
9887
|
if (args.path.startsWith("coralite-component:") || args.path.startsWith("coralite-component-imports:") || args.path.startsWith("coralite-script-module:") || args.path === "chunk-shared" || args.path === "coralite-shared") {
|
|
9871
9888
|
return null;
|
|
9872
9889
|
}
|
|
9873
|
-
if (Object.
|
|
9890
|
+
if (Object.hasOwn(entryPoints, args.path)) {
|
|
9874
9891
|
return null;
|
|
9875
9892
|
}
|
|
9876
9893
|
if (args.path.startsWith("http")) {
|
|
@@ -9988,7 +10005,8 @@ export default {
|
|
|
9988
10005
|
}
|
|
9989
10006
|
}
|
|
9990
10007
|
}
|
|
9991
|
-
const
|
|
10008
|
+
const importEntries = Object.entries(importMap);
|
|
10009
|
+
const importsObjContent = importEntries.length > 0 ? `const componentImports = { ${importEntries.map(([key, value]) => `"${key}": ${value}`).join(", ")} };` : "const componentImports = {};";
|
|
9992
10010
|
contents += importsObjContent + "\n";
|
|
9993
10011
|
contents += "export default componentImports;";
|
|
9994
10012
|
return {
|
|
@@ -10040,7 +10058,8 @@ export default {
|
|
|
10040
10058
|
}
|
|
10041
10059
|
}
|
|
10042
10060
|
}
|
|
10043
|
-
const
|
|
10061
|
+
const importEntries = Object.entries(importMap);
|
|
10062
|
+
const importsObjContent = importEntries.length > 0 ? `const pluginImports = { ${importEntries.map(([key, value]) => `"${key}": ${value}`).join(", ")} };` : "const pluginImports = {};";
|
|
10044
10063
|
contents += importsObjContent + "\n";
|
|
10045
10064
|
const configContent = module.config ? `const pluginConfig = ${JSON.stringify(module.config)};` : "const pluginConfig = {};";
|
|
10046
10065
|
contents += configContent + "\n";
|
|
@@ -10355,58 +10374,77 @@ var refsPlugin = definePlugin({
|
|
|
10355
10374
|
});
|
|
10356
10375
|
|
|
10357
10376
|
// plugins/metadata.js
|
|
10358
|
-
|
|
10359
|
-
|
|
10360
|
-
|
|
10361
|
-
|
|
10362
|
-
|
|
10363
|
-
|
|
10364
|
-
|
|
10365
|
-
|
|
10366
|
-
|
|
10367
|
-
|
|
10368
|
-
|
|
10369
|
-
|
|
10370
|
-
|
|
10371
|
-
if (element.
|
|
10372
|
-
|
|
10373
|
-
|
|
10374
|
-
|
|
10375
|
-
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
|
|
10380
|
-
|
|
10381
|
-
|
|
10382
|
-
|
|
10383
|
-
|
|
10384
|
-
|
|
10385
|
-
|
|
10386
|
-
|
|
10387
|
-
|
|
10388
|
-
|
|
10389
|
-
|
|
10390
|
-
|
|
10391
|
-
|
|
10392
|
-
|
|
10393
|
-
|
|
10394
|
-
|
|
10395
|
-
|
|
10396
|
-
|
|
10377
|
+
async function extractMetadata(context) {
|
|
10378
|
+
const { elements, values, data: data2, coraliteContext } = context;
|
|
10379
|
+
values.page_lang = "";
|
|
10380
|
+
for (let i = 0; i < elements.root.children.length; i++) {
|
|
10381
|
+
const rootNode = elements.root.children[i];
|
|
10382
|
+
if (rootNode.type === "tag" && rootNode.name === "html") {
|
|
10383
|
+
values.page_lang = rootNode.attribs.lang;
|
|
10384
|
+
for (let i2 = 0; i2 < rootNode.children.length; i2++) {
|
|
10385
|
+
const node = rootNode.children[i2];
|
|
10386
|
+
if (node.type === "tag" && node.name === "head") {
|
|
10387
|
+
for (let i3 = 0; i3 < node.children.length; i3++) {
|
|
10388
|
+
const element = node.children[i3];
|
|
10389
|
+
if (element.type === "tag") {
|
|
10390
|
+
if (element.name === "meta" && element.attribs.name && element.attribs.content) {
|
|
10391
|
+
const metaName = "meta_" + element.attribs.name;
|
|
10392
|
+
values[metaName] = element.attribs.content;
|
|
10393
|
+
} else if (element.slots) {
|
|
10394
|
+
const componentElement = await coraliteContext.createComponentElement({
|
|
10395
|
+
id: element.name,
|
|
10396
|
+
values,
|
|
10397
|
+
element,
|
|
10398
|
+
component: (
|
|
10399
|
+
/** @type {any} */
|
|
10400
|
+
{
|
|
10401
|
+
...elements,
|
|
10402
|
+
path: data2.path
|
|
10403
|
+
}
|
|
10404
|
+
),
|
|
10405
|
+
contextId: data2.path.pathname + i3 + element.name,
|
|
10406
|
+
index: i3
|
|
10407
|
+
});
|
|
10408
|
+
if (componentElement) {
|
|
10409
|
+
for (let i4 = 0; i4 < componentElement.children.length; i4++) {
|
|
10410
|
+
const element2 = componentElement.children[i4];
|
|
10411
|
+
if (element2.type === "tag" && element2.name === "meta" && element2.attribs.name && element2.attribs.content) {
|
|
10412
|
+
const metaName = "meta_" + element2.attribs.name;
|
|
10413
|
+
values[metaName] = element2.attribs.content;
|
|
10414
|
+
} else if (element2.type === "tag" && element2.name === "title" && element2.children.length && element2.children[0].type === "text") {
|
|
10415
|
+
values.page_title = element2.children[0].data;
|
|
10397
10416
|
}
|
|
10398
10417
|
}
|
|
10399
|
-
} else if (element.name === "title" && element.children.length && element.children[0].type === "text") {
|
|
10400
|
-
values.meta_pageTitle = element.children[0].data;
|
|
10401
10418
|
}
|
|
10419
|
+
} else if (element.name === "title" && element.children.length && element.children[0].type === "text") {
|
|
10420
|
+
values.page_title = element.children[0].data;
|
|
10402
10421
|
}
|
|
10403
10422
|
}
|
|
10404
|
-
return;
|
|
10405
10423
|
}
|
|
10424
|
+
return;
|
|
10406
10425
|
}
|
|
10407
10426
|
}
|
|
10408
10427
|
}
|
|
10409
10428
|
}
|
|
10429
|
+
}
|
|
10430
|
+
var metadataPlugin = definePlugin({
|
|
10431
|
+
name: "metadata",
|
|
10432
|
+
async onPageSet({ elements, values, data: data2 }) {
|
|
10433
|
+
await extractMetadata({
|
|
10434
|
+
elements,
|
|
10435
|
+
values,
|
|
10436
|
+
data: data2,
|
|
10437
|
+
coraliteContext: this
|
|
10438
|
+
});
|
|
10439
|
+
},
|
|
10440
|
+
async onPageUpdate({ elements, newValue }) {
|
|
10441
|
+
await extractMetadata({
|
|
10442
|
+
elements,
|
|
10443
|
+
values: newValue.result.values,
|
|
10444
|
+
data: newValue,
|
|
10445
|
+
coraliteContext: this
|
|
10446
|
+
});
|
|
10447
|
+
}
|
|
10410
10448
|
});
|
|
10411
10449
|
|
|
10412
10450
|
// lib/plugin.js
|
|
@@ -10626,6 +10664,33 @@ var staticAssetPlugin = (assets = []) => {
|
|
|
10626
10664
|
});
|
|
10627
10665
|
};
|
|
10628
10666
|
|
|
10667
|
+
// plugins/testing.js
|
|
10668
|
+
function traverseAndAddTestId(children) {
|
|
10669
|
+
if (!children || !Array.isArray(children)) return;
|
|
10670
|
+
for (let i = 0; i < children.length; i++) {
|
|
10671
|
+
const node = children[i];
|
|
10672
|
+
if (node.type === "tag" && node.attribs && node.attribs.ref) {
|
|
10673
|
+
node.attribs["data-testid"] = node.attribs.ref;
|
|
10674
|
+
}
|
|
10675
|
+
if (node.children && node.children.length > 0) {
|
|
10676
|
+
traverseAndAddTestId(node.children);
|
|
10677
|
+
}
|
|
10678
|
+
}
|
|
10679
|
+
}
|
|
10680
|
+
var testingPlugin = definePlugin({
|
|
10681
|
+
name: "testing",
|
|
10682
|
+
onComponentSet: (component) => {
|
|
10683
|
+
if (component && component.template && component.template.children) {
|
|
10684
|
+
traverseAndAddTestId(component.template.children);
|
|
10685
|
+
}
|
|
10686
|
+
},
|
|
10687
|
+
onPageSet: ({ elements }) => {
|
|
10688
|
+
if (elements && elements.root && elements.root.children) {
|
|
10689
|
+
traverseAndAddTestId(elements.root.children);
|
|
10690
|
+
}
|
|
10691
|
+
}
|
|
10692
|
+
});
|
|
10693
|
+
|
|
10629
10694
|
// lib/coralite.js
|
|
10630
10695
|
import { mkdir as mkdir2, writeFile } from "node:fs/promises";
|
|
10631
10696
|
import { dirname as dirname5, join as join3, normalize, relative, resolve as resolve2 } from "node:path";
|
|
@@ -10765,6 +10830,9 @@ function Coralite({
|
|
|
10765
10830
|
pages: this.pages
|
|
10766
10831
|
}
|
|
10767
10832
|
};
|
|
10833
|
+
if (this.options.mode === "development") {
|
|
10834
|
+
plugins.unshift(testingPlugin);
|
|
10835
|
+
}
|
|
10768
10836
|
plugins.unshift(defineComponent, refsPlugin, metadataPlugin);
|
|
10769
10837
|
if (assets) {
|
|
10770
10838
|
plugins.unshift(staticAssetPlugin(assets));
|
|
@@ -10913,11 +10981,13 @@ Coralite.prototype.initialise = async function() {
|
|
|
10913
10981
|
}
|
|
10914
10982
|
const urlPathname = pathToFileURL2(join3("/", relative(rootPath, data2.path.pathname))).pathname;
|
|
10915
10983
|
const values = {
|
|
10984
|
+
page_url_pathname: urlPathname,
|
|
10985
|
+
page_url_dirname: pathToFileURL2(dirname5(urlPathname)).pathname,
|
|
10986
|
+
page_pathname: data2.path.pathname,
|
|
10987
|
+
page_dirname: data2.path.dirname,
|
|
10988
|
+
page_filename: data2.path.filename,
|
|
10989
|
+
// DEPRECATED: provide backwards compatibility for legacy plugins
|
|
10916
10990
|
$urlPathname: urlPathname,
|
|
10917
|
-
$urlDirname: pathToFileURL2(dirname5(urlPathname)).pathname,
|
|
10918
|
-
$filePathname: data2.path.pathname,
|
|
10919
|
-
$fileDirname: data2.path.dirname,
|
|
10920
|
-
$filename: data2.path.filename,
|
|
10921
10991
|
...data2.values
|
|
10922
10992
|
};
|
|
10923
10993
|
await this._triggerPluginHook("onPageSet", {
|
|
@@ -10941,14 +11011,14 @@ Coralite.prototype.initialise = async function() {
|
|
|
10941
11011
|
let newCustomElements;
|
|
10942
11012
|
if (!newValue.result) {
|
|
10943
11013
|
const result = await onFileSet(newValue);
|
|
10944
|
-
newValue = result.value;
|
|
11014
|
+
newValue.result = result.value;
|
|
10945
11015
|
newCustomElements = result.value.customElements;
|
|
10946
11016
|
} else {
|
|
10947
11017
|
newCustomElements = newValue.result.customElements;
|
|
10948
11018
|
}
|
|
10949
11019
|
let oldElements = oldValue.result.customElements.slice();
|
|
10950
11020
|
await this._triggerPluginHook("onPageUpdate", {
|
|
10951
|
-
elements:
|
|
11021
|
+
elements: newValue.result,
|
|
10952
11022
|
newValue,
|
|
10953
11023
|
oldValue
|
|
10954
11024
|
});
|
|
@@ -10976,7 +11046,7 @@ Coralite.prototype.initialise = async function() {
|
|
|
10976
11046
|
const pageCustomElement = pageCustomElements[oldElements[i].name];
|
|
10977
11047
|
pageCustomElement.delete(newValue.path.pathname);
|
|
10978
11048
|
}
|
|
10979
|
-
return newValue;
|
|
11049
|
+
return newValue.result;
|
|
10980
11050
|
};
|
|
10981
11051
|
const onPageDelete = async (value) => {
|
|
10982
11052
|
await this._triggerPluginHook("onPageDelete", value);
|
|
@@ -11250,6 +11320,7 @@ const globalSetupValuesPromise = getSetups(globalContext);
|
|
|
11250
11320
|
const globalAbortController = new AbortController();
|
|
11251
11321
|
const componentManifest = ${JSON.stringify(chunkManifest)};
|
|
11252
11322
|
const loadCache = {};
|
|
11323
|
+
const instanceCounters = {};
|
|
11253
11324
|
|
|
11254
11325
|
const loadComponent = (componentId) => {
|
|
11255
11326
|
if (!componentManifest[componentId]) return Promise.resolve();
|
|
@@ -11267,7 +11338,9 @@ const globalSetupValuesPromise = getSetups(globalContext);
|
|
|
11267
11338
|
this.componentId = module.default.componentId;
|
|
11268
11339
|
this._abortController = null;
|
|
11269
11340
|
|
|
11270
|
-
this.
|
|
11341
|
+
instanceCounters[this.componentId] = instanceCounters[this.componentId] || 0;
|
|
11342
|
+
this._index = instanceCounters[this.componentId]++;
|
|
11343
|
+
|
|
11271
11344
|
this._instanceId = \`\${this.componentId}-\${this._index}\`;
|
|
11272
11345
|
|
|
11273
11346
|
this._values = {};
|
|
@@ -11538,7 +11611,13 @@ const globalSetupValuesPromise = getSetups(globalContext);
|
|
|
11538
11611
|
const refName = element.getAttribute('ref');
|
|
11539
11612
|
|
|
11540
11613
|
const dynamicId = \`\${this.componentId}__\${refName}-\${this._index}\`;
|
|
11614
|
+
|
|
11541
11615
|
element.setAttribute('ref', dynamicId);
|
|
11616
|
+
|
|
11617
|
+
const previousTestId = element.getAttribute('data-testid')
|
|
11618
|
+
if (previousTestId !== null) {
|
|
11619
|
+
element.setAttribute('data-testid', dynamicId);
|
|
11620
|
+
}
|
|
11542
11621
|
|
|
11543
11622
|
this._values[\`ref_\${refName}\`] = dynamicId;
|
|
11544
11623
|
}
|
|
@@ -11578,9 +11657,9 @@ const globalSetupValuesPromise = getSetups(globalContext);
|
|
|
11578
11657
|
await Promise.all(loadPromises);
|
|
11579
11658
|
|
|
11580
11659
|
// Invoke inline declarative instances defined in HTML (legacy support for <script> blocks mapped to _generatePages instances if needed)
|
|
11581
|
-
const
|
|
11660
|
+
const declarativeFunctions = [];
|
|
11582
11661
|
${Object.values(instances).map((instance) => `
|
|
11583
|
-
|
|
11662
|
+
declarativeFunctions.push((async() => {
|
|
11584
11663
|
const context = {
|
|
11585
11664
|
instanceId: '${instance.instanceId}',
|
|
11586
11665
|
componentId: '${instance.componentId}',
|
|
@@ -11588,12 +11667,13 @@ const globalSetupValuesPromise = getSetups(globalContext);
|
|
|
11588
11667
|
component: {},
|
|
11589
11668
|
signal: globalAbortController.signal
|
|
11590
11669
|
};
|
|
11591
|
-
const
|
|
11592
|
-
const
|
|
11593
|
-
|
|
11670
|
+
const setupValuesPromise = globalSetupValuesPromise;
|
|
11671
|
+
const helpersPromise = getHelpers(context);
|
|
11672
|
+
const modulePromise = import('${base2}assets/js/${scriptResult.manifest[instance.componentId]}');
|
|
11594
11673
|
|
|
11595
|
-
const module = await
|
|
11596
|
-
|
|
11674
|
+
const [setupValues, helpers, module] = await Promise.all([setupValuesPromise, helpersPromise, modulePromise]);
|
|
11675
|
+
|
|
11676
|
+
context.helpers = helpers;
|
|
11597
11677
|
context.values = { ...module.default.defaultValues, ...context.values, ...setupValues };
|
|
11598
11678
|
|
|
11599
11679
|
// Explicitly load declarative script dependencies if any
|
|
@@ -11604,12 +11684,27 @@ const globalSetupValuesPromise = getSetups(globalContext);
|
|
|
11604
11684
|
}
|
|
11605
11685
|
|
|
11606
11686
|
context.imports = module.default.imports || {};
|
|
11607
|
-
|
|
11608
|
-
|
|
11609
|
-
|
|
11687
|
+
|
|
11688
|
+
return async () => {
|
|
11689
|
+
if (module.default.script) {
|
|
11690
|
+
await module.default.script(context);
|
|
11691
|
+
}
|
|
11692
|
+
};
|
|
11610
11693
|
})());
|
|
11611
11694
|
`).join("\n")}
|
|
11612
|
-
|
|
11695
|
+
|
|
11696
|
+
const executableScripts = await Promise.all(declarativeFunctions);
|
|
11697
|
+
${this.options.mode === "development" ? `
|
|
11698
|
+
for (let i = 0; i < executableScripts.length; i++) {
|
|
11699
|
+
await executableScripts[i]();
|
|
11700
|
+
}
|
|
11701
|
+
` : `
|
|
11702
|
+
const scriptPromises = [];
|
|
11703
|
+
for (let i = 0; i < executableScripts.length; i++) {
|
|
11704
|
+
scriptPromises.push(executableScripts[i]());
|
|
11705
|
+
}
|
|
11706
|
+
await Promise.all(scriptPromises);
|
|
11707
|
+
`}
|
|
11613
11708
|
resolveCoraliteReady();
|
|
11614
11709
|
})();
|
|
11615
11710
|
`;
|
|
@@ -12057,6 +12152,9 @@ Coralite.prototype.createComponentElement = async function({
|
|
|
12057
12152
|
const ref2 = module.values.refs[i];
|
|
12058
12153
|
const uniqueRefValue = `${module.id}__${ref2.name}-${index}`;
|
|
12059
12154
|
ref2.element.attribs.ref = uniqueRefValue;
|
|
12155
|
+
if (ref2.element.attribs["data-testid"]) {
|
|
12156
|
+
ref2.element.attribs["data-testid"] = uniqueRefValue;
|
|
12157
|
+
}
|
|
12060
12158
|
scriptResult.__script__.values[`ref_${ref2.name}`] = uniqueRefValue;
|
|
12061
12159
|
}
|
|
12062
12160
|
renderContext.scripts.add(component.path.pathname, {
|
|
@@ -12072,7 +12170,11 @@ Coralite.prototype.createComponentElement = async function({
|
|
|
12072
12170
|
}
|
|
12073
12171
|
for (let i = 0; i < module.values.refs.length; i++) {
|
|
12074
12172
|
const ref2 = module.values.refs[i];
|
|
12075
|
-
|
|
12173
|
+
const refValue = `${module.id}__${ref2.name}-${index}`;
|
|
12174
|
+
values[`ref_${ref2.name}`] = refValue;
|
|
12175
|
+
if (ref2.element && ref2.element.attribs && ref2.element.attribs["data-testid"] === ref2.name) {
|
|
12176
|
+
ref2.element.attribs["data-testid"] = refValue;
|
|
12177
|
+
}
|
|
12076
12178
|
}
|
|
12077
12179
|
for (let i = 0; i < module.values.attributes.length; i++) {
|
|
12078
12180
|
const item = module.values.attributes[i];
|
|
@@ -12331,12 +12433,18 @@ Coralite.prototype._evaluateDevelopment = async function({
|
|
|
12331
12433
|
};
|
|
12332
12434
|
renderContext.source.currentSourceContextId = contextId;
|
|
12333
12435
|
renderContext.source.contextInstances[contextId] = context;
|
|
12334
|
-
const
|
|
12335
|
-
|
|
12336
|
-
|
|
12436
|
+
const standardBuiltIns = /* @__PURE__ */ new Set(["Object", "Function", "Array", "String", "Boolean", "Number", "Math", "Date", "RegExp", "Error", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "JSON", "Promise", "Proxy", "Reflect", "Map", "Set", "WeakMap", "WeakSet", "ArrayBuffer", "SharedArrayBuffer", "DataView", "Atomics", "Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt", "BigInt64Array", "BigUint64Array", "Symbol", "Infinity", "NaN", "undefined", "globalThis", "decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "escape", "eval", "isFinite", "isNaN", "parseFloat", "parseInt", "unescape"]);
|
|
12437
|
+
const usedGlobals = extractGlobals(module.script);
|
|
12438
|
+
const contextGlobals = {
|
|
12337
12439
|
__coralite_context__: context,
|
|
12338
12440
|
__coralite_plugins__: cachedBoundPlugins
|
|
12339
|
-
}
|
|
12441
|
+
};
|
|
12442
|
+
for (const glob of usedGlobals) {
|
|
12443
|
+
if (!standardBuiltIns.has(glob) && glob in globalThis && globalThis[glob] !== void 0 && !(glob in contextGlobals)) {
|
|
12444
|
+
contextGlobals[glob] = globalThis[glob];
|
|
12445
|
+
}
|
|
12446
|
+
}
|
|
12447
|
+
const contextifiedObject = createContext(contextGlobals);
|
|
12340
12448
|
const moduleComponent = this.components.getItem(module.id);
|
|
12341
12449
|
const script = new SourceTextModule(module.script, {
|
|
12342
12450
|
initializeImportMeta(meta) {
|
|
@@ -12443,12 +12551,19 @@ Coralite.prototype._evaluate = async function(options) {
|
|
|
12443
12551
|
return this._evaluateProduction(options);
|
|
12444
12552
|
};
|
|
12445
12553
|
Coralite.prototype._triggerPluginHook = async function(name, data2) {
|
|
12446
|
-
const
|
|
12554
|
+
const results = [];
|
|
12447
12555
|
const pluginHooks = this._plugins.hooks[name];
|
|
12556
|
+
if (!pluginHooks || pluginHooks.length === 0) {
|
|
12557
|
+
return results;
|
|
12558
|
+
}
|
|
12448
12559
|
for (let i = 0; i < pluginHooks.length; i++) {
|
|
12449
|
-
|
|
12560
|
+
let result = pluginHooks[i](data2);
|
|
12561
|
+
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
12562
|
+
result = await result;
|
|
12563
|
+
}
|
|
12564
|
+
results.push(result);
|
|
12450
12565
|
}
|
|
12451
|
-
return
|
|
12566
|
+
return results;
|
|
12452
12567
|
};
|
|
12453
12568
|
Coralite.prototype._addPluginHook = function(name, callback) {
|
|
12454
12569
|
if (typeof callback !== "function") {
|
|
@@ -12516,6 +12631,7 @@ export {
|
|
|
12516
12631
|
defineComponent,
|
|
12517
12632
|
defineConfig,
|
|
12518
12633
|
definePlugin,
|
|
12634
|
+
extractGlobals,
|
|
12519
12635
|
findAndExtractScript,
|
|
12520
12636
|
getHtmlFile,
|
|
12521
12637
|
getHtmlFileSync,
|
|
@@ -12544,6 +12660,7 @@ export {
|
|
|
12544
12660
|
parseModule,
|
|
12545
12661
|
refsPlugin,
|
|
12546
12662
|
replaceToken,
|
|
12547
|
-
staticAssetPlugin
|
|
12663
|
+
staticAssetPlugin,
|
|
12664
|
+
testingPlugin
|
|
12548
12665
|
};
|
|
12549
12666
|
//# sourceMappingURL=index.js.map
|