From 4616af93cc26035a34a481288c34364254a0a952 Mon Sep 17 00:00:00 2001 From: andreiggr Date: Thu, 15 Dec 2022 12:18:47 +0200 Subject: [PATCH] add advanced link in config for fise --- src/index.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/index.js b/src/index.js index 60916d4..d350deb 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,27 @@ import reducers from '@eeacms/volto-forests-theme/reducers'; import './slate-styles.css'; +import linkSVG from '@plone/volto/icons/link.svg'; +import { makeInlineElementPlugin } from '@plone/volto-slate/elementEditor'; + +import { LINK } from '@plone/volto-slate/constants'; +import { LinkElement } from '@plone/volto-slate/editor/plugins/AdvancedLink/render'; +import { withLink } from '@plone/volto-slate/editor/plugins/AdvancedLink/extensions'; +import { linkDeserializer } from '@plone/volto-slate/editor/plugins/AdvancedLink/deserialize'; +import LinkEditSchema from '@plone/volto-slate/editor/plugins/AdvancedLink/schema'; +import { defineMessages } from 'react-intl'; // , defineMessages + +const messages = defineMessages({ + edit: { + id: 'Edit link', + defaultMessage: 'Edit link', + }, + delete: { + id: 'Remove link', + defaultMessage: 'Remove link', + }, +}); + export default function applyConfig(config) { // Add here your project's configuration here by modifying `config` accordingly config = [ @@ -130,5 +151,33 @@ export default function applyConfig(config) { // { cssClass: 'green-block-text', label: 'Green Text' }, // { cssClass: 'underline-block-text', label: 'Underline Text' }, // ]; + + //advancedlink is currently not working properly/not recognized in fise, so we add it to config manually + const { slate } = config.settings; + + slate.toolbarButtons = [...(slate.toolbarButtons || []), LINK]; + slate.expandedToolbarButtons = [ + ...(slate.expandedToolbarButtons || []), + LINK, + ]; + + slate.htmlTagsToSlate.A = linkDeserializer; + + const opts = { + title: 'Link', + pluginId: LINK, + elementType: LINK, + element: LinkElement, + isInlineElement: true, + editSchema: LinkEditSchema, + extensions: [withLink], + hasValue: (formData) => !!formData.link, + toolbarButtonIcon: linkSVG, + messages, + }; + + const [installLinkEditor] = makeInlineElementPlugin(opts); + config = installLinkEditor(config); + return config; }