coralite 0.40.0 → 0.40.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.
- package/dist/lib/collection-handlers.d.ts.map +1 -1
- package/dist/lib/coralite.d.ts.map +1 -1
- package/dist/lib/index.js +114 -85
- package/dist/lib/index.js.map +3 -3
- package/dist/lib/renderer.d.ts.map +1 -1
- package/dist/lib/utils/client/runtime.d.ts.map +1 -1
- package/dist/types/core.d.ts +17 -1
- package/dist/types/core.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection-handlers.d.ts","sourceRoot":"","sources":["../../lib/collection-handlers.js"],"names":[],"mappings":"AAKA;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AACH,8GARG;IAAkC,GAAG,EAA7B,gBAAgB;IACE,WAAW;IACJ,WAAW,EAApC,eAAe;IACI,QAAQ;IACb,aAAa,GAA3B,GAAG;IACgB,aAAa;CACxC,
|
|
1
|
+
{"version":3,"file":"collection-handlers.d.ts","sourceRoot":"","sources":["../../lib/collection-handlers.js"],"names":[],"mappings":"AAKA;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AACH,8GARG;IAAkC,GAAG,EAA7B,gBAAgB;IACE,WAAW;IACJ,WAAW,EAApC,eAAe;IACI,QAAQ;IACb,aAAa,GAA3B,GAAG;IACgB,aAAa;CACxC,OA2NF;sCAxOS,mBAAmB;qCAAnB,mBAAmB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coralite.d.ts","sourceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAwBA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,2LAHW,cAAc,GACZ,OAAO,CAAC,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"coralite.d.ts","sourceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAwBA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,2LAHW,cAAc,GACZ,OAAO,CAAC,gBAAgB,CAAC,CA0brC;;oCAjcS,mBAAmB;sCAAnB,mBAAmB"}
|
package/dist/lib/index.js
CHANGED
|
@@ -4566,7 +4566,6 @@ function createPageHandlers({
|
|
|
4566
4566
|
scriptManager,
|
|
4567
4567
|
createSession
|
|
4568
4568
|
}) {
|
|
4569
|
-
const { pageCustomElements, childCustomElements } = app._dependencyGraph;
|
|
4570
4569
|
const onFileSetLocal = async (data) => {
|
|
4571
4570
|
const rootPath = data.type === "component" ? app.options.path.components : app.options.path.pages;
|
|
4572
4571
|
const urlPathname = pathToFileURL3(join3("/", relative2(rootPath, data.path.pathname))).pathname;
|
|
@@ -4597,34 +4596,11 @@ function createPageHandlers({
|
|
|
4597
4596
|
};
|
|
4598
4597
|
}
|
|
4599
4598
|
const elements = parseHTML(data.content, app.options.ignoreByAttribute, app.options.skipRenderByAttribute, handleError2);
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
pageCustomElements[name] = /* @__PURE__ */ new Set();
|
|
4606
|
-
app._dependencyGraph.pageCustomElements[name] = pageCustomElements[name];
|
|
4607
|
-
const component = app.components.getItem(name);
|
|
4608
|
-
if (component && component.result && component.result.customElements && component.result.customElements.length) {
|
|
4609
|
-
const stack = [component.result.customElements];
|
|
4610
|
-
while (stack.length > 0) {
|
|
4611
|
-
const current = stack.pop();
|
|
4612
|
-
for (let i2 = 0; i2 < current.length; i2++) {
|
|
4613
|
-
const element = current[i2];
|
|
4614
|
-
if (!childCustomElements[element.name]) {
|
|
4615
|
-
childCustomElements[element.name] = name;
|
|
4616
|
-
const comp = app.components.getItem(element.name);
|
|
4617
|
-
if (comp && comp.result && comp.result.customElements && comp.result.customElements.length) {
|
|
4618
|
-
stack.push(comp.result.customElements);
|
|
4619
|
-
}
|
|
4620
|
-
}
|
|
4621
|
-
}
|
|
4622
|
-
}
|
|
4623
|
-
}
|
|
4624
|
-
}
|
|
4625
|
-
const customElements = pageCustomElements[name];
|
|
4626
|
-
customElements.add(data.path.pathname);
|
|
4627
|
-
}
|
|
4599
|
+
const directPageComponents = app._dependencyGraph.directPageComponents;
|
|
4600
|
+
if (elements && elements.customElements && directPageComponents) {
|
|
4601
|
+
const directComponents = elements.customElements.map((el) => el.name);
|
|
4602
|
+
directPageComponents[data.path.pathname] = directComponents;
|
|
4603
|
+
app._refreshDependencyGraph();
|
|
4628
4604
|
}
|
|
4629
4605
|
const mappedContext = await triggerHook("onPageSet", {
|
|
4630
4606
|
elements,
|
|
@@ -4653,17 +4629,15 @@ function createPageHandlers({
|
|
|
4653
4629
|
};
|
|
4654
4630
|
const onPageUpdateLocal = async (newValue, oldValue) => {
|
|
4655
4631
|
if (app.options.mode === "production") {
|
|
4632
|
+
if (!newValue.result) {
|
|
4633
|
+
await onFileSetLocal(newValue);
|
|
4634
|
+
}
|
|
4656
4635
|
return newValue.result;
|
|
4657
4636
|
}
|
|
4658
|
-
let newCustomElements;
|
|
4659
4637
|
if (!newValue.result) {
|
|
4660
4638
|
const res = await onFileSetLocal(newValue);
|
|
4661
4639
|
newValue.result = res.value;
|
|
4662
|
-
newCustomElements = res.value.customElements;
|
|
4663
|
-
} else {
|
|
4664
|
-
newCustomElements = newValue.result.customElements;
|
|
4665
4640
|
}
|
|
4666
|
-
const oldElements = (oldValue.result.customElements || []).slice();
|
|
4667
4641
|
const mappedContext = await triggerHook("onPageUpdate", {
|
|
4668
4642
|
elements: newValue.result,
|
|
4669
4643
|
page: newValue.result.page,
|
|
@@ -4673,51 +4647,31 @@ function createPageHandlers({
|
|
|
4673
4647
|
});
|
|
4674
4648
|
newValue.result = mappedContext.elements;
|
|
4675
4649
|
newValue = mappedContext.newValue;
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
}
|
|
4685
|
-
}
|
|
4686
|
-
if (!hasElement) {
|
|
4687
|
-
if (!pageCustomElements[name]) {
|
|
4688
|
-
pageCustomElements[name] = /* @__PURE__ */ new Set();
|
|
4689
|
-
app._dependencyGraph.pageCustomElements[name] = pageCustomElements[name];
|
|
4690
|
-
}
|
|
4691
|
-
const customElements = pageCustomElements[name];
|
|
4692
|
-
customElements.add(newValue.path.pathname);
|
|
4650
|
+
const elements = parseHTML(newValue.content, app.options.ignoreByAttribute, app.options.skipRenderByAttribute, handleError2);
|
|
4651
|
+
const directPageComponents = app._dependencyGraph.directPageComponents;
|
|
4652
|
+
if (directPageComponents) {
|
|
4653
|
+
if (elements && elements.customElements) {
|
|
4654
|
+
const directComponents = elements.customElements.map((el) => el.name);
|
|
4655
|
+
directPageComponents[newValue.path.pathname] = directComponents;
|
|
4656
|
+
} else {
|
|
4657
|
+
delete directPageComponents[newValue.path.pathname];
|
|
4693
4658
|
}
|
|
4694
4659
|
}
|
|
4695
|
-
|
|
4696
|
-
if (pageCustomElements[oe.name]) {
|
|
4697
|
-
const customElements = pageCustomElements[oe.name];
|
|
4698
|
-
customElements.delete(newValue.path.pathname);
|
|
4699
|
-
}
|
|
4700
|
-
});
|
|
4660
|
+
app._refreshDependencyGraph();
|
|
4701
4661
|
return newValue.result;
|
|
4702
4662
|
};
|
|
4703
4663
|
const onPageDeleteLocal = async (value) => {
|
|
4704
|
-
if (app.options.mode === "production") {
|
|
4705
|
-
return;
|
|
4706
|
-
}
|
|
4707
4664
|
const res = await triggerHook("onPageDelete", {
|
|
4708
4665
|
data: value,
|
|
4709
4666
|
app
|
|
4710
4667
|
});
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
const customElements = pageCustomElements[ceName];
|
|
4717
|
-
customElements.delete(value.path.pathname);
|
|
4718
|
-
}
|
|
4719
|
-
});
|
|
4668
|
+
const finalData = res?.data || value;
|
|
4669
|
+
const pathname = finalData?.path?.pathname;
|
|
4670
|
+
const directPageComponents = app._dependencyGraph.directPageComponents;
|
|
4671
|
+
if (pathname && directPageComponents) {
|
|
4672
|
+
delete directPageComponents[pathname];
|
|
4720
4673
|
}
|
|
4674
|
+
app._refreshDependencyGraph();
|
|
4721
4675
|
};
|
|
4722
4676
|
const onComponentSetLocal = async (v) => {
|
|
4723
4677
|
if (v.content === void 0) {
|
|
@@ -5080,16 +5034,6 @@ import { getClientContext, createCoraliteClass, globalClientHooks } from '${base
|
|
|
5080
5034
|
customElements.define(id, createCoraliteClass(module.default, getClientContext, globalClientHooks, hydrationData));
|
|
5081
5035
|
if (window.__coralite__ && window.__coralite__.lifecycle) window.__coralite__.lifecycle._markDefined(id);
|
|
5082
5036
|
}
|
|
5083
|
-
|
|
5084
|
-
// Upgrade any existing elements that might have been created before the definition was loaded
|
|
5085
|
-
const elements = document.querySelectorAll(id);
|
|
5086
|
-
for (const el of elements) {
|
|
5087
|
-
if (el.constructor === HTMLElement) {
|
|
5088
|
-
// Re-trigger the lifecycle by replacing the element or manually calling upgrade if supported
|
|
5089
|
-
// For most cases, customElements.define handles this automatically if the element is already in DOM,
|
|
5090
|
-
// but if it's currently disconnected it might need help.
|
|
5091
|
-
}
|
|
5092
|
-
}
|
|
5093
5037
|
}
|
|
5094
5038
|
})();
|
|
5095
5039
|
return loadCache[componentId];
|
|
@@ -6286,6 +6230,17 @@ function createRenderer({
|
|
|
6286
6230
|
try {
|
|
6287
6231
|
const content = await readFile3(manifestPath, "utf8");
|
|
6288
6232
|
manifest = JSON.parse(content);
|
|
6233
|
+
for (const [path2, metadata] of Object.entries(manifest.physical || {})) {
|
|
6234
|
+
if (metadata.dependencies) {
|
|
6235
|
+
app._dependencyGraph.directPageComponents[path2] = metadata.dependencies;
|
|
6236
|
+
}
|
|
6237
|
+
}
|
|
6238
|
+
for (const [path2, metadata] of Object.entries(manifest.virtual || {})) {
|
|
6239
|
+
if (metadata.dependencies) {
|
|
6240
|
+
app._dependencyGraph.directPageComponents[path2] = metadata.dependencies;
|
|
6241
|
+
}
|
|
6242
|
+
}
|
|
6243
|
+
app._refreshDependencyGraph();
|
|
6289
6244
|
} catch (e) {
|
|
6290
6245
|
if (e.code !== "ENOENT") {
|
|
6291
6246
|
handleError2({
|
|
@@ -6303,14 +6258,19 @@ function createRenderer({
|
|
|
6303
6258
|
};
|
|
6304
6259
|
const componentChanges = /* @__PURE__ */ new Map();
|
|
6305
6260
|
const allComponents = app.components.list;
|
|
6261
|
+
let anyComponentChanged = false;
|
|
6306
6262
|
for (const component of allComponents) {
|
|
6307
6263
|
const { changed, metadata } = await checkFileChange(component.path.pathname, manifest.physical[component.path.pathname]);
|
|
6308
6264
|
newManifest.physical[component.path.pathname] = metadata;
|
|
6309
|
-
if (changed) {
|
|
6265
|
+
if (changed || !manifest.physical[component.path.pathname]) {
|
|
6310
6266
|
componentChanges.set(component.result.id, true);
|
|
6267
|
+
anyComponentChanged = true;
|
|
6311
6268
|
await app.components.updateItem(component.path.pathname);
|
|
6312
6269
|
}
|
|
6313
6270
|
}
|
|
6271
|
+
if (anyComponentChanged) {
|
|
6272
|
+
app._refreshDependencyGraph();
|
|
6273
|
+
}
|
|
6314
6274
|
const pageCustomElements = {
|
|
6315
6275
|
...manifest.dependencies,
|
|
6316
6276
|
...app._dependencyGraph.pageCustomElements
|
|
@@ -6385,10 +6345,17 @@ function createRenderer({
|
|
|
6385
6345
|
}
|
|
6386
6346
|
}
|
|
6387
6347
|
}
|
|
6388
|
-
const { pageCustomElements: livePageCustomElements } = app._dependencyGraph;
|
|
6348
|
+
const { pageCustomElements: livePageCustomElements, directPageComponents: liveDirectPageComponents } = app._dependencyGraph;
|
|
6389
6349
|
for (const [id, pages] of Object.entries(livePageCustomElements)) {
|
|
6390
6350
|
newManifest.dependencies[id] = Array.from(pages);
|
|
6391
6351
|
}
|
|
6352
|
+
for (const [path2, deps] of Object.entries(liveDirectPageComponents)) {
|
|
6353
|
+
if (newManifest.physical[path2]) {
|
|
6354
|
+
newManifest.physical[path2].dependencies = deps;
|
|
6355
|
+
} else if (newManifest.virtual[path2]) {
|
|
6356
|
+
newManifest.virtual[path2].dependencies = deps;
|
|
6357
|
+
}
|
|
6358
|
+
}
|
|
6392
6359
|
for (const [id, pages] of Object.entries(manifest.dependencies || {})) {
|
|
6393
6360
|
if (!newManifest.dependencies[id]) {
|
|
6394
6361
|
newManifest.dependencies[id] = pages;
|
|
@@ -6490,7 +6457,6 @@ function createRenderer({
|
|
|
6490
6457
|
});
|
|
6491
6458
|
renderQueues.delete(buildId);
|
|
6492
6459
|
sealedQueues.delete(buildId);
|
|
6493
|
-
app._clearDependencies();
|
|
6494
6460
|
pagesToRender.length = 0;
|
|
6495
6461
|
skippedPages.length = 0;
|
|
6496
6462
|
}
|
|
@@ -6566,6 +6532,7 @@ async function createCoralite({
|
|
|
6566
6532
|
path: path2,
|
|
6567
6533
|
output: output ? normalize(output) : void 0
|
|
6568
6534
|
};
|
|
6535
|
+
const trackedOutputFiles = /* @__PURE__ */ new Set();
|
|
6569
6536
|
const app = {
|
|
6570
6537
|
options: normalizedOptions,
|
|
6571
6538
|
pages: null,
|
|
@@ -6573,16 +6540,65 @@ async function createCoralite({
|
|
|
6573
6540
|
build: null,
|
|
6574
6541
|
save: null,
|
|
6575
6542
|
transform: transformNode,
|
|
6543
|
+
trackOutputFile(path3) {
|
|
6544
|
+
trackedOutputFiles.add(normalize(path3));
|
|
6545
|
+
},
|
|
6546
|
+
getTrackedOutputFiles() {
|
|
6547
|
+
return Array.from(trackedOutputFiles);
|
|
6548
|
+
},
|
|
6549
|
+
async writeFile(dest, content, writeOptions = {}) {
|
|
6550
|
+
if (!app.options.output) {
|
|
6551
|
+
throw new Error('app.writeFile requires "output" to be configured');
|
|
6552
|
+
}
|
|
6553
|
+
const fullPath = join5(app.options.output, dest);
|
|
6554
|
+
await mkdir3(dirname7(fullPath), { recursive: true });
|
|
6555
|
+
await writeFile2(fullPath, content, writeOptions);
|
|
6556
|
+
app.trackOutputFile(fullPath);
|
|
6557
|
+
return fullPath;
|
|
6558
|
+
},
|
|
6576
6559
|
addRenderQueue: null,
|
|
6577
6560
|
getPagePathsUsingCustomElement: null,
|
|
6578
6561
|
createComponentElement: null,
|
|
6579
6562
|
_dependencyGraph: {
|
|
6580
6563
|
pageCustomElements: {},
|
|
6581
|
-
|
|
6564
|
+
directPageComponents: {}
|
|
6565
|
+
},
|
|
6566
|
+
_refreshDependencyGraph: () => {
|
|
6567
|
+
const { pageCustomElements, directPageComponents } = app._dependencyGraph;
|
|
6568
|
+
for (const tag in pageCustomElements) {
|
|
6569
|
+
delete pageCustomElements[tag];
|
|
6570
|
+
}
|
|
6571
|
+
const resolveDependencies = (pagePath, directComponents) => {
|
|
6572
|
+
const visited = /* @__PURE__ */ new Set();
|
|
6573
|
+
const allDependencies = /* @__PURE__ */ new Set();
|
|
6574
|
+
const walk = (tags) => {
|
|
6575
|
+
for (const tag of tags) {
|
|
6576
|
+
if (visited.has(tag)) {
|
|
6577
|
+
continue;
|
|
6578
|
+
}
|
|
6579
|
+
visited.add(tag);
|
|
6580
|
+
allDependencies.add(tag);
|
|
6581
|
+
const sharedFn = scriptManager.sharedFunctions[tag];
|
|
6582
|
+
if (sharedFn && sharedFn.components?.length) {
|
|
6583
|
+
walk(sharedFn.components);
|
|
6584
|
+
}
|
|
6585
|
+
}
|
|
6586
|
+
};
|
|
6587
|
+
walk(directComponents);
|
|
6588
|
+
for (const tag of allDependencies) {
|
|
6589
|
+
if (!pageCustomElements[tag]) {
|
|
6590
|
+
pageCustomElements[tag] = /* @__PURE__ */ new Set();
|
|
6591
|
+
}
|
|
6592
|
+
pageCustomElements[tag].add(pagePath);
|
|
6593
|
+
}
|
|
6594
|
+
};
|
|
6595
|
+
for (const [pagePath, directComponents] of Object.entries(directPageComponents)) {
|
|
6596
|
+
resolveDependencies(pagePath, directComponents);
|
|
6597
|
+
}
|
|
6582
6598
|
},
|
|
6583
6599
|
_clearDependencies: () => {
|
|
6584
6600
|
app._dependencyGraph.pageCustomElements = {};
|
|
6585
|
-
app._dependencyGraph.
|
|
6601
|
+
app._dependencyGraph.directPageComponents = {};
|
|
6586
6602
|
}
|
|
6587
6603
|
};
|
|
6588
6604
|
const plugins = {
|
|
@@ -6751,11 +6767,16 @@ async function createCoralite({
|
|
|
6751
6767
|
const item = app.components.getItem(targetPath);
|
|
6752
6768
|
const results = [];
|
|
6753
6769
|
if (item) {
|
|
6754
|
-
const id =
|
|
6770
|
+
const id = item.result.id;
|
|
6755
6771
|
const pce = app._dependencyGraph.pageCustomElements[id];
|
|
6756
6772
|
if (pce) {
|
|
6757
6773
|
pce.forEach((p) => results.push(p));
|
|
6758
6774
|
}
|
|
6775
|
+
} else {
|
|
6776
|
+
const pce = app._dependencyGraph.pageCustomElements[targetPath];
|
|
6777
|
+
if (pce) {
|
|
6778
|
+
pce.forEach((p) => results.push(p));
|
|
6779
|
+
}
|
|
6759
6780
|
}
|
|
6760
6781
|
return results;
|
|
6761
6782
|
}
|
|
@@ -6767,6 +6788,14 @@ async function createCoralite({
|
|
|
6767
6788
|
if (assets) {
|
|
6768
6789
|
app.options.plugins.unshift(staticAssetPlugin(assets));
|
|
6769
6790
|
}
|
|
6791
|
+
if (externalStyles && output) {
|
|
6792
|
+
for (let i = 0; i < externalStyles.length; i++) {
|
|
6793
|
+
const style = externalStyles[i];
|
|
6794
|
+
if (style.startsWith("/")) {
|
|
6795
|
+
app.trackOutputFile(join5(output, style));
|
|
6796
|
+
}
|
|
6797
|
+
}
|
|
6798
|
+
}
|
|
6770
6799
|
await Promise.all([
|
|
6771
6800
|
initHasher(),
|
|
6772
6801
|
setupPlugins({
|