@plone/volto 18.7.0 → 18.8.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.
@@ -120,9 +120,10 @@ export function moveBlock(formData, source, destination) {
120
120
  * @function deleteBlock
121
121
  * @param {Object} formData Form data
122
122
  * @param {string} blockId Block uid
123
+ * @param {Object} intl intl object.
123
124
  * @return {Object} New form data
124
125
  */
125
- export function deleteBlock(formData, blockId) {
126
+ export function deleteBlock(formData, blockId, intl) {
126
127
  const blocksFieldname = getBlocksFieldname(formData);
127
128
  const blocksLayoutFieldname = getBlocksLayoutFieldname(formData);
128
129
 
@@ -135,7 +136,13 @@ export function deleteBlock(formData, blockId) {
135
136
  };
136
137
 
137
138
  if (newFormData[blocksLayoutFieldname].items.length === 0) {
138
- newFormData = addBlock(newFormData, config.settings.defaultBlockType, 0);
139
+ newFormData = addBlock(
140
+ newFormData,
141
+ config.settings.defaultBlockType,
142
+ 0,
143
+ {},
144
+ intl,
145
+ );
139
146
  }
140
147
 
141
148
  return newFormData;
@@ -147,9 +154,11 @@ export function deleteBlock(formData, blockId) {
147
154
  * @param {Object} formData Form data
148
155
  * @param {string} type Block type
149
156
  * @param {number} index Destination index
157
+ * @param {Object} blocksConfig Blocks configuration.
158
+ * @param {Object} intl intl object.
150
159
  * @return {Array} New block id, New form data
151
160
  */
152
- export function addBlock(formData, type, index, blocksConfig) {
161
+ export function addBlock(formData, type, index, blocksConfig, intl) {
153
162
  const { settings } = config;
154
163
  const id = uuid();
155
164
  const idTrailingBlock = uuid();
@@ -192,6 +201,7 @@ export function addBlock(formData, type, index, blocksConfig) {
192
201
  },
193
202
  selected: id,
194
203
  },
204
+ intl,
195
205
  }),
196
206
  ];
197
207
  }
@@ -208,6 +218,7 @@ export const applyBlockInitialValue = ({
208
218
  value,
209
219
  blocksConfig,
210
220
  formData,
221
+ intl,
211
222
  }) => {
212
223
  const type = value['@type'];
213
224
  blocksConfig = blocksConfig || config.blocks.blocksConfig;
@@ -217,6 +228,7 @@ export const applyBlockInitialValue = ({
217
228
  id,
218
229
  value,
219
230
  formData,
231
+ intl,
220
232
  });
221
233
  const blocksFieldname = getBlocksFieldname(formData);
222
234
  formData[blocksFieldname][id] = value;
@@ -231,9 +243,11 @@ export const applyBlockInitialValue = ({
231
243
  * @param {Object} formData Form data
232
244
  * @param {string} id Block uid to mutate
233
245
  * @param {number} value Block's new value
246
+ * @param {Object} blocksConfig Blocks configuration.
247
+ * @param {Object} intl intl object.
234
248
  * @return {Object} New form data
235
249
  */
236
- export function mutateBlock(formData, id, value, blocksConfig) {
250
+ export function mutateBlock(formData, id, value, blocksConfig, intl) {
237
251
  const { settings } = config;
238
252
  const blocksFieldname = getBlocksFieldname(formData);
239
253
  const blocksLayoutFieldname = getBlocksLayoutFieldname(formData);
@@ -260,6 +274,7 @@ export function mutateBlock(formData, id, value, blocksConfig) {
260
274
  [id]: value || null,
261
275
  },
262
276
  },
277
+ intl,
263
278
  });
264
279
  if (!blockHasValue(block)) {
265
280
  return newFormData;
@@ -288,6 +303,7 @@ export function mutateBlock(formData, id, value, blocksConfig) {
288
303
  ],
289
304
  },
290
305
  },
306
+ intl,
291
307
  });
292
308
  return newFormData;
293
309
  }
@@ -298,6 +314,10 @@ export function mutateBlock(formData, id, value, blocksConfig) {
298
314
  * @param {Object} formData Form data
299
315
  * @param {string} id Insert new block before the block with this id
300
316
  * @param {number} value New block's value
317
+ * @param {Object} current Current block
318
+ * @param {number} offset offset position
319
+ * @param {Object} blocksConfig Blocks configuration.
320
+ * @param {Object} intl intl object.
301
321
  * @return {Array} New block id, New form data
302
322
  */
303
323
  export function insertBlock(
@@ -307,6 +327,7 @@ export function insertBlock(
307
327
  current = {},
308
328
  offset = 0,
309
329
  blocksConfig,
330
+ intl,
310
331
  ) {
311
332
  const blocksFieldname = getBlocksFieldname(formData);
312
333
  const blocksLayoutFieldname = getBlocksLayoutFieldname(formData);
@@ -340,6 +361,7 @@ export function insertBlock(
340
361
  ],
341
362
  },
342
363
  },
364
+ intl,
343
365
  });
