elegance-js 2.0.18 → 2.1.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.
@@ -146,8 +146,8 @@ Object.assign(globalThis, childrenlessElements);
146
146
 
147
147
  // src/client/client.ts
148
148
  console.log("Elegance.JS is loading..");
149
- if (!globalThis.pd) globalThis.pd = {};
150
- if (!globalThis.ld) globalThis.ld = {};
149
+ var pd = {};
150
+ var ld = {};
151
151
  Object.assign(window, {
152
152
  observe: (subjects, updateCallback) => {
153
153
  return {
@@ -330,7 +330,7 @@ var initPageData = (data, currentPage2, previousPage, bindLevel) => {
330
330
  }
331
331
  }
332
332
  };
333
- var loadPage = (previousPage = null) => {
333
+ var loadPage = async (previousPage = null) => {
334
334
  const fixedUrl = new URL(loc.href);
335
335
  fixedUrl.pathname = sanitizePathname(fixedUrl.pathname);
336
336
  const pathname = fixedUrl.pathname;
@@ -341,13 +341,14 @@ var loadPage = (previousPage = null) => {
341
341
  );
342
342
  history.replaceState(null, "", fixedUrl.href);
343
343
  {
344
- let pageData = pd[pathname];
345
- if (!pd) {
346
- console.error(`%cFailed to load! Missing page data!`, "font-size: 20px; font-weight: 600;");
347
- return;
344
+ const pageDataScript = document.head.querySelector(`script[data-page="true"][data-pathname="${sanitizePathname(pathname)}"]`);
345
+ const { data } = await import(pageDataScript.src);
346
+ if (!pd[pathname]) pd[pathname] = data;
347
+ {
348
+ const dataScript = document.querySelector(`script[data-hook="true"][data-pathname="${sanitizePathname(pathname)}"]`);
349
+ if (dataScript) dataScript.remove();
348
350
  }
349
- ;
350
- initPageData(pageData, currentPage, previousPage, 1 /* STRICT */);
351
+ initPageData(pd[pathname], currentPage, previousPage, 1 /* STRICT */);
351
352
  }
352
353
  {
353
354
  const parts = window.location.pathname.split("/").filter(Boolean);
@@ -356,11 +357,17 @@ var loadPage = (previousPage = null) => {
356
357
  "/"
357
358
  ];
358
359
  for (const path of paths) {
359
- const data = ld[path];
360
- if (!data) {
360
+ const layoutDataScript = document.querySelector(`script[data-layout="true"][data-pathname="${path}"]`);
361
+ if (!layoutDataScript) {
361
362
  continue;
362
363
  }
363
- initPageData(data, path, previousPage, 2 /* SCOPED */);
364
+ const { data } = await import(layoutDataScript.src);
365
+ if (!ld[pathname]) ld[pathname] = data;
366
+ {
367
+ const dataScript = document.querySelector(`script[data-hook="true"][data-pathname="${sanitizePathname(pathname)}"]`);
368
+ if (dataScript) dataScript.remove();
369
+ }
370
+ initPageData(ld[pathname], path, previousPage, 2 /* SCOPED */);
364
371
  }
365
372
  }
366
373
  console.info(
@@ -481,7 +488,7 @@ var navigateLocally = async (target, pushState = true) => {
481
488
  update(oldTags, newTags, (node) => node.remove());
482
489
  }
483
490
  if (pushState) history.pushState(null, "", targetURL.href);
484
- loadPage(currentPage);
491
+ await loadPage(currentPage);
485
492
  currentPage = pathname;
486
493
  if (targetURL.hash) {
487
494
  doc.getElementById(targetURL.hash.slice(1))?.scrollIntoView();