coralite 0.40.1 → 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.
@@ -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,OAgRF;sCA7RS,mBAAmB;qCAAnB,mBAAmB"}
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,CA4YrC;;oCAnZS,mBAAmB;sCAAnB,mBAAmB"}
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
- if (true) {
4601
- const customElementsList = elements && elements.customElements ? elements.customElements : [];
4602
- for (let i = 0; i < customElementsList.length; i++) {
4603
- const name = customElementsList[i].name;
4604
- if (!pageCustomElements[name]) {
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
- for (let i = 0; i < newCustomElements.length; i++) {
4677
- const name = newCustomElements[i].name;
4678
- let hasElement = false;
4679
- for (let j = 0; j < oldElements.length; j++) {
4680
- if (name === oldElements[j].name) {
4681
- hasElement = true;
4682
- oldElements.splice(j, 1);
4683
- break;
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
- oldElements.forEach((oe) => {
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
- value = res.data;
4712
- if (value?.result?.customElements) {
4713
- value.result.customElements.forEach((ce) => {
4714
- const ceName = typeof ce === "string" ? ce : ce.name;
4715
- if (pageCustomElements[ceName]) {
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
  }
@@ -6595,11 +6561,44 @@ async function createCoralite({
6595
6561
  createComponentElement: null,
6596
6562
  _dependencyGraph: {
6597
6563
  pageCustomElements: {},
6598
- childCustomElements: {}
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
+ }
6599
6598
  },
6600
6599
  _clearDependencies: () => {
6601
6600
  app._dependencyGraph.pageCustomElements = {};
6602
- app._dependencyGraph.childCustomElements = {};
6601
+ app._dependencyGraph.directPageComponents = {};
6603
6602
  }
6604
6603
  };
6605
6604
  const plugins = {
@@ -6768,11 +6767,16 @@ async function createCoralite({
6768
6767
  const item = app.components.getItem(targetPath);
6769
6768
  const results = [];
6770
6769
  if (item) {
6771
- const id = app._dependencyGraph.childCustomElements[item.result.id] || item.result.id;
6770
+ const id = item.result.id;
6772
6771
  const pce = app._dependencyGraph.pageCustomElements[id];
6773
6772
  if (pce) {
6774
6773
  pce.forEach((p) => results.push(p));
6775
6774
  }
6775
+ } else {
6776
+ const pce = app._dependencyGraph.pageCustomElements[targetPath];
6777
+ if (pce) {
6778
+ pce.forEach((p) => results.push(p));
6779
+ }
6776
6780
  }
6777
6781
  return results;
6778
6782
  }