coralite 0.6.9 → 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,19 @@
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
+ ```
1
17
  # 🎁 Release notes (`v0.6.9`)
2
18
 
3
19
  ## Changes
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({
@@ -801,11 +802,23 @@ export async function parseScript ({
801
802
  })
802
803
  } else if (Array.isArray(result)) {
803
804
  for (let index = 0; index < result.length; index++) {
804
- /** @TODO create a node checker to verify */
805
- elementSlots.push({
806
- name,
807
- node: result[index]
808
- })
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
+ }
809
822
  }
810
823
  }
811
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.9",
3
+ "version": "0.7.0",
4
4
  "description": "HTML modules static site generator",
5
5
  "main": "./lib/coralite.js",
6
6
  "type": "module",