Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #28 from melishev/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
melishev authored Mar 19, 2022
2 parents be17579 + e099f05 commit cd5c0cb
Show file tree
Hide file tree
Showing 23 changed files with 7,248 additions and 2,045 deletions.
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.github
.editorconfig
.gitattributes
.gitignore
.releaserc.js
CHANGELOG.md
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
# [2.0.0-beta.2](https://github.com/melishev/strapi-plugin-editor-js/compare/v2.0.0-beta.1...v2.0.0-beta.2) (2022-03-13)


### Bug Fixes

* fixed the image tool. Now able to add images from the media library, and automatically shuts the media library window after saving. ([fb5a907](https://github.com/melishev/strapi-plugin-editor-js/commit/fb5a907de6d4d6399b6a5e23b596d9893159944c))
* include label for the rich text editor field ([73187d7](https://github.com/melishev/strapi-plugin-editor-js/commit/73187d73977d25ddb317c890cc2b5f48e72ed94c))
* refactored to allow copy and paste images from another website ([3330250](https://github.com/melishev/strapi-plugin-editor-js/commit/3330250a03e64e41095057b8ecd7290e4c6f688c)), closes [#5](https://github.com/melishev/strapi-plugin-editor-js/issues/5)
* returned to making API route only be 'react-editorjs' ([ee9b747](https://github.com/melishev/strapi-plugin-editor-js/commit/ee9b74759786f8bcd87135a80932a14885f5a3f7))
* solution for [#5](https://github.com/melishev/strapi-plugin-editor-js/issues/5) axios ([1f2d9a7](https://github.com/melishev/strapi-plugin-editor-js/commit/1f2d9a73c7fb2a7653d8e7527cbd2c03f76335c5))


### Features

* add background to focused block & differentiate image tool caption ([a5d2b1b](https://github.com/melishev/strapi-plugin-editor-js/commit/a5d2b1b5650926014da076c9844739ffe6a81897))
* add width, height, size, mime, responsive data to image tool ([e07548c](https://github.com/melishev/strapi-plugin-editor-js/commit/e07548ca71e7ffc211acb53e8aa556ef2fe660e6)), closes [#6](https://github.com/melishev/strapi-plugin-editor-js/issues/6) [#16](https://github.com/melishev/strapi-plugin-editor-js/issues/16)
* enabled inline links ([ad11533](https://github.com/melishev/strapi-plugin-editor-js/commit/ad11533f0ba260cb1671bbd62ef7641bfd06512a))

# [2.0.0-beta.1](https://github.com/melishev/strapi-plugin-editor-js/compare/v1.5.1...v2.0.0-beta.1) (2022-02-24)


### Bug Fixes

* added /api/ to byUrl and byFile ([211c1f3](https://github.com/melishev/strapi-plugin-editor-js/commit/211c1f3bbfd8ed551021488dfd24f2c6d4caddf3))


* feat!: updates to allow Strapi v4 functionality ([72b4913](https://github.com/melishev/strapi-plugin-editor-js/commit/72b491313b172629cfab129586c68d80e6c508d8))


### BREAKING CHANGES

* This update refactors the plugin to work in Strapi v4. This code will not work in Strapi v3. At this time, the Image tool is not functioning. The link tool works, but thumbnails are being blocked by Strapi 4's contentSecurityPolicy. The current workaround for this is to replace the 'strapi::security' default export in ./config/middlewares.js to the following code (do this at your own risk):

"{
name: 'strapi::security',
config: {
contentSecurityPolicy: false
},
},"

I've yet to find a solution that can be baked into the plugin itself. I have also added "auth: false" to the routes config so that it is not necessary to give authenticated and public permissions to the plugin. This may need to be removed if it is seen as a security risk.

Custom styles have been added to Wysiwyg/wrapper.js for headers (H1-H6) because Strapi resets styles and there is no styling for the plugin without them.

I have updated editorjs to 2.23.2 and several other of the plugins (see package.json). I've also added @buffetjs/core and @buffetjs/styles to package.json because the library is not in Strapi now. I also removed "axios" because that library is in Strapi. I updated node to the following: "node": ">=10.16.0 <=16.x.x"

## [1.5.1](https://github.com/melishev/strapi-plugin-editor-js/compare/v1.5.0...v1.5.1) (2022-02-23)


Expand Down
73 changes: 60 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

<h1 align="center">🎛 Strapi + ✒️ Editor.js</h1>

⚠️ **This is the Strapi v4 version of this plugin! In order to use with v3, please use [release v.1.5.1](https://github.com/melishev/strapi-plugin-react-editorjs/releases/tag/v1.5.1).**


## 🙉 What it is?

#### This is a plugin for [Strapi Headless CMS](https://strapi.io) that replaces the standard wysiwyg editor with the cool [Editor.js](https://editorjs.io) and all its compatible add-ons.
<br>

Expand Down Expand Up @@ -36,36 +39,80 @@

#### All of the above add-ons (if added) work initially when the plugin is loaded. You can also customize the add-ons available in your application using the instructions below.

> Note: the Image add-on cannot be reconfigured by you personally, this is due to some problems with the work of this add-on. You just better leave it alone.
<br>

## 🤟🏻 Getting Started

```bash
yarn add strapi-plugin-react-editorjs
# or
npm install strapi-plugin-react-editorjs
```
For the plugin to work correctly, you need to give Public and Authenticated role access to the plugin API, at the moment it is necessary for:
1. [Link Tool](https://github.com/editor-js/link)
2. [Image Tool](https://github.com/editor-js/image)

In order for Strapi to show the Link Tool thumbnails correctly, you will need to edit the 'strapi::security' line in ./config/middlewares.js. Change that line to the following (do this at your own risk).

```js
module.exports = [
// ...
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
directives: {
'img-src': ['*'],
},
}
},
},
// ...
];
```

<br>

## ⚙️ How to customize editor (optional)
## ⚙️ How to extend/develop this plugin (optional)

If you want to change the look of the editor or add/remove editorJS plugins, you will need to do the following:

If you want to change the look of the editor or remove unused add-ons, you can add a custom Editor.js configuration to override the default settings:
1. If this plugin is already install via yarn or npm, uninstall:
```bash
yarn remove strapi-plugin-react-editorjs
# or
npm uninstall strapi-plugin-react-editorjs
```
2. Go to the ./src/plugins folder (create it if it doesn't exist) and clone the project:

1. Go to your Strapi folder
2. Copy template config file [`node_modules/strapi-plugin-react-editorjs/admin/src/config/customTools.js`](admin/src/config/customTools.js) to `extensions/react-editorjs/admin/src/config`
3. Set up `extensions/react-editorjs/admin/src/config/customTools.js`
4. Rebuild Strapi
```bash
# If you wish to clone the Master Branch
git clone https://github.com/melishev/strapi-plugin-react-editorjs.git
# If you wish to clone the Beta Branch
git clone --single-branch --branch beta https://github.com/melishev/strapi-plugin-react-editorjs.git
```
3. Go into the plugin and install dependencies:
- `cd strapi-plugin-react-editorjs`
- `yarn install` or `npm install`
4. In an editor add the following code into the main Strapi v4 ./config/plugins.js file (create the file if it doesn't exist)

```js
module.exports = ({ env }) => ({
// ...
'editorjs': {
enabled: true,
resolve: './src/plugins/strapi-plugin-react-editorjs'
},
// ...
})
```

5. To make changes to EditorJS plugins, edit the `./src/plugins/strapi-plugin-react-editorjs/admin/src/config/customTools.js` file.
- Note: the Image Tool add-on has been highly customized in order to work in Strapi and cannot be edited in the `customTools.js` file. If you wish to develop it further, you may, but it will take much more advanced knowledge and testing.
6. Rebuild Strapi after installation and after any changes made in the plugin.
```bash
yarn run build
yarn build
# or
npm run build
```

### Please note that the add-ons are configured for Strapi, be careful when changing the configuration.

<br>
Expand All @@ -80,4 +127,4 @@ npm run build

## ⭐️ Show your support

Give a star if this project helped you.
Give a star if this project helped you.
178 changes: 66 additions & 112 deletions admin/src/components/Wysiwyg/index.js
Original file line number Diff line number Diff line change
@@ -1,130 +1,84 @@
import React from 'react';
import PropTypes from 'prop-types';
import React from "react";
import PropTypes from "prop-types";
import { isEmpty } from 'lodash';
import { LabelIconWrapper } from 'strapi-helper-plugin';
import Editor from '../editorjs';

import Editor from "../editorjs";
import cn from 'classnames';
import { Description, ErrorMessage, Label } from '@buffetjs/styles';
import { Error } from '@buffetjs/core';
import Wrapper from './wrapper';
import { useIntl } from 'react-intl';
import { Box } from '@strapi/design-system/Box';
import { Typography } from '@strapi/design-system/Typography';

// eslint-disable-next-line react/prefer-stateless-function
class WysiwygWithErrors extends React.Component {
render() {
const {
autoFocus,
className,
deactivateErrorHighlight,
disabled,
error: inputError,
inputClassName,
inputDescription,
inputStyle,
label,
labelIcon,
name,
onBlur: handleBlur,
onChange,
placeholder,
resetProps,
style,
tabIndex,
validations,
value,
...rest
} = this.props;

return (
<Error inputError={inputError} name={name} type="text" validations={validations}>
{({ canCheck, onBlur, error, dispatch }) => {
const hasError = Boolean(error);
const Wysiwyg = ({
name,
className,
error,
description,
intlLabel,
required,
onChange,
style,
value,
disabled,
}) => {
const { formatMessage } = useIntl();

return (
<Wrapper
className={`${cn(!isEmpty(className) && className)} ${hasError ? 'bordered' : ''}`}
style={style}
>
<Label htmlFor={name}>
<span>{label}</span>
{labelIcon && (
<LabelIconWrapper title={labelIcon.title}>{labelIcon.icon}</LabelIconWrapper>
)}
</Label>
<Editor
name={name}
onChange={onChange}
value={value}
/>
{!hasError && inputDescription && <Description>{inputDescription}</Description>}
{hasError && <ErrorMessage>{error}</ErrorMessage>}
</Wrapper>
);
}}
</Error>
);
}
}
return (
<Wrapper size={1} className={`${cn(!isEmpty(className) && className)}`} style={style}>
<Box>
<Typography variant="pi" fontWeight="bold">
{formatMessage(intlLabel)}
</Typography>
{required && (
<Typography variant="pi" fontWeight="bold" textColor="danger600">
*
</Typography>
)}
</Box>
<Editor onChange={onChange} value={value} name={name} disabled={disabled} />
{error && (
<Typography variant="pi" textColor="danger600">
{formatMessage({ id: error, defaultMessage: error })}
</Typography>
)}
{description && (
<Typography variant="pi">{formatMessage(description)}</Typography>
)}

</Wrapper>
)
};

WysiwygWithErrors.defaultProps = {
autoFocus: false,
className: '',
deactivateErrorHighlight: false,
didCheckErrors: false,
disabled: false,
error: null,
inputClassName: '',
inputDescription: '',
inputStyle: {},
label: '',
labelIcon: null,
onBlur: false,
placeholder: '',
resetProps: false,
Wysiwyg.defaultProps = {
className: "",
style: {},
tabIndex: '0',
validations: {},
tabIndex: "0",
value: null,
description: '',
disabled: false,
error: undefined,
intlLabel: '',
required: false,
value: '',
};

WysiwygWithErrors.propTypes = {
autoFocus: PropTypes.bool,
Wysiwyg.propTypes = {
className: PropTypes.string,
deactivateErrorHighlight: PropTypes.bool,
didCheckErrors: PropTypes.bool,
style: PropTypes.object,
tabIndex: PropTypes.string,
description: PropTypes.shape({
id: PropTypes.string,
defaultMessage: PropTypes.string,
}),
disabled: PropTypes.bool,
error: PropTypes.string,
inputClassName: PropTypes.string,
inputDescription: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
PropTypes.shape({
id: PropTypes.string,
params: PropTypes.object,
}),
]),
inputStyle: PropTypes.object,
label: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
PropTypes.shape({
id: PropTypes.string,
params: PropTypes.object,
}),
]),
labelIcon: PropTypes.shape({
icon: PropTypes.node.isRequired,
title: PropTypes.string,
intlLabel: PropTypes.shape({
id: PropTypes.string,
defaultMessage: PropTypes.string,
}),
required: PropTypes.bool,
value: PropTypes.string,
name: PropTypes.string.isRequired,
onBlur: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
onChange: PropTypes.func.isRequired,
placeholder: PropTypes.string,
resetProps: PropTypes.bool,
style: PropTypes.object,
tabIndex: PropTypes.string,
validations: PropTypes.object,
value: PropTypes.string,
};

export default WysiwygWithErrors;
export default Wysiwyg;
Loading

0 comments on commit cd5c0cb

Please sign in to comment.