@kitconcept/volto-light-theme 5.0.0 → 6.0.0-alpha.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.draft +26 -10
- package/CHANGELOG.md +44 -0
- package/README.md +7 -367
- package/package.json +23 -10
- package/razzle.extend.js +38 -0
- package/src/components/Anontools/Anontools.jsx +1 -1
- package/src/components/Blocks/Button/schema.js +25 -5
- package/src/components/Blocks/EventMetadata/View.jsx +8 -7
- package/src/components/Blocks/Image/Edit.jsx +4 -6
- package/src/components/Blocks/Image/ImageSidebar.jsx +4 -2
- package/src/components/Blocks/Image/View.jsx +3 -6
- package/src/components/Blocks/Image/schema.js +37 -6
- package/src/components/Blocks/Listing/DefaultTemplate.jsx +3 -2
- package/src/components/Blocks/Listing/GridTemplate.jsx +4 -2
- package/src/components/Blocks/Listing/ImageGallery.jsx +2 -2
- package/src/components/Blocks/Listing/SummaryTemplate.jsx +3 -2
- package/src/components/Blocks/Search/components/SearchInput.jsx +1 -1
- package/src/components/Blocks/Separator/schema.js +59 -0
- package/src/components/Blocks/Slider/DefaultBody.jsx +4 -2
- package/src/components/Blocks/Teaser/schema.js +21 -1
- package/src/components/Blocks/schema.js +16 -15
- package/src/components/Breadcrumbs/Breadcrumbs.jsx +4 -3
- package/src/components/Footer/Footer.jsx +77 -27
- package/src/components/Header/Header.jsx +37 -30
- package/src/components/LanguageSelector/{LanguageSelector.js → LanguageSelector.jsx} +11 -7
- package/src/components/Logo/Logo.jsx +28 -22
- package/src/components/MobileNavigation/MobileNavigation.jsx +3 -2
- package/src/components/MobileNavigation/MobileToolsFooter.jsx +1 -1
- package/src/components/Navigation/Navigation.jsx +4 -3
- package/src/components/SearchWidget/IntranetSearchWidget.jsx +1 -1
- package/src/components/SearchWidget/SearchWidget.jsx +1 -1
- package/src/components/Theme/EventView.jsx +3 -2
- package/src/components/Theme/FileView.jsx +1 -1
- package/src/components/Theme/NewsItemView.jsx +1 -1
- package/src/components/Theming/Theming.tsx +52 -0
- package/src/components/Widgets/AlignWidget.jsx +2 -2
- package/src/components/Widgets/BackgroundColorWidget.tsx +18 -0
- package/src/components/Widgets/BlockAlignmentWidget.tsx +81 -0
- package/src/components/Widgets/BlockWidthWidget.tsx +94 -0
- package/src/components/Widgets/BlocksObjectWidget.tsx +333 -0
- package/src/components/Widgets/ButtonsWidget.tsx +68 -0
- package/src/components/Widgets/ColorPickerWidget.tsx +60 -0
- package/src/components/Widgets/FooterLinksWidget.tsx +106 -0
- package/src/components/Widgets/FooterLogosWidget.tsx +120 -0
- package/src/components/Widgets/ThemingColorPicker.tsx +33 -0
- package/src/config/blocks.tsx +352 -0
- package/src/config/classExtenders.ts +101 -0
- package/src/config/settings.ts +35 -0
- package/src/config/slots.ts +12 -0
- package/src/config/widgets.ts +31 -0
- package/src/customizations/volto/components/theme/View/RenderBlocks.jsx +97 -80
- package/src/customizations/volto/components/theme/View/RenderBlocks.test.jsx +16 -48
- package/src/helpers/helpers.test.ts +51 -0
- package/src/helpers/helpers.ts +48 -0
- package/src/index.ts +54 -0
- package/src/theme/_bgcolor-blocks-layout.scss +1127 -20
- package/src/theme/_footer.scss +8 -5
- package/src/theme/_header.scss +3 -8
- package/src/theme/_layout.scss +24 -7
- package/src/theme/_typo-custom.scss +1 -1
- package/src/theme/_variables.scss +95 -12
- package/src/theme/_widgets.scss +102 -0
- package/src/theme/blocks/_accordion.scss +2 -4
- package/src/theme/blocks/_button.scss +32 -31
- package/src/theme/blocks/_eventMetadata.scss +7 -0
- package/src/theme/blocks/_grid.scss +11 -36
- package/src/theme/blocks/_highlight.scss +1 -0
- package/src/theme/blocks/_image.scss +38 -17
- package/src/theme/blocks/_introduction.scss +16 -0
- package/src/theme/blocks/_listing.scss +1 -6
- package/src/theme/blocks/_search.scss +1 -23
- package/src/theme/blocks/_separator.scss +17 -20
- package/src/theme/blocks/_slider.scss +57 -56
- package/src/theme/blocks/_teaser.scss +3 -3
- package/src/theme/main.scss +1 -0
- package/src/transforms/to6.ts +94 -0
- package/tsconfig.json +33 -0
- package/.release-it.json +0 -31
- package/babel.config.js +0 -17
- package/build/messages/src/components/Anontools/Anontools.json +0 -10
- package/build/messages/src/components/Blocks/Button/schema.json +0 -6
- package/build/messages/src/components/Blocks/EventMetadata/View.json +0 -30
- package/build/messages/src/components/Blocks/Image/Edit.json +0 -10
- package/build/messages/src/components/Blocks/Image/ImageSidebar.json +0 -18
- package/build/messages/src/components/Blocks/Image/schema.json +0 -10
- package/build/messages/src/components/Blocks/Listing/ListingBody.json +0 -26
- package/build/messages/src/components/Blocks/Search/TopSideFacets.json +0 -10
- package/build/messages/src/components/Blocks/Search/components/SearchDetails.json +0 -10
- package/build/messages/src/components/Blocks/Search/components/SearchInput.json +0 -6
- package/build/messages/src/components/Blocks/Slider/DefaultBody.json +0 -18
- package/build/messages/src/components/Blocks/Slider/schema.json +0 -14
- package/build/messages/src/components/Blocks/schema.json +0 -6
- package/build/messages/src/components/Breadcrumbs/Breadcrumbs.json +0 -10
- package/build/messages/src/components/Footer/Footer.json +0 -30
- package/build/messages/src/components/Header/Header.json +0 -6
- package/build/messages/src/components/LanguageSelector/LanguageSelector.json +0 -6
- package/build/messages/src/components/Logo/Logo.json +0 -10
- package/build/messages/src/components/MobileNavigation/MobileNavigation.json +0 -26
- package/build/messages/src/components/Navigation/Navigation.json +0 -10
- package/build/messages/src/components/SearchWidget/IntranetSearchWidget.json +0 -14
- package/build/messages/src/components/SearchWidget/SearchWidget.json +0 -10
- package/build/messages/src/components/Theme/EventView.json +0 -6
- package/build/messages/src/components/Widgets/AlignWidget.json +0 -22
- package/build/messages/src/index.json +0 -10
- package/news/.gitkeep +0 -0
- package/src/components/Atoms/Container/Container.jsx +0 -32
- package/src/components/Atoms/README.md +0 -1
- package/src/components/Atoms/helpers.jsx +0 -9
- package/src/components/CQPolyfill.jsx +0 -9
- package/src/index.js +0 -367
- package/towncrier.toml +0 -33
- /package/src/components/Blocks/Slate/{ExtraAlignWrapper.js → ExtraAlignWrapper.jsx} +0 -0
|
@@ -3,24 +3,28 @@
|
|
|
3
3
|
* REASON: This version enables auto-grouping of blocks that share the same style property
|
|
4
4
|
* in the StylingWrapper. In the future one could improve it by enabling a way to choose the
|
|
5
5
|
* grouping property, eg. using a property other than `backgroundColor`.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* UPDATE 2024-01-11: This allows now the grouping using injected style custom CSS properties from
|
|
7
|
+
* the StyleWrapper.
|
|
8
|
+
* FILE: https://github.com/kitconcept/volto-light-theme/blob/dcd5d46f683c42ac9465098272714359d8f1fb92/src/customizations/volto/components/theme/View/RenderBlocks.jsx
|
|
9
|
+
* FILE VERSION: volto-light-theme 3.0.0-alpha.1
|
|
10
|
+
* DATE: 2024-01-11
|
|
9
11
|
* DEVELOPER: @sneridagh
|
|
10
12
|
*/
|
|
11
13
|
|
|
12
14
|
import React from 'react';
|
|
13
|
-
import { getBaseUrl
|
|
14
|
-
import { defineMessages, useIntl } from 'react-intl';
|
|
15
|
-
import { map } from 'lodash';
|
|
15
|
+
import { getBaseUrl } from '@plone/volto/helpers/Url/Url';
|
|
16
16
|
import {
|
|
17
|
+
applyBlockDefaults,
|
|
17
18
|
getBlocksFieldname,
|
|
18
19
|
getBlocksLayoutFieldname,
|
|
19
20
|
hasBlocksData,
|
|
20
|
-
|
|
21
|
+
findStyleByName,
|
|
22
|
+
} from '@plone/volto/helpers/Blocks/Blocks';
|
|
23
|
+
import { defineMessages, useIntl } from 'react-intl';
|
|
24
|
+
import { map } from 'lodash';
|
|
21
25
|
import StyleWrapper from '@plone/volto/components/manage/Blocks/Block/StyleWrapper';
|
|
22
26
|
import config from '@plone/volto/registry';
|
|
23
|
-
import
|
|
27
|
+
import ViewDefaultBlock from '@plone/volto/components/manage/Blocks/Block/DefaultView';
|
|
24
28
|
import cx from 'classnames';
|
|
25
29
|
import MaybeWrap from '@plone/volto/components/manage/MaybeWrap/MaybeWrap';
|
|
26
30
|
import RenderEmptyBlock from '@plone/volto/components/theme/View/RenderEmptyBlock';
|
|
@@ -36,15 +40,13 @@ const messages = defineMessages({
|
|
|
36
40
|
},
|
|
37
41
|
});
|
|
38
42
|
|
|
39
|
-
export function groupByBGColor(blocks, blocks_layout) {
|
|
43
|
+
export function groupByBGColor(blocks, blocks_layout, colorDefinitions) {
|
|
40
44
|
const result = [];
|
|
41
45
|
let currentArr = [];
|
|
42
46
|
let currentBGColor;
|
|
43
47
|
|
|
44
48
|
blocks_layout.items.forEach((blockId) => {
|
|
45
|
-
let currentBlockColor =
|
|
46
|
-
blocks[blockId]?.styles?.backgroundColor ?? 'transparent';
|
|
47
|
-
|
|
49
|
+
let currentBlockColor = blocks[blockId]?.theme || 'default';
|
|
48
50
|
if (currentBlockColor !== currentBGColor) {
|
|
49
51
|
currentBGColor = currentBlockColor;
|
|
50
52
|
// write it only if the array has some block inside
|
|
@@ -71,90 +73,105 @@ const RenderBlocks = (props) => {
|
|
|
71
73
|
const grouped = groupByBGColor(
|
|
72
74
|
content[blocksFieldname],
|
|
73
75
|
content[blocksLayoutFieldname],
|
|
76
|
+
config.blocks.themes,
|
|
74
77
|
);
|
|
75
78
|
|
|
76
79
|
return hasBlocksData(content) ? (
|
|
77
80
|
<CustomTag>
|
|
78
|
-
{map(grouped, (group) =>
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
!isContainer
|
|
84
|
-
}
|
|
85
|
-
className={cx(
|
|
86
|
-
'blocks-group-wrapper',
|
|
87
|
-
content[blocksFieldname][group[0]]?.styles?.backgroundColor ??
|
|
88
|
-
'transparent',
|
|
89
|
-
)}
|
|
90
|
-
>
|
|
91
|
-
{map(group, (block) => {
|
|
92
|
-
const Block =
|
|
93
|
-
blocksConfig[content[blocksFieldname]?.[block]?.['@type']]
|
|
94
|
-
?.view || ViewDefaultBlock;
|
|
81
|
+
{map(grouped, (group) => {
|
|
82
|
+
const themes =
|
|
83
|
+
config.blocks.blocksConfig[
|
|
84
|
+
content[blocksFieldname][group[0]]['@type']
|
|
85
|
+
].themes ?? config.blocks.themes;
|
|
95
86
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (content[blocksFieldname]?.[block]?.['@type'] === 'empty') {
|
|
104
|
-
return (
|
|
105
|
-
<MaybeWrap
|
|
106
|
-
key={block}
|
|
107
|
-
condition={blockWrapperTag}
|
|
108
|
-
as={blockWrapperTag}
|
|
109
|
-
>
|
|
110
|
-
<RenderEmptyBlock />
|
|
111
|
-
</MaybeWrap>
|
|
112
|
-
);
|
|
87
|
+
return (
|
|
88
|
+
<MaybeWrap
|
|
89
|
+
key={`block-group-${group[0]}`}
|
|
90
|
+
condition={
|
|
91
|
+
config.settings.enableAutoBlockGroupingByBackgroundColor &&
|
|
92
|
+
!isContainer
|
|
113
93
|
}
|
|
94
|
+
className={cx(
|
|
95
|
+
'blocks-group-wrapper',
|
|
96
|
+
content[blocksFieldname][group[0]]?.theme || 'default',
|
|
97
|
+
)}
|
|
98
|
+
style={
|
|
99
|
+
findStyleByName(
|
|
100
|
+
themes,
|
|
101
|
+
content[blocksFieldname][group[0]]?.theme,
|
|
102
|
+
) || findStyleByName(themes, config.blocks.themes[0].name)
|
|
103
|
+
}
|
|
104
|
+
>
|
|
105
|
+
{map(group, (block) => {
|
|
106
|
+
const Block =
|
|
107
|
+
blocksConfig[content[blocksFieldname]?.[block]?.['@type']]
|
|
108
|
+
?.view || ViewDefaultBlock;
|
|
114
109
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
110
|
+
const blockData = applyBlockDefaults({
|
|
111
|
+
data: content[blocksFieldname][block],
|
|
112
|
+
intl,
|
|
113
|
+
metadata,
|
|
114
|
+
properties: content,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (content[blocksFieldname]?.[block]?.['@type'] === 'empty') {
|
|
118
|
+
return (
|
|
119
|
+
<MaybeWrap
|
|
123
120
|
key={block}
|
|
124
|
-
{
|
|
125
|
-
|
|
126
|
-
block={block}
|
|
127
|
-
data={blockData}
|
|
121
|
+
condition={blockWrapperTag}
|
|
122
|
+
as={blockWrapperTag}
|
|
128
123
|
>
|
|
129
|
-
<
|
|
124
|
+
<RenderEmptyBlock />
|
|
125
|
+
</MaybeWrap>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (Block) {
|
|
130
|
+
return (
|
|
131
|
+
<MaybeWrap
|
|
132
|
+
key={block}
|
|
133
|
+
condition={blockWrapperTag}
|
|
134
|
+
as={blockWrapperTag}
|
|
135
|
+
>
|
|
136
|
+
<StyleWrapper
|
|
137
|
+
key={block}
|
|
138
|
+
{...props}
|
|
130
139
|
id={block}
|
|
131
|
-
|
|
132
|
-
properties={content}
|
|
140
|
+
block={block}
|
|
133
141
|
data={blockData}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
>
|
|
143
|
+
<Block
|
|
144
|
+
id={block}
|
|
145
|
+
metadata={metadata}
|
|
146
|
+
properties={content}
|
|
147
|
+
data={blockData}
|
|
148
|
+
path={getBaseUrl(location?.pathname || '')}
|
|
149
|
+
blocksConfig={blocksConfig}
|
|
150
|
+
/>
|
|
151
|
+
</StyleWrapper>
|
|
152
|
+
</MaybeWrap>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (blockData) {
|
|
157
|
+
return (
|
|
158
|
+
<div key={block}>
|
|
159
|
+
{intl.formatMessage(messages.unknownBlock, {
|
|
160
|
+
block: content[blocksFieldname]?.[block]?.['@type'],
|
|
161
|
+
})}
|
|
162
|
+
</div>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
141
165
|
|
|
142
|
-
if (blockData) {
|
|
143
166
|
return (
|
|
144
167
|
<div key={block}>
|
|
145
|
-
{intl.formatMessage(messages.
|
|
146
|
-
block: content[blocksFieldname]?.[block]?.['@type'],
|
|
147
|
-
})}
|
|
168
|
+
{intl.formatMessage(messages.invalidBlock)}
|
|
148
169
|
</div>
|
|
149
170
|
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
155
|
-
})}
|
|
156
|
-
</MaybeWrap>
|
|
157
|
-
))}
|
|
171
|
+
})}
|
|
172
|
+
</MaybeWrap>
|
|
173
|
+
);
|
|
174
|
+
})}
|
|
158
175
|
</CustomTag>
|
|
159
176
|
) : (
|
|
160
177
|
''
|
|
@@ -11,9 +11,7 @@ describe('groupByBGColor', () => {
|
|
|
11
11
|
},
|
|
12
12
|
3: {
|
|
13
13
|
'@type': 'slate',
|
|
14
|
-
|
|
15
|
-
backgroundColor: 'grey',
|
|
16
|
-
},
|
|
14
|
+
theme: 'grey',
|
|
17
15
|
},
|
|
18
16
|
},
|
|
19
17
|
blocks_layout: {
|
|
@@ -32,15 +30,11 @@ describe('groupByBGColor', () => {
|
|
|
32
30
|
},
|
|
33
31
|
2: {
|
|
34
32
|
'@type': 'slate',
|
|
35
|
-
|
|
36
|
-
backgroundColor: 'grey',
|
|
37
|
-
},
|
|
33
|
+
theme: 'grey',
|
|
38
34
|
},
|
|
39
35
|
3: {
|
|
40
36
|
'@type': 'slate',
|
|
41
|
-
|
|
42
|
-
backgroundColor: 'grey',
|
|
43
|
-
},
|
|
37
|
+
theme: 'grey',
|
|
44
38
|
},
|
|
45
39
|
},
|
|
46
40
|
blocks_layout: {
|
|
@@ -56,21 +50,15 @@ describe('groupByBGColor', () => {
|
|
|
56
50
|
blocks: {
|
|
57
51
|
1: {
|
|
58
52
|
'@type': 'slate',
|
|
59
|
-
|
|
60
|
-
backgroundColor: 'grey',
|
|
61
|
-
},
|
|
53
|
+
theme: 'grey',
|
|
62
54
|
},
|
|
63
55
|
2: {
|
|
64
56
|
'@type': 'slate',
|
|
65
|
-
|
|
66
|
-
backgroundColor: 'grey',
|
|
67
|
-
},
|
|
57
|
+
theme: 'grey',
|
|
68
58
|
},
|
|
69
59
|
3: {
|
|
70
60
|
'@type': 'slate',
|
|
71
|
-
|
|
72
|
-
backgroundColor: 'grey',
|
|
73
|
-
},
|
|
61
|
+
theme: 'grey',
|
|
74
62
|
},
|
|
75
63
|
},
|
|
76
64
|
blocks_layout: {
|
|
@@ -86,18 +74,14 @@ describe('groupByBGColor', () => {
|
|
|
86
74
|
blocks: {
|
|
87
75
|
1: {
|
|
88
76
|
'@type': 'slate',
|
|
89
|
-
|
|
90
|
-
backgroundColor: 'grey',
|
|
91
|
-
},
|
|
77
|
+
theme: 'grey',
|
|
92
78
|
},
|
|
93
79
|
2: {
|
|
94
80
|
'@type': 'slate',
|
|
95
81
|
},
|
|
96
82
|
3: {
|
|
97
83
|
'@type': 'slate',
|
|
98
|
-
|
|
99
|
-
backgroundColor: 'grey',
|
|
100
|
-
},
|
|
84
|
+
theme: 'grey',
|
|
101
85
|
},
|
|
102
86
|
},
|
|
103
87
|
blocks_layout: {
|
|
@@ -123,15 +107,11 @@ describe('groupByBGColor', () => {
|
|
|
123
107
|
},
|
|
124
108
|
3: {
|
|
125
109
|
'@type': 'slate',
|
|
126
|
-
|
|
127
|
-
backgroundColor: 'grey',
|
|
128
|
-
},
|
|
110
|
+
theme: 'grey',
|
|
129
111
|
},
|
|
130
112
|
4: {
|
|
131
113
|
'@type': 'slate',
|
|
132
|
-
|
|
133
|
-
backgroundColor: 'grey',
|
|
134
|
-
},
|
|
114
|
+
theme: 'grey',
|
|
135
115
|
},
|
|
136
116
|
5: {
|
|
137
117
|
'@type': 'slate',
|
|
@@ -169,15 +149,11 @@ describe('groupByBGColor', () => {
|
|
|
169
149
|
},
|
|
170
150
|
3: {
|
|
171
151
|
'@type': 'slate',
|
|
172
|
-
|
|
173
|
-
backgroundColor: 'grey',
|
|
174
|
-
},
|
|
152
|
+
theme: 'grey',
|
|
175
153
|
},
|
|
176
154
|
4: {
|
|
177
155
|
'@type': 'slate',
|
|
178
|
-
|
|
179
|
-
backgroundColor: 'grey',
|
|
180
|
-
},
|
|
156
|
+
theme: 'grey',
|
|
181
157
|
},
|
|
182
158
|
5: {
|
|
183
159
|
'@type': 'slate',
|
|
@@ -221,15 +197,11 @@ describe('groupByBGColor', () => {
|
|
|
221
197
|
},
|
|
222
198
|
3: {
|
|
223
199
|
'@type': 'slate',
|
|
224
|
-
|
|
225
|
-
backgroundColor: 'grey',
|
|
226
|
-
},
|
|
200
|
+
theme: 'grey',
|
|
227
201
|
},
|
|
228
202
|
4: {
|
|
229
203
|
'@type': 'slate',
|
|
230
|
-
|
|
231
|
-
backgroundColor: 'grey',
|
|
232
|
-
},
|
|
204
|
+
theme: 'grey',
|
|
233
205
|
},
|
|
234
206
|
5: {
|
|
235
207
|
'@type': 'slate',
|
|
@@ -270,15 +242,11 @@ describe('groupByBGColor', () => {
|
|
|
270
242
|
},
|
|
271
243
|
4: {
|
|
272
244
|
'@type': 'slate',
|
|
273
|
-
|
|
274
|
-
backgroundColor: 'grey',
|
|
275
|
-
},
|
|
245
|
+
theme: 'grey',
|
|
276
246
|
},
|
|
277
247
|
5: {
|
|
278
248
|
'@type': 'slate',
|
|
279
|
-
|
|
280
|
-
backgroundColor: 'grey',
|
|
281
|
-
},
|
|
249
|
+
theme: 'grey',
|
|
282
250
|
},
|
|
283
251
|
6: {
|
|
284
252
|
'@type': 'slate',
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { getCurrentStyleByName } from './helpers';
|
|
2
|
+
|
|
3
|
+
describe('getCurrentStyleByName', () => {
|
|
4
|
+
const styleDefinitions = [
|
|
5
|
+
{
|
|
6
|
+
style: { color: 'red' },
|
|
7
|
+
name: 'Red',
|
|
8
|
+
label: 'Red',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
style: { color: 'blue' },
|
|
12
|
+
name: 'Blue',
|
|
13
|
+
label: 'Blue',
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
it('should return the current block color when it exists in style definitions', () => {
|
|
18
|
+
const fieldName = 'color';
|
|
19
|
+
const block = {
|
|
20
|
+
styles: {
|
|
21
|
+
color: { color: 'red' },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const result = getCurrentStyleByName(styleDefinitions, fieldName, block);
|
|
26
|
+
|
|
27
|
+
expect(result).toBe('Red');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return undefined when the current block style does not exist in style definitions', () => {
|
|
31
|
+
const fieldName = 'color';
|
|
32
|
+
const block = {
|
|
33
|
+
styles: {
|
|
34
|
+
color: { color: 'green' },
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const result = getCurrentStyleByName(styleDefinitions, fieldName, block);
|
|
39
|
+
|
|
40
|
+
expect(result).toBeUndefined();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should return undefined when the block styles object is undefined', () => {
|
|
44
|
+
const fieldName = 'color';
|
|
45
|
+
const block = {};
|
|
46
|
+
|
|
47
|
+
const result = getCurrentStyleByName(styleDefinitions, fieldName, block);
|
|
48
|
+
|
|
49
|
+
expect(result).toBeUndefined();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { StyleDefinition } from '@plone/types';
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
3
|
+
import find from 'lodash/find';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generate empty blocks blocks/blocks_layout pair given the type
|
|
7
|
+
* (could be empty, if not type given) and the number of blocks
|
|
8
|
+
* @function blocksFormGenerator
|
|
9
|
+
* @param number How many blocks to generate of the type (could be "empty", if no type provided)
|
|
10
|
+
* @param type The type of the blocks
|
|
11
|
+
* @return pair filled with the generated blocks
|
|
12
|
+
*/
|
|
13
|
+
export function blocksFormGenerator(number: number, type: string, data: any) {
|
|
14
|
+
const idMap = [...Array(number).keys()].map(() => uuid());
|
|
15
|
+
const start = {
|
|
16
|
+
blocks: {},
|
|
17
|
+
blocks_layout: { items: idMap },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
...start,
|
|
22
|
+
...data,
|
|
23
|
+
blocks: Object.fromEntries(
|
|
24
|
+
start.blocks_layout.items.map((item) => [
|
|
25
|
+
item,
|
|
26
|
+
{ '@type': type || 'empty' },
|
|
27
|
+
]),
|
|
28
|
+
),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getCurrentStyleByName(
|
|
33
|
+
styleDefinitions: Array<StyleDefinition>,
|
|
34
|
+
fieldName: string,
|
|
35
|
+
block: any,
|
|
36
|
+
) {
|
|
37
|
+
let currentBlockColor;
|
|
38
|
+
let currentBlockStyle = block?.styles?.[fieldName];
|
|
39
|
+
// Find in color definitions the current style value
|
|
40
|
+
if (currentBlockStyle) {
|
|
41
|
+
const foundStyle = find(styleDefinitions, {
|
|
42
|
+
style: currentBlockStyle,
|
|
43
|
+
});
|
|
44
|
+
currentBlockColor = foundStyle?.name;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return currentBlockColor;
|
|
48
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ConfigType } from '@plone/registry';
|
|
2
|
+
|
|
3
|
+
import { defineMessages } from 'react-intl';
|
|
4
|
+
import { Container } from '@plone/components';
|
|
5
|
+
|
|
6
|
+
import EventView from './components/Theme/EventView';
|
|
7
|
+
|
|
8
|
+
import { migrateToVLT6ColorAndWidthModel } from './transforms/to6';
|
|
9
|
+
|
|
10
|
+
import installSettings from './config/settings';
|
|
11
|
+
import installBlocks from './config/blocks';
|
|
12
|
+
import installClassExtenders from './config/classExtenders';
|
|
13
|
+
import installWidgets from './config/widgets';
|
|
14
|
+
import installSlots from './config/slots';
|
|
15
|
+
|
|
16
|
+
import '@plone/components/dist/basic.css';
|
|
17
|
+
|
|
18
|
+
defineMessages({
|
|
19
|
+
Press: {
|
|
20
|
+
id: 'Press',
|
|
21
|
+
defaultMessage: 'Press',
|
|
22
|
+
},
|
|
23
|
+
Sitemap: {
|
|
24
|
+
id: 'Sitemap',
|
|
25
|
+
defaultMessage: 'Sitemap',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const applyConfig = (config: ConfigType) => {
|
|
30
|
+
installSettings(config);
|
|
31
|
+
installBlocks(config);
|
|
32
|
+
installClassExtenders(config);
|
|
33
|
+
installWidgets(config);
|
|
34
|
+
installSlots(config);
|
|
35
|
+
|
|
36
|
+
// Register a custom Container component from @plone/components
|
|
37
|
+
config.registerComponent({
|
|
38
|
+
name: 'Container',
|
|
39
|
+
component: Container,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
config.registerUtility({
|
|
43
|
+
name: 'migrateToVLT6ColorAndWidthModel',
|
|
44
|
+
type: 'transform',
|
|
45
|
+
dependencies: { reducer: 'content' },
|
|
46
|
+
method: migrateToVLT6ColorAndWidthModel,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
config.views.contentTypesViews.Event = EventView;
|
|
50
|
+
|
|
51
|
+
return config;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default applyConfig;
|