@eeacms/volto-eea-website-policy 1.0.4 → 1.1.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.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ ### [1.1.0](https://github.com/eea/volto-eea-website-policy/compare/1.0.4...1.1.0) - 29 November 2022
8
+
9
+ #### :hammer_and_wrench: Others
10
+
11
+ - Release 1.1.0 [Alin Voinea - [`0291b3b`](https://github.com/eea/volto-eea-website-policy/commit/0291b3bb7b4c6ab09ca98728885cea4051eac8e3)]
12
+ - Remove Blocks customization, it's outdated [Tiberiu Ichim - [`97306cb`](https://github.com/eea/volto-eea-website-policy/commit/97306cb6a9ac53f00576559dd919197cef7439b8)]
7
13
  ### [1.0.4](https://github.com/eea/volto-eea-website-policy/compare/1.0.3...1.0.4) - 22 November 2022
8
14
 
9
15
  #### :nail_care: Enhancements
@@ -49,7 +55,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
49
55
 
50
56
  #### :hammer_and_wrench: Others
51
57
 
52
- - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`d153f54`](https://github.com/eea/volto-eea-website-policy/commit/d153f54e55e918fa4746e05488c734624eaf14a9)]
53
58
  ### [0.4.0](https://github.com/eea/volto-eea-website-policy/compare/0.3.3...0.4.0) - 19 September 2022
54
59
 
55
60
  #### :hammer_and_wrench: Others
@@ -125,7 +130,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
125
130
  - format index.js [Andrei Grigore - [`db4481a`](https://github.com/eea/volto-eea-website-policy/commit/db4481aeeba59a769272659f33278c902fc69bec)]
126
131
  - Update index.js [Alexandru Ghica - [`dc09886`](https://github.com/eea/volto-eea-website-policy/commit/dc0988640a76a9914381b120f58bb61a9ab1eb39)]
127
132
  - Added externalRoutes [Alexandru Ghica - [`b68135b`](https://github.com/eea/volto-eea-website-policy/commit/b68135b013fafa93a41ea602ea2fad30879abe0f)]
128
- - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`575cca6`](https://github.com/eea/volto-eea-website-policy/commit/575cca674602ca2e1c2a41300c47ba594ff49aa0)]
129
133
  ### [0.1.1](https://github.com/eea/volto-eea-website-policy/compare/0.1.0...0.1.1) - 4 March 2022
130
134
 
131
135
  #### :hammer_and_wrench: Others
@@ -138,5 +142,4 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
138
142
 
139
143
  #### :hammer_and_wrench: Others
140
144
 
141
- - yarn bootstrap [Alin Voinea - [`9b4d197`](https://github.com/eea/volto-eea-website-policy/commit/9b4d197cbc7992566cb36524d190078d5ad21a44)]
142
145
  - Initial commit [Alin Voinea - [`3800692`](https://github.com/eea/volto-eea-website-policy/commit/3800692f7a4de6460815bd6061facacb986cbef0)]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-website-policy",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "@eeacms/volto-eea-website-policy: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -17,10 +17,9 @@
17
17
  "url": "git@github.com:eea/volto-eea-website-policy.git"
18
18
  },
19
19
  "addons": [],
20
- "dependencies": {},
21
20
  "devDependencies": {
22
- "@plone/scripts": "*",
23
21
  "@cypress/code-coverage": "^3.10.0",
22
+ "@plone/scripts": "*",
24
23
  "babel-plugin-transform-class-properties": "^6.24.1",
25
24
  "md5": "^2.3.0"
26
25
  },
@@ -1,440 +0,0 @@
1
- /**
2
- * Blocks helper.
3
- * @module helpers/Blocks
4
- */
5
-
6
- import { omit, without, endsWith, find, isObject, keys, toPairs } from 'lodash';
7
- import move from 'lodash-move';
8
- import { v4 as uuid } from 'uuid';
9
- import config from '@plone/volto/registry';
10
- import { applySchemaEnhancer } from '@plone/volto/helpers';
11
-
12
- /**
13
- * Get blocks field.
14
- * @function getBlocksFieldname
15
- * @param {Object} props Properties.
16
- * @return {string} Field name of the blocks
17
- */
18
- export function getBlocksFieldname(props) {
19
- return (
20
- find(
21
- keys(props),
22
- (key) => key !== 'volto.blocks' && endsWith(key, 'blocks'),
23
- ) || null
24
- );
25
- }
26
-
27
- /**
28
- * Get blocks layout field.
29
- * @function getBlocksLayoutFieldname
30
- * @param {Object} props Properties.
31
- * @return {string} Field name of the blocks layout
32
- */
33
- export function getBlocksLayoutFieldname(props) {
34
- return (
35
- find(
36
- keys(props),
37
- (key) => key !== 'volto.blocks' && endsWith(key, 'blocks_layout'),
38
- ) || null
39
- );
40
- }
41
-
42
- /**
43
- * Has blocks data.
44
- * @function hasBlocksData
45
- * @param {Object} props Properties.
46
- * @return {boolean} True if it has blocks data.
47
- */
48
- export function hasBlocksData(props) {
49
- return (
50
- find(
51
- keys(props),
52
- (key) => key !== 'volto.blocks' && endsWith(key, 'blocks'),
53
- ) !== undefined
54
- );
55
- }
56
-
57
- /**
58
- * Pluggable method to test if a block has a set value (any non-empty value)
59
- * @function blockHasValue
60
- * @param {Object} data Block data
61
- * @return {boolean} True if block has a non-empty value
62
- */
63
- export function blockHasValue(data) {
64
- const { blocks } = config;
65
- const blockType = data['@type'];
66
- const check = blocks.blocksConfig[blockType]?.blockHasValue;
67
- if (!check) {
68
- return true;
69
- }
70
- return check(data);
71
- }
72
-
73
- /**
74
- * Get block pairs of [id, block] from content properties
75
- * @function getBlocks
76
- * @param {Object} properties
77
- * @return {Array} a list of block [id, value] pairs, in order from layout
78
- */
79
- export const getBlocks = (properties) => {
80
- const blocksFieldName = getBlocksFieldname(properties);
81
- const blocksLayoutFieldname = getBlocksLayoutFieldname(properties);
82
- return (
83
- properties[blocksLayoutFieldname]?.items?.map((n) => [
84
- n,
85
- properties[blocksFieldName][n],
86
- ]) || []
87
- );
88
- };
89
-
90
- /**
91
- * Move block to different location index within blocks_layout
92
- * @function moveBlock
93
- * @param {Object} formData Form data
94
- * @param {number} source index within form blocks_layout items
95
- * @param {number} destination index within form blocks_layout items
96
- * @return {Object} New form data
97
- */
98
- export function moveBlock(formData, source, destination) {
99
- const blocksLayoutFieldname = getBlocksLayoutFieldname(formData);
100
- return {
101
- ...formData,
102
- [blocksLayoutFieldname]: {
103
- items: move(formData[blocksLayoutFieldname].items, source, destination),
104
- },
105
- };
106
- }
107
-
108
- /**
109
- * Delete block by id
110
- * @function deleteBlock
111
- * @param {Object} formData Form data
112
- * @param {string} blockId Block uid
113
- * @return {Object} New form data
114
- */
115
- export function deleteBlock(formData, blockId) {
116
- const blocksFieldname = getBlocksFieldname(formData);
117
- const blocksLayoutFieldname = getBlocksLayoutFieldname(formData);
118
-
119
- let newFormData = {
120
- ...formData,
121
- [blocksLayoutFieldname]: {
122
- items: without(formData[blocksLayoutFieldname].items, blockId),
123
- },
124
- [blocksFieldname]: omit(formData[blocksFieldname], [blockId]),
125
- };
126
-
127
- if (newFormData[blocksLayoutFieldname].items.length === 0) {
128
- newFormData = addBlock(newFormData, config.settings.defaultBlockType, 0);
129
- }
130
-
131
- return newFormData;
132
- }
133
-
134
- /**
135
- * Add block
136
- * @function addBlock
137
- * @param {Object} formData Form data
138
- * @param {string} type Block type
139
- * @param {number} index Destination index
140
- * @return {Array} New block id, New form data
141
- */
142
- export function addBlock(formData, type, index) {
143
- const { settings } = config;
144
- const id = uuid();
145
- const idTrailingBlock = uuid();
146
- const blocksFieldname = getBlocksFieldname(formData);
147
- const blocksLayoutFieldname = getBlocksLayoutFieldname(formData);
148
- const totalItems = formData[blocksLayoutFieldname].items.length;
149
- const insert = index === -1 ? totalItems : index;
150
-
151
- return [
152
- id,
153
- {
154
- ...formData,
155
- [blocksLayoutFieldname]: {
156
- items: [
157
- ...formData[blocksLayoutFieldname].items.slice(0, insert),
158
- id,
159
- ...(type !== settings.defaultBlockType ? [idTrailingBlock] : []),
160
- ...formData[blocksLayoutFieldname].items.slice(insert),
161
- ],
162
- },
163
- [blocksFieldname]: {
164
- ...formData[blocksFieldname],
165
- [id]: {
166
- '@type': type,
167
- },
168
- ...(type !== settings.defaultBlockType && {
169
- [idTrailingBlock]: {
170
- '@type': settings.defaultBlockType,
171
- },
172
- }),
173
- },
174
- selected: id,
175
- },
176
- ];
177
- }
178
-
179
- /**
180
- * Mutate block
181
- * @function mutateBlock
182
- * @param {Object} formData Form data
183
- * @param {string} id Block uid to mutate
184
- * @param {number} value Block's new value
185
- * @return {Object} New form data
186
- */
187
- export function mutateBlock(formData, id, value) {
188
- const { settings } = config;
189
- const blocksFieldname = getBlocksFieldname(formData);
190
- const blocksLayoutFieldname = getBlocksLayoutFieldname(formData);
191
- const index = formData[blocksLayoutFieldname].items.indexOf(id) + 1;
192
-
193
- // Test if block at index is already a placeholder (trailing) block
194
- const trailId = formData[blocksLayoutFieldname].items[index];
195
- if (trailId) {
196
- const block = formData[blocksFieldname][trailId];
197
- if (!blockHasValue(block)) {
198
- return {
199
- ...formData,
200
- [blocksFieldname]: {
201
- ...formData[blocksFieldname],
202
- [id]: value || null,
203
- },
204
- };
205
- }
206
- }
207
-
208
- const idTrailingBlock = uuid();
209
- return {
210
- ...formData,
211
- [blocksFieldname]: {
212
- ...formData[blocksFieldname],
213
- [id]: value || null,
214
- [idTrailingBlock]: {
215
- '@type': settings.defaultBlockType,
216
- },
217
- },
218
- [blocksLayoutFieldname]: {
219
- items: [
220
- ...formData[blocksLayoutFieldname].items.slice(0, index),
221
- idTrailingBlock,
222
- ...formData[blocksLayoutFieldname].items.slice(index),
223
- ],
224
- },
225
- };
226
- }
227
-
228
- /**
229
- * Insert new block before another block
230
- * @function insertBlock
231
- * @param {Object} formData Form data
232
- * @param {string} id Insert new block before the block with this id
233
- * @param {number} value New block's value
234
- * @return {Array} New block id, New form data
235
- */
236
- export function insertBlock(formData, id, value, current = {}) {
237
- const blocksFieldname = getBlocksFieldname(formData);
238
- const blocksLayoutFieldname = getBlocksLayoutFieldname(formData);
239
- const index = formData[blocksLayoutFieldname].items.indexOf(id);
240
-
241
- const newBlockId = uuid();
242
- return [
243
- newBlockId,
244
- {
245
- ...formData,
246
- [blocksFieldname]: {
247
- ...formData[blocksFieldname],
248
- [newBlockId]: value || null,
249
- [id]: {
250
- ...formData[blocksFieldname][id],
251
- ...current,
252
- },
253
- },
254
- [blocksLayoutFieldname]: {
255
- items: [
256
- ...formData[blocksLayoutFieldname].items.slice(0, index),
257
- newBlockId,
258
- ...formData[blocksLayoutFieldname].items.slice(index),
259
- ],
260
- },
261
- },
262
- ];
263
- }
264
-
265
- /**
266
- * Change block
267
- * @function changeBlock
268
- * @param {Object} formData Form data
269
- * @param {string} id Block uid to change
270
- * @param {number} value Block's new value
271
- * @return {Object} New form data
272
- */
273
- export function changeBlock(formData, id, value) {
274
- const blocksFieldname = getBlocksFieldname(formData);
275
- return {
276
- ...formData,
277
- [blocksFieldname]: {
278
- ...formData[blocksFieldname],
279
- [id]: value || null,
280
- },
281
- };
282
- }
283
-
284
- /**
285
- * Get the next block UID within form
286
- * @function nextBlockId
287
- * @param {Object} formData Form data
288
- * @param {string} currentBlock Block uid
289
- * @return {string} Next block uid
290
- */
291
- export function nextBlockId(formData, currentBlock) {
292
- const blocksLayoutFieldname = getBlocksLayoutFieldname(formData);
293
- const currentIndex = formData[blocksLayoutFieldname].items.indexOf(
294
- currentBlock,
295
- );
296
-
297
- if (currentIndex === formData[blocksLayoutFieldname].items.length - 1) {
298
- // We are already at the bottom block don't do anything
299
- return null;
300
- }
301
-
302
- const newIndex = currentIndex + 1;
303
- return formData[blocksLayoutFieldname].items[newIndex];
304
- }
305
-
306
- /**
307
- * Get the previous block UID within form
308
- * @function previousBlockId
309
- * @param {Object} formData Form data
310
- * @param {string} currentBlock Block uid
311
- * @return {string} Previous block uid
312
- */
313
- export function previousBlockId(formData, currentBlock) {
314
- const blocksLayoutFieldname = getBlocksLayoutFieldname(formData);
315
- const currentIndex = formData[blocksLayoutFieldname].items.indexOf(
316
- currentBlock,
317
- );
318
-
319
- if (currentIndex === 0) {
320
- // We are already at the top block don't do anything
321
- return null;
322
- }
323
- const newindex = currentIndex - 1;
324
- return formData[blocksLayoutFieldname].items[newindex];
325
- }
326
-
327
- /**
328
- * Generate empty block form
329
- * @function emptyBlocksForm
330
- * @param {Object} formData Form data
331
- * @return {Object} Empty blocks form with one defaultBlockType block
332
- */
333
- export function emptyBlocksForm() {
334
- const { settings } = config;
335
- const id = uuid();
336
- return {
337
- blocks: {
338
- [id]: {
339
- '@type': settings.defaultBlockType,
340
- },
341
- },
342
- blocks_layout: { items: [id] },
343
- };
344
- }
345
-
346
- /**
347
- * Recursively discover blocks in data and call the provided callback
348
- * @function visitBlocks
349
- * @param {Object} content A content data structure (an object with blocks and blocks_layout)
350
- * @param {Function} callback A function to call on each discovered block
351
- */
352
- export function visitBlocks(content, callback) {
353
- const queue = getBlocks(content);
354
- while (queue.length > 0) {
355
- const [id, blockdata] = queue.shift();
356
- callback([id, blockdata]);
357
-
358
- // assumes that a block value is like: {blocks, blocks_layout} or
359
- // { data: {blocks, blocks_layout}}
360
- if (Object.keys(blockdata || {}).indexOf('blocks') > -1) {
361
- queue.push(...getBlocks(blockdata));
362
- }
363
- if (Object.keys(blockdata?.data || {}).indexOf('blocks') > -1) {
364
- queue.push(...getBlocks(blockdata.data));
365
- }
366
- }
367
- }
368
-
369
- /**
370
- * Initializes data with the default values coming from schema
371
- */
372
- export function applySchemaDefaults({ data = {}, schema }) {
373
- const derivedData = {
374
- ...Object.keys(schema.properties).reduce((accumulator, currentField) => {
375
- return schema.properties[currentField].default
376
- ? {
377
- ...accumulator,
378
- [currentField]: schema.properties[currentField].default,
379
- }
380
- : accumulator;
381
- }, {}),
382
- ...data,
383
- };
384
- return derivedData;
385
- }
386
-
387
- /**
388
- * Apply the block's default (as defined in schema) to the block data.
389
- *
390
- * @function applyBlockDefaults
391
- * @param {Object} params An object with data, intl and anything else
392
- * @return {Object} Derived data, with the defaults extracted from the schema
393
- */
394
- export function applyBlockDefaults({ data = {}, intl, ...rest }, blocksConfig) {
395
- const block_type = data['@type'];
396
- const { blockSchema } =
397
- (blocksConfig || config.blocks.blocksConfig)[block_type] || {};
398
- if (!blockSchema) return data;
399
-
400
- let schema =
401
- typeof blockSchema === 'function'
402
- ? blockSchema({ data, intl, ...rest })
403
- : blockSchema;
404
- schema = applySchemaEnhancer({ schema, formData: data, intl });
405
-
406
- return applySchemaDefaults({ data, schema });
407
- }
408
-
409
- export const buildStyleClassNamesFromData = (styles) => {
410
- // styles has the form
411
- // const styles = {
412
- // color: 'red',
413
- // backgroundColor: '#AABBCC',
414
- // }
415
- // Returns: ['has--color--red', 'has--backgroundColor--AABBCC']
416
- let styleArray = [];
417
- const pairedStyles = toPairs(styles);
418
- pairedStyles.forEach((item) => {
419
- if (isObject(item[1])) {
420
- const flattenedNestedStyles = toPairs(item[1]).map((nested) => [
421
- item[0],
422
- ...nested,
423
- ]);
424
- flattenedNestedStyles.forEach((sub) => styleArray.push(sub));
425
- } else {
426
- styleArray.push(item);
427
- }
428
- });
429
- return styleArray.map((item) => {
430
- const classname = item.map((item) => {
431
- const str_item = item ? item.toString() : '';
432
- return str_item && str_item.startsWith('#')
433
- ? str_item.replace('#', '')
434
- : str_item;
435
- });
436
- return `has--${classname[0]}--${classname[1]}${
437
- classname[2] ? `--${classname[2]}` : ''
438
- }`;
439
- });
440
- };