coralite 0.5.0 → 0.5.1
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/lib/coralite.js +2 -2
- package/lib/html-module.js +4 -3
- package/lib/parse.js +21 -3
- package/package.json +1 -1
- package/types/index.js +5 -0
package/lib/coralite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @import { CoraliteElement, CoraliteTextNode } from '#types'
|
|
2
|
+
* @import { CoraliteElement, CoraliteTextNode, CoraliteAggregateTemplate } from '#types'
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -30,7 +30,7 @@ export async function defineComponent (options) {
|
|
|
30
30
|
* Aggregates HTML content from specified paths into a single collection of components.
|
|
31
31
|
*
|
|
32
32
|
* @param {Object} options - Configuration object for the aggregation process
|
|
33
|
-
* @param {string} options.
|
|
33
|
+
* @param {CoraliteAggregateTemplate | string} options.template - Templates used to display the result
|
|
34
34
|
* @param {string} options.path - The path to aggregate, relative to pages directory
|
|
35
35
|
* @returns {Promise<(CoraliteElement | CoraliteTextNode)[]>}
|
|
36
36
|
*/
|
package/lib/html-module.js
CHANGED
|
@@ -11,7 +11,8 @@ import { createComponent, parseHTMLMeta } from './parse.js'
|
|
|
11
11
|
*
|
|
12
12
|
* @param {Object} options - Configuration object for the aggregation process
|
|
13
13
|
* @param {string} options.path - The path to aggregate, relative to pages directory
|
|
14
|
-
* @param {
|
|
14
|
+
* @param {Object} options.template - Templates used to display the result
|
|
15
|
+
* @param {string} options.template.item - Unique identifier for the component used for each document
|
|
15
16
|
* @param {boolean} [options.recursive] - Whether to recursively search subdirectories
|
|
16
17
|
* @param {CoraliteTokenOptions} [options.tokens] - Token configuration options
|
|
17
18
|
* @param {CoraliteModuleValues} values - Default token values
|
|
@@ -24,7 +25,7 @@ import { createComponent, parseHTMLMeta } from './parse.js'
|
|
|
24
25
|
* aggregate({
|
|
25
26
|
* path: 'button',
|
|
26
27
|
* recursive: true,
|
|
27
|
-
*
|
|
28
|
+
* template: { item: 'my-component' }
|
|
28
29
|
* }, {
|
|
29
30
|
* className: 'btn'
|
|
30
31
|
* }, components, document);
|
|
@@ -62,7 +63,7 @@ export async function aggregate (options, values, components, document) {
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
const component = await createComponent({
|
|
65
|
-
id: options.
|
|
66
|
+
id: options.template.item,
|
|
66
67
|
values: pageValues,
|
|
67
68
|
components,
|
|
68
69
|
document
|
package/lib/parse.js
CHANGED
|
@@ -18,6 +18,7 @@ import { invalidCustomTags, validTags } from './tags.js'
|
|
|
18
18
|
* CoraliteDocumentRoot,
|
|
19
19
|
* CoraliteContentNode,
|
|
20
20
|
* CoraliteModuleValues,
|
|
21
|
+
* CoraliteAggregateTemplate
|
|
21
22
|
* } from '#types'
|
|
22
23
|
*/
|
|
23
24
|
|
|
@@ -625,6 +626,7 @@ export async function createComponent ({
|
|
|
625
626
|
*/
|
|
626
627
|
export async function parseScript (component, values, element, components, document) {
|
|
627
628
|
const contextifiedObject = vm.createContext({
|
|
629
|
+
crypto,
|
|
628
630
|
coralite: {
|
|
629
631
|
tokens: values,
|
|
630
632
|
/**
|
|
@@ -692,15 +694,31 @@ export async function parseScript (component, values, element, components, docum
|
|
|
692
694
|
return values
|
|
693
695
|
},
|
|
694
696
|
/**
|
|
697
|
+
* @overload
|
|
695
698
|
* @param {Object} options
|
|
696
|
-
* @param {string} options.
|
|
699
|
+
* @param {string} options.template - Templates used to display the result
|
|
700
|
+
* @param {string} options.path
|
|
701
|
+
*/
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* @param {Object} options
|
|
705
|
+
* @param {CoraliteAggregateTemplate} options.template - Templates used to display the result
|
|
697
706
|
* @param {string} options.path
|
|
698
707
|
*/
|
|
699
708
|
async aggregate (options) {
|
|
700
|
-
|
|
709
|
+
/** @type {string} */
|
|
710
|
+
let templateId
|
|
711
|
+
|
|
712
|
+
if (typeof options.template === 'string') {
|
|
713
|
+
templateId = options.template
|
|
714
|
+
} else {
|
|
715
|
+
templateId = options.template.item
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
const component = components[templateId]
|
|
701
719
|
|
|
702
720
|
if (!component) {
|
|
703
|
-
throw new Error('Aggregate: no
|
|
721
|
+
throw new Error('Aggregate: no template found by the id: ' + templateId)
|
|
704
722
|
}
|
|
705
723
|
|
|
706
724
|
return await aggregate(options, values, components, document)
|
package/package.json
CHANGED
package/types/index.js
CHANGED
|
@@ -123,3 +123,8 @@
|
|
|
123
123
|
* @property {CoraliteElement[]} customElements - Custom elements defined in the document
|
|
124
124
|
* @property {CoralitePath} path - Document's file path
|
|
125
125
|
*/
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @typedef {Object} CoraliteAggregateTemplate - Templates used to display the result
|
|
129
|
+
* @property {string} item - Unique identifier for the component used for each document
|
|
130
|
+
*/
|