# @hellospruce/strapi-custom-ckeditor5

> Custom CkEditor for Strapi

Latest version **1.1.1** (published 2021-03-30) · 0 weekly downloads

## Install

```sh
npm install @hellospruce/strapi-custom-ckeditor5
pnpm add @hellospruce/strapi-custom-ckeditor5
yarn add @hellospruce/strapi-custom-ckeditor5
bun add @hellospruce/strapi-custom-ckeditor5
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2021-03-30 |
| First published | 2021-02-03 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 20 |
| Unpacked size | 5 MB |
| Known vulnerabilities | 0 (+4 in 4 direct dependencies) |
| Install scripts | no |
| Author | Hello Spruce Developers |
| Maintainers | renatokoyama, jakeranallo, spruce_xaun |

## Links

- npm: https://www.npmjs.com/package/@hellospruce/strapi-custom-ckeditor5
- npm.io page: https://npm.io/package/@hellospruce/strapi-custom-ckeditor5

## Dependencies (20)

- [webpack-cli](https://npm.io/package/webpack-cli.md) ^3.3.11
- [@ckeditor/ckeditor5-ui](https://npm.io/package/@ckeditor/ckeditor5-ui.md) ^25.0.0
- [@ckeditor/ckeditor5-link](https://npm.io/package/@ckeditor/ckeditor5-link.md) ^25.0.0
- [@ckeditor/ckeditor5-list](https://npm.io/package/@ckeditor/ckeditor5-list.md) ^25.0.0
- [@ckeditor/ckeditor5-image](https://npm.io/package/@ckeditor/ckeditor5-image.md) ^25.0.0
- [@ckeditor/ckeditor5-table](https://npm.io/package/@ckeditor/ckeditor5-table.md) ^25.0.0
- [@ckeditor/ckeditor5-indent](https://npm.io/package/@ckeditor/ckeditor5-indent.md) ^25.0.0
- [@ckeditor/ckeditor5-typing](https://npm.io/package/@ckeditor/ckeditor5-typing.md) ^25.0.0
- [@ckeditor/ckeditor5-heading](https://npm.io/package/@ckeditor/ckeditor5-heading.md) ^25.0.0
- [@ckeditor/ckeditor5-ckfinder](https://npm.io/package/@ckeditor/ckeditor5-ckfinder.md) ^25.0.0
- [@ckeditor/ckeditor5-paragraph](https://npm.io/package/@ckeditor/ckeditor5-paragraph.md) ^25.0.0
- [@ckeditor/ckeditor5-autoformat](https://npm.io/package/@ckeditor/ckeditor5-autoformat.md) ^25.0.0
- [@ckeditor/ckeditor5-easy-image](https://npm.io/package/@ckeditor/ckeditor5-easy-image.md) ^25.0.0
- [@ckeditor/ckeditor5-essentials](https://npm.io/package/@ckeditor/ckeditor5-essentials.md) ^25.0.0
- [@ckeditor/ckeditor5-block-quote](https://npm.io/package/@ckeditor/ckeditor5-block-quote.md) ^25.0.0
- [@ckeditor/ckeditor5-media-embed](https://npm.io/package/@ckeditor/ckeditor5-media-embed.md) ^25.0.0
- [@ckeditor/ckeditor5-basic-styles](https://npm.io/package/@ckeditor/ckeditor5-basic-styles.md) ^25.0.0
- [@ckeditor/ckeditor5-editor-balloon](https://npm.io/package/@ckeditor/ckeditor5-editor-balloon.md) ^25.0.0
- [@ckeditor/ckeditor5-adapter-ckfinder](https://npm.io/package/@ckeditor/ckeditor5-adapter-ckfinder.md) ^25.0.0
- [@ckeditor/ckeditor5-paste-from-office](https://npm.io/package/@ckeditor/ckeditor5-paste-from-office.md) ^25.0.0

## Recent versions

- 1.1.1 (latest) — 2021-03-30
- 1.1.0 — 2021-03-30
- 1.0.5 — 2021-02-04
- 1.0.4 — 2021-02-04
- 1.0.3 — 2021-02-04
- 1.0.1 — 2021-02-03
- 1.0.0 — 2021-02-03

## README

Custom Editor for Strapi, It was build on top of CKEditor 5 balloon block editor build

## Documentation

See:

* [Installation](https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/installation.html) for how to install this package and what it contains.
* [Basic API](https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/basic-api.html) for how to create an editor and interact with it.
* [Configuration](https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/configuration.html) for how to configure the editor.
* [Creating custom builds](https://ckeditor.com/docs/ckeditor5/latest/builds/guides/development/custom-builds.html) for how to customize the build (configure and rebuild the editor bundle).

## Quick start

First, install the build from npm:

```bash
npm install --save @hellospruce/strapi-custom-ckeditor5
```
or 

```bash
yarn add @hellospruce/strapi-custom-ckeditor5
```

And use it in on strapi:
Create the CKEditor component at:
```bash
strapi/app/extensions/content-manager/admin/src/components/CKEditor/index.js
```
```jsx
import { CKEditor } from '@ckeditor/ckeditor5-react';
import PropTypes from 'prop-types';
import React, { useState, useEffect } from 'react';
import { auth } from 'strapi-helper-plugin'
import cheerio from 'cheerio' 
import CustomEditor from '@hellospruce/strapi-custom-ckeditor5'

