@adobe/helix-md2jcr 1.1.0 → 1.1.2

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,17 @@
1
+ ## [1.1.2](https://github.com/adobe/helix-md2jcr/compare/v1.1.1...v1.1.2) (2025-02-26)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **sites-29541:** allow model fields to be in mixed order ([#62](https://github.com/adobe/helix-md2jcr/issues/62)) ([c7592c4](https://github.com/adobe/helix-md2jcr/commit/c7592c4a6825bc9b2a53b48034a1691fef263001))
7
+
8
+ ## [1.1.1](https://github.com/adobe/helix-md2jcr/compare/v1.1.0...v1.1.1) (2025-02-25)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update dependency @adobe/remark-gridtables to v3.0.10 ([#61](https://github.com/adobe/helix-md2jcr/issues/61)) ([f6e113d](https://github.com/adobe/helix-md2jcr/commit/f6e113d532bc9e844c09744452a9a8e18c7e821b))
14
+
1
15
  # [1.1.0](https://github.com/adobe/helix-md2jcr/compare/v1.0.16...v1.1.0) (2025-02-25)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-md2jcr",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Helix Service that converts markdown to JCR content structure",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  "@adobe/fetch": "4.1.11",
32
32
  "@adobe/helix-markdown-support": "7.1.12",
33
33
  "@adobe/helix-shared-process-queue": "3.1.1",
34
- "@adobe/remark-gridtables": "3.0.9",
34
+ "@adobe/remark-gridtables": "3.0.10",
35
35
  "entities": "^5.0.0",
36
36
  "github-slugger": "2.0.0",
37
37
  "handlebars": "^4.7.8",
@@ -62,6 +62,7 @@
62
62
  "@semantic-release/exec": "6.0.3",
63
63
  "@semantic-release/git": "10.0.1",
64
64
  "c8": "10.1.3",
65
+ "chai": "^5.2.0",
65
66
  "dotenv": "16.4.7",
66
67
  "eslint": "8.57.1",
67
68
  "eslint-import-resolver-exports": "1.0.0-beta.5",
@@ -19,7 +19,7 @@ class Component {
19
19
  * Create a new Component.
20
20
  * @param {string} name
21
21
  * @param {string} id
22
- * @param {object} template
22
+ * @param {Object} template
23
23
  */
24
24
  constructor(name, id, template) {
25
25
  this._template = template;
@@ -30,27 +30,50 @@ class Component {
30
30
  this._id = id;
31
31
  }
32
32
 
33
+ /**
34
+ * Get the ID for the component.
35
+ * @return {string}
36
+ */
33
37
  get id() {
34
38
  return this._id;
35
39
  }
36
40
 
41
+ /**
42
+ * Get the filter ID for the component.
43
+ * @return {string}
44
+ */
37
45
  get filterId() {
38
46
  return this._filterId;
39
47
  }
40
48
 
49
+ /**
50
+ * Get the model ID for the component.
51
+ * @return {string}
52
+ */
41
53
  get modelId() {
42
54
  return this._modelId;
43
55
  }
44
56
 
57
+ /**
58
+ * Return true or false if the component is a key-value component.
59
+ * @return {boolean}
60
+ */
45
61
  get keyValue() {
46
62
  return this._keyValue;
47
63
  }
48
64
 
65
+ /**
66
+ * Get the name of the component.
67
+ * @return {string}
68
+ */
49
69
  get name() {
50
70
  return this._name;
51
71
  }
52
72
 
53
- /* eslint-disable no-unused-vars */
73
+ /**
74
+ * Return the component's default fields specified in the template section.
75
+ * @return {Object}
76
+ */
54
77
  get defaultFields() {
55
78
  return this._template;
56
79
  }
@@ -27,7 +27,7 @@ class ModelHelper {
27
27
  */
28
28
  constructor(blockName, models, definition, filters) {
29
29
  this.blockName = blockName;
30
- this._checkFieldOrder(models);
30
+ this._fixFieldOrder(models);
31
31
  this.models = models;
32
32
  this.definition = definition;
33
33
  this.filters = filters;
@@ -35,37 +35,31 @@ class ModelHelper {
35
35
  this._groupModelFields();
36
36
  }
37
37
 
38
+ /**
39
+ * The field order in the models is not guaranteed to be correct. This method will fix the order
40
+ * of the fields in the models so that the base field is followed by the suffix fields.
41
+ * @param {Array<Model>} models The models to fix the field order.
42
+ * @private {void}
43
+ */
38
44
  // eslint-disable-next-line class-methods-use-this
39
- _checkFieldOrder(models) {
45
+ _fixFieldOrder(models) {
40
46
  const suffixes = ['Alt', 'MimeType', 'Type', 'Text', 'Title'];
41
47
 
42
48
  models.forEach((model) => {
43
- const seenBaseFields = new Set();
44
- let warningGenerated = false;
45
- const warnings = [];
46
-
47
- model.fields.forEach((field) => {
48
- const suffixMatch = suffixes.find((suffix) => field.name.endsWith(suffix));
49
- const baseName = suffixMatch ? field.name.slice(0, -suffixMatch.length) : field.name;
50
-
51
- if (suffixMatch) {
52
- // This is a suffix field, we need to check if its base field exists
53
- if (!seenBaseFields.has(baseName)) {
54
- if (!warningGenerated) {
55
- warnings.push(`Warning in model '${model.id}': Fields with suffixes should follow their base field.`);
56
- warningGenerated = true;
57
- }
58
- warnings.push(` - Field '${field.name}' appears before its base field '${baseName}'.`);
59
- }
60
- } else {
61
- // This is a base field, add it to seenBaseFields
62
- seenBaseFields.add(baseName);
63
- }
64
- });
65
-
66
- if (warningGenerated) {
67
- throw new Error(warnings.join('\n'));
68
- }
49
+ // collect the name of all the model fields that do not have a suffix
50
+ const baseFields = model.fields
51
+ .filter((field) => !suffixes.some((suffix) => field.name.endsWith(suffix)))
52
+ .map((field) => field.name);
53
+
54
+ // for each base field, find the associated fields with suffixes and update the model
55
+ // fixing the order so that we can later group things together
56
+ // eslint-disable-next-line no-param-reassign
57
+ model.fields = baseFields.flatMap((baseField) => [
58
+ // will return array with [field, fieldText, fieldType, etc]
59
+ model.fields.find((field) => field.name === baseField),
60
+ ...suffixes
61
+ .map((suffix) => model.fields.find((field) => field.name === `${baseField}${suffix}`))
62
+ .filter(Boolean)]);
69
63
  });
70
64
  }
71
65