Skip to content

Commit

Permalink
filter allowed elements in dropzones
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Fabel authored and Oliver Fabel committed Nov 21, 2022
1 parent 3c45245 commit ac84c83
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 20 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.10.4-rc.1] - 21.11.2022

### Fixed

* Filter allowed elements for dropzones in respect of the elements listed in groups.

## [1.10.3] - 08.08.2022

### Fixed
Expand Down Expand Up @@ -463,6 +469,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

[Unreleased]: https://github.com/bsi-software/bsi-cx-design-build/compare/1.10.3...HEAD

[1.10.4-rc.1]: https://github.com/bsi-software/bsi-cx-design-build/compare/1.10.4-rc.1...HEAD

[1.10.3]: https://github.com/bsi-software/bsi-cx-design-build/compare/1.10.2...1.10.3

[1.10.2]: https://github.com/bsi-software/bsi-cx-design-build/compare/1.10.1...1.10.2
Expand Down
33 changes: 26 additions & 7 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/types.d.ts.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bsi-cx/design-build",
"version": "1.10.3",
"version": "1.10.4-rc.1",
"description": "A webpack config builder to create a design for BSI CX.",
"private": false,
"engines": {
Expand Down
33 changes: 26 additions & 7 deletions src/bsi-cx-webpack-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,49 @@ class _BsiCxWebpackPlugin {
* @private
*/
_createReplaceMap(designJsonObj) {
/**
* @type {Set<string>}
*/
let knownElements = this._createSetOfKnownElements(designJsonObj);
/**
* @type {Map<string, function(string):string>}
*/
let replaceMap = new Map();

this._addDropzonesToReplaceMap(designJsonObj, replaceMap);
this._addDropzonesToReplaceMap(designJsonObj, replaceMap, knownElements);

designJsonObj[DesignJsonProperty.CONTENT_ELEMENT_GROUPS]
?.forEach(group => group[DesignJsonProperty.CONTENT_ELEMENTS]
?.forEach(element => this._addElementToReplaceMap(element, replaceMap)));
?.forEach(element => this._addElementToReplaceMap(element, replaceMap, knownElements)));

let website = designJsonObj[DesignJsonProperty.WEBSITE] ?? {};
Object.values(website[DesignJsonProperty.INCLUDES] ?? {})
.forEach(include => this._addDropzonesToReplaceMap(include, replaceMap));
.forEach(include => this._addDropzonesToReplaceMap(include, replaceMap, knownElements));

return replaceMap;
}

/**
* @param {{}} designJsonObj
* @returns {Set<string>}
* @private
*/
_createSetOfKnownElements(designJsonObj) {
let knownElements = designJsonObj[DesignJsonProperty.CONTENT_ELEMENT_GROUPS]
?.flatMap(group => group[DesignJsonProperty.CONTENT_ELEMENTS]
?.map(element => element[DesignJsonProperty.ELEMENT_ID]));

return new Set(knownElements);
}

/**
* @param {{}} element
* @param {Map<string, function(string):string>} replaceMap
* @param {Set<string>} knownElements
* @private
*/
_addElementToReplaceMap(element, replaceMap) {
this._addDropzonesToReplaceMap(element, replaceMap);
_addElementToReplaceMap(element, replaceMap, knownElements) {
this._addDropzonesToReplaceMap(element, replaceMap, knownElements);

element[DesignJsonProperty.PARTS]
?.filter(part => !!part[DesignJsonProperty.ID])
Expand All @@ -214,17 +232,18 @@ class _BsiCxWebpackPlugin {
/**
* @param {{}} objScope
* @param {Map<string, function(string):string>} replaceMap
* @param {Set<string>} knownElements
* @private
*/
_addDropzonesToReplaceMap(objScope, replaceMap) {
_addDropzonesToReplaceMap(objScope, replaceMap, knownElements) {
/**
* @type {{}[]}
*/
let dropzones = objScope[DesignJsonPropertyExtension.DROPZONES] ?? [];

dropzones.forEach(dropzone => {
let dropzoneId = dropzone[DesignJsonPropertyExtension.DROPZONE];
let allowedElements = dropzone[DesignJsonPropertyExtension.ALLOWED_ELEMENTS]?.join(' ');
let allowedElements = dropzone[DesignJsonPropertyExtension.ALLOWED_ELEMENTS]?.filter(id => knownElements.has(id)).join(' ');
let maxElements = dropzone[DesignJsonPropertyExtension.MAX_ALLOWED_ELEMENTS];
let removeAllowed = dropzone[DesignJsonPropertyExtension.REMOVE_ALLOWED];
let moveAllowed = dropzone[DesignJsonPropertyExtension.MOVE_ALLOWED];
Expand Down
2 changes: 1 addition & 1 deletion test/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = WebpackConfigBuilder.fromConfigs(
.withName('landingpage')
.withVersion('1.0.0-alpha')
.withDesignType(DesignType.WEBSITE)
.withTargetVersion(Version.CX_1_3)
.withTargetVersion(Version.CX_22_0)
.withRootPath(path.resolve(__dirname, 'templates', 'landingpage'))
.withPropertiesFilePath('properties.js')
.withWebpackPlugins(new webpack.ProvidePlugin({
Expand Down

0 comments on commit ac84c83

Please sign in to comment.