Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #247 from eea/develop
Browse files Browse the repository at this point in the history
Add clear formatting button to the toolbar. (#246)
  • Loading branch information
avoinea authored Aug 26, 2022
2 parents 0cc30e7 + aad81d5 commit f17d2f5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [6.3.0](https://github.com/eea/volto-slate/compare/6.2.2...6.3.0)

- Add clear formatting button to the toolbar. [`#246`](https://github.com/eea/volto-slate/pull/246)
- Release 6.3.0 [`b00265f`](https://github.com/eea/volto-slate/commit/b00265fae96cb9dd81e9cb1fbbd2ec11493a623b)

#### [6.2.2](https://github.com/eea/volto-slate/compare/6.2.1...6.2.2)

> 30 June 2022

#### [6.2.1](https://github.com/eea/volto-slate/compare/6.2.0...6.2.1)

Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pipeline {
NAMESPACE = ""
SONARQUBE_TAGS = "volto.eea.europa.eu,climate-energy.eea.europa.eu,forest.eea.europa.eu,biodiversity.europa.eu,www.eea.europa.eu-ims,sustainability.eionet.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,circularity.eea.europa.eu"
DEPENDENCIES = "volto-slate:asCypressDefault"
VOLTO = "alpha"
VOLTO = "16.0.0-alpha.14"
}

stages {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "volto-slate",
"version": "6.2.2",
"version": "6.3.0",
"description": "Slate.js integration with Volto",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
7 changes: 7 additions & 0 deletions src/editor/config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';

import boldIcon from '@plone/volto/icons/bold.svg';
import codeIcon from '@plone/volto/icons/code.svg';
import formatClearIcon from '@plone/volto/icons/format-clear.svg';
import headingIcon from '@plone/volto/icons/heading.svg';
import italicIcon from '@plone/volto/icons/italic.svg';
import listBulletIcon from '@plone/volto/icons/list-bullet.svg';
Expand All @@ -19,6 +20,7 @@ import {
MarkButton,
MarkElementButton,
BlockButton,
ClearFormattingButton,
Separator,
Expando,
} from './ui';
Expand Down Expand Up @@ -107,6 +109,9 @@ export const buttons = {
'heading-four': (props) => (
<BlockButton title="Heading 4" format="h4" icon={subTextIcon} {...props} />
),
clearformatting: (props) => (
<ClearFormattingButton title="Clear formatting" icon={formatClearIcon} />
),
'numbered-list': (props) => (
<BlockButton
title="Numbered list"
Expand All @@ -132,6 +137,8 @@ export const defaultToolbarButtons = [
'heading-three',
'heading-four',
'separator',
'clearformatting',
'separator',
'sub',
'sup',
'separator',
Expand Down
21 changes: 21 additions & 0 deletions src/editor/ui/ClearFormattingButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { useSlate } from 'slate-react';
import { clearFormatting } from 'volto-slate/utils';

import ToolbarButton from './ToolbarButton';

const ClearFormattingButton = ({ icon, ...props }) => {
const editor = useSlate();

const handleMouseDown = React.useCallback(
(event) => {
event.preventDefault();
clearFormatting(editor);
},
[editor],
);

return <ToolbarButton {...props} onMouseDown={handleMouseDown} icon={icon} />;
};

export default ClearFormattingButton;
1 change: 1 addition & 0 deletions src/editor/ui/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export BasicToolbar from './BasicToolbar';
export BlockButton from './BlockButton';
export ClearFormattingButton from './ClearFormattingButton';
export ExpandedToolbar from './ExpandedToolbar';
export Expando from './Expando';
export MarkButton from './MarkButton';
Expand Down
12 changes: 12 additions & 0 deletions src/utils/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,15 @@ export const getAllBlocks = (properties, blocks) => {
}
return blocks;
};

export const clearFormatting = (editor) => {
const { slate } = config.settings;
Transforms.setNodes(editor, {
type: slate.defaultBlockType,
});
Transforms.unwrapNodes(editor, {
match: (n) => n.type && n.type !== slate.defaultBlockType,
mode: 'all',
split: false,
});
};

0 comments on commit f17d2f5

Please sign in to comment.