@adobe/helix-md2jcr 1.2.21 → 1.4.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/CHANGELOG.md +21 -0
- package/README.md +6 -0
- package/docs/block-options.md +116 -0
- package/docs/section-styles.md +65 -0
- package/docs/superpowers/plans/2026-06-08-section-style-grouping.md +969 -0
- package/package.json +3 -3
- package/src/mdast2jcr/domain/FieldGroup.js +3 -1
- package/src/mdast2jcr/domain/GroupOptions.js +112 -0
- package/src/mdast2jcr/domain/Models.js +29 -2
- package/src/mdast2jcr/hb/helpers/section-helper.js +23 -0
- package/src/mdast2jcr/hb/partials/grid-table.js +10 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-md2jcr",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Helix Service that converts markdown to JCR content structure",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -74,12 +74,12 @@
|
|
|
74
74
|
"husky": "^9.1.7",
|
|
75
75
|
"junit-report-builder": "5.1.2",
|
|
76
76
|
"lint-staged": "16.4.0",
|
|
77
|
-
"mocha": "11.7.
|
|
77
|
+
"mocha": "11.7.6",
|
|
78
78
|
"mocha-multi-reporters": "1.5.1",
|
|
79
79
|
"nock": "13.5.6",
|
|
80
80
|
"semantic-release": "25.0.3",
|
|
81
81
|
"unist-util-inspect": "8.1.0",
|
|
82
|
-
"yauzl": "3.3.
|
|
82
|
+
"yauzl": "3.3.1"
|
|
83
83
|
},
|
|
84
84
|
"lint-staged": {
|
|
85
85
|
"*.js": "eslint"
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
+
import { isClassesField } from './Models.js';
|
|
13
|
+
|
|
12
14
|
class FieldGroup {
|
|
13
15
|
/**
|
|
14
16
|
* Constructor.
|
|
@@ -35,7 +37,7 @@ class FieldGroup {
|
|
|
35
37
|
|
|
36
38
|
this.model.fields
|
|
37
39
|
.filter((field) => field.component !== 'tab')
|
|
38
|
-
.filter((field) => field.name
|
|
40
|
+
.filter((field) => !isClassesField(field.name))
|
|
39
41
|
.forEach((field) => {
|
|
40
42
|
if (field.name.includes('_')) {
|
|
41
43
|
const groupName = field.name.split('_')[0];
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { isGroupField } from './Models.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {import('../index.d.ts').ModelDef} Model
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Recursively collect every option `value` from a field's options tree
|
|
20
|
+
* (options may be nested under `children`).
|
|
21
|
+
* @param {Array<object>} options - The field's options array.
|
|
22
|
+
* @return {Array<string>} The flat list of option values.
|
|
23
|
+
*/
|
|
24
|
+
function collectOptionValues(options) {
|
|
25
|
+
return (options || []).flatMap((option) => {
|
|
26
|
+
if (option.children) {
|
|
27
|
+
return collectOptionValues(option.children);
|
|
28
|
+
}
|
|
29
|
+
return option.value !== undefined ? [option.value] : [];
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Distribute element-grouping tokens (a block header's classes, a container
|
|
35
|
+
* child's leading cell, or a section's `style` cell) across the model's group
|
|
36
|
+
* fields, per the AEM "element grouping for block options" rules:
|
|
37
|
+
*
|
|
38
|
+
* - a boolean field receives "true" when its name suffix (after `${group}_`)
|
|
39
|
+
* appears as a token (e.g. token "fullwidth" -> `${group}_fullwidth`="true");
|
|
40
|
+
* - a text/select field with options claims the tokens that match its option
|
|
41
|
+
* values (e.g. token "light" -> `${group}_background`="light");
|
|
42
|
+
* - any remaining tokens fall back to the base `${group}` field, which also
|
|
43
|
+
* covers the common single-field case (a free-form `${group}` field).
|
|
44
|
+
*
|
|
45
|
+
* Multi fields are written as `[a, b]`; single fields as a comma-separated list.
|
|
46
|
+
* The result is emitted in model-field order so callers that do not sort
|
|
47
|
+
* (e.g. sections) get deterministic, readable output.
|
|
48
|
+
* @param {Model} model - The block, item, or section model.
|
|
49
|
+
* @param {Array<string>} tokens - The option tokens.
|
|
50
|
+
* @param {string} [group] - The group name (defaults to `classes`).
|
|
51
|
+
* @return {Object<string, string>} A map of group field name to property value.
|
|
52
|
+
*/
|
|
53
|
+
function distributeGroupOptions(model, tokens, group = 'classes') {
|
|
54
|
+
const groupFields = (model?.fields || []).filter((f) => isGroupField(f.name, group));
|
|
55
|
+
if (groupFields.length === 0 || tokens.length === 0) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const suffixRegExp = new RegExp(`^${group}_`);
|
|
60
|
+
const remaining = [...tokens];
|
|
61
|
+
const assigned = new Map();
|
|
62
|
+
|
|
63
|
+
// boolean fields: the suffix after `${group}_` becomes the option when present
|
|
64
|
+
groupFields
|
|
65
|
+
.filter((field) => field.component === 'boolean')
|
|
66
|
+
.forEach((field) => {
|
|
67
|
+
const suffix = field.name.replace(suffixRegExp, '');
|
|
68
|
+
const idx = remaining.indexOf(suffix);
|
|
69
|
+
if (idx !== -1) {
|
|
70
|
+
assigned.set(field.name, true);
|
|
71
|
+
remaining.splice(idx, 1);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// text/select fields with options: claim the tokens that match their values
|
|
76
|
+
groupFields
|
|
77
|
+
.filter((field) => field.component !== 'boolean' && field.options)
|
|
78
|
+
.forEach((field) => {
|
|
79
|
+
const values = collectOptionValues(field.options);
|
|
80
|
+
const matched = remaining.filter((t) => values.includes(t));
|
|
81
|
+
if (matched.length > 0) {
|
|
82
|
+
assigned.set(field.name, matched);
|
|
83
|
+
matched.forEach((m) => remaining.splice(remaining.indexOf(m), 1));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// leftover tokens fall back to the base `${group}` field (and the single-field case)
|
|
88
|
+
const base = groupFields.find((f) => f.name === group && f.component !== 'boolean');
|
|
89
|
+
if (remaining.length > 0 && base) {
|
|
90
|
+
assigned.set(group, [...(assigned.get(group) || []), ...remaining]);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// emit in model-field order for deterministic, readable output
|
|
94
|
+
const result = {};
|
|
95
|
+
groupFields.forEach((field) => {
|
|
96
|
+
if (!assigned.has(field.name)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const value = assigned.get(field.name);
|
|
100
|
+
if (value === true) {
|
|
101
|
+
result[field.name] = 'true';
|
|
102
|
+
} else {
|
|
103
|
+
result[field.name] = field.multi === true ? `[${value.join(', ')}]` : value.join(', ');
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
collectOptionValues,
|
|
111
|
+
distributeGroupOptions,
|
|
112
|
+
};
|
|
@@ -42,7 +42,33 @@ function getField(model, fieldName) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Returns true if the field name belongs to an element-grouping group — either
|
|
46
|
+
* the base field named exactly `group`, or a grouped option field `group_<name>`
|
|
47
|
+
* (element grouping for block options / section styles).
|
|
48
|
+
* @param {string} name The field name.
|
|
49
|
+
* @param {string} group The group name (e.g. `classes` or `style`).
|
|
50
|
+
* @return {boolean}
|
|
51
|
+
*/
|
|
52
|
+
function isGroupField(name, group) {
|
|
53
|
+
return name === group || name.startsWith(`${group}_`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns true if the field name belongs to the `classes` block-options group —
|
|
58
|
+
* either the base `classes` field or a grouped `classes_*` option field
|
|
59
|
+
* (element grouping for block options).
|
|
60
|
+
* @param {string} name The field name.
|
|
61
|
+
* @return {boolean}
|
|
62
|
+
*/
|
|
63
|
+
function isClassesField(name) {
|
|
64
|
+
return isGroupField(name, 'classes');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Return a list of field names in the model. Block-option / section-style group
|
|
69
|
+
* fields (`classes`, `classes_*`, `style`, `style_*`) are included so the
|
|
70
|
+
* Universal Editor can render their controls; only `tab` fields (a UE layout
|
|
71
|
+
* construct, not a content field) are excluded.
|
|
46
72
|
* @param {Model} model The model.
|
|
47
73
|
* @return {Array<string>} An array of field names.
|
|
48
74
|
*/
|
|
@@ -51,7 +77,6 @@ function getModelFieldNames(model) {
|
|
|
51
77
|
? model.fields
|
|
52
78
|
.filter((f) => f.component !== 'tab')
|
|
53
79
|
.map((f) => f.name)
|
|
54
|
-
.filter((f) => f !== 'classes')
|
|
55
80
|
: [];
|
|
56
81
|
}
|
|
57
82
|
|
|
@@ -59,4 +84,6 @@ export {
|
|
|
59
84
|
getField,
|
|
60
85
|
findModelById,
|
|
61
86
|
getModelFieldNames,
|
|
87
|
+
isClassesField,
|
|
88
|
+
isGroupField,
|
|
62
89
|
};
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
getField,
|
|
19
19
|
getModelFieldNames,
|
|
20
20
|
} from '../../domain/Models.js';
|
|
21
|
+
import { distributeGroupOptions } from '../../domain/GroupOptions.js';
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Normalizes strings by converting to lowercase and replacing spaces with hyphens
|
|
@@ -61,6 +62,12 @@ function processMetadataRows(rows, model) {
|
|
|
61
62
|
// always push the model fields so UE can use them, even if no attributes are found
|
|
62
63
|
const modelFields = getModelFieldNames(model);
|
|
63
64
|
|
|
65
|
+
// a section uses element grouping when it declares a `style_*` field; in that
|
|
66
|
+
// case the single well-known `style` cell collapses the whole style group and
|
|
67
|
+
// must be distributed back across style / style_* fields. A model with only a
|
|
68
|
+
// base `style` field keeps the simple per-row mapping below.
|
|
69
|
+
const hasStyleGroup = (model?.fields || []).some((f) => f.name.startsWith('style_'));
|
|
70
|
+
|
|
64
71
|
for (const row of rows) {
|
|
65
72
|
const cells = findAll(row, (n) => n.type === 'gtCell', true);
|
|
66
73
|
if (cells.length < 2) {
|
|
@@ -77,6 +84,22 @@ function processMetadataRows(rows, model) {
|
|
|
77
84
|
continue;
|
|
78
85
|
}
|
|
79
86
|
|
|
87
|
+
// element grouping for section styles: route the flat `style` cell across
|
|
88
|
+
// the model's style group fields (boolean by name suffix, select/multiselect
|
|
89
|
+
// by declared options, leftovers to the base `style` field)
|
|
90
|
+
if (hasStyleGroup && key === 'style') {
|
|
91
|
+
Object.assign(
|
|
92
|
+
attributes,
|
|
93
|
+
distributeGroupOptions(
|
|
94
|
+
model,
|
|
95
|
+
value.split(',').map((s) => s.trim()).filter(Boolean),
|
|
96
|
+
'style',
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
// eslint-disable-next-line no-continue
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
80
103
|
const field = getField(model, key);
|
|
81
104
|
if (!field) {
|
|
82
105
|
// eslint-disable-next-line no-continue
|
|
@@ -19,8 +19,9 @@ import { toHtml } from 'hast-util-to-html';
|
|
|
19
19
|
import { getComponentById, getComponentByTitle, getModelId } from '../../domain/Definitions.js';
|
|
20
20
|
import {
|
|
21
21
|
findModelById,
|
|
22
|
-
|
|
22
|
+
getModelFieldNames, isClassesField,
|
|
23
23
|
} from '../../domain/Models.js';
|
|
24
|
+
import { distributeGroupOptions } from '../../domain/GroupOptions.js';
|
|
24
25
|
import { findAll } from '../../utils/mdast.js';
|
|
25
26
|
import link from './supports/link.js';
|
|
26
27
|
import {
|
|
@@ -105,14 +106,10 @@ function extractBlockHeaderProperties(models, definition, mdast) {
|
|
|
105
106
|
|
|
106
107
|
const model = findModelById(models, blockDetails.modelId);
|
|
107
108
|
|
|
108
|
-
// section metadata may not have a model
|
|
109
|
+
// section metadata may not have a model. Distribute the header's block options
|
|
110
|
+
// across the model's classes group fields (element grouping for block options).
|
|
109
111
|
if (model) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (blockDetails.classes.length > 0 && classesField) {
|
|
113
|
-
props.classes = (classesField.multi === true)
|
|
114
|
-
? `[${blockDetails.classes.join(', ')}]` : blockDetails.classes.join(', ');
|
|
115
|
-
}
|
|
112
|
+
Object.assign(props, distributeGroupOptions(model, blockDetails.classes, 'classes'));
|
|
116
113
|
}
|
|
117
114
|
|
|
118
115
|
return props;
|
|
@@ -353,14 +350,10 @@ function extractProperties(
|
|
|
353
350
|
|
|
354
351
|
// the first cells is the header row, so we skip it
|
|
355
352
|
const rows = findAll(mdast, (node) => node.type === 'gtRow', false);
|
|
356
|
-
let classesField;
|
|
357
353
|
if (mode === 'blockItem') {
|
|
358
|
-
|
|
359
|
-
//
|
|
360
|
-
if (
|
|
361
|
-
// if we are a block item we need to look at the first cell to see if it has any class
|
|
362
|
-
// properties by inspecting the text value for any commas
|
|
363
|
-
// if there is a comma that then becomes the classes property for the block item
|
|
354
|
+
// if our model defines any classes group field then dig the block options out
|
|
355
|
+
// of the first cell (the component id followed by optional class names)
|
|
356
|
+
if ((model.fields || []).some((f) => isClassesField(f.name))) {
|
|
364
357
|
const firstCell = rows[0].children[0];
|
|
365
358
|
const textValue = toString(firstCell);
|
|
366
359
|
const classes = textValue.split(',').map((c) => c.trim());
|
|
@@ -368,11 +361,8 @@ function extractProperties(
|
|
|
368
361
|
// discard the component name leaving only the block option names (class names)
|
|
369
362
|
classes.shift();
|
|
370
363
|
|
|
371
|
-
//
|
|
372
|
-
|
|
373
|
-
properties.classes = classesField?.multi === true
|
|
374
|
-
? `[${classes.join(', ')}]` : classes.join(', ');
|
|
375
|
-
}
|
|
364
|
+
// distribute the options across the model's classes group fields
|
|
365
|
+
Object.assign(properties, distributeGroupOptions(model, classes, 'classes'));
|
|
376
366
|
}
|
|
377
367
|
} else {
|
|
378
368
|
// get rid of the header row, no need for that
|