344
366
 
345
367
  return [newBlockId, newFormData];
@@ -568,6 +568,52 @@ describe('Blocks', () => {
568
568
  marker: true,
569
569
  });
570
570
  });
571
+
572
+ it('initialValue with intl', () => {
573
+ // Mock intl with formatMessage function
574
+ const intl = {
575
+ formatMessage: jest.fn(({ id }) => id),
576
+ };
577
+
578
+ const messages = {
579
+ intl: {
580
+ id: 'intl',
581
+ defaultMessage: 'intl',
582
+ },
583
+ };
584
+
585
+ config.blocks.blocksConfig.text.initialValue = ({
586
+ id,
587
+ value,
588
+ formData,
589
+ intl,
590
+ }) => {
591
+ return {
592
+ ...formData.blocks[id],
593
+ intl: intl.formatMessage(messages.intl),
594
+ };
595
+ };
596
+ const [newId, form] = addBlock(
597
+ {
598
+ blocks: { a: { value: 1 }, b: { value: 2 } },
599
+ blocks_layout: { items: ['a', 'b'] },
600
+ },
601
+ 'text',
602
+ 1,
603
+ config.blocks.blocksConfig,
604
+ intl,
605
+ );
606
+
607
+ delete config.blocks.blocksConfig.text.initialValue;
608
+
609
+ expect(form.blocks[newId]).toStrictEqual({
610
+ '@type': 'text',
611
+ booleanField: false,
612
+ description: 'Default description',
613
+ title: 'Default title',
614
+ intl: 'intl',
615
+ });
616
+ });
571
617
  });
572
618
 
