@eeacms/volto-eea-website-policy 2.3.0 → 2.3.2

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,18 @@ 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
+ ### [2.3.2](https://github.com/eea/volto-eea-website-policy/compare/2.3.1...2.3.2) - 30 January 2025
8
+
9
+ #### :bug: Bug Fixes
10
+
11
+ - fix: Move restricted block to common addon volto-eea-website-theme [alin - [`8301aba`](https://github.com/eea/volto-eea-website-policy/commit/8301aba89acf4db73fd6f2d2c8c41464255eb355)]
12
+
13
+ ### [2.3.1](https://github.com/eea/volto-eea-website-policy/compare/2.3.0...2.3.1) - 30 January 2025
14
+
15
+ #### :bug: Bug Fixes
16
+
17
+ - fix: error on edititing html block and make it readonly - refs #282438 [Teodor Voicu - [`302e393`](https://github.com/eea/volto-eea-website-policy/commit/302e393c8214465673d757b50b89d89574f0f4a8)]
18
+
7
19
  ### [2.3.0](https://github.com/eea/volto-eea-website-policy/compare/2.2.3...2.3.0) - 11 October 2024
8
20
 
9
21
  #### :rocket: New Features
@@ -45,6 +57,12 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
45
57
  - removed double rolesWhoCanChangeLayout setting [David Ichim - [`37dab9e`](https://github.com/eea/volto-eea-website-policy/commit/37dab9ef04dc1497655e49186f398b5dd53f39b1)]
46
58
  - use contextnavigation in policy [nileshgulia1 - [`eea2258`](https://github.com/eea/volto-eea-website-policy/commit/eea2258244c146ff682e055ffb88cf0b9020da93)]
47
59
  - move contextNav to volto-eea-website-theme [nileshgulia1 - [`07aa147`](https://github.com/eea/volto-eea-website-policy/commit/07aa14746a0253f75dc7c63610e1998eae6ffbf5)]
60
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`f620f72`](https://github.com/eea/volto-eea-website-policy/commit/f620f72b1bee27d9215b4cec5ddbe125ae0f7030)]
61
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`13b94c3`](https://github.com/eea/volto-eea-website-policy/commit/13b94c308e20970b4a30e1ec12734e8eaabfffb9)]
62
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`8ebc23d`](https://github.com/eea/volto-eea-website-policy/commit/8ebc23dac8134ffed5b8f89d117cec1a13790c2c)]
63
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`a57c3eb`](https://github.com/eea/volto-eea-website-policy/commit/a57c3eb88ad31cc50f5321c406ac5b5d918bf623)]
64
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`f26c537`](https://github.com/eea/volto-eea-website-policy/commit/f26c537fa75fcb6eedad808a933a8a0689eda9f8)]
65
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`b1491ca`](https://github.com/eea/volto-eea-website-policy/commit/b1491ca3c9f07a7b91b9e892b0e53e4cf82762ce)]
48
66
  - Added extra handleOutsideClick on Accordion mobile and tablet to close when clicking besides the smaller menu [David Ichim - [`6d36534`](https://github.com/eea/volto-eea-website-policy/commit/6d365349ba9f779b527344d6d109c77d77501acf)]
49
67
  - close nav on tablet or mobile resolution by default [David Ichim - [`9e119d2`](https://github.com/eea/volto-eea-website-policy/commit/9e119d23d50dd5a614279da6ec3ccc369a16ba19)]
50
68
  - dropped useless code [David Ichim - [`7f5c122`](https://github.com/eea/volto-eea-website-policy/commit/7f5c122c596eb4db7f0ea4c81708b3c88aca657b)]
@@ -69,6 +87,14 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
69
87
 
70
88
  #### :hammer_and_wrench: Others
71
89
 
90
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`74f7cb1`](https://github.com/eea/volto-eea-website-policy/commit/74f7cb1b4f7dd3232f9a6c0ad35e50bc86b64e60)]
91
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`c8978f0`](https://github.com/eea/volto-eea-website-policy/commit/c8978f02c53c38d88b654544051aa28ba5ccd05c)]
92
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`fb31e28`](https://github.com/eea/volto-eea-website-policy/commit/fb31e285959820147aa07e827cea25589d27be63)]
93
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`3b0c059`](https://github.com/eea/volto-eea-website-policy/commit/3b0c059772a0ca32f398c17b6ddb74be8e2f0060)]
94
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`25d16e4`](https://github.com/eea/volto-eea-website-policy/commit/25d16e401b4d2685a201a1b3a9830916ed4c5b80)]
95
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`d4fdfaf`](https://github.com/eea/volto-eea-website-policy/commit/d4fdfaf94d8fa962906cf713c865202bbff1ff60)]
96
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`742d72c`](https://github.com/eea/volto-eea-website-policy/commit/742d72c1f020fc7a2ed553dc739be54daeb2283d)]
97
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`e3dc5ef`](https://github.com/eea/volto-eea-website-policy/commit/e3dc5ef5da18aa64091388d8779dcc2819e5ad80)]
72
98
  ### [2.2.2](https://github.com/eea/volto-eea-website-policy/compare/2.2.1...2.2.2) - 28 August 2024
73
99
 
74
100
  #### :bug: Bug Fixes
@@ -77,6 +103,10 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
77
103
 
78
104
  #### :hammer_and_wrench: Others
79
105
 
106
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`2703b09`](https://github.com/eea/volto-eea-website-policy/commit/2703b09f3803fa058b45f3f55c5343ab548139a1)]
107
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`2506307`](https://github.com/eea/volto-eea-website-policy/commit/2506307c355c2de50a40b76a6c09ac1989d11be1)]
108
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`48999a4`](https://github.com/eea/volto-eea-website-policy/commit/48999a4a5a16593ca90981a72a4606abc4a02e89)]
109
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`de57cc0`](https://github.com/eea/volto-eea-website-policy/commit/de57cc0093cec55cf372fe4beb610f77588b4bb3)]
80
110
  ### [2.2.1](https://github.com/eea/volto-eea-website-policy/compare/2.2.0...2.2.1) - 27 August 2024
81
111
 
82
112
  #### :bug: Bug Fixes
@@ -85,6 +115,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
85
115
 
86
116
  #### :hammer_and_wrench: Others
87
117
 
118
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`e333afd`](https://github.com/eea/volto-eea-website-policy/commit/e333afd4354f5a78f7c2aec9026df928219c144a)]
119
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`9cb821a`](https://github.com/eea/volto-eea-website-policy/commit/9cb821a08010dfae144a5a4ae30e1c40da65d02a)]
88
120
  ### [2.2.0](https://github.com/eea/volto-eea-website-policy/compare/2.1.1...2.2.0) - 26 August 2024
89
121
 
90
122
  #### :rocket: New Features
@@ -93,6 +125,20 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
93
125
 
94
126
  #### :hammer_and_wrench: Others
95
127
 
128
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`9864108`](https://github.com/eea/volto-eea-website-policy/commit/9864108aea2be5def74d4d89542e0babf1fbc93b)]
129
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`d406101`](https://github.com/eea/volto-eea-website-policy/commit/d40610109bd581903a4a6212867197a352b3cc06)]
130
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`16936d4`](https://github.com/eea/volto-eea-website-policy/commit/16936d4b67baead7f2572eb19c47c9423da1af5a)]
131
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`1c1c92b`](https://github.com/eea/volto-eea-website-policy/commit/1c1c92bc8ea0a036cebf2b854197c52dd1f8681a)]
132
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`21accb1`](https://github.com/eea/volto-eea-website-policy/commit/21accb12e958b832f7463da93684f470420d1714)]
133
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`4898d16`](https://github.com/eea/volto-eea-website-policy/commit/4898d1673ba71098d18385d123f1fa403ff8089e)]
134
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`c4e596f`](https://github.com/eea/volto-eea-website-policy/commit/c4e596f4efbee0f835bf293f713da21669bc8c00)]
135
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`aa79040`](https://github.com/eea/volto-eea-website-policy/commit/aa7904074d9b90208218b4a801ea68491727de68)]
136
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`6c3aa38`](https://github.com/eea/volto-eea-website-policy/commit/6c3aa382200cd756f4bd7b40fee96bef71d5079e)]
137
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`9adc480`](https://github.com/eea/volto-eea-website-policy/commit/9adc480e0edf278386a065bf30b66c138592ee82)]
138
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`5554c13`](https://github.com/eea/volto-eea-website-policy/commit/5554c13183d7adda41dca07593fd51846b0d1375)]
139
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`e526958`](https://github.com/eea/volto-eea-website-policy/commit/e52695821dce6790ff89213f967569bce223680b)]
140
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`7e0381c`](https://github.com/eea/volto-eea-website-policy/commit/7e0381cd77ef067541585421a94536849dbdf4b5)]
141
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`3473b02`](https://github.com/eea/volto-eea-website-policy/commit/3473b02f98ea09fe4afa46389f14468c1897586d)]
96
142
  ### [2.1.1](https://github.com/eea/volto-eea-website-policy/compare/2.1.0...2.1.1) - 30 May 2024
97
143
 
98
144
  #### :house: Internal changes
@@ -101,6 +147,12 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
101
147
 
102
148
  #### :hammer_and_wrench: Others
103
149
 
150
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`c297b9e`](https://github.com/eea/volto-eea-website-policy/commit/c297b9efe743ad1f95ab662007a2186b5f042f4c)]
151
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`b11c055`](https://github.com/eea/volto-eea-website-policy/commit/b11c055d0a41c89a60f70875124994ba52772e48)]
152
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`a77d04e`](https://github.com/eea/volto-eea-website-policy/commit/a77d04e9f1e4d6b8657e09fd1a2bcde66499f77f)]
153
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`12c6e92`](https://github.com/eea/volto-eea-website-policy/commit/12c6e92e4157896bf812dbbd8996c754b491d3ea)]
154
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`0aa866d`](https://github.com/eea/volto-eea-website-policy/commit/0aa866dc6fb5f4226a99a3e192a958af60385185)]
155
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`7517f96`](https://github.com/eea/volto-eea-website-policy/commit/7517f96d82efd6a7ddaa746c81a51997583363f6)]
104
156
  ### [2.1.0](https://github.com/eea/volto-eea-website-policy/compare/2.0.0...2.1.0) - 9 May 2024
105
157
 
106
158
  #### :rocket: New Features
@@ -110,6 +162,10 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
110
162
  #### :hammer_and_wrench: Others
111
163
 
112
164
  - Release 2.1.0 [alin - [`da22af4`](https://github.com/eea/volto-eea-website-policy/commit/da22af436092236d7ef6e8568e3eca4813d517b5)]
165
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`9a5d706`](https://github.com/eea/volto-eea-website-policy/commit/9a5d7064e829622e2627c616c4ca1ce71511dfcb)]
166
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`f8b40e9`](https://github.com/eea/volto-eea-website-policy/commit/f8b40e961138efc4090d0ab45a5689905c672b15)]
167
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`4ab2144`](https://github.com/eea/volto-eea-website-policy/commit/4ab2144e02291d98064b001d9eb40417da4d1795)]
168
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`5af4642`](https://github.com/eea/volto-eea-website-policy/commit/5af464227c6695c7e2d3ccd9f240c2a5071bfefa)]
113
169
  ## [2.0.0](https://github.com/eea/volto-eea-website-policy/compare/1.15.0...2.0.0) - 22 April 2024
114
170
 
115
171
  #### :rocket: New Features
@@ -182,6 +238,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
182
238
 
183
239
  #### :hammer_and_wrench: Others
184
240
 
241
+ - test: [JENKINS] fail with logs on coverage [valentinab25 - [`5cf68f8`](https://github.com/eea/volto-eea-website-policy/commit/5cf68f8db34448d10fe993d16541ad9732434cc8)]
185
242
  ### [1.12.0-beta.1](https://github.com/eea/volto-eea-website-policy/compare/1.11.1...1.12.0-beta.1) - 12 January 2024
186
243
 
187
244
  #### :hammer_and_wrench: Others
@@ -202,6 +259,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
202
259
  #### :hammer_and_wrench: Others
203
260
 
204
261
  - Release 1.11.0 [Alin Voinea - [`3249160`](https://github.com/eea/volto-eea-website-policy/commit/3249160422c6c6e0cf14823b614f8885101a847a)]
262
+ - test: [JENKINS] Use java17 for sonarqube scanner [valentinab25 - [`8beb7e7`](https://github.com/eea/volto-eea-website-policy/commit/8beb7e7a12cbc314e56e4b1aceab5ef8d00ca6f3)]
263
+ - test: [JENKINS] Run cypress in started frontend container [valentinab25 - [`12d3da1`](https://github.com/eea/volto-eea-website-policy/commit/12d3da12e9a3b0882cf55efe2d40f3032724d41b)]
264
+ - test: [JENKINS] Add cpu limit on cypress docker [valentinab25 - [`0af0764`](https://github.com/eea/volto-eea-website-policy/commit/0af076467120ed9a80c697931e869837b92a0a4c)]
265
+ - test: [JENKINS] Increase shm-size to cypress docker [valentinab25 - [`8662e3e`](https://github.com/eea/volto-eea-website-policy/commit/8662e3e5fc3640d678ce320eb8856a37d419306c)]
266
+ - test: [JENKINS] Improve cypress time [valentinab25 - [`ef1074f`](https://github.com/eea/volto-eea-website-policy/commit/ef1074fdf968cafdf476d4ee4951eb18ebac048a)]
205
267
  ### [1.10.0](https://github.com/eea/volto-eea-website-policy/compare/1.9.2...1.10.0) - 2 November 2023
206
268
 
207
269
  #### :rocket: New Features
@@ -210,6 +272,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
210
272
 
211
273
  #### :house: Internal changes
212
274
 
275
+ - chore: [JENKINS] Refactor automated testing [valentinab25 - [`8b1b422`](https://github.com/eea/volto-eea-website-policy/commit/8b1b42297b46d9fb7325589b3bd043233c0d66e9)]
213
276
  - chore: husky, lint-staged use fixed versions [valentinab25 - [`44ac62e`](https://github.com/eea/volto-eea-website-policy/commit/44ac62e6f8b7e5b7d57edfbf82812c91dc5d6bba)]
214
277
  - chore:volto 16 in tests, update docs, fix stylelint overrides [valentinab25 - [`b9a46d8`](https://github.com/eea/volto-eea-website-policy/commit/b9a46d85a64739188a3df9e8cbe645418b5d8b0a)]
215
278
 
@@ -330,6 +393,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
330
393
 
331
394
  - Release 1.5.0 [Alin Voinea - [`a3dea8e`](https://github.com/eea/volto-eea-website-policy/commit/a3dea8ea15cb8d2a876dc10da926ece3a5707ea9)]
332
395
  - test(Jenkinsfile): Use latest stable volto for testing [Alin Voinea - [`a8f7123`](https://github.com/eea/volto-eea-website-policy/commit/a8f712364187f9638886667c249fa102cb49b5c0)]
396
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`124a8f8`](https://github.com/eea/volto-eea-website-policy/commit/124a8f8ad4ced507aeec27012d725f2e2b977e08)]
333
397
  ### [1.4.0](https://github.com/eea/volto-eea-website-policy/compare/1.3.4...1.4.0) - 21 February 2023
334
398
 
335
399
  #### :rocket: New Features
@@ -409,6 +473,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
409
473
  #### :hammer_and_wrench: Others
410
474
 
411
475
  - Release 1.1.0 [Alin Voinea - [`0291b3b`](https://github.com/eea/volto-eea-website-policy/commit/0291b3bb7b4c6ab09ca98728885cea4051eac8e3)]
476
+ - yarn 3 [Alin Voinea - [`593aa58`](https://github.com/eea/volto-eea-website-policy/commit/593aa58eaa4d28aced0603b7f7dd125c857a6f54)]
412
477
  ### [1.0.4](https://github.com/eea/volto-eea-website-policy/compare/1.0.3...1.0.4) - 22 November 2022
413
478
 
414
479
  #### :nail_care: Enhancements
@@ -454,6 +519,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
454
519
 
455
520
  #### :hammer_and_wrench: Others
456
521
 
522
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`d153f54`](https://github.com/eea/volto-eea-website-policy/commit/d153f54e55e918fa4746e05488c734624eaf14a9)]
457
523
  ### [0.4.0](https://github.com/eea/volto-eea-website-policy/compare/0.3.3...0.4.0) - 19 September 2022
458
524
 
459
525
  #### :hammer_and_wrench: Others
@@ -529,6 +595,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
529
595
  - format index.js [Andrei Grigore - [`db4481a`](https://github.com/eea/volto-eea-website-policy/commit/db4481aeeba59a769272659f33278c902fc69bec)]
530
596
  - Update index.js [Alexandru Ghica - [`dc09886`](https://github.com/eea/volto-eea-website-policy/commit/dc0988640a76a9914381b120f58bb61a9ab1eb39)]
531
597
  - Added externalRoutes [Alexandru Ghica - [`b68135b`](https://github.com/eea/volto-eea-website-policy/commit/b68135b013fafa93a41ea602ea2fad30879abe0f)]
598
+ - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`575cca6`](https://github.com/eea/volto-eea-website-policy/commit/575cca674602ca2e1c2a41300c47ba594ff49aa0)]
532
599
  ### [0.1.1](https://github.com/eea/volto-eea-website-policy/compare/0.1.0...0.1.1) - 4 March 2022
533
600
 
534
601
  #### :hammer_and_wrench: Others
@@ -541,4 +608,5 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
541
608
 
542
609
  #### :hammer_and_wrench: Others
543
610
 
611
+ - yarn bootstrap [Alin Voinea - [`9b4d197`](https://github.com/eea/volto-eea-website-policy/commit/9b4d197cbc7992566cb36524d190078d5ad21a44)]
544
612
  - 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": "2.3.0",
3
+ "version": "2.3.2",
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",
@@ -0,0 +1,371 @@
1
+ /**
2
+ * Edit html block.
3
+ * @module components/manage/Blocks/HTML/Edit
4
+ */
5
+
6
+ import { compose } from 'redux';
7
+ import React, { Component } from 'react';
8
+ import PropTypes from 'prop-types';
9
+ import { Button, Popup } from 'semantic-ui-react';
10
+ import { defineMessages, injectIntl } from 'react-intl';
11
+ import loadable from '@loadable/component';
12
+ import { isEqual } from 'lodash';
13
+
14
+ import { Icon } from '@plone/volto/components';
15
+ import { injectLazyLibs } from '@plone/volto/helpers/Loadable/Loadable';
16
+ import showSVG from '@plone/volto/icons/show.svg';
17
+ // import clearSVG from '@plone/volto/icons/clear.svg';
18
+ // import codeSVG from '@plone/volto/icons/code.svg';
19
+ // import indentSVG from '@plone/volto/icons/indent.svg';
20
+
21
+ const Editor = loadable(() => import('react-simple-code-editor'));
22
+
23
+ const messages = defineMessages({
24
+ source: {
25
+ id: 'Source',
26
+ defaultMessage: 'Source',
27
+ },
28
+ preview: {
29
+ id: 'Preview',
30
+ defaultMessage: 'Preview',
31
+ },
32
+ placeholder: {
33
+ id: '<p>Add some HTML here</p>',
34
+ defaultMessage: '<p>Add some HTML here</p>',
35
+ },
36
+ prettier: {
37
+ id: 'Prettify your code',
38
+ defaultMessage: 'Prettify your code',
39
+ },
40
+ clear: {
41
+ id: 'Clear',
42
+ defaultMessage: 'Clear',
43
+ },
44
+ code: {
45
+ id: 'Code',
46
+ defaultMessage: 'Code',
47
+ },
48
+ });
49
+
50
+ /**
51
+ * Edit html block class.
52
+ * @class Edit
53
+ * @extends Component
54
+ */
55
+ class Edit extends Component {
56
+ /**
57
+ * Property types.
58
+ * @property {Object} propTypes Property types.
59
+ * @static
60
+ */
61
+ static propTypes = {
62
+ selected: PropTypes.bool.isRequired,
63
+ block: PropTypes.string.isRequired,
64
+ index: PropTypes.number.isRequired,
65
+ data: PropTypes.objectOf(PropTypes.any).isRequired,
66
+ onChangeBlock: PropTypes.func.isRequired,
67
+ onSelectBlock: PropTypes.func.isRequired,
68
+ onDeleteBlock: PropTypes.func.isRequired,
69
+ handleKeyDown: PropTypes.func.isRequired,
70
+ editable: PropTypes.bool,
71
+ };
72
+
73
+ /**
74
+ * Default properties
75
+ * @property {Object} defaultProps Default properties.
76
+ * @static
77
+ */
78
+ static defaultProps = {
79
+ editable: true,
80
+ };
81
+ /**
82
+ * Constructor
83
+ * @method constructor
84
+ * @param {Object} props Component properties
85
+ */
86
+ constructor(props) {
87
+ super(props);
88
+ this.state = {
89
+ isPreview: false,
90
+ };
91
+ this.onChangeCode = this.onChangeCode.bind(this);
92
+ this.onPreview = this.onPreview.bind(this);
93
+ this.onCodeEditor = this.onCodeEditor.bind(this);
94
+ }
95
+
96
+ codeEditorRef = React.createRef();
97
+ savedSelection = {};
98
+
99
+ componentDidUpdate(prevProps, prevState, snapshot) {
100
+ if (this.codeEditorRef.current) {
101
+ this.savedSelection = snapshot;
102
+ this.restoreSelectionAndFocus(this.codeEditorRef.current);
103
+ }
104
+ }
105
+
106
+ /**
107
+ * @param {*} nextProps
108
+ * @param {*} nextState
109
+ * @returns {boolean}
110
+ * @memberof Edit
111
+ */
112
+ shouldComponentUpdate(nextProps) {
113
+ // Always rerender when the DOM node is not created for the Editor (the
114
+ // first call to shouldComponentUpdate).
115
+ if (!this._input) {
116
+ return true;
117
+ }
118
+
119
+ // Rerender the entire component when the Editor in it changes its selection
120
+ // because this way we get a call to getSnapshotBeforeUpdate where we can
121
+ // save the selection.
122
+ return (
123
+ this.props.selected ||
124
+ !isEqual(this.props.data, nextProps.data) ||
125
+ this._input.selectionStart !== this.savedSelection.selectionStart ||
126
+ this._input.selectionEnd !== this.savedSelection.selectionEnd
127
+ );
128
+ }
129
+
130
+ /**
131
+ * Change html handler
132
+ * @method onChangeCode
133
+ * @param {string} code New value html
134
+ * @returns {undefined}
135
+ */
136
+ onChangeCode(code) {
137
+ this.props.onChangeBlock(this.props.block, {
138
+ ...this.props.data,
139
+ html: code,
140
+ });
141
+ }
142
+
143
+ getValue() {
144
+ return this.props.data.html || '';
145
+ }
146
+
147
+ /**
148
+ * Preview mode handler
149
+ * @method onPreview
150
+ * @returns {undefined}
151
+ */
152
+ async onPreview() {
153
+ try {
154
+ const code = (
155
+ await this.props.prettierStandalone.format(this.getValue(), {
156
+ parser: 'html',
157
+ plugins: [this.props.prettierParserHtml],
158
+ })
159
+ ).trim();
160
+ this.setState(
161
+ {
162
+ isPreview: !this.state.isPreview,
163
+ },
164
+ () => this.onChangeCode(code),
165
+ );
166
+ } catch (ex) {
167
+ // error while parsing the user-typed HTML
168
+ // TODO: show a toast notification or something similar to the user
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Prettify handler
174
+ * @method onPrettify
175
+ * @returns {undefined}
176
+ */
177
+ onPrettify = async () => {
178
+ try {
179
+ const code = (
180
+ await this.props.prettierStandalone.format(this.getValue(), {
181
+ parser: 'html',
182
+ plugins: [this.props.prettierParserHtml],
183
+ })
184
+ ).trim();
185
+ this.onChangeCode(code);
186
+ } catch (ex) {
187
+ // error while parsing the user-typed HTML
188
+ // TODO: show a toast notification or something similar to the user
189
+ }
190
+ };
191
+
192
+ /**
193
+ * Code Editor mode handler
194
+ * @method onPreview
195
+ * @returns {undefined}
196
+ */
197
+ onCodeEditor() {
198
+ this.setState({ isPreview: !this.state.isPreview });
199
+ }
200
+
201
+ getSelection = (editor) => {
202
+ if (!editor || !editor._input) {
203
+ return {};
204
+ }
205
+
206
+ return {
207
+ selectionStart: editor._input.selectionStart || 0,
208
+ selectionEnd: editor._input.selectionEnd || 0,
209
+ };
210
+ };
211
+
212
+ getSnapshotBeforeUpdate(prevProps, prevState) {
213
+ return this.codeEditorRef.current
214
+ ? this.getSelection(this.codeEditorRef.current)
215
+ : {};
216
+ }
217
+
218
+ restoreSelectionAndFocus = (editor) => {
219
+ if (!editor || !editor._input) {
220
+ return;
221
+ }
222
+ // Don't restore selection when the block is not selected.
223
+ if (
224
+ this.props.selected &&
225
+ editor._input &&
226
+ typeof this.savedSelection?.selectionStart === 'number' &&
227
+ typeof this.savedSelection?.selectionEnd === 'number'
228
+ ) {
229
+ editor._input.selectionStart = this.savedSelection?.selectionStart;
230
+ editor._input.selectionEnd = this.savedSelection?.selectionEnd;
231
+ editor._input.focus();
232
+ }
233
+ };
234
+
235
+ /**
236
+ * Render method.
237
+ * @method render
238
+ * @returns {string} Markup for the component.
239
+ */
240
+ render() {
241
+ const placeholder =
242
+ this.props.data.placeholder ||
243
+ this.props.intl.formatMessage(messages.placeholder);
244
+ const value = this.getValue();
245
+ return (
246
+ <>
247
+ {this.props.selected && value && (
248
+ <div className="toolbar">
249
+ {/* Hide temporary this feature in toolbar.*/}
250
+ {/* <Popup
251
+ trigger={
252
+ <Button
253
+ icon
254
+ basic
255
+ aria-label={this.props.intl.formatMessage(messages.source)}
256
+ active={!this.state.isPreview}
257
+ onClick={this.onCodeEditor}
258
+ >
259
+ <Icon name={codeSVG} size="24px" />
260
+ </Button>
261
+ }
262
+ position="top center"
263
+ content={this.props.intl.formatMessage(messages.code)}
264
+ size="mini"
265
+ /> */}
266
+ <Popup
267
+ trigger={
268
+ <Button
269
+ icon
270
+ basic
271
+ aria-label={this.props.intl.formatMessage(messages.preview)}
272
+ active={this.state.isPreview}
273
+ onClick={this.onPreview}
274
+ >
275
+ <Icon name={showSVG} size="24px" />
276
+ </Button>
277
+ }
278
+ position="top center"
279
+ content={this.props.intl.formatMessage(messages.preview)}
280
+ size="mini"
281
+ />
282
+ {/* Hide temporary this feature in toolbar. */}
283
+ {/* <Popup
284
+ trigger={
285
+ <Button
286
+ icon
287
+ basic
288
+ aria-label={this.props.intl.formatMessage(messages.prettier)}
289
+ onClick={this.onPrettify}
290
+ >
291
+ <Icon name={indentSVG} size="24px" />
292
+ </Button>
293
+ }
294
+ position="top center"
295
+ content={this.props.intl.formatMessage(messages.prettier)}
296
+ size="mini"
297
+ />
298
+ <div className="separator" />
299
+ <Popup
300
+ trigger={
301
+ <Button.Group>
302
+ <Button icon basic onClick={() => this.onChangeCode('')}>
303
+ <Icon name={clearSVG} size="24px" color="#e40166" />
304
+ </Button>
305
+ </Button.Group>
306
+ }
307
+ position="top center"
308
+ content={this.props.intl.formatMessage(messages.clear)}
309
+ size="mini"
310
+ /> */}
311
+ </div>
312
+ )}
313
+ {this.state.isPreview ? (
314
+ <div dangerouslySetInnerHTML={{ __html: value }} />
315
+ ) : (
316
+ <Editor
317
+ value={this.getValue()}
318
+ readOnly={true}
319
+ placeholder={placeholder}
320
+ onValueChange={(code) => this.onChangeCode(code)}
321
+ highlight={
322
+ this.props.prismCore?.highlight &&
323
+ this.props.prismCore?.languages?.html
324
+ ? (code) =>
325
+ this.props.prismCore.highlight(
326
+ code,
327
+ this.props.prismCore.languages.html,
328
+ 'html',
329
+ )
330
+ : () => {}
331
+ }
332
+ padding={8}
333
+ className="html-editor"
334
+ ref={(node) => {
335
+ if (node) {
336
+ this.codeEditorRef.current = node;
337
+ }
338
+ }}
339
+ ignoreTabKey={true}
340
+ />
341
+ )}
342
+ </>
343
+ );
344
+ }
345
+ }
346
+
347
+ const withPrismMarkup = (WrappedComponent) => (props) => {
348
+ const [loaded, setLoaded] = React.useState();
349
+ const promise = React.useRef(null);
350
+ const cancelled = React.useRef(false);
351
+
352
+ React.useEffect(() => {
353
+ promise.current = import('prismjs/components/prism-markup');
354
+ promise.current.then(() => {
355
+ if (!cancelled.current) {
356
+ setLoaded(true);
357
+ }
358
+ });
359
+ return () => {
360
+ cancelled.current = true;
361
+ };
362
+ }, []);
363
+
364
+ return loaded ? <WrappedComponent {...props} /> : null;
365
+ };
366
+
367
+ export default compose(
368
+ injectLazyLibs(['prettierStandalone', 'prettierParserHtml', 'prismCore']),
369
+ withPrismMarkup,
370
+ injectIntl,
371
+ )(Edit);