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.
Files changed (194) hide show
  1. package/.github/workflows/slate.yml +47 -0
  2. package/.yarn/cache/@babel-helper-module-imports-npm-7.24.3-edb733448b-c23492189b.zip +0 -0
  3. package/.yarn/cache/@babel-types-npm-7.24.0-a0508cb308-4b574a37d4.zip +0 -0
  4. package/.yarn/cache/babel-plugin-lodash-npm-3.3.4-c7161075b6-044a4261e6.zip +0 -0
  5. package/.yarn/cache/require-package-name-npm-2.0.1-ac9a206b63-00f4e9e467.zip +0 -0
  6. 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
  7. package/.yarn/install-state.gz +0 -0
  8. package/CHANGELOG.md +878 -904
  9. package/RELEASE.md +8 -0
  10. package/locales/de/LC_MESSAGES/volto.po +86 -18
  11. package/locales/en/LC_MESSAGES/volto.po +86 -18
  12. package/locales/es/LC_MESSAGES/volto.po +86 -18
  13. package/locales/fr/LC_MESSAGES/volto.po +86 -18
  14. package/locales/it/LC_MESSAGES/volto.po +86 -18
  15. package/locales/volto.pot +87 -19
  16. package/package.json +4 -2
  17. package/publiccode.yml +2 -2
  18. package/src/components/Collapse.jsx +1 -0
  19. package/src/components/ItaliaTheme/Blocks/Accordion/Block/EditBlock.jsx +29 -24
  20. package/src/components/ItaliaTheme/Blocks/Accordion/Block/ViewBlock.jsx +4 -12
  21. package/src/components/ItaliaTheme/Blocks/Accordion/Edit.jsx +67 -6
  22. package/src/components/ItaliaTheme/Blocks/Alert/Edit.jsx +60 -113
  23. package/src/components/ItaliaTheme/Blocks/Alert/Sidebar.jsx +1 -0
  24. package/src/components/ItaliaTheme/Blocks/Alert/View.jsx +5 -14
  25. package/src/components/ItaliaTheme/Blocks/ArgumentsInEvidence/Block.jsx +16 -11
  26. package/src/components/ItaliaTheme/Blocks/ArgumentsInEvidence/Body.jsx +2 -1
  27. package/src/components/ItaliaTheme/Blocks/ArgumentsInEvidence/Edit.jsx +39 -1
  28. package/src/components/ItaliaTheme/Blocks/CTABlock/Block.jsx +35 -95
  29. package/src/components/ItaliaTheme/Blocks/Callout/Edit.jsx +108 -0
  30. package/src/components/ItaliaTheme/Blocks/Callout/Sidebar.jsx +173 -0
  31. package/src/components/ItaliaTheme/Blocks/Callout/View.jsx +45 -0
  32. package/src/components/ItaliaTheme/Blocks/ContactsBlock/Block/EditBlock.jsx +84 -63
  33. package/src/components/ItaliaTheme/Blocks/ContactsBlock/Block/ViewBlock.jsx +19 -39
  34. package/src/components/ItaliaTheme/Blocks/ContactsBlock/Edit.jsx +92 -19
  35. package/src/components/ItaliaTheme/Blocks/ContactsBlock/View.jsx +13 -21
  36. package/src/components/ItaliaTheme/Blocks/CountDown/Edit.jsx +21 -25
  37. package/src/components/ItaliaTheme/Blocks/CountDown/View.jsx +6 -15
  38. package/src/components/ItaliaTheme/Blocks/IconBlocks/Block/EditBlock.jsx +40 -15
  39. package/src/components/ItaliaTheme/Blocks/IconBlocks/Block/ViewBlock.jsx +6 -21
  40. package/src/components/ItaliaTheme/Blocks/IconBlocks/Edit.jsx +93 -20
  41. package/src/components/ItaliaTheme/Blocks/IconBlocks/Sidebar.jsx +1 -9
  42. package/src/components/ItaliaTheme/Blocks/IconBlocks/View.jsx +4 -17
  43. package/src/components/ItaliaTheme/Blocks/NumbersBlock/Block/EditBlock.jsx +46 -15
  44. package/src/components/ItaliaTheme/Blocks/NumbersBlock/Block/ViewBlock.jsx +2 -18
  45. package/src/components/ItaliaTheme/Blocks/NumbersBlock/Edit.jsx +84 -11
  46. package/src/components/ItaliaTheme/Blocks/NumbersBlock/View.jsx +2 -11
  47. package/src/components/ItaliaTheme/Blocks/TextCard/CardWithImage/Block.jsx +33 -67
  48. package/src/components/ItaliaTheme/Blocks/TextCard/CardWithImage/Edit.jsx +2 -8
  49. package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/BodyWrapper.jsx +2 -1
  50. package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/Edit.jsx +98 -84
  51. package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/View.jsx +20 -3
  52. package/src/components/ItaliaTheme/Blocks/__tests__/Accordion.test.jsx +11 -28
  53. package/src/components/ItaliaTheme/Blocks/__tests__/Alert.test.jsx +10 -14
  54. package/src/components/ItaliaTheme/Blocks/__tests__/ArgumentsInEvidence.test.jsx +20 -28
  55. package/src/components/ItaliaTheme/Blocks/__tests__/CTABlock.test.jsx +14 -29
  56. package/src/components/ItaliaTheme/Blocks/__tests__/CardWithImage.test.jsx +11 -28
  57. package/src/components/ItaliaTheme/Blocks/__tests__/ContactsBlock.test.jsx +75 -140
  58. package/src/components/ItaliaTheme/Blocks/__tests__/Countdown.test.jsx +20 -28
  59. package/src/components/ItaliaTheme/Blocks/__tests__/IconBlocks.test.jsx +22 -56
  60. package/src/components/ItaliaTheme/Blocks/__tests__/NumbersBlock.test.jsx +14 -43
  61. package/src/components/ItaliaTheme/Blocks/__tests__/SimpleCard.test.jsx +14 -30
  62. package/src/components/ItaliaTheme/Footer/FooterInfos.jsx +22 -8
  63. package/src/components/ItaliaTheme/Footer/FooterNavigation.jsx +3 -3
  64. package/src/components/ItaliaTheme/MegaMenu/MegaMenu.jsx +5 -1
  65. package/src/components/ItaliaTheme/Slider/SingleSlideWrapper.jsx +2 -3
  66. package/src/components/ItaliaTheme/View/BandoView/BandoApprofondimenti.jsx +1 -2
  67. package/src/components/ItaliaTheme/View/CartellaModulisticaView/DocRow.jsx +14 -5
  68. package/src/components/ItaliaTheme/View/Commons/Attachment.jsx +19 -3
  69. package/src/components/ItaliaTheme/View/Commons/Attachments.jsx +0 -1
  70. package/src/components/ItaliaTheme/View/Commons/DownloadFileFormat.jsx +11 -7
  71. package/src/components/ItaliaTheme/View/Commons/Module.jsx +7 -6
  72. package/src/components/ItaliaTheme/View/Commons/PageHeader/PageHeaderLinkServizio.jsx +6 -2
  73. package/src/components/ItaliaTheme/View/Commons/RichTextRender.jsx +8 -6
  74. package/src/components/ItaliaTheme/View/Commons/__tests__/RichText.test.jsx +14 -17
  75. package/src/components/ItaliaTheme/View/ServizioView/ServizioAccedi.jsx +5 -6
  76. package/src/components/ItaliaTheme/View/ServizioView/ServizioMetatag.jsx +4 -0
  77. package/src/components/ItaliaTheme/View/__tests__/CartellaModulisticaView.test.jsx +12 -1
  78. package/src/components/ItaliaTheme/View/__tests__/IncaricoView.test.jsx +24 -30
  79. package/src/components/ItaliaTheme/View/__tests__/PageView.test.jsx +24 -2
  80. package/src/components/ItaliaTheme/View/__tests__/PersonaView.test.jsx +96 -92
  81. package/src/components/ItaliaTheme/View/__tests__/ServizioAChiSiRivolge.test.jsx +240 -286
  82. package/src/components/ItaliaTheme/View/__tests__/ServizioAccedi.test.jsx +240 -286
  83. package/src/components/ItaliaTheme/View/__tests__/ServizioCasiParticolari.test.jsx +240 -286
  84. package/src/components/ItaliaTheme/View/__tests__/ServizioComeFare.test.jsx +240 -286
  85. package/src/components/ItaliaTheme/View/__tests__/ServizioCondizioni.test.jsx +240 -286
  86. package/src/components/ItaliaTheme/View/__tests__/ServizioContatti.test.jsx +240 -286
  87. package/src/components/ItaliaTheme/View/__tests__/ServizioCosE.test.jsx +240 -286
  88. package/src/components/ItaliaTheme/View/__tests__/ServizioCosaServe.test.jsx +240 -286
  89. package/src/components/ItaliaTheme/View/__tests__/ServizioCosaSiOttiene.test.jsx +240 -286
  90. package/src/components/ItaliaTheme/View/__tests__/ServizioCostiVincoli.test.jsx +240 -286
  91. package/src/components/ItaliaTheme/View/__tests__/ServizioMetadati.test.jsx +240 -286
  92. package/src/components/ItaliaTheme/View/__tests__/ServizioModulistica.test.jsx +240 -286
  93. package/src/components/ItaliaTheme/View/__tests__/ServizioProcedure.test.jsx +240 -286
  94. package/src/components/ItaliaTheme/View/__tests__/ServizioSitiEsterni.test.jsx +240 -286
  95. package/src/components/ItaliaTheme/View/__tests__/ServizioTempiScadenze.test.jsx +240 -286
  96. package/src/components/ItaliaTheme/View/__tests__/ServizioUlterioriInformazioni.test.jsx +240 -286
  97. package/src/components/ItaliaTheme/View/__tests__/ServizioView.test.jsx +470 -560
  98. package/src/components/ItaliaTheme/View/__tests__/TrasparenzaView.test.jsx +12 -1
  99. package/src/components/ItaliaTheme/manage/Widgets/ColorListWidget.jsx +11 -2
  100. package/src/components/ItaliaTheme/manage/Widgets/HtmlSlateWidget.jsx +154 -0
  101. package/src/components/ItaliaTheme/manage/Widgets/RichTextWidget.jsx +88 -0
  102. package/src/components/ItaliaTheme/manage/Widgets/SimpleTextEditorWidget.jsx +158 -0
  103. package/src/components/ItaliaTheme/manage/Widgets/TextEditorWidget.jsx +167 -270
  104. package/src/config/Blocks/ListingOptions/index.js +0 -1
  105. package/src/config/Blocks/ListingOptions/utils.js +0 -7
  106. package/src/config/Blocks/blocks.js +29 -8
  107. package/src/config/Blocks/listingVariations.js +1 -1
  108. package/src/config/Slate/Alignment/AlignMenu.jsx +169 -0
  109. package/src/config/Slate/Alignment/index.js +42 -0
  110. package/src/config/Slate/Blockquote/BlockquoteMenu.jsx +151 -0
  111. package/src/config/Slate/Blockquote/index.js +12 -0
  112. package/src/config/Slate/Headings/HeadingsMenu.jsx +139 -0
  113. package/src/config/Slate/Headings/headingsMenu.scss +44 -0
  114. package/src/config/Slate/Headings/index.js +62 -0
  115. package/src/config/Slate/Link/deserializer.js +25 -0
  116. package/src/config/Slate/Link/index.js +126 -0
  117. package/src/config/Slate/Link/renderer.jsx +99 -0
  118. package/src/config/Slate/LinkButton/index.js +47 -0
  119. package/src/config/Slate/TextLarger/index.js +51 -0
  120. package/src/config/Slate/Underline/index.js +10 -0
  121. package/src/config/Slate/config.js +43 -0
  122. package/src/config/Slate/deserializers.js +66 -0
  123. package/src/config/Slate/dropdownStyle.scss +14 -0
  124. package/src/config/Slate/dropdownUtils.js +422 -0
  125. package/src/config/Slate/extensions/breakList.js +91 -0
  126. package/src/config/Slate/handlers.js +243 -0
  127. package/src/config/Slate/utils.js +73 -0
  128. package/src/config/Widgets/widgets.js +1 -2
  129. package/src/config/italiaConfig.js +7 -54
  130. package/src/customizations/volto/components/manage/AnchorPlugin/components/LinkButton/AddLinkForm.jsx +360 -0
  131. package/src/customizations/volto/components/manage/Blocks/HeroImageLeft/Edit.jsx +75 -200
  132. package/src/customizations/volto/components/manage/Blocks/Video/Edit.jsx +1 -1
  133. package/src/customizations/volto/components/manage/Form/BlocksToolbar.jsx +1 -1
  134. package/src/customizations/volto/components/manage/UniversalLink/UniversalLink.jsx +59 -6
  135. package/src/customizations/volto-form-block/components/Field.jsx +45 -22
  136. package/src/customizations/volto-form-block/components/FormResult.jsx +74 -0
  137. package/src/customizations/volto-form-block/components/FormView.jsx +79 -66
  138. package/src/customizations/volto-form-block/components/Widget/Button.jsx +50 -0
  139. package/src/helpers/EnhanceLink.js +44 -0
  140. package/src/helpers/FormValidation/FormValidationHelpers.js +3 -0
  141. package/src/helpers/blocks.js +86 -0
  142. package/src/helpers/files.js +14 -14
  143. package/src/helpers/index.js +4 -3
  144. package/src/helpers/richTextHelper.js +10 -0
  145. package/src/icons/Group.svg +1 -0
  146. package/src/icons/blocco-icone.svg +0 -3
  147. package/src/icons/blockquote-card-dark.svg +1 -0
  148. package/src/icons/blockquote-card.svg +1 -0
  149. package/src/icons/blockquote-simple.svg +1 -0
  150. package/src/icons/text-larger.svg +1 -0
  151. package/src/theme/ItaliaTheme/Blocks/_accordion.scss +1 -10
  152. package/src/theme/ItaliaTheme/Blocks/_alert.scss +53 -1
  153. package/src/theme/ItaliaTheme/Blocks/_bandiInEvidenceTemplate.scss +1 -0
  154. package/src/theme/ItaliaTheme/Blocks/_callout.scss +32 -0
  155. package/src/theme/ItaliaTheme/Blocks/_contacts.scss +15 -32
  156. package/src/theme/ItaliaTheme/Blocks/_ctaBlock.scss +0 -14
  157. package/src/theme/ItaliaTheme/Blocks/_gridBlock.scss +1 -1
  158. package/src/theme/ItaliaTheme/Blocks/_hero.scss +1 -8
  159. package/src/theme/ItaliaTheme/Blocks/_iconBlocks.scss +0 -30
  160. package/src/theme/ItaliaTheme/Blocks/_imageCardTextBlock.scss +3 -2
  161. package/src/theme/ItaliaTheme/Blocks/_numbers.scss +1 -5
  162. package/src/theme/ItaliaTheme/Blocks/_simpleCardTextBlock.scss +8 -2
  163. package/src/theme/ItaliaTheme/Blocks/_tableOfContents.scss +1 -0
  164. package/src/theme/ItaliaTheme/Components/_megamenu.scss +0 -4
  165. package/src/theme/ItaliaTheme/Subsites/ItaliaTheme/Blocks/_cta.scss +1 -0
  166. package/src/theme/ItaliaTheme/Subsites/ItaliaTheme/Blocks/_searchSections.scss +1 -0
  167. package/src/theme/ItaliaTheme/Subsites/bootstrap-italia/custom/_headercenter.scss +1 -0
  168. package/src/theme/ItaliaTheme/Views/_cartellaModulistica.scss +11 -2
  169. package/src/theme/ItaliaTheme/Views/_slider.scss +3 -3
  170. package/src/theme/ItaliaTheme/Widgets/_iconWidget.scss +4 -0
  171. package/src/theme/ItaliaTheme/_main.scss +42 -54
  172. package/src/theme/_cms-ui.scss +59 -161
  173. package/src/theme/extras/_forms.scss +2 -14
  174. package/src/theme/site.scss +1 -0
  175. package/test-setup-config.js +58 -0
  176. package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/Block.jsx +0 -151
  177. package/src/config/RichTextEditor/LinkEntity.jsx +0 -27
  178. package/src/config/RichTextEditor/Plugins/AnchorPlugin/components/Link/index.jsx +0 -44
  179. package/src/config/RichTextEditor/Plugins/AnchorPlugin/components/LinkButton/AddLinkForm.jsx +0 -349
  180. package/src/config/RichTextEditor/Plugins/AnchorPlugin/components/LinkButton/index.js +0 -150
  181. package/src/config/RichTextEditor/Plugins/AnchorPlugin/index.js +0 -88
  182. package/src/config/RichTextEditor/ToolbarButtons/AlignButton.jsx +0 -61
  183. package/src/config/RichTextEditor/ToolbarButtons/ButtonsButton.jsx +0 -14
  184. package/src/config/RichTextEditor/ToolbarButtons/CalloutsButton.jsx +0 -38
  185. package/src/config/RichTextEditor/ToolbarButtons/DraftJsDropdownButton.jsx +0 -106
  186. package/src/config/RichTextEditor/ToolbarButtons/HeadingsButton.jsx +0 -57
  187. package/src/config/RichTextEditor/ToolbarButtons/TextSizeButton.jsx +0 -65
  188. package/src/config/RichTextEditor/ToolbarButtons/UnderlineButton.jsx +0 -14
  189. package/src/config/RichTextEditor/config.js +0 -253
  190. package/src/config/volto-gdpr-privacy-defaultPanelConfig.js +0 -292
  191. package/src/customizations/volto/components/manage/Blocks/ToC/View.jsx +0 -134
  192. package/src/customizations/volto/components/manage/Blocks/ToC/variations/DefaultTocRenderer.jsx +0 -99
  193. package/src/customizations/volto/config/RichTextEditor/Plugins.jsx +0 -63
  194. 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': 'text',
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 { id, title, required, value, onChange, intl, colors, className } =
48
- this.props;
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;