const Editor = ({ onChange, name, value }) => {
  const uploadUrl = `${strapi.backendURL}/upload`;
  const [content, setContent] = useState();
  const headers = {
    Authorization: 'Bearer ' + auth.getToken(),
  };
  
  useEffect(()=>{
    if(value){
      const $ = cheerio.load(value, null, false);
      const videos = $('.w-richtext-figure-type-video iframe');
      for(let i=0; i< videos.length; i++){
        let video = videos[i];
        let source = video.attribs['src'];
        video.parent.attribs['data-oembed-url']= source;
      }
  
      setContent($.html());
    }
  }, [value]);

  return (
    <div>
      <CKEditor
        editor={CustomEditor}
        data={content}
        onChange={(event, editor) => {
          const data = editor.getData();
          onChange({ target: { name, value: data } });
        }}
        config={{
          strapiUpload: {
            uploadUrl,
            headers,
          }
        }}
      />
    </div>
  );
};

Editor.propTypes = {
  onChange: PropTypes.func.isRequired,
  name: PropTypes.string.isRequired,
  value: PropTypes.string,
};

export default Editor;
```

Create a component to override the default strapi rich text component:
```bash
strapi/app/extensions/content-manager/admin/src/components/WysiwygWithErrors/index.js
```
```jsx
import React from 'react';
import PropTypes from 'prop-types';
import { isEmpty } from 'lodash';
import { Label, InputDescription, InputErrors } from 'strapi-helper-plugin';
import Editor from '../CKEditor';

const WysiwygWithErrors = ({
  inputDescription,
  errors,
  label,
  name,
  noErrorsDescription,
  onChange,
  value,
}) => {
  let spacer = !isEmpty(inputDescription) ? (
    <div style={{ height: '.4rem' }} />
  ) : (
    <div />
  );
    
  if (!noErrorsDescription && !isEmpty(errors)) {
    spacer = <div />;
  }
  
  return (
    <div
      style={{
        marginBottom: '1.6rem',
        fontSize: '1.3rem',
        fontFamily: 'Lato',
      }}
    >
      <Label htmlFor={name} message={label} style={{ marginBottom: 10 }} />
      <Editor name={name} onChange={onChange} value={value} />
      <InputDescription
        message={inputDescription}
        style={!isEmpty(inputDescription) ? { marginTop: '1.4rem' } : {}}
      />
      <InputErrors
        errors={(!noErrorsDescription && errors) || []}
        name={name}
      />
      {spacer}
    </div>
  );
};

WysiwygWithErrors.defaultProps = {
  errors: [],
  label: '',
  noErrorsDescription: false,
  value: '',
};

WysiwygWithErrors.propTypes = {
  errors: PropTypes.array,
  inputDescription: PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.func,
    PropTypes.shape({
      id: PropTypes.string,
      params: PropTypes.object,
    }),
  ]),
  label: PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.func,
    PropTypes.shape({
      id: PropTypes.string,
      params: PropTypes.object,
    }),
  ]),
  name: PropTypes.string.isRequired,
  noErrorsDescription: PropTypes.bool,
  onChange: PropTypes.func.isRequired,
  value: PropTypes.string,
};

export default WysiwygWithErrors;
```

---
_Source: https://npm.io/package/@hellospruce/strapi-custom-ckeditor5 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