573
619
  describe('moveBlock', () => {
@@ -171,7 +171,9 @@ export const patternValidator = ({
171
171
  }
172
172
  const regex = new RegExp(field.pattern);
173
173
  const isValid = regex.test(value);
174
- return !isValid ? formatMessage(messages.pattern) : null;
174
+ return !isValid
175
+ ? formatMessage(messages.pattern, { pattern: field.pattern })
176
+ : null;
175
177
  };
176
178
 
177
179
  export const maxItemsValidator = ({
@@ -1,10 +1,12 @@
1
1
  /**
2
- * Sitemap helper.
3
- * @module helpers/Sitemap
2
+ * Robots helper.
3
+ * @module helpers/Robots
4
4
  */
5
5
 
6
6
  import superagent from 'superagent';
7
+
7
8
  import config from '@plone/volto/registry';
9
+ import { formatUrl } from '@plone/volto/helpers/Api/Api';
8
10
  import { addHeadersFactory } from '@plone/volto/helpers/Proxy/Proxy';
9
11
 
10
12
  /**
@@ -15,43 +17,22 @@ import { addHeadersFactory } from '@plone/volto/helpers/Proxy/Proxy';
15
17
  */
16
18
  export const generateRobots = (req) =>
17
19
  new Promise((resolve) => {
18
- const internalUrl =
19
- config.settings.internalApiPath ??
20
- config.settings.devProxyToApiPath ??
21
- config.settings.apiPath;
22
- const request = superagent.get(`${internalUrl}/robots.txt`);
23
- request.set('Accept', 'text/plain');
20
+ const request = superagent.get(formatUrl('@site'));
21
+ request.set('Accept', 'application/json');
24
22
  const authToken = req.universalCookies.get('auth_token');
25
23
  if (authToken) {
26
24
  request.set('Authorization', `Bearer ${authToken}`);
27
25
  }
28
26
  request.use(addHeadersFactory(req));
29
- request.end((error, { text }) => {
27
+ request.end((error, { text, body }) => {
30
28
  if (error) {
31
29
  resolve(text || error);
32
30
  } else {
33
- // It appears that express does not take the x-forwarded headers into
34
- // consideration, so we do it ourselves.
35
- const {
36
- 'x-forwarded-proto': forwardedProto,
37
- 'x-forwarded-host': forwardedHost,
38
- 'x-forwarded-port': forwardedPort,
39
- } = req.headers;
40
- const proto = forwardedProto ?? req.protocol;
41
- const host = forwardedHost ?? req.get('Host');
42
- const portNum = forwardedPort ?? req.get('Port');
43
- const port =
44
- (proto === 'https' && '' + portNum === '443') ||
45
- (proto === 'http' && '' + portNum === '80')
46
- ? ''
47
- : `:${portNum}`;
48
- // Plone has probably returned the sitemap link with the internal url.
49
- // If so, let's replace it with the current one.
50
- const url = `${proto}://${host}${port}`;
51
- text = text.replace(internalUrl, url);
52
- // Replace the sitemap with the sitemap index.
53
- text = text.replace('sitemap.xml.gz', 'sitemap-index.xml');
54
- resolve(text);
31
+ resolve(
32
+ body['plone.robots_txt']
33
+ .replace('{portal_url}', config.settings.publicURL)
34
+ .replace('sitemap.xml.gz', 'sitemap-index.xml'),
35
+ );
55
36
  }
56
37
  });
57
38
  });
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Format the url.
3
+ * @function formatUrl
4
+ * @param {string} path Path (or URL) to be formatted.
5
+ * @returns {string} Formatted path.
6
+ */
7
+ export function formatUrl(path: string): string;
1
8
  export default Api;
2
9
  /**
3
10
  * Api class.
@@ -40,36 +40,45 @@ export function moveBlock(formData: any, source: number, destination: number): a
40
40
  * @function deleteBlock
41
41
  * @param {Object} formData Form data
42
42
  * @param {string} blockId Block uid
43
+ * @param {Object} intl intl object.
43
44
  * @return {Object} New form data
44
45
  */
45
- export function deleteBlock(formData: any, blockId: string): any;
46
+ export function deleteBlock(formData: any, blockId: string, intl: any): any;
46
47
  /**
47
48
  * Adds a block to the blocks form
48
49
  * @function addBlock
49
50
  * @param {Object} formData Form data
50
51
  * @param {string} type Block type
51
52
  * @param {number} index Destination index
53
+ * @param {Object} blocksConfig Blocks configuration.
54
+ * @param {Object} intl intl object.
52
55
  * @return {Array} New block id, New form data
53
56
  */
54
- export function addBlock(formData: any, type: string, index: number, blocksConfig: any): any[];
57
+ export function addBlock(formData: any, type: string, index: number, blocksConfig: any, intl: any): any[];
55
58
  /**
56
59
  * Mutate block, changes the block @type
57
60
  * @function mutateBlock
58
61
  * @param {Object} formData Form data
59
62
  * @param {string} id Block uid to mutate
60
63
  * @param {number} value Block's new value
64
+ * @param {Object} blocksConfig Blocks configuration.
65
+ * @param {Object} intl intl object.
61
66
  * @return {Object} New form data
62
67
  */
63
- export function mutateBlock(formData: any, id: string, value: number, blocksConfig: any): any;
68
+ export function mutateBlock(formData: any, id: string, value: number, blocksConfig: any, intl: any): any;
64
69
  /**
65
70
  * Insert new block before another block
66
71
  * @function insertBlock
67
72
  * @param {Object} formData Form data
68
73
  * @param {string} id Insert new block before the block with this id
69
74
  * @param {number} value New block's value
75
+ * @param {Object} current Current block
76
+ * @param {number} offset offset position
77
+ * @param {Object} blocksConfig Blocks configuration.
78
+ * @param {Object} intl intl object.
70
79
  * @return {Array} New block id, New form data
71
80
  */
72
- export function insertBlock(formData: any, id: string, value: number, current: {}, offset: number, blocksConfig: any): any[];
81
+ export function insertBlock(formData: any, id: string, value: number, current: any, offset: number, blocksConfig: any, intl: any): any[];
73
82
  /**
74
83
  * Change block
75
84
  * @function changeBlock
@@ -167,11 +176,12 @@ export function findBlocks(blocks: {}, types: any, result?: any[]): any[];
167
176
  */
168
177
  export function moveBlockEnhanced(formData: any, { source, destination }: number): any;
169
178
  export function getBlocks(properties: any): any[];
170
- export function applyBlockInitialValue({ id, value, blocksConfig, formData, }: {
179
+ export function applyBlockInitialValue({ id, value, blocksConfig, formData, intl, }: {
171
180
  id: any;
172
181
  value: any;
173
182
  blocksConfig: any;
174
183
  formData: any;
184
+ intl: any;
175
185
  }): any;
176
186
  export function styleToClassName(key: any, value: any, prefix?: string): any;
177
187
  export function buildStyleClassNamesFromData(obj?: {}, prefix?: string): any;
@@ -1,36 +0,0 @@
1
- /*
2
- This file is autogenerated. Don't change it directly.
3
- Instead, change the "addons" setting in your package.json file.
4
- */
5
-
6
- const addonsInfo = [];
7
- export { addonsInfo };
8
-
9
- const safeWrapper = (func) => (config) => {
10
- const res = func(config);
11
- if (typeof res === 'undefined') {
12
- throw new Error("Configuration function doesn't return config");
13
- }
14
- return res;
15
- };
16
-
17
- const projectConfigLoader = false;
18
- const projectConfig = (config) => {
19
- return projectConfigLoader &&
20
- typeof projectConfigLoader.default === 'function'
21
- ? projectConfigLoader.default(config)
22
- : config;
23
- };
24
-
25
- const load = (config) => {
26
- const addonLoaders = [];
27
- if (!addonLoaders.every((el) => typeof el === 'function')) {
28
- throw new TypeError(
29
- 'Each addon has to provide a function applying its configuration to the projects configuration.',
30
- );
31
- }
32
- return projectConfig(
33
- addonLoaders.reduce((acc, apply) => safeWrapper(apply)(acc), config),
34
- );
35
- };
36
- export default load;
package/public/robots.txt DELETED
@@ -1,2 +0,0 @@
1
- User-agent: *
2
-