@eeacms/volto-group-block 4.2.3 → 4.3.3

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,15 +4,42 @@ 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.3](https://github.com/eea/volto-group-block/compare/4.3.2...4.3.3)
8
+
9
+ - Add SonarQube badges [`bd17cc7`](https://github.com/eea/volto-group-block/commit/bd17cc7542d94a1338f4d47e167704cdd082e452)
10
+
11
+ #### [4.3.2](https://github.com/eea/volto-group-block/compare/4.3.1...4.3.2)
12
+
13
+ > 10 December 2021
14
+
15
+ - Develop [`#14`](https://github.com/eea/volto-group-block/pull/14)
16
+ - Correct Cypress tests [`#13`](https://github.com/eea/volto-group-block/pull/13)
17
+ - Refs #142010 - Optimize Volto-addons gitflow pipelines [`bc36cf5`](https://github.com/eea/volto-group-block/commit/bc36cf58c39e2b43c2fbf5189df6ddefc1260857)
18
+
19
+ #### [4.3.1](https://github.com/eea/volto-group-block/compare/4.3.0...4.3.1)
20
+
21
+ > 11 October 2021
22
+
23
+ - Possibility to ignore spaces with maxChars [`#11`](https://github.com/eea/volto-group-block/pull/11)
24
+ - No space count [`#10`](https://github.com/eea/volto-group-block/pull/10)
25
+
26
+ #### [4.3.0](https://github.com/eea/volto-group-block/compare/4.2.3...4.3.0)
27
+
28
+ > 24 June 2021
29
+
30
+ - Refactor counter to use CSS class instead of inline style [`#9`](https://github.com/eea/volto-group-block/pull/9)
31
+ - Show help icon only if block instructions differ from section instructions [`a4ca4e5`](https://github.com/eea/volto-group-block/commit/a4ca4e58968dcfb947072a255c8f797df7977852)
32
+
7
33
  #### [4.2.3](https://github.com/eea/volto-group-block/compare/4.2.2...4.2.3)
8
34
 
35
+ > 27 May 2021
36
+
9
37
  - Cypress coverage [`#8`](https://github.com/eea/volto-group-block/pull/8)
10
38
 
11
39
  #### [4.2.2](https://github.com/eea/volto-group-block/compare/4.2.1...4.2.2)
12
40
 
13
41
  > 14 May 2021
14
42
 
15
- - [JENKINS] - Auto-release pipeline [`#7`](https://github.com/eea/volto-group-block/pull/7)
16
43
 
17
44
  #### [4.2.1](https://github.com/eea/volto-group-block/compare/4.2.0...4.2.1)
18
45
 
@@ -92,7 +119,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
92
119
 
93
120
  - Drop volto-blocks-form dependency [`#6`](https://github.com/eea/volto-group-block/pull/6)
94
121
  - Release 3.0.0 [`a83216e`](https://github.com/eea/volto-group-block/commit/a83216ed496b3a14ea49fd9697cd50ac64866092)
95
- - Cleanup Jenkinsfile DEPENDENCIES [`9d2a5d0`](https://github.com/eea/volto-group-block/commit/9d2a5d04308ecef93ca2682d928d0919b0f861ea)
96
122
  - Cosmetics [`03d6ed8`](https://github.com/eea/volto-group-block/commit/03d6ed8cbb796bacef3b3b78a1cee4114874033c)
97
123
  - Fix focus management [`35327d7`](https://github.com/eea/volto-group-block/commit/35327d7b457beeed15b7129541bb1665cab4586b)
98
124
  - Change imports from volto core [`d1dcc14`](https://github.com/eea/volto-group-block/commit/d1dcc14116fa408731d545d45d01669a06563b46)
@@ -135,19 +161,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
135
161
 
136
162
  - Release 1.0.0 [`b6ef873`](https://github.com/eea/volto-group-block/commit/b6ef873cb6f61e17db66fdd4de1d9d4902a66fc6)
137
163
  - Update package meta info [`143b7d4`](https://github.com/eea/volto-group-block/commit/143b7d44438d7afa5e346a9d21a85352df4e925f)
138
- - [JENKINS] - Fix SONAR tags [`512b56c`](https://github.com/eea/volto-group-block/commit/512b56ce931aa4c14f353e2a4c5bbbb614fe632f)
139
- - [JENKINS] - Update [`2204acd`](https://github.com/eea/volto-group-block/commit/2204acdefee84114bd403f9772a1e610348dc3dd)
140
- - [JENKINS] - Fix code-analysis [`88a5b3d`](https://github.com/eea/volto-group-block/commit/88a5b3d58b951ecfbc6e813accf065ca5e8be990)
141
- - [JENKINS] - Fix SonarQube report [`7fca879`](https://github.com/eea/volto-group-block/commit/7fca879b526be822cd63312ed51447d6e6a59cf2)
142
- - [JENKINS] - Fix unit tests pipeline [`5b9b28f`](https://github.com/eea/volto-group-block/commit/5b9b28f1de060635f1c665a80939bfa66918a918)
143
- - [JENKINS] - Add jest unit tests [`d8af5b7`](https://github.com/eea/volto-group-block/commit/d8af5b7932988b490a079d86079e359b5584fd7f)
144
- - [JENKINS] - Fix develop badge [`857b4ab`](https://github.com/eea/volto-group-block/commit/857b4ab5bc0aa9947c2ed76f35cec7d409c7fa66)
145
- - [JENKINS] - Add jenkins builds badges [`6cebd3e`](https://github.com/eea/volto-group-block/commit/6cebd3e970a840c4951c614a5d130dab05ae553f)
146
- - [JENKINS] - Cleanup console.log [`df38b6f`](https://github.com/eea/volto-group-block/commit/df38b6f7a630176e911ff89263c21e519ab44efa)
147
- - [JENKINS] - Fix eslint pipeline [`ca7c87a`](https://github.com/eea/volto-group-block/commit/ca7c87a4f74f2b0ea354ea5369f0700b8bee92af)
148
- - [JENKINS] - Fix style [`0e2c5a3`](https://github.com/eea/volto-group-block/commit/0e2c5a39b2f785ae1d942d39e7f8b2789dafc795)
149
164
  - Add Jenkinkins pipeline [`866a4e1`](https://github.com/eea/volto-group-block/commit/866a4e14ea1eb8f5adb01222e576e5ab6dc73a70)
150
- - yarn prettier [`e3fe0a3`](https://github.com/eea/volto-group-block/commit/e3fe0a36b89878769341b45198d6c9e2f2584d15)
151
165
 
152
166
  #### [0.1.3](https://github.com/eea/volto-group-block/compare/0.1.2...0.1.3)
153
167
 
@@ -192,5 +206,4 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
192
206
  - Render meta block [`0d44560`](https://github.com/eea/volto-group-block/commit/0d4456011ca56454068a54c610250b02df4ccb3b)
193
207
  - Implement meta block allowedBlocks settings [`f24feb1`](https://github.com/eea/volto-group-block/commit/f24feb1a1751f04841c21c7cd52a517fb02074ba)
194
208
  - Edit meta block [`236d291`](https://github.com/eea/volto-group-block/commit/236d29156fa835a7aa54eecdb4f120de0d64b271)
195
- - yarn bootstrap [`e009dfb`](https://github.com/eea/volto-group-block/commit/e009dfb6b9b74d101a6722f0982a5359fc522b6b)
196
209
  - Initial commit [`6a7b0de`](https://github.com/eea/volto-group-block/commit/6a7b0deb8f873d1462fd6a9c61edfc1562b3aace)
package/Jenkinsfile CHANGED
@@ -4,13 +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,water.europa.eu-freshwater"
8
8
  DEPENDENCIES = ""
9
9
  }
10
10
 
11
11
  stages {
12
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
+
13
30
  stage('Code') {
31
+ when {
32
+ allOf {
33
+ environment name: 'CHANGE_ID', value: ''
34
+ not { changelog '.*^Automated release [0-9\\.]+$' }
35
+ not { branch 'master' }
36
+ }
37
+ }
14
38
  steps {
15
39
  parallel(
16
40
 
@@ -36,6 +60,15 @@ pipeline {
36
60
  }
37
61
 
38
62
  stage('Tests') {
63
+ when {
64
+ allOf {
65
+ environment name: 'CHANGE_ID', value: ''
66
+ anyOf {
67
+ not { changelog '.*^Automated release [0-9\\.]+$' }
68
+ branch 'master'
69
+ }
70
+ }
71
+ }
39
72
  steps {
40
73
  parallel(
41
74
 
@@ -75,6 +108,15 @@ pipeline {
75
108
  }
76
109
 
77
110
  stage('Integration tests') {
111
+ when {
112
+ allOf {
113
+ environment name: 'CHANGE_ID', value: ''
114
+ anyOf {
115
+ not { changelog '.*^Automated release [0-9\\.]+$' }
116
+ branch 'master'
117
+ }
118
+ }
119
+ }
78
120
  steps {
79
121
  parallel(
80
122
 
@@ -122,10 +164,16 @@ pipeline {
122
164
  }
123
165
 
124
166
  stage('Report to SonarQube') {
125
- // Exclude Pull-Requests
126
167
  when {
127
168
  allOf {
128
169
  environment name: 'CHANGE_ID', value: ''
170
+ anyOf {
171
+ branch 'master'
172
+ allOf {
173
+ branch 'develop'
174
+ not { changelog '.*^Automated release [0-9\\.]+$' }
175
+ }
176
+ }
129
177
  }
130
178
  }
131
179
  steps {
@@ -156,8 +204,8 @@ pipeline {
156
204
  steps {
157
205
  node(label: 'docker') {
158
206
  script {
159
- if ( env.CHANGE_BRANCH != "develop" && !( env.CHANGE_BRANCH.startsWith("hotfix")) ) {
160
- error "Pipeline aborted due to PR not made from develop or hotfix branch"
207
+ if ( env.CHANGE_BRANCH != "develop" ) {
208
+ error "Pipeline aborted due to PR not made from develop branch"
161
209
  }
162
210
  withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN')]) {
163
211
  sh '''docker pull eeacms/gitflow'''
@@ -168,23 +216,6 @@ pipeline {
168
216
  }
169
217
  }
170
218
 
171
- stage('Release') {
172
- when {
173
- allOf {
174
- environment name: 'CHANGE_ID', value: ''
175
- branch 'master'
176
- }
177
- }
178
- steps {
179
- node(label: 'docker') {
180
- withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'),string(credentialsId: 'eea-jenkins-npm-token', variable: 'NPM_TOKEN')]) {
181
- sh '''docker pull eeacms/gitflow'''
182
- 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'''
183
- }
184
- }
185
- }
186
- }
187
-
188
219
  }
189
220
 
190
221
  post {
package/README.md CHANGED
@@ -1,7 +1,19 @@
1
1
  # volto-group-block
2
+
2
3
  [![Releases](https://img.shields.io/github/v/release/eea/volto-group-block)](https://github.com/eea/volto-group-block/releases)
4
+
3
5
  [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-group-block%2Fmaster&subject=master)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-group-block/job/master/display/redirect)
6
+ [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-group-block-master&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-group-block-master)
7
+ [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-group-block-master&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-group-block-master)
8
+ [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-group-block-master&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-group-block-master)
9
+ [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-group-block-master&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-group-block-master)
10
+
4
11
  [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-group-block%2Fdevelop&subject=develop)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-group-block/job/develop/display/redirect)
12
+ [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-group-block-develop&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-group-block-develop)
13
+ [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-group-block-develop&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-group-block-develop)
14
+ [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-group-block-develop&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-group-block-develop)
15
+ [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-group-block-develop&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-group-block-develop)
16
+
5
17
 
6
18
  [Volto](https://github.com/plone/volto) add-on to group blocks in sections and filter available blocks per content-type per section
7
19
 
@@ -72,6 +84,81 @@
72
84
 
73
85
  1. Happy editing!
74
86
 
87
+ ## Release
88
+
89
+ ### Automatic release using Jenkins
90
+
91
+ * The automatic release is started by creating a [Pull Request](../../compare/master...develop) from `develop` to `master`. The pull request status checks correlated to the branch and PR Jenkins jobs need to be processed successfully. 1 review from a github user with rights is mandatory.
92
+ * It runs on every commit on `master` branch, which is protected from direct commits, only allowing pull request merge commits.
93
+ * The automatic release is done by [Jenkins](https://ci.eionet.europa.eu). The status of the release job can be seen both in the Readme.md badges and the green check/red cross/yellow circle near the last commit information. If you click on the icon, you will have the list of checks that were run. The `continuous-integration/jenkins/branch` link goes to the Jenkins job execution webpage.
94
+ * Automated release scripts are located in the `eeacms/gitflow` docker image, specifically [js-release.sh](https://github.com/eea/eea.docker.gitflow/blob/master/src/js-release.sh) script. It uses the `release-it` tool.
95
+ * As long as a PR request is open from develop to master, the PR Jenkins job will automatically re-create the CHANGELOG.md and package.json files to be production-ready.
96
+ * The version format must be MAJOR.MINOR.PATCH. By default, next release is set to next minor version (with patch 0).
97
+ * You can manually change the version in `package.json`. The new version must not be already present in the tags/releases of the repository, otherwise it will be automatically increased by the script. Any changes to the version will trigger a `CHANGELOG.md` re-generation.
98
+ * Automated commits and commits with [JENKINS] or [YARN] in the commit log are excluded from `CHANGELOG.md` file.
99
+
100
+ ### Manual release from the develop branch ( beta release )
101
+
102
+ #### Installation and configuration of release-it
103
+
104
+ You need to first install the [release-it](https://github.com/release-it/release-it) client.
105
+
106
+ ```
107
+ npm install -g release-it
108
+ ```
109
+
110
+ Release-it uses the configuration written in the [`.release-it.json`](./.release-it.json) file located in the root of the repository.
111
+
112
+ Release-it is a tool that automates 4 important steps in the release process:
113
+
114
+ 1. Version increase in `package.json` ( increased from the current version in `package.json`)
115
+ 2. `CHANGELOG.md` automatic generation from commit messages ( grouped by releases )
116
+ 3. GitHub release on the commit with the changelog and package.json modification on the develop branch
117
+ 4. NPM release ( by default it's disabled, but can be enabled in the configuration file )
118
+
119
+ To configure the authentification, you need to export GITHUB_TOKEN for [GitHub](https://github.com/settings/tokens)
120
+
121
+ ```
122
+ export GITHUB_TOKEN=XXX-XXXXXXXXXXXXXXXXXXXXXX
123
+ ```
124
+
125
+ To configure npm, you can use the `npm login` command or use a configuration file with a TOKEN :
126
+
127
+ ```
128
+ echo "//registry.npmjs.org/:_authToken=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" > .npmrc
129
+ ```
130
+
131
+ #### Using release-it tool
132
+
133
+ There are 3 yarn scripts that can be run to do the release
134
+
135
+ ##### yarn release-beta
136
+
137
+ Automatically calculates and presents 3 beta versions - patch, minor and major for you to choose ( or Other for manual input).
138
+
139
+ ```
140
+ ? Select increment (next version):
141
+ ❯ prepatch (0.1.1-beta.0)
142
+ preminor (0.2.0-beta.0)
143
+ premajor (1.0.0-beta.0)
144
+ Other, please specify...
145
+ ```
146
+
147
+ ##### yarn release-major-beta
148
+
149
+ Same as `yarn release-beta`, but with premajor version pre-selected.
150
+
151
+ ##### yarn release
152
+
153
+ Generic command, does not automatically add the `beta` to version, but you can still manually write it if you choose Other.
154
+
155
+ #### Important notes
156
+
157
+ > Do not use release-it tool on master branch, the commit on CHANGELOG.md file and the version increase in the package.json file can't be done without a PULL REQUEST.
158
+
159
+ > Do not keep Pull Requests from develop to master branches open when you are doing beta releases from the develop branch. As long as a PR to master is open, an automatic script will run on every commit and will update both the version and the changelog to a production-ready state - ( MAJOR.MINOR.PATCH mandatory format for version).
160
+
161
+
75
162
  ## How to contribute
76
163
 
77
164
  See [DEVELOP.md](https://github.com/eea/volto-group-block/blob/master/DEVELOP.md).
@@ -5,16 +5,17 @@ describe('Blocks Tests', () => {
5
5
  afterEach(tearDownAfterEach);
6
6
 
7
7
  it('Add Block: Empty', () => {
8
+ // without this the clear command below does nothing sometimes
9
+ cy.wait(500);
10
+
8
11
  // Change page title
9
- cy.get('.documentFirstHeading > .public-DraftStyleDefault-block')
10
- .clear()
11
- .type('My Add-on Page')
12
- .get('.documentFirstHeading span[data-text]')
13
- .contains('My Add-on Page');
14
-
15
- cy.get('.documentFirstHeading > .public-DraftStyleDefault-block').type(
16
- '{enter}',
17
- );
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}');
18
19
 
19
20
  // Add block
20
21
  cy.get('.ui.basic.icon.button.block-add-button').first().click();
@@ -44,7 +44,7 @@ export const setupBeforeEach = () => {
44
44
  cy.waitForResourceToLoad('@types');
45
45
  cy.waitForResourceToLoad('my-page');
46
46
  cy.navigate('/cypress/my-page/edit');
47
- cy.get(`.block.title [data-contents]`);
47
+ cy.get(`.block.title h1`);
48
48
  };
49
49
 
50
50
  export const tearDownAfterEach = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-group-block",
3
- "version": "4.2.3",
3
+ "version": "4.3.3",
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",
@@ -25,6 +25,8 @@
25
25
  },
26
26
  "scripts": {
27
27
  "release": "release-it",
28
+ "release-major-beta": "release-it major --preRelease=beta",
29
+ "release-beta": "release-it --preRelease=beta",
28
30
  "bootstrap": "npm install -g ejs; npm link ejs; node bootstrap",
29
31
  "stylelint": "../../../node_modules/stylelint/bin/stylelint.js --allow-empty-input 'src/**/*.{css,less}'",
30
32
  "stylelint:overrides": "../../../node_modules/.bin/stylelint --syntax less --allow-empty-input 'theme/**/*.overrides' 'src/**/*.overrides'",
@@ -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 {