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

Commit

Permalink
Add simpleLink addon profile
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed May 22, 2021
1 parent 692df9b commit 81dcda9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
47 changes: 38 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,52 @@

[Watch a 5 minutes "elevator pitch" for volto-slate](https://www.youtube.com/watch?v=SOz-rk5e4_w)

An alternative text editor for Volto, capable of completely replacing the default richtext editor while offering enhanced functionality and behavior. We believe that, in order to succeed, Volto's richtext form editor (the Volto Composite Page editor) needs strong integration between the rich text capabilities and the rest of the Volto blocks. Some examples of the kind of strong integration we have in mind:

- Pasting complex documents inside a volto-slate text block will create multiple Volto blocks: images will be converted to Volto Image blocks, tables will be converted to Volto Table blocks, etc.
An alternative text editor for Volto, capable of completely replacing the
default richtext editor while offering enhanced functionality and behavior. We
believe that, in order to succeed, Volto's richtext form editor (the Volto
Composite Page editor) needs strong integration between the rich text
capabilities and the rest of the Volto blocks. Some examples of the kind of
strong integration we have in mind:

- Pasting complex documents inside a volto-slate text block will create
multiple Volto blocks: images will be converted to Volto Image blocks, tables
will be converted to Volto Table blocks, etc.
- The text block accepts drag&drop images and it will upload them as Volto Image blocks.
- volto-slate has a Table button with the familiar size input, but it create a Table block

While this addon is still in an early alpha stage, we've solved most of the big issues, the API starts to stabilize and we've already started several addons based on it: https://github.com/eea/volto-slate-metadata-mentions/ and https://github.com/eea/volto-slate-zotero
While this addon is still in an early alpha stage, we've solved most of the big
issues, the API starts to stabilize and we've already started several addons
based on it: https://github.com/eea/volto-slate-metadata-mentions/ and
https://github.com/eea/volto-slate-zotero

## Why

Some of the main reasons that drove us to create volto-slate instead of enhancing Volto's draftjs implementation:
Some of the main reasons that drove us to create volto-slate instead of
enhancing Volto's draftjs implementation:

- Volto's draftjs implementation depends on draft-js-plugins, a third-party
project that introduces its own set of bugs and maintanance issues
- Slate has a modern, developer-friendly api that makes developing plugins
something easy to do. Getting the editor in a plugin is as easy as `const
editor = useSlate()`, overriding core functionality is something that's built
in as pluggable, directly in Slate.

- Volto's draft based implementation depends on Redraft for its final output,
which comes with its own bugs and issues. While it is nice to have view-mode
components, this is something that volto-slate implements just as well.
- Because Slate's internal storage uses a tree modeled on the DOM pattern, its
final rendered output is very clean. Note: The Slate editor value is a JSON
object, similar to the Draftjs based implementation.

## Available profiles.

- Volto's draftjs implementation depends on draft-js-plugins, a third-party project that introduces its own set of bugs and maintanance issues
- Slate has a modern, developer-friendly api that makes developing plugins something easy to do. Getting the editor in a plugin is as easy as `const editor = useSlate()`, overriding core functionality is something that's built in as pluggable, directly in Slate.
volto-slate provides several optional configuration:

- Volto's draft based implementation depends on Redraft for its final output, which comes with its own bugs and issues. While it is nice to have view-mode components, this is something that volto-slate implements just as well.
- Because Slate's internal storage uses a tree modeled on the DOM pattern, its final rendered output is very clean. Note: The Slate editor value is a JSON object, similar to the Draftjs based implementation.
- `asDefault` which makes the volto-slate as the default richtext block editor
- `minimalDefault`, same as the above, but uses a set of toolbar buttons
similar to Volto
- `simplePlugin` reuses Volto's link plugin and makes for a better replacement
of Volto's rich text editor.

## Features

Expand Down
2 changes: 0 additions & 2 deletions src/editor/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import installLinkPlugin from './Link';
import installMarkdown from './Markdown';
import installTable from './Table';
import installStyleMenu from './StyleMenu';
import installSimpleLink from './SimpleLink';

export default function install(config) {
return [
Expand All @@ -14,6 +13,5 @@ export default function install(config) {
installImage,
installTable,
installStyleMenu,
installSimpleLink,
].reduce((acc, apply) => apply(acc), config);
}
5 changes: 5 additions & 0 deletions src/editor/ui/SlateToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const SlateToolbar = (props) => {

function renderButton(name, index) {
const Btn = buttons[name];
if (!Btn) {
// eslint-disable-next-line
console.warn('Button not found:', name);
return null;
}
// using also name because some buttons can be like "Separator"
return <Btn key={`${name}-${index}`} />;
}
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import RichTextWidget from './widgets/RichTextWidget';
import { BlocksBrowserWidget } from './widgets/BlocksBrowser';
import HashLink from './editor/plugins/Link/AppExtras/HashLink';
import installCallout from './editor/plugins/Callout';
import installSimpleLink from './editor/plugins/SimpleLink';

export default (config) => {
config = [
Expand Down Expand Up @@ -59,6 +60,10 @@ export function minimalDefault(config) {
return config;
}

export function simpleLink(config) {
return installSimpleLink(config);
}

export function asDefault(config) {
config.settings.defaultBlockType = 'slate';

Expand Down

0 comments on commit 81dcda9

Please sign in to comment.