@plone/volto 16.6.0 → 16.8.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 +5 -8
- package/.yarn/install-state.gz +0 -0
- package/CHANGELOG.md +84 -41
- package/README.md +1 -1
- package/cypress/support/commands.js +90 -46
- package/package.json +3 -6
- package/packages/volto-slate/package.json +1 -1
- package/packages/volto-slate/src/blocks/Text/SlashMenu.jsx +42 -13
- package/src/components/manage/Blocks/Block/StyleWrapper.jsx +15 -4
- package/src/components/manage/Blocks/LeadImage/Edit.jsx +5 -1
- package/src/components/manage/Controlpanels/VersionOverview.jsx +14 -1
- package/src/components/manage/Diff/DiffField.jsx +64 -67
- package/src/components/manage/Widgets/ArrayWidget.jsx +2 -1
- package/src/components/manage/Widgets/QueryWidget.jsx +18 -0
- package/src/config/Style.jsx +2 -0
- package/src/config/index.js +2 -1
- package/src/helpers/Blocks/Blocks.js +38 -0
- package/src/helpers/Blocks/Blocks.test.js +248 -0
- package/src/helpers/index.js +2 -0
- package/test-setup-config.js +5 -1
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
applyBlockDefaults,
|
|
18
18
|
applySchemaDefaults,
|
|
19
19
|
buildStyleClassNamesFromData,
|
|
20
|
+
buildStyleClassNamesExtenders,
|
|
21
|
+
getPreviousNextBlock,
|
|
20
22
|
} from './Blocks';
|
|
21
23
|
|
|
22
24
|
import config from '@plone/volto/registry';
|
|
@@ -938,4 +940,250 @@ describe('Blocks', () => {
|
|
|
938
940
|
expect(buildStyleClassNamesFromData(styles)).toEqual([]);
|
|
939
941
|
});
|
|
940
942
|
});
|
|
943
|
+
|
|
944
|
+
describe('getPreviousNextBlock', () => {
|
|
945
|
+
it('basic functionality', () => {
|
|
946
|
+
const content = {
|
|
947
|
+
blocks: {
|
|
948
|
+
1: {
|
|
949
|
+
'@type': 'slate',
|
|
950
|
+
styles: {
|
|
951
|
+
backgroundColor: 'grey',
|
|
952
|
+
},
|
|
953
|
+
},
|
|
954
|
+
2: {
|
|
955
|
+
'@type': 'slate',
|
|
956
|
+
},
|
|
957
|
+
3: {
|
|
958
|
+
'@type': 'slate',
|
|
959
|
+
styles: {
|
|
960
|
+
backgroundColor: 'grey',
|
|
961
|
+
},
|
|
962
|
+
},
|
|
963
|
+
},
|
|
964
|
+
blocks_layout: {
|
|
965
|
+
items: [1, 2, 3],
|
|
966
|
+
},
|
|
967
|
+
};
|
|
968
|
+
const block = 2;
|
|
969
|
+
const [previousBlock, nextBlock] = getPreviousNextBlock({
|
|
970
|
+
content,
|
|
971
|
+
block,
|
|
972
|
+
});
|
|
973
|
+
expect(previousBlock).toEqual({
|
|
974
|
+
'@type': 'slate',
|
|
975
|
+
styles: {
|
|
976
|
+
backgroundColor: 'grey',
|
|
977
|
+
},
|
|
978
|
+
});
|
|
979
|
+
expect(nextBlock).toEqual({
|
|
980
|
+
'@type': 'slate',
|
|
981
|
+
styles: {
|
|
982
|
+
backgroundColor: 'grey',
|
|
983
|
+
},
|
|
984
|
+
});
|
|
985
|
+
});
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
describe('buildStyleClassNamesExtenders', () => {
|
|
989
|
+
beforeAll(() => {
|
|
990
|
+
// Example styleClassNameExtenders
|
|
991
|
+
config.settings.styleClassNameExtenders = [
|
|
992
|
+
({ block, content, data, classNames }) => {
|
|
993
|
+
let styles = [];
|
|
994
|
+
const [previousBlock, nextBlock] = getPreviousNextBlock({
|
|
995
|
+
content,
|
|
996
|
+
block,
|
|
997
|
+
});
|
|
998
|
+
|
|
999
|
+
if (nextBlock?.['@type']) {
|
|
1000
|
+
styles.push(`next--is--${nextBlock['@type']}`);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
if (data?.['@type'] === previousBlock?.['@type']) {
|
|
1004
|
+
styles.push('previous--is--same--block-type');
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
if (data?.['@type'] === nextBlock?.['@type']) {
|
|
1008
|
+
styles.push('next--is--same--block-type');
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
if (data?.['@type'] !== previousBlock?.['@type']) {
|
|
1012
|
+
styles.push('is--first--of--block-type');
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
if (data?.['@type'] !== nextBlock?.['@type']) {
|
|
1016
|
+
styles.push('is--last--of--block-type');
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
const previousColor =
|
|
1020
|
+
previousBlock?.styles?.backgroundColor ?? 'transparent';
|
|
1021
|
+
const currentColor = data?.styles?.backgroundColor ?? 'transparent';
|
|
1022
|
+
const nextColor = nextBlock?.styles?.backgroundColor ?? 'transparent';
|
|
1023
|
+
|
|
1024
|
+
if (currentColor === previousColor) {
|
|
1025
|
+
styles.push('previous--has--same--backgroundColor');
|
|
1026
|
+
} else if (currentColor !== previousColor) {
|
|
1027
|
+
styles.push('previous--has--different--backgroundColor');
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
if (currentColor === nextColor) {
|
|
1031
|
+
styles.push('next--has--same--backgroundColor');
|
|
1032
|
+
} else if (currentColor !== nextColor) {
|
|
1033
|
+
styles.push('next--has--different--backgroundColor');
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
return [...classNames, ...styles];
|
|
1037
|
+
},
|
|
1038
|
+
];
|
|
1039
|
+
});
|
|
1040
|
+
|
|
1041
|
+
it('slate grey + slate + slate grey ', () => {
|
|
1042
|
+
const content = {
|
|
1043
|
+
blocks: {
|
|
1044
|
+
1: {
|
|
1045
|
+
'@type': 'slate',
|
|
1046
|
+
styles: {
|
|
1047
|
+
backgroundColor: 'grey',
|
|
1048
|
+
},
|
|
1049
|
+
},
|
|
1050
|
+
2: {
|
|
1051
|
+
'@type': 'slate',
|
|
1052
|
+
},
|
|
1053
|
+
3: {
|
|
1054
|
+
'@type': 'slate',
|
|
1055
|
+
styles: {
|
|
1056
|
+
backgroundColor: 'grey',
|
|
1057
|
+
},
|
|
1058
|
+
},
|
|
1059
|
+
},
|
|
1060
|
+
blocks_layout: {
|
|
1061
|
+
items: [1, 2, 3],
|
|
1062
|
+
},
|
|
1063
|
+
};
|
|
1064
|
+
const block = 2;
|
|
1065
|
+
const data = content['blocks'][2];
|
|
1066
|
+
|
|
1067
|
+
expect(
|
|
1068
|
+
buildStyleClassNamesExtenders({ block, content, data }),
|
|
1069
|
+
).toStrictEqual([
|
|
1070
|
+
'next--is--slate',
|
|
1071
|
+
'previous--is--same--block-type',
|
|
1072
|
+
'next--is--same--block-type',
|
|
1073
|
+
'previous--has--different--backgroundColor',
|
|
1074
|
+
'next--has--different--backgroundColor',
|
|
1075
|
+
]);
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
it('slate grey + slate grey + slate grey ', () => {
|
|
1079
|
+
const content = {
|
|
1080
|
+
blocks: {
|
|
1081
|
+
1: {
|
|
1082
|
+
'@type': 'slate',
|
|
1083
|
+
styles: {
|
|
1084
|
+
backgroundColor: 'grey',
|
|
1085
|
+
},
|
|
1086
|
+
},
|
|
1087
|
+
2: {
|
|
1088
|
+
'@type': 'slate',
|
|
1089
|
+
styles: {
|
|
1090
|
+
backgroundColor: 'grey',
|
|
1091
|
+
},
|
|
1092
|
+
},
|
|
1093
|
+
3: {
|
|
1094
|
+
'@type': 'slate',
|
|
1095
|
+
styles: {
|
|
1096
|
+
backgroundColor: 'grey',
|
|
1097
|
+
},
|
|
1098
|
+
},
|
|
1099
|
+
},
|
|
1100
|
+
blocks_layout: {
|
|
1101
|
+
items: [1, 2, 3],
|
|
1102
|
+
},
|
|
1103
|
+
};
|
|
1104
|
+
const block = 2;
|
|
1105
|
+
const data = content['blocks'][2];
|
|
1106
|
+
|
|
1107
|
+
expect(
|
|
1108
|
+
buildStyleClassNamesExtenders({ block, content, data }),
|
|
1109
|
+
).toStrictEqual([
|
|
1110
|
+
'next--is--slate',
|
|
1111
|
+
'previous--is--same--block-type',
|
|
1112
|
+
'next--is--same--block-type',
|
|
1113
|
+
'previous--has--same--backgroundColor',
|
|
1114
|
+
'next--has--same--backgroundColor',
|
|
1115
|
+
]);
|
|
1116
|
+
});
|
|
1117
|
+
|
|
1118
|
+
it('grid + slate grey + slate grey ', () => {
|
|
1119
|
+
const content = {
|
|
1120
|
+
blocks: {
|
|
1121
|
+
1: {
|
|
1122
|
+
'@type': '__grid',
|
|
1123
|
+
},
|
|
1124
|
+
2: {
|
|
1125
|
+
'@type': 'slate',
|
|
1126
|
+
styles: {
|
|
1127
|
+
backgroundColor: 'grey',
|
|
1128
|
+
},
|
|
1129
|
+
},
|
|
1130
|
+
3: {
|
|
1131
|
+
'@type': 'slate',
|
|
1132
|
+
styles: {
|
|
1133
|
+
backgroundColor: 'grey',
|
|
1134
|
+
},
|
|
1135
|
+
},
|
|
1136
|
+
},
|
|
1137
|
+
blocks_layout: {
|
|
1138
|
+
items: [1, 2, 3],
|
|
1139
|
+
},
|
|
1140
|
+
};
|
|
1141
|
+
const block = 2;
|
|
1142
|
+
const data = content['blocks'][2];
|
|
1143
|
+
|
|
1144
|
+
expect(
|
|
1145
|
+
buildStyleClassNamesExtenders({ block, content, data }),
|
|
1146
|
+
).toStrictEqual([
|
|
1147
|
+
'next--is--slate',
|
|
1148
|
+
'next--is--same--block-type',
|
|
1149
|
+
'is--first--of--block-type',
|
|
1150
|
+
'previous--has--different--backgroundColor',
|
|
1151
|
+
'next--has--same--backgroundColor',
|
|
1152
|
+
]);
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
it('grid + grid + slate grey ', () => {
|
|
1156
|
+
const content = {
|
|
1157
|
+
blocks: {
|
|
1158
|
+
1: {
|
|
1159
|
+
'@type': '__grid',
|
|
1160
|
+
},
|
|
1161
|
+
2: {
|
|
1162
|
+
'@type': '__grid',
|
|
1163
|
+
},
|
|
1164
|
+
3: {
|
|
1165
|
+
'@type': 'slate',
|
|
1166
|
+
styles: {
|
|
1167
|
+
backgroundColor: 'grey',
|
|
1168
|
+
},
|
|
1169
|
+
},
|
|
1170
|
+
},
|
|
1171
|
+
blocks_layout: {
|
|
1172
|
+
items: [1, 2, 3],
|
|
1173
|
+
},
|
|
1174
|
+
};
|
|
1175
|
+
const block = 2;
|
|
1176
|
+
const data = content['blocks'][2];
|
|
1177
|
+
|
|
1178
|
+
expect(
|
|
1179
|
+
buildStyleClassNamesExtenders({ block, content, data }),
|
|
1180
|
+
).toStrictEqual([
|
|
1181
|
+
'next--is--slate',
|
|
1182
|
+
'previous--is--same--block-type',
|
|
1183
|
+
'is--last--of--block-type',
|
|
1184
|
+
'previous--has--same--backgroundColor',
|
|
1185
|
+
'next--has--different--backgroundColor',
|
|
1186
|
+
]);
|
|
1187
|
+
});
|
|
1188
|
+
});
|
|
941
1189
|
});
|
package/src/helpers/index.js
CHANGED
|
@@ -56,6 +56,8 @@ export {
|
|
|
56
56
|
applyBlockDefaults,
|
|
57
57
|
applySchemaDefaults,
|
|
58
58
|
buildStyleClassNamesFromData,
|
|
59
|
+
buildStyleClassNamesExtenders,
|
|
60
|
+
getPreviousNextBlock,
|
|
59
61
|
} from '@plone/volto/helpers/Blocks/Blocks';
|
|
60
62
|
export BodyClass from '@plone/volto/helpers/BodyClass/BodyClass';
|
|
61
63
|
export ScrollToTop from '@plone/volto/helpers/ScrollToTop/ScrollToTop';
|
package/test-setup-config.js
CHANGED
|
@@ -20,7 +20,10 @@ import {
|
|
|
20
20
|
} from '@plone/volto/config/RichTextEditor/Blocks';
|
|
21
21
|
import FromHTMLCustomBlockFn from '@plone/volto/config/RichTextEditor/FromHTML';
|
|
22
22
|
import { contentIcons } from '@plone/volto/config/ContentIcons';
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
styleClassNameConverters,
|
|
25
|
+
styleClassNameExtenders,
|
|
26
|
+
} from '@plone/volto/config/Style';
|
|
24
27
|
|
|
25
28
|
import {
|
|
26
29
|
controlPanelsIcons,
|
|
@@ -76,6 +79,7 @@ config.set('settings', {
|
|
|
76
79
|
downloadableObjects: ['File'],
|
|
77
80
|
viewableInBrowserObjects: [],
|
|
78
81
|
styleClassNameConverters,
|
|
82
|
+
styleClassNameExtenders,
|
|
79
83
|
});
|
|
80
84
|
config.set('blocks', {
|
|
81
85
|
blocksConfig: {
|