coralite 0.6.8 → 0.7.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/changelog.md CHANGED
@@ -1,3 +1,34 @@
1
+ # 🎁 Release notes (`v0.7.0`)
2
+
3
+ ## Changes
4
+ - d7b183d (HEAD -> main, tag: v0.7.0, origin/main) fix: use type helper to confirm child is a node - (*Thomas David*)
5
+ - b574569 feat: check if slot is a node - (*Thomas David*)
6
+ - de05e38 feat: type helper functions - (*Thomas David*)
7
+ - 24f3935 test: cover nested components attributes - (*Thomas David*)
8
+ - 8dc8f5d fix: apply nested custom component attribute values - (*Thomas David*)
9
+ - 3fa3eb5 chore: version bump - (*Thomas David*)
10
+
11
+ ## Metadata
12
+ ```
13
+ This version -------- v0.7.0
14
+ Previous version ---- v0.6.9
15
+ Total commits ------- 6
16
+ ```
17
+ # 🎁 Release notes (`v0.6.9`)
18
+
19
+ ## Changes
20
+ - e79d7c9 (HEAD -> main, tag: v0.6.9, origin/main) fix: aggregation limit is offset by offset - (*[Thomas David](https://codeberg.org/tjdavid)*)
21
+ - 6f8253f test: cover nested document root components - (*[Thomas David](https://codeberg.org/tjdavid)*)
22
+ - 77d0e36 feat: create nested custom elements on document root - (*[Thomas David](https://codeberg.org/tjdavid)*)
23
+ - 2c176e5 chore: update changelog - (*[Thomas David](https://codeberg.org/tjdavid)*)
24
+ - f5a3639 chore: version bump - (*[Thomas David](https://codeberg.org/tjdavid)*)
25
+
26
+ ## Metadata
27
+ ```
28
+ This version -------- v0.6.9
29
+ Previous version ---- v0.6.8
30
+ Total commits ------- 5
31
+ ```
1
32
  # 🎁 Release notes (`v0.6.8`)
2
33
 
3
34
  ## Changes
@@ -62,18 +62,23 @@ export async function aggregate (options, values, components, document) {
62
62
  let startIndex = 0
63
63
  let endIndex = pages.length
64
64
 
65
- if (options.limit && options.limit < pages.length) {
66
- endIndex = options.limit
67
- }
68
-
69
65
  if (options.offset) {
70
66
  if (options.offset > endIndex) {
71
- startIndex = endIndex - 1
67
+ startIndex = endIndex
72
68
  } else {
73
69
  startIndex = options.offset
74
70
  }
75
71
  }
76
72
 
73
+ if (options.limit) {
74
+ const limit = options.limit + startIndex
75
+
76
+ if (limit < endIndex) {
77
+ endIndex = limit
78
+ }
79
+ }
80
+
81
+
77
82
  for (let i = startIndex; i < endIndex; i++) {
78
83
  const page = pages[i]
79
84
  const meta = parseHTMLMeta(page.content)
package/lib/parse.js CHANGED
@@ -3,6 +3,8 @@ import { aggregate } from './html-module.js'
3
3
  import vm from 'node:vm'
4
4
  import { invalidCustomTags, validTags } from './tags.js'
5
5
  import { join } from 'path'
6
+ import { isCoraliteComment, isCoraliteElement, isCoraliteTextNode } from './type-helper.js'
7
+
6
8
  /**
7
9
  * @import {Module} from 'node:vm'
8
10
  * @import {
@@ -567,7 +569,8 @@ export async function createComponent ({
567
569
  node
568
570
  }
569
571
 
570
- if (node.attribs && node.attribs.slot) {
572
+ if (isCoraliteElement(node)) {
573
+ // @ts-ignore
571
574
  slotElement.name = node.attribs.slot
572
575
  }
573
576
 
@@ -576,10 +579,8 @@ export async function createComponent ({
576
579
  }
577
580
 
578
581
  // append custom attributes to values
579
- for (const key in customElement.attribs) {
580
- if (!values.hasOwnProperty(key)) {
581
- values[key] = customElement.attribs[key]
582
- }
582
+ if (customElement.attribs) {
583
+ values = Object.assign(values, customElement.attribs)
583
584
  }
584
585
 
585
586
  const component = await createComponent({
@@ -643,6 +644,27 @@ export async function createComponent ({
643
644
  if (!slotNodes.length) {
644
645
  // set default content
645
646
  slotNodes = slot.element.children || []
647
+ } else {
648
+ const startIndex = slotNodes.length - 1
649
+
650
+ for (let i = startIndex; i > -1; i--) {
651
+ const node = slotNodes[i]
652
+ const component = components[node.name]
653
+
654
+ if (component) {
655
+ const component = await createComponent({
656
+ id: node.name,
657
+ values,
658
+ element: node,
659
+ components,
660
+ document
661
+ })
662
+
663
+ if (component) {
664
+ slotNodes.splice(i, 1, ...component.children)
665
+ }
666
+ }
667
+ }
646
668
  }
647
669
 
648
670
  // replace slot element with content
@@ -780,11 +802,23 @@ export async function parseScript ({
780
802
  })
781
803
  } else if (Array.isArray(result)) {
782
804
  for (let index = 0; index < result.length; index++) {
783
- /** @TODO create a node checker to verify */
784
- elementSlots.push({
785
- name,
786
- node: result[index]
787
- })
805
+ const node = result[index]
806
+
807
+ if (
808
+ isCoraliteElement(node)
809
+ || isCoraliteTextNode(node)
810
+ || isCoraliteComment(node)
811
+ ) {
812
+ elementSlots.push({
813
+ name,
814
+ node: result[index]
815
+ })
816
+ } else {
817
+ throw new Error('Unexpected slot value, expected a node but found: '
818
+ + '\n result: ' + JSON.stringify(node)
819
+ + '\n component: "' + component.id + '"'
820
+ + '\n path: "' + join(document.parentPath, document.name) +'"')
821
+ }
788
822
  }
789
823
  }
790
824
 
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Check if value is an object
3
+ * @param {Object} obj - The object to check
4
+ */
5
+ function isObject (obj) {
6
+ return typeof obj === 'object' && obj !== null
7
+ }
8
+
9
+ /**
10
+ * Checks if an object is a CoraliteElement.
11
+ * @param {Object} obj - The object to check.
12
+ * @returns {boolean} True if the object is a CoraliteElement, false otherwise.
13
+ */
14
+ function isCoraliteElement (obj) {
15
+ return isObject(obj) && obj.type === 'tag'
16
+ }
17
+
18
+ /**
19
+ * Checks if an object is a CoraliteTextNode.
20
+ * @param {Object} obj - The object to check.
21
+ * @returns {boolean} True if the object is a CoraliteTextNode, false otherwise.
22
+ */
23
+ function isCoraliteTextNode (obj) {
24
+ return isObject(obj) && obj.type === 'text'
25
+ }
26
+
27
+ /**
28
+ * Checks if an object is a CoraliteComment.
29
+ * @param {Object} obj - The object to check.
30
+ * @returns {boolean} True if the object is a CoraliteComment, false otherwise.
31
+ */
32
+ function isCoraliteComment (obj) {
33
+ return isObject(obj) && obj.type === 'comment'
34
+ }
35
+
36
+
37
+ // Export the functions (if using modules) - important for reusability
38
+ export {
39
+ isCoraliteElement,
40
+ isCoraliteTextNode,
41
+ isCoraliteComment
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coralite",
3
- "version": "0.6.8",
3
+ "version": "0.7.0",
4
4
  "description": "HTML modules static site generator",
5
5
  "main": "./lib/coralite.js",
6
6
  "type": "module",