elegance-js 1.11.26 → 1.11.28

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/build.mjs CHANGED
@@ -352,12 +352,12 @@ var processOptionAsObjectAttribute = (element, optionName, optionValue, objectAt
352
352
  }
353
353
  objectAttributes.push({ ...optionValue, key, attribute: optionFinal });
354
354
  };
355
- var processPageElements = (element, objectAttributes, parent) => {
355
+ var processPageElements = async (element, objectAttributes, parent) => {
356
356
  if (typeof element === "boolean" || typeof element === "number" || Array.isArray(element)) return element;
357
357
  if (typeof element === "string") {
358
358
  return element;
359
359
  }
360
- const processElementOptionsAsChildAndReturn = () => {
360
+ const processElementOptionsAsChildAndReturn = async () => {
361
361
  const children = element.children;
362
362
  element.children = [
363
363
  element.options,
@@ -366,7 +366,7 @@ var processPageElements = (element, objectAttributes, parent) => {
366
366
  element.options = {};
367
367
  for (let i = 0; i < children.length + 1; i++) {
368
368
  const child2 = element.children[i];
369
- const processedChild = processPageElements(child2, objectAttributes, element);
369
+ const processedChild = await processPageElements(child2, objectAttributes, element);
370
370
  element.children[i] = processedChild;
371
371
  }
372
372
  return {
@@ -375,7 +375,7 @@ var processPageElements = (element, objectAttributes, parent) => {
375
375
  };
376
376
  };
377
377
  if (typeof element.options !== "object") {
378
- return processElementOptionsAsChildAndReturn();
378
+ return await processElementOptionsAsChildAndReturn();
379
379
  }
380
380
  const {
381
381
  tag: elementTag,
@@ -383,7 +383,7 @@ var processPageElements = (element, objectAttributes, parent) => {
383
383
  children: elementChildren
384
384
  } = element.options;
385
385
  if (elementTag && elementOptions && elementChildren) {
386
- return processElementOptionsAsChildAndReturn();
386
+ return await processElementOptionsAsChildAndReturn();
387
387
  }
388
388
  const options2 = element.options;
389
389
  for (const [optionName, optionValue] of Object.entries(options2)) {
@@ -412,7 +412,7 @@ var processPageElements = (element, objectAttributes, parent) => {
412
412
  if (element.children) {
413
413
  for (let i = 0; i < element.children.length; i++) {
414
414
  const child2 = element.children[i];
415
- const processedChild = processPageElements(child2, objectAttributes, element);
415
+ const processedChild = await processPageElements(child2, objectAttributes, element);
416
416
  element.children[i] = processedChild;
417
417
  }
418
418
  }
@@ -423,7 +423,7 @@ var generateSuitablePageElements = async (pageLocation, pageElements, metadata,
423
423
  return [];
424
424
  }
425
425
  const objectAttributes = [];
426
- const processedPageElements = processPageElements(pageElements, objectAttributes, []);
426
+ const processedPageElements = await processPageElements(pageElements, objectAttributes, []);
427
427
  elementKey = 0;
428
428
  const renderedPage = await serverSideRenderPage(
429
429
  processedPageElements,
@@ -579,6 +579,9 @@ var buildDynamicPage = async (filePath, DIST_DIR, req, res) => {
579
579
  console.warn(`WARNING: Dynamic ${filePath} should export a const page, which is of type BuiltElement<"body">.`);
580
580
  }
581
581
  if (typeof pageElements === "function") {
582
+ if (pageElements.constructor.name === "AsyncFunction") {
583
+ pageElements = await pageElements();
584
+ }
582
585
  pageElements = pageElements();
583
586
  }
584
587
  const state = getState();
@@ -325,8 +325,12 @@ var loadPage = (deprecatedKeys = [], newBreakpoints) => {
325
325
  }
326
326
  const loadHooks = pageData.lh;
327
327
  for (const loadHook of loadHooks || []) {
328
- const bind = loadHook.bind;
329
- if (bind !== void 0 && newBreakpoints && !newBreakpoints.includes(`${bind}`)) {
328
+ const bind = loadHook.bind ?? "";
329
+ if (
330
+ // generateClientPageData makes undefined binds into empty strings
331
+ // so that the page_data.js is *smaller*
332
+ bind !== "" && newBreakpoints && !newBreakpoints.includes(`${bind}`)
333
+ ) {
330
334
  continue;
331
335
  }
332
336
  const fn = loadHook.fn;
@@ -355,12 +355,12 @@ var processOptionAsObjectAttribute = (element, optionName, optionValue, objectAt
355
355
  }
356
356
  objectAttributes.push({ ...optionValue, key, attribute: optionFinal });
357
357
  };
358
- var processPageElements = (element, objectAttributes, parent) => {
358
+ var processPageElements = async (element, objectAttributes, parent) => {
359
359
  if (typeof element === "boolean" || typeof element === "number" || Array.isArray(element)) return element;
360
360
  if (typeof element === "string") {
361
361
  return element;
362
362
  }
363
- const processElementOptionsAsChildAndReturn = () => {
363
+ const processElementOptionsAsChildAndReturn = async () => {
364
364
  const children = element.children;
365
365
  element.children = [
366
366
  element.options,
@@ -369,7 +369,7 @@ var processPageElements = (element, objectAttributes, parent) => {
369
369
  element.options = {};
370
370
  for (let i = 0; i < children.length + 1; i++) {
371
371
  const child2 = element.children[i];
372
- const processedChild = processPageElements(child2, objectAttributes, element);
372
+ const processedChild = await processPageElements(child2, objectAttributes, element);
373
373
  element.children[i] = processedChild;
374
374
  }
375
375
  return {
@@ -378,7 +378,7 @@ var processPageElements = (element, objectAttributes, parent) => {
378
378
  };
379
379
  };
380
380
  if (typeof element.options !== "object") {
381
- return processElementOptionsAsChildAndReturn();
381
+ return await processElementOptionsAsChildAndReturn();
382
382
  }
383
383
  const {
384
384
  tag: elementTag,
@@ -386,7 +386,7 @@ var processPageElements = (element, objectAttributes, parent) => {
386
386
  children: elementChildren
387
387
  } = element.options;
388
388
  if (elementTag && elementOptions && elementChildren) {
389
- return processElementOptionsAsChildAndReturn();
389
+ return await processElementOptionsAsChildAndReturn();
390
390
  }
391
391
  const options2 = element.options;
392
392
  for (const [optionName, optionValue] of Object.entries(options2)) {
@@ -415,7 +415,7 @@ var processPageElements = (element, objectAttributes, parent) => {
415
415
  if (element.children) {
416
416
  for (let i = 0; i < element.children.length; i++) {
417
417
  const child2 = element.children[i];
418
- const processedChild = processPageElements(child2, objectAttributes, element);
418
+ const processedChild = await processPageElements(child2, objectAttributes, element);
419
419
  element.children[i] = processedChild;
420
420
  }
421
421
  }
@@ -426,7 +426,7 @@ var generateSuitablePageElements = async (pageLocation, pageElements, metadata,
426
426
  return [];
427
427
  }
428
428
  const objectAttributes = [];
429
- const processedPageElements = processPageElements(pageElements, objectAttributes, []);
429
+ const processedPageElements = await processPageElements(pageElements, objectAttributes, []);
430
430
  elementKey = 0;
431
431
  const renderedPage = await serverSideRenderPage(
432
432
  processedPageElements,
@@ -582,6 +582,9 @@ var buildDynamicPage = async (filePath, DIST_DIR, req, res) => {
582
582
  console.warn(`WARNING: Dynamic ${filePath} should export a const page, which is of type BuiltElement<"body">.`);
583
583
  }
584
584
  if (typeof pageElements === "function") {
585
+ if (pageElements.constructor.name === "AsyncFunction") {
586
+ pageElements = await pageElements();
587
+ }
585
588
  pageElements = pageElements();
586
589
  }
587
590
  const state = getState();
@@ -1,2 +1,2 @@
1
- export declare const processPageElements: (element: Child, objectAttributes: Array<any>, parent: Child) => Child;
1
+ export declare const processPageElements: (element: Child, objectAttributes: Array<any>, parent: Child) => Promise<Child>;
2
2
  export declare const buildDynamicPage: (filePath: string, DIST_DIR: string, req: any, res: any) => Promise<string | false>;
@@ -308,12 +308,12 @@ var processOptionAsObjectAttribute = (element, optionName, optionValue, objectAt
308
308
  }
309
309
  objectAttributes.push({ ...optionValue, key, attribute: optionFinal });
310
310
  };
311
- var processPageElements = (element, objectAttributes, parent) => {
311
+ var processPageElements = async (element, objectAttributes, parent) => {
312
312
  if (typeof element === "boolean" || typeof element === "number" || Array.isArray(element)) return element;
313
313
  if (typeof element === "string") {
314
314
  return element;
315
315
  }
316
- const processElementOptionsAsChildAndReturn = () => {
316
+ const processElementOptionsAsChildAndReturn = async () => {
317
317
  const children = element.children;
318
318
  element.children = [
319
319
  element.options,
@@ -322,7 +322,7 @@ var processPageElements = (element, objectAttributes, parent) => {
322
322
  element.options = {};
323
323
  for (let i = 0; i < children.length + 1; i++) {
324
324
  const child = element.children[i];
325
- const processedChild = processPageElements(child, objectAttributes, element);
325
+ const processedChild = await processPageElements(child, objectAttributes, element);
326
326
  element.children[i] = processedChild;
327
327
  }
328
328
  return {
@@ -331,7 +331,7 @@ var processPageElements = (element, objectAttributes, parent) => {
331
331
  };
332
332
  };
333
333
  if (typeof element.options !== "object") {
334
- return processElementOptionsAsChildAndReturn();
334
+ return await processElementOptionsAsChildAndReturn();
335
335
  }
336
336
  const {
337
337
  tag: elementTag,
@@ -339,7 +339,7 @@ var processPageElements = (element, objectAttributes, parent) => {
339
339
  children: elementChildren
340
340
  } = element.options;
341
341
  if (elementTag && elementOptions && elementChildren) {
342
- return processElementOptionsAsChildAndReturn();
342
+ return await processElementOptionsAsChildAndReturn();
343
343
  }
344
344
  const options = element.options;
345
345
  for (const [optionName, optionValue] of Object.entries(options)) {
@@ -368,7 +368,7 @@ var processPageElements = (element, objectAttributes, parent) => {
368
368
  if (element.children) {
369
369
  for (let i = 0; i < element.children.length; i++) {
370
370
  const child = element.children[i];
371
- const processedChild = processPageElements(child, objectAttributes, element);
371
+ const processedChild = await processPageElements(child, objectAttributes, element);
372
372
  element.children[i] = processedChild;
373
373
  }
374
374
  }
@@ -379,7 +379,7 @@ var generateSuitablePageElements = async (pageLocation, pageElements, metadata,
379
379
  return [];
380
380
  }
381
381
  const objectAttributes = [];
382
- const processedPageElements = processPageElements(pageElements, objectAttributes, []);
382
+ const processedPageElements = await processPageElements(pageElements, objectAttributes, []);
383
383
  elementKey = 0;
384
384
  const renderedPage = await serverSideRenderPage(
385
385
  processedPageElements,
@@ -535,6 +535,9 @@ var buildDynamicPage = async (filePath, DIST_DIR, req, res) => {
535
535
  console.warn(`WARNING: Dynamic ${filePath} should export a const page, which is of type BuiltElement<"body">.`);
536
536
  }
537
537
  if (typeof pageElements === "function") {
538
+ if (pageElements.constructor.name === "AsyncFunction") {
539
+ pageElements = await pageElements();
540
+ }
538
541
  pageElements = pageElements();
539
542
  }
540
543
  const state = getState();
@@ -20,7 +20,7 @@ export type LoadHook = {
20
20
  bind: number | string;
21
21
  };
22
22
  export type ClientLoadHook = {
23
- bind: number;
23
+ bind: string;
24
24
  fn: (state: State) => (void | (() => void) | Promise<(void | (() => void))>);
25
25
  };
26
26
  export declare const resetLoadHooks: () => never[];
@@ -308,12 +308,12 @@ var processOptionAsObjectAttribute = (element, optionName, optionValue, objectAt
308
308
  }
309
309
  objectAttributes.push({ ...optionValue, key, attribute: optionFinal });
310
310
  };
311
- var processPageElements = (element, objectAttributes, parent) => {
311
+ var processPageElements = async (element, objectAttributes, parent) => {
312
312
  if (typeof element === "boolean" || typeof element === "number" || Array.isArray(element)) return element;
313
313
  if (typeof element === "string") {
314
314
  return element;
315
315
  }
316
- const processElementOptionsAsChildAndReturn = () => {
316
+ const processElementOptionsAsChildAndReturn = async () => {
317
317
  const children = element.children;
318
318
  element.children = [
319
319
  element.options,
@@ -322,7 +322,7 @@ var processPageElements = (element, objectAttributes, parent) => {
322
322
  element.options = {};
323
323
  for (let i = 0; i < children.length + 1; i++) {
324
324
  const child = element.children[i];
325
- const processedChild = processPageElements(child, objectAttributes, element);
325
+ const processedChild = await processPageElements(child, objectAttributes, element);
326
326
  element.children[i] = processedChild;
327
327
  }
328
328
  return {
@@ -331,7 +331,7 @@ var processPageElements = (element, objectAttributes, parent) => {
331
331
  };
332
332
  };
333
333
  if (typeof element.options !== "object") {
334
- return processElementOptionsAsChildAndReturn();
334
+ return await processElementOptionsAsChildAndReturn();
335
335
  }
336
336
  const {
337
337
  tag: elementTag,
@@ -339,7 +339,7 @@ var processPageElements = (element, objectAttributes, parent) => {
339
339
  children: elementChildren
340
340
  } = element.options;
341
341
  if (elementTag && elementOptions && elementChildren) {
342
- return processElementOptionsAsChildAndReturn();
342
+ return await processElementOptionsAsChildAndReturn();
343
343
  }
344
344
  const options = element.options;
345
345
  for (const [optionName, optionValue] of Object.entries(options)) {
@@ -368,7 +368,7 @@ var processPageElements = (element, objectAttributes, parent) => {
368
368
  if (element.children) {
369
369
  for (let i = 0; i < element.children.length; i++) {
370
370
  const child = element.children[i];
371
- const processedChild = processPageElements(child, objectAttributes, element);
371
+ const processedChild = await processPageElements(child, objectAttributes, element);
372
372
  element.children[i] = processedChild;
373
373
  }
374
374
  }
@@ -379,7 +379,7 @@ var generateSuitablePageElements = async (pageLocation, pageElements, metadata,
379
379
  return [];
380
380
  }
381
381
  const objectAttributes = [];
382
- const processedPageElements = processPageElements(pageElements, objectAttributes, []);
382
+ const processedPageElements = await processPageElements(pageElements, objectAttributes, []);
383
383
  elementKey = 0;
384
384
  const renderedPage = await serverSideRenderPage(
385
385
  processedPageElements,
@@ -535,6 +535,9 @@ var buildDynamicPage = async (filePath, DIST_DIR, req, res) => {
535
535
  console.warn(`WARNING: Dynamic ${filePath} should export a const page, which is of type BuiltElement<"body">.`);
536
536
  }
537
537
  if (typeof pageElements === "function") {
538
+ if (pageElements.constructor.name === "AsyncFunction") {
539
+ pageElements = await pageElements();
540
+ }
538
541
  pageElements = pageElements();
539
542
  }
540
543
  const state = getState();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elegance-js",
3
- "version": "1.11.26",
3
+ "version": "1.11.28",
4
4
  "description": "Web-Framework",
5
5
  "type": "module",
6
6
  "bin": {