design-comuni-plone-theme 11.10.1 → 12.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/slate.yml +47 -0
- package/.yarn/cache/@babel-helper-module-imports-npm-7.24.3-edb733448b-c23492189b.zip +0 -0
- package/.yarn/cache/@babel-types-npm-7.24.0-a0508cb308-4b574a37d4.zip +0 -0
- package/.yarn/cache/babel-plugin-lodash-npm-3.3.4-c7161075b6-044a4261e6.zip +0 -0
- package/.yarn/cache/require-package-name-npm-2.0.1-ac9a206b63-00f4e9e467.zip +0 -0
- package/.yarn/cache/{volto-form-block-npm-3.7.2-f24953a510-7387a1b85a.zip → volto-form-block-npm-3.8.2-e49cbe07d5-5b72a06a5e.zip} +0 -0
- package/.yarn/install-state.gz +0 -0
- package/CHANGELOG.md +878 -904
- package/RELEASE.md +8 -0
- package/locales/de/LC_MESSAGES/volto.po +86 -18
- package/locales/en/LC_MESSAGES/volto.po +86 -18
- package/locales/es/LC_MESSAGES/volto.po +86 -18
- package/locales/fr/LC_MESSAGES/volto.po +86 -18
- package/locales/it/LC_MESSAGES/volto.po +86 -18
- package/locales/volto.pot +87 -19
- package/package.json +4 -2
- package/publiccode.yml +2 -2
- package/src/components/Collapse.jsx +1 -0
- package/src/components/ItaliaTheme/Blocks/Accordion/Block/EditBlock.jsx +29 -24
- package/src/components/ItaliaTheme/Blocks/Accordion/Block/ViewBlock.jsx +4 -12
- package/src/components/ItaliaTheme/Blocks/Accordion/Edit.jsx +67 -6
- package/src/components/ItaliaTheme/Blocks/Alert/Edit.jsx +60 -113
- package/src/components/ItaliaTheme/Blocks/Alert/Sidebar.jsx +1 -0
- package/src/components/ItaliaTheme/Blocks/Alert/View.jsx +5 -14
- package/src/components/ItaliaTheme/Blocks/ArgumentsInEvidence/Block.jsx +16 -11
- package/src/components/ItaliaTheme/Blocks/ArgumentsInEvidence/Body.jsx +2 -1
- package/src/components/ItaliaTheme/Blocks/ArgumentsInEvidence/Edit.jsx +39 -1
- package/src/components/ItaliaTheme/Blocks/CTABlock/Block.jsx +35 -95
- package/src/components/ItaliaTheme/Blocks/Callout/Edit.jsx +108 -0
- package/src/components/ItaliaTheme/Blocks/Callout/Sidebar.jsx +173 -0
- package/src/components/ItaliaTheme/Blocks/Callout/View.jsx +45 -0
- package/src/components/ItaliaTheme/Blocks/ContactsBlock/Block/EditBlock.jsx +84 -63
- package/src/components/ItaliaTheme/Blocks/ContactsBlock/Block/ViewBlock.jsx +19 -39
- package/src/components/ItaliaTheme/Blocks/ContactsBlock/Edit.jsx +92 -19
- package/src/components/ItaliaTheme/Blocks/ContactsBlock/View.jsx +13 -21
- package/src/components/ItaliaTheme/Blocks/CountDown/Edit.jsx +21 -25
- package/src/components/ItaliaTheme/Blocks/CountDown/View.jsx +6 -15
- package/src/components/ItaliaTheme/Blocks/IconBlocks/Block/EditBlock.jsx +40 -15
- package/src/components/ItaliaTheme/Blocks/IconBlocks/Block/ViewBlock.jsx +6 -21
- package/src/components/ItaliaTheme/Blocks/IconBlocks/Edit.jsx +93 -20
- package/src/components/ItaliaTheme/Blocks/IconBlocks/Sidebar.jsx +1 -9
- package/src/components/ItaliaTheme/Blocks/IconBlocks/View.jsx +4 -17
- package/src/components/ItaliaTheme/Blocks/NumbersBlock/Block/EditBlock.jsx +46 -15
- package/src/components/ItaliaTheme/Blocks/NumbersBlock/Block/ViewBlock.jsx +2 -18
- package/src/components/ItaliaTheme/Blocks/NumbersBlock/Edit.jsx +84 -11
- package/src/components/ItaliaTheme/Blocks/NumbersBlock/View.jsx +2 -11
- package/src/components/ItaliaTheme/Blocks/TextCard/CardWithImage/Block.jsx +33 -67
- package/src/components/ItaliaTheme/Blocks/TextCard/CardWithImage/Edit.jsx +2 -8
- package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/BodyWrapper.jsx +2 -1
- package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/Edit.jsx +98 -84
- package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/View.jsx +20 -3
- package/src/components/ItaliaTheme/Blocks/__tests__/Accordion.test.jsx +11 -28
- package/src/components/ItaliaTheme/Blocks/__tests__/Alert.test.jsx +10 -14
- package/src/components/ItaliaTheme/Blocks/__tests__/ArgumentsInEvidence.test.jsx +20 -28
- package/src/components/ItaliaTheme/Blocks/__tests__/CTABlock.test.jsx +14 -29
- package/src/components/ItaliaTheme/Blocks/__tests__/CardWithImage.test.jsx +11 -28
- package/src/components/ItaliaTheme/Blocks/__tests__/ContactsBlock.test.jsx +75 -140
- package/src/components/ItaliaTheme/Blocks/__tests__/Countdown.test.jsx +20 -28
- package/src/components/ItaliaTheme/Blocks/__tests__/IconBlocks.test.jsx +22 -56
- package/src/components/ItaliaTheme/Blocks/__tests__/NumbersBlock.test.jsx +14 -43
- package/src/components/ItaliaTheme/Blocks/__tests__/SimpleCard.test.jsx +14 -30
- package/src/components/ItaliaTheme/Footer/FooterInfos.jsx +22 -8
- package/src/components/ItaliaTheme/Footer/FooterNavigation.jsx +3 -3
- package/src/components/ItaliaTheme/MegaMenu/MegaMenu.jsx +5 -1
- package/src/components/ItaliaTheme/Slider/SingleSlideWrapper.jsx +2 -3
- package/src/components/ItaliaTheme/View/BandoView/BandoApprofondimenti.jsx +1 -2
- package/src/components/ItaliaTheme/View/CartellaModulisticaView/DocRow.jsx +14 -5
- package/src/components/ItaliaTheme/View/Commons/Attachment.jsx +19 -3
- package/src/components/ItaliaTheme/View/Commons/Attachments.jsx +0 -1
- package/src/components/ItaliaTheme/View/Commons/DownloadFileFormat.jsx +11 -7
- package/src/components/ItaliaTheme/View/Commons/Module.jsx +7 -6
- package/src/components/ItaliaTheme/View/Commons/PageHeader/PageHeaderLinkServizio.jsx +6 -2
- package/src/components/ItaliaTheme/View/Commons/RichTextRender.jsx +8 -6
- package/src/components/ItaliaTheme/View/Commons/__tests__/RichText.test.jsx +14 -17
- package/src/components/ItaliaTheme/View/ServizioView/ServizioAccedi.jsx +5 -6
- package/src/components/ItaliaTheme/View/ServizioView/ServizioMetatag.jsx +4 -0
- package/src/components/ItaliaTheme/View/__tests__/CartellaModulisticaView.test.jsx +12 -1
- package/src/components/ItaliaTheme/View/__tests__/IncaricoView.test.jsx +24 -30
- package/src/components/ItaliaTheme/View/__tests__/PageView.test.jsx +24 -2
- package/src/components/ItaliaTheme/View/__tests__/PersonaView.test.jsx +96 -92
- package/src/components/ItaliaTheme/View/__tests__/ServizioAChiSiRivolge.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioAccedi.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioCasiParticolari.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioComeFare.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioCondizioni.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioContatti.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioCosE.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioCosaServe.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioCosaSiOttiene.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioCostiVincoli.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioMetadati.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioModulistica.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioProcedure.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioSitiEsterni.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioTempiScadenze.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioUlterioriInformazioni.test.jsx +240 -286
- package/src/components/ItaliaTheme/View/__tests__/ServizioView.test.jsx +470 -560
- package/src/components/ItaliaTheme/View/__tests__/TrasparenzaView.test.jsx +12 -1
- package/src/components/ItaliaTheme/manage/Widgets/ColorListWidget.jsx +11 -2
- package/src/components/ItaliaTheme/manage/Widgets/HtmlSlateWidget.jsx +154 -0
- package/src/components/ItaliaTheme/manage/Widgets/RichTextWidget.jsx +88 -0
- package/src/components/ItaliaTheme/manage/Widgets/SimpleTextEditorWidget.jsx +158 -0
- package/src/components/ItaliaTheme/manage/Widgets/TextEditorWidget.jsx +167 -270
- package/src/config/Blocks/ListingOptions/index.js +0 -1
- package/src/config/Blocks/ListingOptions/utils.js +0 -7
- package/src/config/Blocks/blocks.js +29 -8
- package/src/config/Blocks/listingVariations.js +1 -1
- package/src/config/Slate/Alignment/AlignMenu.jsx +169 -0
- package/src/config/Slate/Alignment/index.js +42 -0
- package/src/config/Slate/Blockquote/BlockquoteMenu.jsx +151 -0
- package/src/config/Slate/Blockquote/index.js +12 -0
- package/src/config/Slate/Headings/HeadingsMenu.jsx +139 -0
- package/src/config/Slate/Headings/headingsMenu.scss +44 -0
- package/src/config/Slate/Headings/index.js +62 -0
- package/src/config/Slate/Link/deserializer.js +25 -0
- package/src/config/Slate/Link/index.js +126 -0
- package/src/config/Slate/Link/renderer.jsx +99 -0
- package/src/config/Slate/LinkButton/index.js +47 -0
- package/src/config/Slate/TextLarger/index.js +51 -0
- package/src/config/Slate/Underline/index.js +10 -0
- package/src/config/Slate/config.js +43 -0
- package/src/config/Slate/deserializers.js +66 -0
- package/src/config/Slate/dropdownStyle.scss +14 -0
- package/src/config/Slate/dropdownUtils.js +422 -0
- package/src/config/Slate/extensions/breakList.js +91 -0
- package/src/config/Slate/handlers.js +243 -0
- package/src/config/Slate/utils.js +73 -0
- package/src/config/Widgets/widgets.js +1 -2
- package/src/config/italiaConfig.js +7 -54
- package/src/customizations/volto/components/manage/AnchorPlugin/components/LinkButton/AddLinkForm.jsx +360 -0
- package/src/customizations/volto/components/manage/Blocks/HeroImageLeft/Edit.jsx +75 -200
- package/src/customizations/volto/components/manage/Blocks/Video/Edit.jsx +1 -1
- package/src/customizations/volto/components/manage/Form/BlocksToolbar.jsx +1 -1
- package/src/customizations/volto/components/manage/UniversalLink/UniversalLink.jsx +59 -6
- package/src/customizations/volto-form-block/components/Field.jsx +45 -22
- package/src/customizations/volto-form-block/components/FormResult.jsx +74 -0
- package/src/customizations/volto-form-block/components/FormView.jsx +79 -66
- package/src/customizations/volto-form-block/components/Widget/Button.jsx +50 -0
- package/src/helpers/EnhanceLink.js +44 -0
- package/src/helpers/FormValidation/FormValidationHelpers.js +3 -0
- package/src/helpers/blocks.js +86 -0
- package/src/helpers/files.js +14 -14
- package/src/helpers/index.js +4 -3
- package/src/helpers/richTextHelper.js +10 -0
- package/src/icons/Group.svg +1 -0
- package/src/icons/blocco-icone.svg +0 -3
- package/src/icons/blockquote-card-dark.svg +1 -0
- package/src/icons/blockquote-card.svg +1 -0
- package/src/icons/blockquote-simple.svg +1 -0
- package/src/icons/text-larger.svg +1 -0
- package/src/theme/ItaliaTheme/Blocks/_accordion.scss +1 -10
- package/src/theme/ItaliaTheme/Blocks/_alert.scss +53 -1
- package/src/theme/ItaliaTheme/Blocks/_bandiInEvidenceTemplate.scss +1 -0
- package/src/theme/ItaliaTheme/Blocks/_callout.scss +32 -0
- package/src/theme/ItaliaTheme/Blocks/_contacts.scss +15 -32
- package/src/theme/ItaliaTheme/Blocks/_ctaBlock.scss +0 -14
- package/src/theme/ItaliaTheme/Blocks/_gridBlock.scss +1 -1
- package/src/theme/ItaliaTheme/Blocks/_hero.scss +1 -8
- package/src/theme/ItaliaTheme/Blocks/_iconBlocks.scss +0 -30
- package/src/theme/ItaliaTheme/Blocks/_imageCardTextBlock.scss +3 -2
- package/src/theme/ItaliaTheme/Blocks/_numbers.scss +1 -5
- package/src/theme/ItaliaTheme/Blocks/_simpleCardTextBlock.scss +8 -2
- package/src/theme/ItaliaTheme/Blocks/_tableOfContents.scss +1 -0
- package/src/theme/ItaliaTheme/Components/_megamenu.scss +0 -4
- package/src/theme/ItaliaTheme/Subsites/ItaliaTheme/Blocks/_cta.scss +1 -0
- package/src/theme/ItaliaTheme/Subsites/ItaliaTheme/Blocks/_searchSections.scss +1 -0
- package/src/theme/ItaliaTheme/Subsites/bootstrap-italia/custom/_headercenter.scss +1 -0
- package/src/theme/ItaliaTheme/Views/_cartellaModulistica.scss +11 -2
- package/src/theme/ItaliaTheme/Views/_slider.scss +3 -3
- package/src/theme/ItaliaTheme/Widgets/_iconWidget.scss +4 -0
- package/src/theme/ItaliaTheme/_main.scss +42 -54
- package/src/theme/_cms-ui.scss +59 -161
- package/src/theme/extras/_forms.scss +2 -14
- package/src/theme/site.scss +1 -0
- package/test-setup-config.js +58 -0
- package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/Block.jsx +0 -151
- package/src/config/RichTextEditor/LinkEntity.jsx +0 -27
- package/src/config/RichTextEditor/Plugins/AnchorPlugin/components/Link/index.jsx +0 -44
- package/src/config/RichTextEditor/Plugins/AnchorPlugin/components/LinkButton/AddLinkForm.jsx +0 -349
- package/src/config/RichTextEditor/Plugins/AnchorPlugin/components/LinkButton/index.js +0 -150
- package/src/config/RichTextEditor/Plugins/AnchorPlugin/index.js +0 -88
- package/src/config/RichTextEditor/ToolbarButtons/AlignButton.jsx +0 -61
- package/src/config/RichTextEditor/ToolbarButtons/ButtonsButton.jsx +0 -14
- package/src/config/RichTextEditor/ToolbarButtons/CalloutsButton.jsx +0 -38
- package/src/config/RichTextEditor/ToolbarButtons/DraftJsDropdownButton.jsx +0 -106
- package/src/config/RichTextEditor/ToolbarButtons/HeadingsButton.jsx +0 -57
- package/src/config/RichTextEditor/ToolbarButtons/TextSizeButton.jsx +0 -65
- package/src/config/RichTextEditor/ToolbarButtons/UnderlineButton.jsx +0 -14
- package/src/config/RichTextEditor/config.js +0 -253
- package/src/config/volto-gdpr-privacy-defaultPanelConfig.js +0 -292
- package/src/customizations/volto/components/manage/Blocks/ToC/View.jsx +0 -134
- package/src/customizations/volto/components/manage/Blocks/ToC/variations/DefaultTocRenderer.jsx +0 -99
- package/src/customizations/volto/config/RichTextEditor/Plugins.jsx +0 -63
- package/src/helpers/redraftHelper.js +0 -9
|
@@ -62,7 +62,18 @@ const mock_allfields = {
|
|
|
62
62
|
'@type': 'title',
|
|
63
63
|
},
|
|
64
64
|
'fbd627d2-46a1-4d32-b610-6aed2a142b36': {
|
|
65
|
-
'@type': '
|
|
65
|
+
'@type': 'slate',
|
|
66
|
+
plaintext: '',
|
|
67
|
+
value: [
|
|
68
|
+
{
|
|
69
|
+
children: [
|
|
70
|
+
{
|
|
71
|
+
text: '',
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
type: 'p',
|
|
75
|
+
},
|
|
76
|
+
],
|
|
66
77
|
},
|
|
67
78
|
},
|
|
68
79
|
blocks_layout: {
|
|
@@ -44,8 +44,16 @@ class ColorListWidget extends Component {
|
|
|
44
44
|
* @returns {string} Markup for the component.
|
|
45
45
|
*/
|
|
46
46
|
render() {
|
|
47
|
-
const {
|
|
48
|
-
|
|
47
|
+
const {
|
|
48
|
+
id,
|
|
49
|
+
title,
|
|
50
|
+
required,
|
|
51
|
+
value,
|
|
52
|
+
onChange,
|
|
53
|
+
intl,
|
|
54
|
+
colors,
|
|
55
|
+
className,
|
|
56
|
+
} = this.props;
|
|
49
57
|
return colors.length > 0 ? (
|
|
50
58
|
<Form.Field
|
|
51
59
|
inline
|
|
@@ -78,6 +86,7 @@ class ColorListWidget extends Component {
|
|
|
78
86
|
active={value === color.name}
|
|
79
87
|
circular
|
|
80
88
|
aria-label={color.label}
|
|
89
|
+
title={color.label}
|
|
81
90
|
/>
|
|
82
91
|
);
|
|
83
92
|
})}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HtmlSlateWidget, a slate widget variant that saves its data as HTML
|
|
3
|
+
* CUSTOMIZATIONS:
|
|
4
|
+
* - rimossi i bottoni di allinemento, textlarger e blockquote perchè non funzionano nel widget e non servono in questi campi
|
|
5
|
+
* - aggiunta la classe public-ui
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import ReactDOMServer from 'react-dom/server';
|
|
10
|
+
import configureStore from 'redux-mock-store';
|
|
11
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
12
|
+
import { Provider, useSelector } from 'react-redux';
|
|
13
|
+
import { defineMessages, injectIntl } from 'react-intl';
|
|
14
|
+
|
|
15
|
+
import { FormFieldWrapper } from '@plone/volto/components';
|
|
16
|
+
import SlateEditor from '@plone/volto-slate/editor/SlateEditor';
|
|
17
|
+
import { serializeNodes } from '@plone/volto-slate/editor/render';
|
|
18
|
+
import { makeEditor } from '@plone/volto-slate/utils';
|
|
19
|
+
import deserialize from '@plone/volto-slate/editor/deserialize';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
createEmptyParagraph,
|
|
23
|
+
normalizeExternalData,
|
|
24
|
+
} from '@plone/volto-slate/utils';
|
|
25
|
+
import { ErrorBoundary } from '@plone/volto-slate/widgets/ErrorBoundary';
|
|
26
|
+
import config from '@plone/volto/registry';
|
|
27
|
+
|
|
28
|
+
import { getRichTextWidgetToolbarButtons } from 'design-comuni-plone-theme/config/Slate/utils';
|
|
29
|
+
|
|
30
|
+
import '@plone/volto-slate/widgets/style.css';
|
|
31
|
+
|
|
32
|
+
const messages = defineMessages({
|
|
33
|
+
error: {
|
|
34
|
+
id:
|
|
35
|
+
'An error has occurred while editing "{name}" field. We have been notified and we are looking into it. Please save your work and retry. If the issue persists please contact the site administrator.',
|
|
36
|
+
defaultMessage:
|
|
37
|
+
'An error has occurred while editing "{name}" field. We have been notified and we are looking into it. Please save your work and retry. If the issue persists please contact the site administrator.',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const HtmlSlateWidget = (props) => {
|
|
42
|
+
const {
|
|
43
|
+
id,
|
|
44
|
+
onChange,
|
|
45
|
+
value,
|
|
46
|
+
focus,
|
|
47
|
+
className,
|
|
48
|
+
block,
|
|
49
|
+
placeholder,
|
|
50
|
+
properties,
|
|
51
|
+
intl,
|
|
52
|
+
} = props;
|
|
53
|
+
|
|
54
|
+
const [selected, setSelected] = React.useState(focus);
|
|
55
|
+
|
|
56
|
+
const editor = React.useMemo(() => makeEditor(), []);
|
|
57
|
+
|
|
58
|
+
const token = useSelector((state) => state.userSession.token);
|
|
59
|
+
|
|
60
|
+
const toHtml = React.useCallback(
|
|
61
|
+
(value) => {
|
|
62
|
+
const mockStore = configureStore();
|
|
63
|
+
const html = ReactDOMServer.renderToStaticMarkup(
|
|
64
|
+
<Provider store={mockStore({ userSession: { token } })}>
|
|
65
|
+
<MemoryRouter>{serializeNodes(value || [])}</MemoryRouter>
|
|
66
|
+
</Provider>,
|
|
67
|
+
);
|
|
68
|
+
//console.log('toHtml', value, ' ----> ', html);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
'content-type': value ? value['content-type'] : 'text/html',
|
|
72
|
+
encoding: value ? value.encoding : 'utf8',
|
|
73
|
+
data: html,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
[token],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const fromHtml = React.useCallback(
|
|
80
|
+
(value) => {
|
|
81
|
+
const html = value?.data || '';
|
|
82
|
+
|
|
83
|
+
const parsed = new DOMParser().parseFromString(html, 'text/html');
|
|
84
|
+
const body =
|
|
85
|
+
parsed.getElementsByTagName('google-sheets-html-origin').length > 0
|
|
86
|
+
? parsed.querySelector('google-sheets-html-origin > table')
|
|
87
|
+
: parsed.body;
|
|
88
|
+
|
|
89
|
+
let data = deserialize(editor, body, { collapseWhitespace: false });
|
|
90
|
+
data = normalizeExternalData(editor, data);
|
|
91
|
+
|
|
92
|
+
// editor.children = data;
|
|
93
|
+
// Editor.normalize(editor);
|
|
94
|
+
// TODO: need to add {text: ""} placeholders between elements
|
|
95
|
+
const res = data.length ? data : [createEmptyParagraph()];
|
|
96
|
+
// console.log('from html', { html: value?.data, res });
|
|
97
|
+
return res;
|
|
98
|
+
},
|
|
99
|
+
[editor],
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const valueFromHtml = React.useMemo(() => {
|
|
103
|
+
//console.log('fromhtml', value, '--->', fromHtml(value));
|
|
104
|
+
return fromHtml(value);
|
|
105
|
+
}, [value, fromHtml]);
|
|
106
|
+
|
|
107
|
+
const handleChange = React.useCallback(
|
|
108
|
+
(newValue) => {
|
|
109
|
+
onChange(id, toHtml(newValue));
|
|
110
|
+
},
|
|
111
|
+
[onChange, toHtml, id],
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const handleClick = React.useCallback(() => {
|
|
115
|
+
setSelected(true);
|
|
116
|
+
}, []);
|
|
117
|
+
|
|
118
|
+
let toolbarButtons = getRichTextWidgetToolbarButtons(config);
|
|
119
|
+
|
|
120
|
+
const slateSettings = {
|
|
121
|
+
...config.settings.slate,
|
|
122
|
+
toolbarButtons: toolbarButtons,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<FormFieldWrapper {...props} draggable={false} className="slate_wysiwyg">
|
|
127
|
+
<div
|
|
128
|
+
className="slate_wysiwyg_box public-ui"
|
|
129
|
+
role="textbox"
|
|
130
|
+
tabIndex="-1"
|
|
131
|
+
style={{ boxSizing: 'initial' }}
|
|
132
|
+
onClick={handleClick}
|
|
133
|
+
onKeyDown={() => {}}
|
|
134
|
+
>
|
|
135
|
+
<ErrorBoundary name={intl.formatMessage(messages.error, { name: id })}>
|
|
136
|
+
<SlateEditor
|
|
137
|
+
className={className}
|
|
138
|
+
id={id}
|
|
139
|
+
name={id}
|
|
140
|
+
value={valueFromHtml}
|
|
141
|
+
onChange={handleChange}
|
|
142
|
+
block={block}
|
|
143
|
+
selected={selected}
|
|
144
|
+
properties={properties}
|
|
145
|
+
placeholder={placeholder}
|
|
146
|
+
slateSettings={slateSettings}
|
|
147
|
+
/>
|
|
148
|
+
</ErrorBoundary>
|
|
149
|
+
</div>
|
|
150
|
+
</FormFieldWrapper>
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export default injectIntl(HtmlSlateWidget);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Slate widget that uses internal JSON representation as its value
|
|
3
|
+
* CUSTOMIZATIONS:
|
|
4
|
+
* - rimossi i bottoni di allinemento, textlarger e blockquote perchè non funzionano nel widget e non servono in questi campi
|
|
5
|
+
* - aggiunta la classe public-ui
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import isUndefined from 'lodash/isUndefined';
|
|
10
|
+
import isString from 'lodash/isString';
|
|
11
|
+
import { FormFieldWrapper } from '@plone/volto/components';
|
|
12
|
+
import SlateEditor from '@plone/volto-slate/editor/SlateEditor';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
createEmptyParagraph,
|
|
16
|
+
createParagraph,
|
|
17
|
+
} from '@plone/volto-slate/utils/blocks';
|
|
18
|
+
|
|
19
|
+
import '@plone/volto-slate/widgets/style.css';
|
|
20
|
+
import { getRichTextWidgetToolbarButtons } from 'design-comuni-plone-theme/config/Slate/utils';
|
|
21
|
+
|
|
22
|
+
import config from '@plone/volto/registry';
|
|
23
|
+
|
|
24
|
+
const getValue = (value) => {
|
|
25
|
+
if (isUndefined(value) || !isUndefined(value?.data)) {
|
|
26
|
+
return [createEmptyParagraph()];
|
|
27
|
+
}
|
|
28
|
+
// Previously this was a text field
|
|
29
|
+
if (isString(value)) {
|
|
30
|
+
return [createParagraph(value)];
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const SlateRichTextWidget = (props) => {
|
|
36
|
+
const {
|
|
37
|
+
id,
|
|
38
|
+
onChange,
|
|
39
|
+
value,
|
|
40
|
+
focus,
|
|
41
|
+
className,
|
|
42
|
+
block,
|
|
43
|
+
placeholder,
|
|
44
|
+
properties,
|
|
45
|
+
readOnly = false,
|
|
46
|
+
} = props;
|
|
47
|
+
const [selected, setSelected] = React.useState(focus);
|
|
48
|
+
|
|
49
|
+
let toolbarButtons = getRichTextWidgetToolbarButtons(config);
|
|
50
|
+
|
|
51
|
+
const slateSettings = {
|
|
52
|
+
...config.settings.slate,
|
|
53
|
+
toolbarButtons: toolbarButtons,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<FormFieldWrapper {...props} draggable={false} className="slate_wysiwyg">
|
|
58
|
+
<div
|
|
59
|
+
className="slate_wysiwyg_box public-ui"
|
|
60
|
+
role="textbox"
|
|
61
|
+
tabIndex="-1"
|
|
62
|
+
style={{ boxSizing: 'initial' }}
|
|
63
|
+
onClick={() => {
|
|
64
|
+
setSelected(true);
|
|
65
|
+
}}
|
|
66
|
+
onKeyDown={() => {}}
|
|
67
|
+
>
|
|
68
|
+
<SlateEditor
|
|
69
|
+
className={className}
|
|
70
|
+
readOnly={readOnly}
|
|
71
|
+
id={id}
|
|
72
|
+
name={id}
|
|
73
|
+
value={getValue(value)}
|
|
74
|
+
onChange={(newValue) => {
|
|
75
|
+
onChange(id, newValue);
|
|
76
|
+
}}
|
|
77
|
+
block={block}
|
|
78
|
+
selected={selected}
|
|
79
|
+
properties={properties}
|
|
80
|
+
placeholder={placeholder}
|
|
81
|
+
slateSettings={slateSettings}
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
84
|
+
</FormFieldWrapper>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default SlateRichTextWidget;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edit simple text block.
|
|
3
|
+
* @module components/Widgets/SimpleTextEditorWidget/SimpleTextEditorWidget
|
|
4
|
+
*
|
|
5
|
+
* E' un editor di testo da mettere nei blocchi, senza formattazione.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React, { useRef, useEffect } from 'react';
|
|
9
|
+
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
import { defineMessages, useIntl } from 'react-intl';
|
|
12
|
+
import { useInView } from 'react-intersection-observer';
|
|
13
|
+
|
|
14
|
+
import config from '@plone/volto/registry';
|
|
15
|
+
|
|
16
|
+
const messages = defineMessages({
|
|
17
|
+
text: {
|
|
18
|
+
id: 'Type text…',
|
|
19
|
+
defaultMessage: 'Type text…',
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const SimpleTextEditorWidget = (props) => {
|
|
24
|
+
const intl = useIntl();
|
|
25
|
+
const {
|
|
26
|
+
data,
|
|
27
|
+
setSelected,
|
|
28
|
+
onSelectBlock,
|
|
29
|
+
onChangeBlock,
|
|
30
|
+
fieldName,
|
|
31
|
+
block,
|
|
32
|
+
value,
|
|
33
|
+
selected,
|
|
34
|
+
placeholder,
|
|
35
|
+
} = props;
|
|
36
|
+
const { ref, inView } = useInView({
|
|
37
|
+
threshold: 0,
|
|
38
|
+
rootMargin: '0px 0px 200px 0px',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const fieldRef = useRef();
|
|
42
|
+
|
|
43
|
+
const handleKey = (event) => {
|
|
44
|
+
const { slate } = config.settings;
|
|
45
|
+
|
|
46
|
+
const handlers = slate.textblockDetachedKeyboardHandlers[event.key];
|
|
47
|
+
|
|
48
|
+
if (handlers) {
|
|
49
|
+
// a handler can return `true` to signify it has handled the event in this
|
|
50
|
+
// case, the execution flow is stopped
|
|
51
|
+
const handlerProps = {
|
|
52
|
+
getBlockProps: () => {
|
|
53
|
+
return { ...props };
|
|
54
|
+
},
|
|
55
|
+
getSavedSelection: () => null,
|
|
56
|
+
};
|
|
57
|
+
return handlers.find((handler) =>
|
|
58
|
+
handler({ editor: handlerProps, event }),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (selected) {
|
|
65
|
+
fieldRef.current.focus();
|
|
66
|
+
}
|
|
67
|
+
}, [selected]);
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
//inizializzazione del valore nel campo
|
|
71
|
+
const _value = value ?? data[fieldName];
|
|
72
|
+
if (fieldRef.current && _value?.length > 0) {
|
|
73
|
+
fieldRef.current.innerText = _value;
|
|
74
|
+
}
|
|
75
|
+
}, []);
|
|
76
|
+
|
|
77
|
+
const selectThis = () => {
|
|
78
|
+
if (setSelected) {
|
|
79
|
+
setSelected(fieldName ?? true);
|
|
80
|
+
} else if (onSelectBlock) {
|
|
81
|
+
onSelectBlock(block);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const pasteAsTextPlain = (e) => {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
var text = '';
|
|
88
|
+
if (e.clipboardData || e.originalEvent.clipboardData) {
|
|
89
|
+
text = (e.originalEvent || e).clipboardData.getData('text/plain');
|
|
90
|
+
} else if (window.clipboardData) {
|
|
91
|
+
text = window.clipboardData.getData('Text');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
text = text.replaceAll('\n', ' ');
|
|
95
|
+
|
|
96
|
+
if (document.queryCommandSupported('insertText')) {
|
|
97
|
+
document.execCommand('insertText', false, text);
|
|
98
|
+
} else {
|
|
99
|
+
document.execCommand('paste', false, text);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<div className="simple-text-editor-widget" ref={ref}>
|
|
105
|
+
<span
|
|
106
|
+
className="simple-text-input"
|
|
107
|
+
contentEditable={inView} //se è in view è editabile, altrimenti è readOnly
|
|
108
|
+
dir="ltr"
|
|
109
|
+
suppressContentEditableWarning={true}
|
|
110
|
+
role="textbox"
|
|
111
|
+
tabIndex={0}
|
|
112
|
+
placeholder={placeholder || intl.formatMessage(messages.text)}
|
|
113
|
+
onInput={(e) => {
|
|
114
|
+
let retVal = {
|
|
115
|
+
value: e.target.textContent,
|
|
116
|
+
};
|
|
117
|
+
if (fieldName) {
|
|
118
|
+
retVal = { [fieldName]: e.target.textContent };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
onChangeBlock(block, { ...data, ...retVal });
|
|
122
|
+
}}
|
|
123
|
+
onFocus={(e) => {
|
|
124
|
+
if (!selected) {
|
|
125
|
+
selectThis();
|
|
126
|
+
}
|
|
127
|
+
}}
|
|
128
|
+
onBlur={(e) => {
|
|
129
|
+
setSelected(fieldName ? null : false);
|
|
130
|
+
}}
|
|
131
|
+
onPaste={(e) => {
|
|
132
|
+
pasteAsTextPlain(e);
|
|
133
|
+
}}
|
|
134
|
+
onKeyDown={handleKey}
|
|
135
|
+
ref={fieldRef}
|
|
136
|
+
/>
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
SimpleTextEditorWidget.propTypes = {
|
|
142
|
+
data: PropTypes.objectOf(PropTypes.any).isRequired,
|
|
143
|
+
setSelected: PropTypes.func.isRequired,
|
|
144
|
+
onSelectBlock: PropTypes.func.isRequired,
|
|
145
|
+
onChangeBlock: PropTypes.func.isRequired,
|
|
146
|
+
block: PropTypes.string.isRequired,
|
|
147
|
+
value: PropTypes.string,
|
|
148
|
+
selected: PropTypes.bool.isRequired,
|
|
149
|
+
placeholder: PropTypes.string.isRequired,
|
|
150
|
+
focusPrevField: PropTypes.func,
|
|
151
|
+
focusNextField: PropTypes.func,
|
|
152
|
+
//from block props:
|
|
153
|
+
properties: PropTypes.objectOf(PropTypes.any).isRequired,
|
|
154
|
+
onFocusPreviousBlock: PropTypes.func.isRequired,
|
|
155
|
+
onFocusNextBlock: PropTypes.func.isRequired,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export default SimpleTextEditorWidget;
|