@eeacms/volto-group-block 4.2.2 → 4.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.
@@ -0,0 +1,9 @@
1
+ const defaultBabel = require('@plone/volto/babel');
2
+
3
+ function applyDefault(api) {
4
+ const voltoBabel = defaultBabel(api);
5
+ voltoBabel.plugins.push('@babel/plugin-transform-modules-commonjs', 'transform-class-properties', 'istanbul');
6
+ return voltoBabel;
7
+ }
8
+
9
+ module.exports = applyDefault;
package/CHANGELOG.md CHANGED
@@ -4,9 +4,35 @@ 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
+ #### [4.3.2](https://github.com/eea/volto-group-block/compare/4.3.1...4.3.2)
8
+
9
+ - Correct Cypress tests [`#13`](https://github.com/eea/volto-group-block/pull/13)
10
+ - Refs #142010 - Optimize Volto-addons gitflow pipelines [`bc36cf5`](https://github.com/eea/volto-group-block/commit/bc36cf58c39e2b43c2fbf5189df6ddefc1260857)
11
+
12
+ #### [4.3.1](https://github.com/eea/volto-group-block/compare/4.3.0...4.3.1)
13
+
14
+ > 11 October 2021
15
+
16
+ - Possibility to ignore spaces with maxChars [`#11`](https://github.com/eea/volto-group-block/pull/11)
17
+ - No space count [`#10`](https://github.com/eea/volto-group-block/pull/10)
18
+
19
+ #### [4.3.0](https://github.com/eea/volto-group-block/compare/4.2.3...4.3.0)
20
+
21
+ > 24 June 2021
22
+
23
+ - Refactor counter to use CSS class instead of inline style [`#9`](https://github.com/eea/volto-group-block/pull/9)
24
+ - Show help icon only if block instructions differ from section instructions [`a4ca4e5`](https://github.com/eea/volto-group-block/commit/a4ca4e58968dcfb947072a255c8f797df7977852)
25
+
26
+ #### [4.2.3](https://github.com/eea/volto-group-block/compare/4.2.2...4.2.3)
27
+
28
+ > 27 May 2021
29
+
30
+ - Cypress coverage [`#8`](https://github.com/eea/volto-group-block/pull/8)
31
+
7
32
  #### [4.2.2](https://github.com/eea/volto-group-block/compare/4.2.1...4.2.2)
8
33
 
9
- - [JENKINS] - Auto-release pipeline [`#7`](https://github.com/eea/volto-group-block/pull/7)
34
+ > 14 May 2021
35
+
10
36
 
11
37
  #### [4.2.1](https://github.com/eea/volto-group-block/compare/4.2.0...4.2.1)
12
38
 
@@ -86,7 +112,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
86
112
 
87
113
  - Drop volto-blocks-form dependency [`#6`](https://github.com/eea/volto-group-block/pull/6)
88
114
  - Release 3.0.0 [`a83216e`](https://github.com/eea/volto-group-block/commit/a83216ed496b3a14ea49fd9697cd50ac64866092)
89
- - Cleanup Jenkinsfile DEPENDENCIES [`9d2a5d0`](https://github.com/eea/volto-group-block/commit/9d2a5d04308ecef93ca2682d928d0919b0f861ea)
90
115
  - Cosmetics [`03d6ed8`](https://github.com/eea/volto-group-block/commit/03d6ed8cbb796bacef3b3b78a1cee4114874033c)
91
116
  - Fix focus management [`35327d7`](https://github.com/eea/volto-group-block/commit/35327d7b457beeed15b7129541bb1665cab4586b)
92
117
  - Change imports from volto core [`d1dcc14`](https://github.com/eea/volto-group-block/commit/d1dcc14116fa408731d545d45d01669a06563b46)
@@ -129,19 +154,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
129
154
 
130
155
  - Release 1.0.0 [`b6ef873`](https://github.com/eea/volto-group-block/commit/b6ef873cb6f61e17db66fdd4de1d9d4902a66fc6)
131
156
  - Update package meta info [`143b7d4`](https://github.com/eea/volto-group-block/commit/143b7d44438d7afa5e346a9d21a85352df4e925f)
132
- - [JENKINS] - Fix SONAR tags [`512b56c`](https://github.com/eea/volto-group-block/commit/512b56ce931aa4c14f353e2a4c5bbbb614fe632f)
133
- - [JENKINS] - Update [`2204acd`](https://github.com/eea/volto-group-block/commit/2204acdefee84114bd403f9772a1e610348dc3dd)
134
- - [JENKINS] - Fix code-analysis [`88a5b3d`](https://github.com/eea/volto-group-block/commit/88a5b3d58b951ecfbc6e813accf065ca5e8be990)
135
- - [JENKINS] - Fix SonarQube report [`7fca879`](https://github.com/eea/volto-group-block/commit/7fca879b526be822cd63312ed51447d6e6a59cf2)
136
- - [JENKINS] - Fix unit tests pipeline [`5b9b28f`](https://github.com/eea/volto-group-block/commit/5b9b28f1de060635f1c665a80939bfa66918a918)
137
- - [JENKINS] - Add jest unit tests [`d8af5b7`](https://github.com/eea/volto-group-block/commit/d8af5b7932988b490a079d86079e359b5584fd7f)
138
- - [JENKINS] - Fix develop badge [`857b4ab`](https://github.com/eea/volto-group-block/commit/857b4ab5bc0aa9947c2ed76f35cec7d409c7fa66)
139
- - [JENKINS] - Add jenkins builds badges [`6cebd3e`](https://github.com/eea/volto-group-block/commit/6cebd3e970a840c4951c614a5d130dab05ae553f)
140
- - [JENKINS] - Cleanup console.log [`df38b6f`](https://github.com/eea/volto-group-block/commit/df38b6f7a630176e911ff89263c21e519ab44efa)
141
- - [JENKINS] - Fix eslint pipeline [`ca7c87a`](https://github.com/eea/volto-group-block/commit/ca7c87a4f74f2b0ea354ea5369f0700b8bee92af)
142
- - [JENKINS] - Fix style [`0e2c5a3`](https://github.com/eea/volto-group-block/commit/0e2c5a39b2f785ae1d942d39e7f8b2789dafc795)
143
157
  - Add Jenkinkins pipeline [`866a4e1`](https://github.com/eea/volto-group-block/commit/866a4e14ea1eb8f5adb01222e576e5ab6dc73a70)
144
- - yarn prettier [`e3fe0a3`](https://github.com/eea/volto-group-block/commit/e3fe0a36b89878769341b45198d6c9e2f2584d15)
145
158
 
146
159
  #### [0.1.3](https://github.com/eea/volto-group-block/compare/0.1.2...0.1.3)
147
160
 
@@ -186,5 +199,4 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
186
199
  - Render meta block [`0d44560`](https://github.com/eea/volto-group-block/commit/0d4456011ca56454068a54c610250b02df4ccb3b)
187
200
  - Implement meta block allowedBlocks settings [`f24feb1`](https://github.com/eea/volto-group-block/commit/f24feb1a1751f04841c21c7cd52a517fb02074ba)
188
201
  - Edit meta block [`236d291`](https://github.com/eea/volto-group-block/commit/236d29156fa835a7aa54eecdb4f120de0d64b271)
189
- - yarn bootstrap [`e009dfb`](https://github.com/eea/volto-group-block/commit/e009dfb6b9b74d101a6722f0982a5359fc522b6b)
190
202
  - Initial commit [`6a7b0de`](https://github.com/eea/volto-group-block/commit/6a7b0deb8f873d1462fd6a9c61edfc1562b3aace)
package/Jenkinsfile CHANGED
@@ -4,12 +4,37 @@ pipeline {
4
4
  environment {
5
5
  GIT_NAME = "volto-group-block"
6
6
  NAMESPACE = "@eeacms"
7
- SONARQUBE_TAGS = "volto.eea.europa.eu"
7
+ SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu"
8
+ DEPENDENCIES = ""
8
9
  }
9
10
 
10
11
  stages {
11
12
 
13
+ stage('Release') {
14
+ when {
15
+ allOf {
16
+ environment name: 'CHANGE_ID', value: ''
17
+ branch 'master'
18
+ }
19
+ }
20
+ steps {
21
+ node(label: 'docker') {
22
+ withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'),string(credentialsId: 'eea-jenkins-npm-token', variable: 'NPM_TOKEN')]) {
23
+ sh '''docker pull eeacms/gitflow'''
24
+ sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-master" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_NAME="$GIT_NAME" -e GIT_TOKEN="$GITHUB_TOKEN" -e NPM_TOKEN="$NPM_TOKEN" -e LANGUAGE=javascript eeacms/gitflow'''
25
+ }
26
+ }
27
+ }
28
+ }
29
+
12
30
  stage('Code') {
31
+ when {
32
+ allOf {
33
+ environment name: 'CHANGE_ID', value: ''
34
+ not { branch 'master' }
35
+ not { changelog '.*^Automated release [0-9\\.]+$' }
36
+ }
37
+ }
13
38
  steps {
14
39
  parallel(
15
40
 
@@ -35,6 +60,12 @@ pipeline {
35
60
  }
36
61
 
37
62
  stage('Tests') {
63
+ when {
64
+ allOf {
65
+ environment name: 'CHANGE_ID', value: ''
66
+ not { changelog '.*^Automated release [0-9\\.]+$' }
67
+ }
68
+ }
38
69
  steps {
39
70
  parallel(
40
71
 
@@ -44,13 +75,13 @@ pipeline {
44
75
  try {
45
76
  sh '''docker pull plone/volto-addon-ci'''
46
77
  sh '''docker run -i --name="$BUILD_TAG-volto" -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" plone/volto-addon-ci'''
78
+ sh '''rm -rf xunit-reports'''
47
79
  sh '''mkdir -p xunit-reports'''
48
80
  sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/coverage xunit-reports/'''
49
81
  sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/junit.xml xunit-reports/'''
50
82
  sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/unit_tests_log.txt xunit-reports/'''
51
- stash name: "xunit-reports", includes: "xunit-reports/**/*"
52
- junit 'xunit-reports/junit.xml'
53
- archiveArtifacts artifacts: 'xunit-reports/unit_tests_log.txt', fingerprint: true
83
+ stash name: "xunit-reports", includes: "xunit-reports/**"
84
+ archiveArtifacts artifacts: "xunit-reports/unit_tests_log.txt", fingerprint: true
54
85
  publishHTML (target : [
55
86
  allowMissing: false,
56
87
  alwaysLinkToLastBuild: true,
@@ -61,7 +92,10 @@ pipeline {
61
92
  reportTitles: 'Unit Tests Code Coverage'
62
93
  ])
63
94
  } finally {
64
- sh '''docker rm -v $BUILD_TAG-volto'''
95
+ catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
96
+ junit testResults: 'xunit-reports/junit.xml', allowEmptyResults: true
97
+ }
98
+ sh script: '''docker rm -v $BUILD_TAG-volto''', returnStatus: true
65
99
  }
66
100
  }
67
101
  }
@@ -70,23 +104,79 @@ pipeline {
70
104
  }
71
105
  }
72
106
 
73
- stage('Report to SonarQube') {
74
- // Exclude Pull-Requests
107
+ stage('Integration tests') {
75
108
  when {
76
109
  allOf {
77
110
  environment name: 'CHANGE_ID', value: ''
111
+ not { changelog '.*^Automated release [0-9\\.]+$' }
78
112
  }
79
113
  }
114
+ steps {
115
+ parallel(
116
+
117
+ "Cypress": {
118
+ node(label: 'docker') {
119
+ script {
120
+ try {
121
+ sh '''docker pull plone; docker run -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e PROFILES="profile-plone.restapi:blocks" plone fg'''
122
+ sh '''docker pull plone/volto-addon-ci; docker run -i --name="$BUILD_TAG-cypress" --link $BUILD_TAG-plone:plone -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e DEPENDENCIES="$DEPENDENCIES" plone/volto-addon-ci cypress'''
123
+ } finally {
124
+ try {
125
+ sh '''rm -rf cypress-reports cypress-results cypress-coverage'''
126
+ sh '''mkdir -p cypress-reports cypress-results cypress-coverage'''
127
+ sh '''docker cp $BUILD_TAG-cypress:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/cypress/videos cypress-reports/'''
128
+ sh '''docker cp $BUILD_TAG-cypress:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/cypress/reports cypress-results/'''
129
+ coverage = sh script: '''docker cp $BUILD_TAG-cypress:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/coverage cypress-coverage/''', returnStatus: true
130
+ if ( coverage == 0 ) {
131
+ publishHTML (target : [allowMissing: false,
132
+ alwaysLinkToLastBuild: true,
133
+ keepAll: true,
134
+ reportDir: 'cypress-coverage/coverage/lcov-report',
135
+ reportFiles: 'index.html',
136
+ reportName: 'CypressCoverage',
137
+ reportTitles: 'Integration Tests Code Coverage'])
138
+ }
139
+ archiveArtifacts artifacts: 'cypress-reports/videos/*.mp4', fingerprint: true
140
+ stash name: "cypress-coverage", includes: "cypress-coverage/**", allowEmpty: true
141
+ }
142
+ finally {
143
+ catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
144
+ junit testResults: 'cypress-results/**/*.xml', allowEmptyResults: true
145
+ }
146
+ sh script: "docker stop $BUILD_TAG-plone", returnStatus: true
147
+ sh script: "docker rm -v $BUILD_TAG-plone", returnStatus: true
148
+ sh script: "docker rm -v $BUILD_TAG-cypress", returnStatus: true
149
+
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ )
157
+ }
158
+ }
159
+
160
+ stage('Report to SonarQube') {
161
+ when {
162
+ environment name: 'CHANGE_ID', value: ''
163
+ anyOf {
164
+ branch 'master'
165
+ branch 'develop'
166
+ }
167
+ not { changelog '.*^Automated release [0-9\\.]+$' }
168
+ }
80
169
  steps {
81
170
  node(label: 'swarm') {
82
171
  script{
83
172
  checkout scm
84
173
  unstash "xunit-reports"
174
+ unstash "cypress-coverage"
85
175
  def scannerHome = tool 'SonarQubeScanner';
86
176
  def nodeJS = tool 'NodeJS11';
87
177
  withSonarQubeEnv('Sonarqube') {
88
178
  sh '''sed -i "s#/opt/frontend/my-volto-project/src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info'''
89
- sh "export PATH=$PATH:${scannerHome}/bin:${nodeJS}/bin; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info -Dsonar.sources=./src -Dsonar.coverage.exclusions=src/**/*.test.js -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
179
+ sh "export PATH=$PATH:${scannerHome}/bin:${nodeJS}/bin; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info,./cypress-coverage/coverage/lcov.info -Dsonar.sources=./src -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
90
180
  sh '''try=2; while [ \$try -gt 0 ]; do curl -s -XPOST -u "${SONAR_AUTH_TOKEN}:" "${SONAR_HOST_URL}api/project_tags/set?project=${GIT_NAME}-${BRANCH_NAME}&tags=${SONARQUBE_TAGS},${BRANCH_NAME}" > set_tags_result; if [ \$(grep -ic error set_tags_result ) -eq 0 ]; then try=0; else cat set_tags_result; echo "... Will retry"; sleep 60; try=\$(( \$try - 1 )); fi; done'''
91
181
  }
92
182
  }
@@ -104,56 +194,36 @@ pipeline {
104
194
  steps {
105
195
  node(label: 'docker') {
106
196
  script {
107
- if ( env.CHANGE_BRANCH != "develop" && !( env.CHANGE_BRANCH.startsWith("hotfix")) ) {
108
- error "Pipeline aborted due to PR not made from develop or hotfix branch"
197
+ if ( env.CHANGE_BRANCH != "develop" ) {
198
+ error "Pipeline aborted due to PR not made from develop branch"
109
199
  }
110
200
  withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN')]) {
111
201
  sh '''docker pull eeacms/gitflow'''
112
- sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-pr" -e GIT_CHANGE_TARGET="$CHANGE_TARGET" -e GIT_CHANGE_BRANCH="$CHANGE_BRANCH" -e GIT_CHANGE_AUTHOR="$CHANGE_AUTHOR" -e GIT_CHANGE_TITLE="$CHANGE_TITLE" -e GIT_TOKEN="$GITHUB_TOKEN" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e GIT_ORG="$GIT_ORG" -e GIT_NAME="$GIT_NAME" eeacms/gitflow'''
202
+ sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-pr" -e GIT_CHANGE_TARGET="$CHANGE_TARGET" -e GIT_CHANGE_BRANCH="$CHANGE_BRANCH" -e GIT_CHANGE_AUTHOR="$CHANGE_AUTHOR" -e GIT_CHANGE_TITLE="$CHANGE_TITLE" -e GIT_TOKEN="$GITHUB_TOKEN" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e GIT_ORG="$GIT_ORG" -e GIT_NAME="$GIT_NAME" -e LANGUAGE=javascript eeacms/gitflow'''
113
203
  }
114
204
  }
115
205
  }
116
206
  }
117
207
  }
118
208
 
119
- stage('Release') {
120
- when {
121
- allOf {
122
- environment name: 'CHANGE_ID', value: ''
123
- branch 'master'
124
- }
125
- }
126
- steps {
127
- node(label: 'docker') {
128
- withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'),string(credentialsId: 'eea-jenkins-npm-token', variable: 'NPM_TOKEN')]) {
129
- sh '''docker pull eeacms/gitflow'''
130
- sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-master" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_NAME="$GIT_NAME" -e GIT_TOKEN="$GITHUB_TOKEN" -e NPM_TOKEN="$NPM_TOKEN" eeacms/gitflow'''
131
- }
132
- }
133
- }
134
- }
135
-
136
209
  }
137
210
 
138
211
  post {
212
+ always {
213
+ cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
214
+ }
139
215
  changed {
140
216
  script {
141
- def url = "${env.BUILD_URL}/display/redirect"
142
- def status = currentBuild.currentResult
143
- def subject = "${status}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
144
- def summary = "${subject} (${url})"
145
- def details = """<h1>${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${status}</h1>
146
- <p>Check console output at <a href="${url}">${env.JOB_BASE_NAME} - #${env.BUILD_NUMBER}</a></p>
217
+ def details = """<h1>${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${currentBuild.currentResult}</h1>
218
+ <p>Check console output at <a href="${env.BUILD_URL}/display/redirect">${env.JOB_BASE_NAME} - #${env.BUILD_NUMBER}</a></p>
147
219
  """
148
-
149
- def color = '#FFFF00'
150
- if (status == 'SUCCESS') {
151
- color = '#00FF00'
152
- } else if (status == 'FAILURE') {
153
- color = '#FF0000'
154
- }
155
-
156
- emailext (subject: '$DEFAULT_SUBJECT', to: '$DEFAULT_RECIPIENTS', body: details)
220
+ emailext(
221
+ subject: '$DEFAULT_SUBJECT',
222
+ body: details,
223
+ attachLog: true,
224
+ compressLog: true,
225
+ recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'CulpritsRecipientProvider']]
226
+ )
157
227
  }
158
228
  }
159
229
  }
package/bootstrap CHANGED
@@ -1,5 +1,6 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
+ const ejs = require('ejs');
3
4
 
4
5
  const currentDir = path.basename(process.cwd());
5
6
 
@@ -8,13 +9,23 @@ const bootstrap = function (ofile) {
8
9
  if (err) {
9
10
  return console.log(err);
10
11
  }
11
- var result = data.replace(/volto-addon-template/g, currentDir);
12
-
13
- fs.writeFile(ofile, result, 'utf8', function (err) {
12
+ const result = ejs.render(data, {
13
+ addonName: `@eeacms/${currentDir}`,
14
+ name: currentDir
15
+ });
16
+ const output = ofile.replace('.tpl', '');
17
+ fs.writeFile(output, result, 'utf8', function (err) {
14
18
  if (err) {
15
19
  return console.log(err);
16
20
  }
17
21
  });
22
+ if (ofile.includes('.tpl')) {
23
+ fs.unlink(ofile, (err) => {
24
+ if (err) {
25
+ return console.error(err);
26
+ }
27
+ });
28
+ }
18
29
  });
19
30
  }
20
31
 
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Using fixtures to represent data",
3
+ "email": "hello@cypress.io",
4
+ "body": "Fixtures are a great way to mock data for responses to routes"
5
+ }
@@ -0,0 +1,33 @@
1
+ import { setupBeforeEach, tearDownAfterEach } from '../support';
2
+
3
+ describe('Blocks Tests', () => {
4
+ beforeEach(setupBeforeEach);
5
+ afterEach(tearDownAfterEach);
6
+
7
+ it('Add Block: Empty', () => {
8
+ // without this the clear command below does nothing sometimes
9
+ cy.wait(500);
10
+
11
+ // Change page title
12
+ cy.get('[contenteditable=true]').first().clear();
13
+
14
+ cy.get('[contenteditable=true]').first().type('My Add-on Page');
15
+
16
+ cy.get('.documentFirstHeading').contains('My Add-on Page');
17
+
18
+ cy.get('[contenteditable=true]').first().type('{enter}');
19
+
20
+ // Add block
21
+ cy.get('.ui.basic.icon.button.block-add-button').first().click();
22
+ cy.get('.blocks-chooser .title').contains('Media').click();
23
+ cy.get('.content.active.media .button.image').contains('Image').click();
24
+
25
+ // Save
26
+ cy.get('#toolbar-save').click();
27
+ cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');
28
+
29
+ // then the page view should contain our changes
30
+ cy.contains('My Add-on Page');
31
+ cy.get('.block.image');
32
+ });
33
+ });
@@ -0,0 +1,26 @@
1
+ /// <reference types="cypress" />
2
+ // ***********************************************************
3
+ // This example plugins/index.js can be used to load plugins
4
+ //
5
+ // You can change the location of this file or turn off loading
6
+ // the plugins file with the 'pluginsFile' configuration option.
7
+ //
8
+ // You can read more here:
9
+ // https://on.cypress.io/plugins-guide
10
+ // ***********************************************************
11
+
12
+ // This function is called when a project is opened or re-opened (e.g. due to
13
+ // the project's config changing)
14
+
15
+ /**
16
+ * @type {Cypress.PluginConfig}
17
+ */
18
+ module.exports = (on, config) => {
19
+ // `on` is used to hook into various events Cypress emits
20
+ // `config` is the resolved Cypress config
21
+ /* coverage-start
22
+ require('@cypress/code-coverage/task')(on, config)
23
+ on('file:preprocessor', require('@cypress/code-coverage/use-babelrc'))
24
+ return config
25
+ coverage-end */
26
+ };
@@ -0,0 +1,315 @@
1
+ /* eslint no-console: ["error", { allow: ["log"] }] */
2
+
3
+ // --- AUTOLOGIN -------------------------------------------------------------
4
+ Cypress.Commands.add('autologin', () => {
5
+ let api_url, user, password;
6
+ api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
7
+ user = 'admin';
8
+ password = 'admin';
9
+
10
+ return cy
11
+ .request({
12
+ method: 'POST',
13
+ url: `${api_url}/@login`,
14
+ headers: { Accept: 'application/json' },
15
+ body: { login: user, password: password },
16
+ })
17
+ .then((response) => cy.setCookie('auth_token', response.body.token));
18
+ });
19
+
20
+ // --- CREATE CONTENT --------------------------------------------------------
21
+ Cypress.Commands.add(
22
+ 'createContent',
23
+ ({
24
+ contentType,
25
+ contentId,
26
+ contentTitle,
27
+ path = '',
28
+ allow_discussion = false,
29
+ }) => {
30
+ let api_url, auth;
31
+ api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
32
+ auth = {
33
+ user: 'admin',
34
+ pass: 'admin',
35
+ };
36
+ if (contentType === 'File') {
37
+ return cy.request({
38
+ method: 'POST',
39
+ url: `${api_url}/${path}`,
40
+ headers: {
41
+ Accept: 'application/json',
42
+ },
43
+ auth: auth,
44
+ body: {
45
+ '@type': contentType,
46
+ id: contentId,
47
+ title: contentTitle,
48
+ file: {
49
+ data: 'dGVzdGZpbGUK',
50
+ encoding: 'base64',
51
+ filename: 'lorem.txt',
52
+ 'content-type': 'text/plain',
53
+ },
54
+ allow_discussion: allow_discussion,
55
+ },
56
+ });
57
+ }
58
+ if (contentType === 'Image') {
59
+ return cy.request({
60
+ method: 'POST',
61
+ url: `${api_url}/${path}`,
62
+ headers: {
63
+ Accept: 'application/json',
64
+ },
65
+ auth: auth,
66
+ body: {
67
+ '@type': contentType,
68
+ id: contentId,
69
+ title: contentTitle,
70
+ image: {
71
+ data:
72
+ 'iVBORw0KGgoAAAANSUhEUgAAANcAAAA4CAMAAABZsZ3QAAAAM1BMVEX29fK42OU+oMvn7u9drtIPisHI4OhstdWZyt4fkcXX5+sAg74umMhNp86p0eJ7vNiKw9v/UV4wAAAAAXRSTlMAQObYZgAABBxJREFUeF7tmuty4yAMhZG4X2zn/Z92J5tsBJwWXG/i3XR6frW2Y/SBLIRAfaQUDNt8E5tLUt9BycfcKfq3R6Mlfyimtx4rzp+K3dtibXkor99zsEqLYZltblTecciogoh+TXfY1Ve4dn07rCDGG9dHSEEOg/GmXl0U1XDxTKxNK5De7BxsyyBr6gGm2/vPxKJ8F6f7BXKfRMp1xIWK9A+5ks25alSb353dWnDJN1k35EL5f8dVGifTf/4tjUuuFq7u4srmXC60yAmldLXIWbg65RKU87lcGxJCFqUPv0IacW0PmSivOZFLE908inPToMmii/roG+MRV/O8FU88i8tFsxV3a06MFUw0Qu7RmAtdV5/HVVaOVMTWNOWSwMljLhzhcB6XIS7OK5V6AvRDNN7t5VJWQs1J40UmalbK56usBG/CuCHSYuc+rkUGeMCViNRARPrzW52N3oQLe6WifNliSuuGaH3czbVNudI9s7ZLUCLHVwWlyES522o1t14uvmbblmVTKqFjaZYJFSTPP4dLL1kU1z7p0lzdbRulmEWLxoQX+z9ce7A8GqEEucllLxePuZwdJl1Lezu0hoswvTPt61DrFcRuujV/2cmlxaGBC7Aw6cpovGANwRiSdOAWJ5AGy4gLL64dl0QhUEAuEUNws+XxV+OKGPdw/hESGYF9XEGaFC7sNLMSXWJjHsnanYi87VK428N2uxpOjOFANcagLM5l+7mSycM8KknZpKLcGi6jmzWGr/vLurZ/0g4u9AZuAoeb5r1ceQhyiTPY1E4wUR6u/F3H2ojSpXMMriBPT9cezTto8Cx+MsglHL4fv1Rxrb1LVw9yvyQpJ3AhFnLZfuRLH2QsOG3FGGD20X/th/u5bFAt16Bt308KjF+MNOXgl/SquIEySX3GhaZvc67KZbDxcCDORz2N8yCWPaY5lyQZO7lQ29fnZbt3Xu6qoge4+DjXl/MocySPOp9rlvdyznahRyHEYd77v3LhugOXDv4J65QXfl803BDAdaWBEDhfVx7nKofjoVCgxnUAqw/UAUDPn788BDvQuG4TDtdtUPvzjSlXAB8DvaDOhhrmhwbywylXAm8CvaouikJTL93gs3y7Yy4VYbIxOHrcMizPqWOjqO9l3Uz52kibQy4xxOgqhJvD+w5rvokOcAlGvNCfeqCv1ste1stzLm0f71Iq3ZfTrPfuE5nhPtF+LvQE2lffQC7pYtQy3tdzdrKvd5TLVVzDetScS3nEKmmwDyt1Cev1kX3YfbvzNK4fzrlw+cB6vm+uiUgf2zdXI62241LawCb7Pi5FXFPF8KpzDoF/Sw2lg+GrHNbno1mhPu+VCF/vfMnw06PnUl6j48dVHD3jHNHPua+fc3o/5yp/zsGi0vYtzi3Pz5mHd4T6BWMIlewacd63AAAAAElFTkSuQmCC',
73
+ encoding: 'base64',
74
+ filename: 'image.png',
75
+ 'content-type': 'image/png',
76
+ },
77
+ },
78
+ });
79
+ }
80
+ if (['Document', 'Folder', 'CMSFolder'].includes(contentType)) {
81
+ return cy
82
+ .request({
83
+ method: 'POST',
84
+ url: `${api_url}/${path}`,
85
+ headers: {
86
+ Accept: 'application/json',
87
+ },
88
+ auth: auth,
89
+ body: {
90
+ '@type': contentType,
91
+ id: contentId,
92
+ title: contentTitle,
93
+ blocks: {
94
+ 'd3f1c443-583f-4e8e-a682-3bf25752a300': { '@type': 'title' },
95
+ '7624cf59-05d0-4055-8f55-5fd6597d84b0': { '@type': 'text' },
96
+ },
97
+ blocks_layout: {
98
+ items: [
99
+ 'd3f1c443-583f-4e8e-a682-3bf25752a300',
100
+ '7624cf59-05d0-4055-8f55-5fd6597d84b0',
101
+ ],
102
+ },
103
+ allow_discussion: allow_discussion,
104
+ },
105
+ })
106
+ .then(() => console.log(`${contentType} created`));
107
+ } else {
108
+ return cy
109
+ .request({
110
+ method: 'POST',
111
+ url: `${api_url}/${path}`,
112
+ headers: {
113
+ Accept: 'application/json',
114
+ },
115
+ auth: auth,
116
+ body: {
117
+ '@type': contentType,
118
+ id: contentId,
119
+ title: contentTitle,
120
+ allow_discussion: allow_discussion,
121
+ },
122
+ })
123
+ .then(() => console.log(`${contentType} created`));
124
+ }
125
+ },
126
+ );
127
+
128
+ // --- REMOVE CONTENT --------------------------------------------------------
129
+ Cypress.Commands.add('removeContent', (path) => {
130
+ let api_url, auth;
131
+ api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
132
+ auth = {
133
+ user: 'admin',
134
+ pass: 'admin',
135
+ };
136
+ return cy
137
+ .request({
138
+ method: 'DELETE',
139
+ url: `${api_url}/${path}`,
140
+ headers: {
141
+ Accept: 'application/json',
142
+ },
143
+ auth: auth,
144
+ body: {},
145
+ })
146
+ .then(() => console.log(`${path} removed`));
147
+ });
148
+
149
+ // --- SET WORKFLOW ----------------------------------------------------------
150
+ Cypress.Commands.add(
151
+ 'setWorkflow',
152
+ ({
153
+ path = '/',
154
+ actor = 'admin',
155
+ review_state = 'publish',
156
+ time = '1995-07-31T18:30:00',
157
+ title = '',
158
+ comment = '',
159
+ effective = '2018-01-21T08:00:00',
160
+ expires = '2019-01-21T08:00:00',
161
+ include_children = true,
162
+ }) => {
163
+ let api_url, auth;
164
+ api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
165
+ auth = {
166
+ user: 'admin',
167
+ pass: 'admin',
168
+ };
169
+ return cy.request({
170
+ method: 'POST',
171
+ url: `${api_url}/${path}/@workflow/${review_state}`,
172
+ headers: {
173
+ Accept: 'application/json',
174
+ },
175
+ auth: auth,
176
+ body: {
177
+ actor: actor,
178
+ review_state: review_state,
179
+ time: time,
180
+ title: title,
181
+ comment: comment,
182
+ effective: effective,
183
+ expires: expires,
184
+ include_children: include_children,
185
+ },
186
+ });
187
+ },
188
+ );
189
+
190
+ // --- waitForResourceToLoad ----------------------------------------------------------
191
+ Cypress.Commands.add('waitForResourceToLoad', (fileName, type) => {
192
+ const resourceCheckInterval = 40;
193
+
194
+ return new Cypress.Promise((resolve) => {
195
+ const checkIfResourceHasBeenLoaded = () => {
196
+ const resource = cy
197
+ .state('window')
198
+ .performance.getEntriesByType('resource')
199
+ .filter((entry) => !type || entry.initiatorType === type)
200
+ .find((entry) => entry.name.includes(fileName));
201
+
202
+ if (resource) {
203
+ resolve();
204
+
205
+ return;
206
+ }
207
+
208
+ setTimeout(checkIfResourceHasBeenLoaded, resourceCheckInterval);
209
+ };
210
+
211
+ checkIfResourceHasBeenLoaded();
212
+ });
213
+ });
214
+
215
+ // Low level command reused by `setSelection` and low level command `setCursor`
216
+ Cypress.Commands.add('selection', { prevSubject: true }, (subject, fn) => {
217
+ cy.wrap(subject).trigger('mousedown').then(fn).trigger('mouseup');
218
+
219
+ cy.document().trigger('selectionchange');
220
+ return cy.wrap(subject);
221
+ });
222
+
223
+ Cypress.Commands.add(
224
+ 'setSelection',
225
+ { prevSubject: true },
226
+ (subject, query, endQuery) => {
227
+ return cy.wrap(subject).selection(($el) => {
228
+ if (typeof query === 'string') {
229
+ const anchorNode = getTextNode($el[0], query);
230
+ const focusNode = endQuery ? getTextNode($el[0], endQuery) : anchorNode;
231
+ const anchorOffset = anchorNode.wholeText.indexOf(query);
232
+ const focusOffset = endQuery
233
+ ? focusNode.wholeText.indexOf(endQuery) + endQuery.length
234
+ : anchorOffset + query.length;
235
+ setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
236
+ } else if (typeof query === 'object') {
237
+ const el = $el[0];
238
+ const anchorNode = getTextNode(el.querySelector(query.anchorQuery));
239
+ const anchorOffset = query.anchorOffset || 0;
240
+ const focusNode = query.focusQuery
241
+ ? getTextNode(el.querySelector(query.focusQuery))
242
+ : anchorNode;
243
+ const focusOffset = query.focusOffset || 0;
244
+ setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
245
+ }
246
+ });
247
+ },
248
+ );
249
+
250
+ // Low level command reused by `setCursorBefore` and `setCursorAfter`, equal to `setCursorAfter`
251
+ Cypress.Commands.add(
252
+ 'setCursor',
253
+ { prevSubject: true },
254
+ (subject, query, atStart) => {
255
+ return cy.wrap(subject).selection(($el) => {
256
+ const node = getTextNode($el[0], query);
257
+ const offset =
258
+ node.wholeText.indexOf(query) + (atStart ? 0 : query.length);
259
+ const document = node.ownerDocument;
260
+ document.getSelection().removeAllRanges();
261
+ document.getSelection().collapse(node, offset);
262
+ });
263
+ // Depending on what you're testing, you may need to chain a `.click()` here to ensure
264
+ // further commands are picked up by whatever you're testing (this was required for Slate, for example).
265
+ },
266
+ );
267
+
268
+ Cypress.Commands.add(
269
+ 'setCursorBefore',
270
+ { prevSubject: true },
271
+ (subject, query) => {
272
+ cy.wrap(subject).setCursor(query, true);
273
+ },
274
+ );
275
+
276
+ Cypress.Commands.add(
277
+ 'setCursorAfter',
278
+ { prevSubject: true },
279
+ (subject, query) => {
280
+ cy.wrap(subject).setCursor(query);
281
+ },
282
+ );
283
+
284
+ // Helper functions
285
+ function getTextNode(el, match) {
286
+ const walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false);
287
+ if (!match) {
288
+ return walk.nextNode();
289
+ }
290
+
291
+ let node;
292
+ while ((node = walk.nextNode())) {
293
+ if (node.wholeText.includes(match)) {
294
+ return node;
295
+ }
296
+ }
297
+ }
298
+
299
+ function setBaseAndExtent(...args) {
300
+ const document = args[0].ownerDocument;
301
+ document.getSelection().removeAllRanges();
302
+ document.getSelection().setBaseAndExtent(...args);
303
+ }
304
+
305
+ Cypress.Commands.add('navigate', (route = '') => {
306
+ return cy.window().its('appHistory').invoke('push', route);
307
+ });
308
+
309
+ Cypress.Commands.add('store', () => {
310
+ return cy.window().its('store').invoke('getStore', '');
311
+ });
312
+
313
+ Cypress.Commands.add('settings', (key, value) => {
314
+ return cy.window().its('settings');
315
+ });
@@ -0,0 +1,53 @@
1
+ // ***********************************************************
2
+ // This example support/index.js is processed and
3
+ // loaded automatically before your test files.
4
+ //
5
+ // This is a great place to put global configuration and
6
+ // behavior that modifies Cypress.
7
+ //
8
+ // You can change the location of this file or turn off
9
+ // automatically serving support files with the
10
+ // 'supportFile' configuration option.
11
+ //
12
+ // You can read more here:
13
+ // https://on.cypress.io/configuration
14
+ // ***********************************************************
15
+
16
+ // Import commands.js using ES2015 syntax:
17
+ import './commands';
18
+
19
+ // Alternatively you can use CommonJS syntax:
20
+ // require('./commands')
21
+
22
+ /* coverage-start
23
+ //Generate code-coverage
24
+ import '@cypress/code-coverage/support';
25
+ coverage-end */
26
+
27
+ export const setupBeforeEach = () => {
28
+ cy.autologin();
29
+ cy.createContent({
30
+ contentType: 'Folder',
31
+ contentId: 'cypress',
32
+ contentTitle: 'Cypress',
33
+ });
34
+ cy.createContent({
35
+ contentType: 'Document',
36
+ contentId: 'my-page',
37
+ contentTitle: 'My Page',
38
+ path: 'cypress',
39
+ });
40
+ cy.visit('/cypress/my-page');
41
+ cy.waitForResourceToLoad('@navigation');
42
+ cy.waitForResourceToLoad('@breadcrumbs');
43
+ cy.waitForResourceToLoad('@actions');
44
+ cy.waitForResourceToLoad('@types');
45
+ cy.waitForResourceToLoad('my-page');
46
+ cy.navigate('/cypress/my-page/edit');
47
+ cy.get(`.block.title h1`);
48
+ };
49
+
50
+ export const tearDownAfterEach = () => {
51
+ cy.autologin();
52
+ cy.removeContent('cypress');
53
+ };
package/cypress.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "video": true,
7
7
  "reporterOptions": {
8
8
  "mochaFile": "cypress/reports/cypress-[hash].xml",
9
+ "jenkinsMode": true,
9
10
  "toConsole": true
10
11
  }
11
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-group-block",
3
- "version": "4.2.2",
3
+ "version": "4.3.2",
4
4
  "description": "volto-group-block: Volto block to be used to group other blocks",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -19,15 +19,21 @@
19
19
  "url": "git@github.com:eea/volto-group-block.git"
20
20
  },
21
21
  "dependencies": {},
22
+ "devDependencies": {
23
+ "@cypress/code-coverage": "^3.9.5",
24
+ "babel-plugin-transform-class-properties": "^6.24.1"
25
+ },
22
26
  "scripts": {
23
27
  "release": "release-it",
24
- "bootstrap": "node bootstrap",
28
+ "bootstrap": "npm install -g ejs; npm link ejs; node bootstrap",
25
29
  "stylelint": "../../../node_modules/stylelint/bin/stylelint.js --allow-empty-input 'src/**/*.{css,less}'",
26
30
  "stylelint:overrides": "../../../node_modules/.bin/stylelint --syntax less --allow-empty-input 'theme/**/*.overrides' 'src/**/*.overrides'",
27
31
  "stylelint:fix": "yarn stylelint --fix && yarn stylelint:overrides --fix",
28
32
  "prettier": "../../../node_modules/.bin/prettier --single-quote --check 'src/**/*.{js,jsx,json,css,less,md}'",
29
33
  "prettier:fix": "../../../node_modules/.bin/prettier --single-quote --write 'src/**/*.{js,jsx,json,css,less,md}'",
30
34
  "lint": "../../../node_modules/eslint/bin/eslint.js --max-warnings=0 'src/**/*.{js,jsx}'",
31
- "lint:fix": "../../../node_modules/eslint/bin/eslint.js --fix 'src/**/*.{js,jsx}'"
35
+ "lint:fix": "../../../node_modules/eslint/bin/eslint.js --fix 'src/**/*.{js,jsx}'",
36
+ "cypress:run": "../../../node_modules/cypress/bin/cypress run",
37
+ "cypress:open": "../../../node_modules/cypress/bin/cypress open"
32
38
  }
33
39
  }
@@ -14,6 +14,7 @@ import { Button, Segment } from 'semantic-ui-react';
14
14
  import EditBlockWrapper from './EditBlockWrapper';
15
15
  import EditSchema from './EditSchema';
16
16
  import helpSVG from '@plone/volto/icons/help.svg';
17
+ import cx from 'classnames';
17
18
  import './editor.less';
18
19
 
19
20
  const Edit = (props) => {
@@ -29,9 +30,8 @@ const Edit = (props) => {
29
30
  } = props;
30
31
 
31
32
  const metadata = props.metadata || props.properties;
32
- const properties = isEmpty(data?.data?.blocks)
33
- ? emptyBlocksForm()
34
- : data.data;
33
+ const data_blocks = data?.data?.blocks;
34
+ const properties = isEmpty(data_blocks) ? emptyBlocksForm() : data.data;
35
35
 
36
36
  const [selectedBlock, setSelectedBlock] = useState(
37
37
  properties.blocks_layout.items[0],
@@ -39,7 +39,7 @@ const Edit = (props) => {
39
39
 
40
40
  React.useEffect(() => {
41
41
  if (
42
- isEmpty(data?.data?.blocks) &&
42
+ isEmpty(data_blocks) &&
43
43
  properties.blocks_layout.items[0] !== selectedBlock
44
44
  ) {
45
45
  setSelectedBlock(properties.blocks_layout.items[0]);
@@ -48,59 +48,79 @@ const Edit = (props) => {
48
48
  data: properties,
49
49
  });
50
50
  }
51
- }, [
52
- onChangeBlock,
53
- properties,
54
- selectedBlock,
55
- block,
56
- data,
57
- data?.data?.blocks,
58
- ]);
51
+ }, [onChangeBlock, properties, selectedBlock, block, data, data_blocks]);
59
52
 
60
53
  const blockState = {};
61
54
  let charCount = 0;
62
55
 
56
+ /**
57
+ * Count the number of characters that are anything except using Regex
58
+ * @param {string} paragraph
59
+ * @returns
60
+ */
61
+ const countCharsWithoutSpaces = (paragraph) => {
62
+ const regex = /[^\s\\]/g;
63
+
64
+ return (paragraph.match(regex) || []).length;
65
+ };
66
+
67
+ /**
68
+ * Count the number of characters
69
+ * @param {string} paragraph
70
+ * @returns
71
+ */
72
+ const countCharsWithSpaces = (paragraph) => {
73
+ return paragraph?.length || 0;
74
+ };
75
+
76
+ /**
77
+ * Recursively look for any block that contains text or plaintext
78
+ * @param {Object} blocksObject
79
+ * @returns
80
+ */
63
81
  const countTextInBlocks = (blocksObject) => {
64
82
  let groupCharCount = 0;
65
83
 
66
84
  Object.keys(blocksObject).forEach((blockId) => {
67
- const charCountTemp = blocksObject[blockId]?.plaintext
68
- ? blocksObject[blockId]?.plaintext.length
85
+ const foundText = blocksObject[blockId]?.plaintext
86
+ ? blocksObject[blockId]?.plaintext
69
87
  : blocksObject[blockId]?.text?.blocks[0]?.text
70
- ? blocksObject[blockId].text.blocks[0].text.length
88
+ ? blocksObject[blockId].text.blocks[0].text
71
89
  : blocksObject[blockId]?.data?.blocks
72
90
  ? countTextInBlocks(blocksObject[blockId]?.data?.blocks)
73
91
  : blocksObject[blockId]?.blocks
74
92
  ? countTextInBlocks(blocksObject[blockId]?.blocks)
75
- : 0;
76
- groupCharCount = groupCharCount + charCountTemp;
93
+ : '';
94
+ const resultText =
95
+ typeof foundText === 'string' || foundText instanceof String
96
+ ? foundText
97
+ : '';
98
+
99
+ groupCharCount += props.data.ignoreSpaces
100
+ ? countCharsWithoutSpaces(resultText)
101
+ : countCharsWithSpaces(resultText);
77
102
  });
78
103
 
79
104
  return groupCharCount;
80
105
  };
81
106
 
82
107
  const showCharCounter = () => {
83
- if (props.data?.data?.blocks) {
84
- charCount = countTextInBlocks(props.data?.data?.blocks);
108
+ if (data_blocks) {
109
+ charCount = countTextInBlocks(data_blocks);
85
110
  }
86
111
  };
87
112
  showCharCounter();
88
113
 
89
- const colors = { ok: '#CCC', warning: 'darkorange', danger: 'crimson' };
90
- const counterStyle = {
91
- color:
92
- charCount < Math.ceil(props.data.maxChars / 1.05)
93
- ? colors.ok
94
- : charCount < props.data.maxChars
95
- ? colors.warning
96
- : colors.danger,
97
- textAlign: 'end',
98
- };
114
+ const counterClass =
115
+ charCount < Math.ceil(props.data.maxChars / 1.05)
116
+ ? 'info'
117
+ : charCount < props.data.maxChars
118
+ ? 'warning'
119
+ : 'danger';
99
120
 
100
121
  const counterComponent = props.data.maxChars ? (
101
122
  <p
102
- style={counterStyle}
103
- className="counter"
123
+ className={cx('counter', counterClass)}
104
124
  onClick={() => {
105
125
  setSelectedBlock();
106
126
  props.setSidebarTab(1);
@@ -86,6 +86,12 @@ class EditBlockWrapper extends React.Component {
86
86
  ? data.required
87
87
  : includes(config.blocks.requiredBlocks, type);
88
88
 
89
+ // Get editing instructions from block settings or props
90
+ let instructions = data?.instructions?.data || data?.instructions;
91
+ if (!instructions || instructions === '<p><br/></p>') {
92
+ instructions = '';
93
+ }
94
+
89
95
  return (
90
96
  <div ref={this.blockNode}>
91
97
  <div
@@ -104,7 +110,7 @@ class EditBlockWrapper extends React.Component {
104
110
  )}
105
111
  {visible && (
106
112
  <div className="block-toolbar">
107
- {extraControls}
113
+ {instructions ? extraControls : ''}
108
114
 
109
115
  {!disabled && (
110
116
  <>
@@ -11,6 +11,7 @@ const Schema = {
11
11
  'allowedBlocks',
12
12
  'as',
13
13
  'maxChars',
14
+ 'ignoreSpaces',
14
15
  'readOnlySettings',
15
16
  'disableInnerButtons',
16
17
  'required',
@@ -67,6 +68,11 @@ const Schema = {
67
68
  type: 'integer',
68
69
  factory: 'Integer',
69
70
  },
71
+ ignoreSpaces: {
72
+ title: 'Ignore spaces',
73
+ description: 'Ignore spaces while calculating maximum characters',
74
+ type: 'boolean',
75
+ },
70
76
  required: {
71
77
  title: 'Required',
72
78
  description: "Don't allow deletion of this block",
@@ -50,6 +50,19 @@
50
50
  font-size: 85%;
51
51
  grid-gap: 0.5em;
52
52
  grid-template-columns: 98% auto;
53
+ text-align: end;
54
+
55
+ &.info {
56
+ color: #ccc;
57
+ }
58
+
59
+ &.danger {
60
+ color: crimson;
61
+ }
62
+
63
+ &.warning {
64
+ color: darkorange;
65
+ }
53
66
  }
54
67
 
55
68
  .blocks-form {