design-comuni-plone-theme 11.10.2 → 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 (195) 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/cache/{volto-gdpr-privacy-npm-2.2.1-bc93b3e168-bce76108c3.zip → volto-gdpr-privacy-npm-2.2.0-6be0f74d53-8a93254251.zip} +0 -0
  8. package/.yarn/install-state.gz +0 -0
  9. package/CHANGELOG.md +878 -916
  10. package/RELEASE.md +8 -0
  11. package/locales/de/LC_MESSAGES/volto.po +86 -18
  12. package/locales/en/LC_MESSAGES/volto.po +86 -18
  13. package/locales/es/LC_MESSAGES/volto.po +86 -18
  14. package/locales/fr/LC_MESSAGES/volto.po +86 -18
  15. package/locales/it/LC_MESSAGES/volto.po +86 -18
  16. package/locales/volto.pot +87 -19
  17. package/package.json +5 -3
  18. package/publiccode.yml +2 -2
  19. package/src/components/Collapse.jsx +1 -0
  20. package/src/components/ItaliaTheme/Blocks/Accordion/Block/EditBlock.jsx +29 -24
  21. package/src/components/ItaliaTheme/Blocks/Accordion/Block/ViewBlock.jsx +4 -12
  22. package/src/components/ItaliaTheme/Blocks/Accordion/Edit.jsx +67 -6
  23. package/src/components/ItaliaTheme/Blocks/Alert/Edit.jsx +60 -113
  24. package/src/components/ItaliaTheme/Blocks/Alert/Sidebar.jsx +1 -0
  25. package/src/components/ItaliaTheme/Blocks/Alert/View.jsx +5 -14
  26. package/src/components/ItaliaTheme/Blocks/ArgumentsInEvidence/Block.jsx +16 -11
  27. package/src/components/ItaliaTheme/Blocks/ArgumentsInEvidence/Body.jsx +2 -1
  28. package/src/components/ItaliaTheme/Blocks/ArgumentsInEvidence/Edit.jsx +39 -1
  29. package/src/components/ItaliaTheme/Blocks/CTABlock/Block.jsx +35 -95
  30. package/src/components/ItaliaTheme/Blocks/Callout/Edit.jsx +108 -0
  31. package/src/components/ItaliaTheme/Blocks/Callout/Sidebar.jsx +173 -0
  32. package/src/components/ItaliaTheme/Blocks/Callout/View.jsx +45 -0
  33. package/src/components/ItaliaTheme/Blocks/ContactsBlock/Block/EditBlock.jsx +84 -63
  34. package/src/components/ItaliaTheme/Blocks/ContactsBlock/Block/ViewBlock.jsx +19 -39
  35. package/src/components/ItaliaTheme/Blocks/ContactsBlock/Edit.jsx +92 -19
  36. package/src/components/ItaliaTheme/Blocks/ContactsBlock/View.jsx +13 -21
  37. package/src/components/ItaliaTheme/Blocks/CountDown/Edit.jsx +21 -25
  38. package/src/components/ItaliaTheme/Blocks/CountDown/View.jsx +6 -15
  39. package/src/components/ItaliaTheme/Blocks/IconBlocks/Block/EditBlock.jsx +40 -15
  40. package/src/components/ItaliaTheme/Blocks/IconBlocks/Block/ViewBlock.jsx +6 -21
  41. package/src/components/ItaliaTheme/Blocks/IconBlocks/Edit.jsx +93 -20
  42. package/src/components/ItaliaTheme/Blocks/IconBlocks/Sidebar.jsx +1 -9
  43. package/src/components/ItaliaTheme/Blocks/IconBlocks/View.jsx +4 -17
  44. package/src/components/ItaliaTheme/Blocks/NumbersBlock/Block/EditBlock.jsx +46 -15
  45. package/src/components/ItaliaTheme/Blocks/NumbersBlock/Block/ViewBlock.jsx +2 -18
  46. package/src/components/ItaliaTheme/Blocks/NumbersBlock/Edit.jsx +84 -11
  47. package/src/components/ItaliaTheme/Blocks/NumbersBlock/View.jsx +2 -11
  48. package/src/components/ItaliaTheme/Blocks/TextCard/CardWithImage/Block.jsx +33 -67
  49. package/src/components/ItaliaTheme/Blocks/TextCard/CardWithImage/Edit.jsx +2 -8
  50. package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/BodyWrapper.jsx +2 -1
  51. package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/Edit.jsx +98 -84
  52. package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/View.jsx +20 -3
  53. package/src/components/ItaliaTheme/Blocks/__tests__/Accordion.test.jsx +11 -28
  54. package/src/components/ItaliaTheme/Blocks/__tests__/Alert.test.jsx +10 -14
  55. package/src/components/ItaliaTheme/Blocks/__tests__/ArgumentsInEvidence.test.jsx +20 -28
  56. package/src/components/ItaliaTheme/Blocks/__tests__/CTABlock.test.jsx +14 -29
  57. package/src/components/ItaliaTheme/Blocks/__tests__/CardWithImage.test.jsx +11 -28
  58. package/src/components/ItaliaTheme/Blocks/__tests__/ContactsBlock.test.jsx +75 -140
  59. package/src/components/ItaliaTheme/Blocks/__tests__/Countdown.test.jsx +20 -28
  60. package/src/components/ItaliaTheme/Blocks/__tests__/IconBlocks.test.jsx +22 -56
  61. package/src/components/ItaliaTheme/Blocks/__tests__/NumbersBlock.test.jsx +14 -43
  62. package/src/components/ItaliaTheme/Blocks/__tests__/SimpleCard.test.jsx +14 -30
  63. package/src/components/ItaliaTheme/Footer/FooterInfos.jsx +22 -8
  64. package/src/components/ItaliaTheme/Footer/FooterNavigation.jsx +3 -3
  65. package/src/components/ItaliaTheme/MegaMenu/MegaMenu.jsx +5 -1
  66. package/src/components/ItaliaTheme/Slider/SingleSlideWrapper.jsx +2 -3
  67. package/src/components/ItaliaTheme/View/BandoView/BandoApprofondimenti.jsx +1 -2
  68. package/src/components/ItaliaTheme/View/CartellaModulisticaView/DocRow.jsx +14 -5
  69. package/src/components/ItaliaTheme/View/Commons/Attachment.jsx +19 -3
  70. package/src/components/ItaliaTheme/View/Commons/Attachments.jsx +0 -1
  71. package/src/components/ItaliaTheme/View/Commons/DownloadFileFormat.jsx +11 -7
  72. package/src/components/ItaliaTheme/View/Commons/Module.jsx +7 -6
  73. package/src/components/ItaliaTheme/View/Commons/PageHeader/PageHeaderLinkServizio.jsx +6 -2
  74. package/src/components/ItaliaTheme/View/Commons/RichTextRender.jsx +8 -6
  75. package/src/components/ItaliaTheme/View/Commons/__tests__/RichText.test.jsx +14 -17
  76. package/src/components/ItaliaTheme/View/ServizioView/ServizioAccedi.jsx +5 -6
  77. package/src/components/ItaliaTheme/View/ServizioView/ServizioMetatag.jsx +4 -0
  78. package/src/components/ItaliaTheme/View/__tests__/CartellaModulisticaView.test.jsx +12 -1
  79. package/src/components/ItaliaTheme/View/__tests__/IncaricoView.test.jsx +24 -30
  80. package/src/components/ItaliaTheme/View/__tests__/PageView.test.jsx +24 -2
  81. package/src/components/ItaliaTheme/View/__tests__/PersonaView.test.jsx +96 -92
  82. package/src/components/ItaliaTheme/View/__tests__/ServizioAChiSiRivolge.test.jsx +240 -286
  83. package/src/components/ItaliaTheme/View/__tests__/ServizioAccedi.test.jsx +240 -286
  84. package/src/components/ItaliaTheme/View/__tests__/ServizioCasiParticolari.test.jsx +240 -286
  85. package/src/components/ItaliaTheme/View/__tests__/ServizioComeFare.test.jsx +240 -286
  86. package/src/components/ItaliaTheme/View/__tests__/ServizioCondizioni.test.jsx +240 -286
  87. package/src/components/ItaliaTheme/View/__tests__/ServizioContatti.test.jsx +240 -286
  88. package/src/components/ItaliaTheme/View/__tests__/ServizioCosE.test.jsx +240 -286
  89. package/src/components/ItaliaTheme/View/__tests__/ServizioCosaServe.test.jsx +240 -286
  90. package/src/components/ItaliaTheme/View/__tests__/ServizioCosaSiOttiene.test.jsx +240 -286
  91. package/src/components/ItaliaTheme/View/__tests__/ServizioCostiVincoli.test.jsx +240 -286
  92. package/src/components/ItaliaTheme/View/__tests__/ServizioMetadati.test.jsx +240 -286
  93. package/src/components/ItaliaTheme/View/__tests__/ServizioModulistica.test.jsx +240 -286
  94. package/src/components/ItaliaTheme/View/__tests__/ServizioProcedure.test.jsx +240 -286
  95. package/src/components/ItaliaTheme/View/__tests__/ServizioSitiEsterni.test.jsx +240 -286
  96. package/src/components/ItaliaTheme/View/__tests__/ServizioTempiScadenze.test.jsx +240 -286
  97. package/src/components/ItaliaTheme/View/__tests__/ServizioUlterioriInformazioni.test.jsx +240 -286
  98. package/src/components/ItaliaTheme/View/__tests__/ServizioView.test.jsx +470 -560
  99. package/src/components/ItaliaTheme/View/__tests__/TrasparenzaView.test.jsx +12 -1
  100. package/src/components/ItaliaTheme/manage/Widgets/ColorListWidget.jsx +11 -2
  101. package/src/components/ItaliaTheme/manage/Widgets/HtmlSlateWidget.jsx +154 -0
  102. package/src/components/ItaliaTheme/manage/Widgets/RichTextWidget.jsx +88 -0
  103. package/src/components/ItaliaTheme/manage/Widgets/SimpleTextEditorWidget.jsx +158 -0
  104. package/src/components/ItaliaTheme/manage/Widgets/TextEditorWidget.jsx +167 -270
  105. package/src/config/Blocks/ListingOptions/index.js +0 -1
  106. package/src/config/Blocks/ListingOptions/utils.js +0 -7
  107. package/src/config/Blocks/blocks.js +29 -8
  108. package/src/config/Blocks/listingVariations.js +1 -1
  109. package/src/config/Slate/Alignment/AlignMenu.jsx +169 -0
  110. package/src/config/Slate/Alignment/index.js +42 -0
  111. package/src/config/Slate/Blockquote/BlockquoteMenu.jsx +151 -0
  112. package/src/config/Slate/Blockquote/index.js +12 -0
  113. package/src/config/Slate/Headings/HeadingsMenu.jsx +139 -0
  114. package/src/config/Slate/Headings/headingsMenu.scss +44 -0
  115. package/src/config/Slate/Headings/index.js +62 -0
  116. package/src/config/Slate/Link/deserializer.js +25 -0
  117. package/src/config/Slate/Link/index.js +126 -0
  118. package/src/config/Slate/Link/renderer.jsx +99 -0
  119. package/src/config/Slate/LinkButton/index.js +47 -0
  120. package/src/config/Slate/TextLarger/index.js +51 -0
  121. package/src/config/Slate/Underline/index.js +10 -0
  122. package/src/config/Slate/config.js +43 -0
  123. package/src/config/Slate/deserializers.js +66 -0
  124. package/src/config/Slate/dropdownStyle.scss +14 -0
  125. package/src/config/Slate/dropdownUtils.js +422 -0
  126. package/src/config/Slate/extensions/breakList.js +91 -0
  127. package/src/config/Slate/handlers.js +243 -0
  128. package/src/config/Slate/utils.js +73 -0
  129. package/src/config/Widgets/widgets.js +1 -2
  130. package/src/config/italiaConfig.js +7 -54
  131. package/src/customizations/volto/components/manage/AnchorPlugin/components/LinkButton/AddLinkForm.jsx +360 -0
  132. package/src/customizations/volto/components/manage/Blocks/HeroImageLeft/Edit.jsx +75 -200
  133. package/src/customizations/volto/components/manage/Blocks/Video/Edit.jsx +1 -1
  134. package/src/customizations/volto/components/manage/Form/BlocksToolbar.jsx +1 -1
  135. package/src/customizations/volto/components/manage/UniversalLink/UniversalLink.jsx +59 -6
  136. package/src/customizations/volto-form-block/components/Field.jsx +45 -22
  137. package/src/customizations/volto-form-block/components/FormResult.jsx +74 -0
  138. package/src/customizations/volto-form-block/components/FormView.jsx +79 -66
  139. package/src/customizations/volto-form-block/components/Widget/Button.jsx +50 -0
  140. package/src/helpers/EnhanceLink.js +44 -0
  141. package/src/helpers/FormValidation/FormValidationHelpers.js +3 -0
  142. package/src/helpers/blocks.js +86 -0
  143. package/src/helpers/files.js +14 -14
  144. package/src/helpers/index.js +4 -3
  145. package/src/helpers/richTextHelper.js +10 -0
  146. package/src/icons/Group.svg +1 -0
  147. package/src/icons/blocco-icone.svg +0 -3
  148. package/src/icons/blockquote-card-dark.svg +1 -0
  149. package/src/icons/blockquote-card.svg +1 -0
  150. package/src/icons/blockquote-simple.svg +1 -0
  151. package/src/icons/text-larger.svg +1 -0
  152. package/src/theme/ItaliaTheme/Blocks/_accordion.scss +1 -10
  153. package/src/theme/ItaliaTheme/Blocks/_alert.scss +53 -1
  154. package/src/theme/ItaliaTheme/Blocks/_bandiInEvidenceTemplate.scss +1 -0
  155. package/src/theme/ItaliaTheme/Blocks/_callout.scss +32 -0
  156. package/src/theme/ItaliaTheme/Blocks/_contacts.scss +15 -32
  157. package/src/theme/ItaliaTheme/Blocks/_ctaBlock.scss +0 -14
  158. package/src/theme/ItaliaTheme/Blocks/_gridBlock.scss +1 -1
  159. package/src/theme/ItaliaTheme/Blocks/_hero.scss +1 -8
  160. package/src/theme/ItaliaTheme/Blocks/_iconBlocks.scss +0 -30
  161. package/src/theme/ItaliaTheme/Blocks/_imageCardTextBlock.scss +3 -2
  162. package/src/theme/ItaliaTheme/Blocks/_numbers.scss +1 -5
  163. package/src/theme/ItaliaTheme/Blocks/_simpleCardTextBlock.scss +8 -2
  164. package/src/theme/ItaliaTheme/Blocks/_tableOfContents.scss +1 -0
  165. package/src/theme/ItaliaTheme/Components/_megamenu.scss +0 -4
  166. package/src/theme/ItaliaTheme/Subsites/ItaliaTheme/Blocks/_cta.scss +1 -0
  167. package/src/theme/ItaliaTheme/Subsites/ItaliaTheme/Blocks/_searchSections.scss +1 -0
  168. package/src/theme/ItaliaTheme/Subsites/bootstrap-italia/custom/_headercenter.scss +1 -0
  169. package/src/theme/ItaliaTheme/Views/_cartellaModulistica.scss +11 -2
  170. package/src/theme/ItaliaTheme/Views/_slider.scss +3 -3
  171. package/src/theme/ItaliaTheme/Widgets/_iconWidget.scss +4 -0
  172. package/src/theme/ItaliaTheme/_main.scss +42 -54
  173. package/src/theme/_cms-ui.scss +59 -161
  174. package/src/theme/extras/_forms.scss +2 -14
  175. package/src/theme/site.scss +1 -0
  176. package/test-setup-config.js +58 -0
  177. package/src/components/ItaliaTheme/Blocks/TextCard/SimpleCard/Block.jsx +0 -151
  178. package/src/config/RichTextEditor/LinkEntity.jsx +0 -27
  179. package/src/config/RichTextEditor/Plugins/AnchorPlugin/components/Link/index.jsx +0 -44
  180. package/src/config/RichTextEditor/Plugins/AnchorPlugin/components/LinkButton/AddLinkForm.jsx +0 -349
  181. package/src/config/RichTextEditor/Plugins/AnchorPlugin/components/LinkButton/index.js +0 -150
  182. package/src/config/RichTextEditor/Plugins/AnchorPlugin/index.js +0 -88
  183. package/src/config/RichTextEditor/ToolbarButtons/AlignButton.jsx +0 -61
  184. package/src/config/RichTextEditor/ToolbarButtons/ButtonsButton.jsx +0 -14
  185. package/src/config/RichTextEditor/ToolbarButtons/CalloutsButton.jsx +0 -38
  186. package/src/config/RichTextEditor/ToolbarButtons/DraftJsDropdownButton.jsx +0 -106
  187. package/src/config/RichTextEditor/ToolbarButtons/HeadingsButton.jsx +0 -57
  188. package/src/config/RichTextEditor/ToolbarButtons/TextSizeButton.jsx +0 -65
  189. package/src/config/RichTextEditor/ToolbarButtons/UnderlineButton.jsx +0 -14
  190. package/src/config/RichTextEditor/config.js +0 -253
  191. package/src/config/volto-gdpr-privacy-defaultPanelConfig.js +0 -292
  192. package/src/customizations/volto/components/manage/Blocks/ToC/View.jsx +0 -134
  193. package/src/customizations/volto/components/manage/Blocks/ToC/variations/DefaultTocRenderer.jsx +0 -99
  194. package/src/customizations/volto/config/RichTextEditor/Plugins.jsx +0 -63
  195. package/src/helpers/redraftHelper.js +0 -9
@@ -0,0 +1,422 @@
1
+ /* eslint no-console: ["error", { allow: ["warn", "error"] }] */
2
+ import { Editor, Transforms } from 'slate';
3
+ import { isBlockActive } from '@plone/volto-slate/utils';
4
+ import config from '@plone/volto/registry';
5
+
6
+ export const toggleFormat = (editor, format, allowedChildren) => {
7
+ const { slate } = config.settings;
8
+ const isActive = isBlockActive(editor, format);
9
+ const type = isActive ? slate.defaultBlockType : format;
10
+ Transforms.setNodes(editor, {
11
+ type,
12
+ });
13
+ const selectedChildren = editor.selection.focus.path[0];
14
+ allowedChildren?.length &&
15
+ Transforms.unwrapNodes(editor, {
16
+ mode: 'all',
17
+ at: [selectedChildren],
18
+ match: (n, path) => {
19
+ const isMatch =
20
+ path.length > 1 && // we don't deal with the parent nodes
21
+ !(Text.isText(n) || allowedChildren.includes(n?.type));
22
+ return isMatch;
23
+ },
24
+ });
25
+ };
26
+
27
+ /**
28
+ * Toggles a style (e.g. in the StyleMenu plugin).
29
+ * @param {Editor} editor
30
+ * @param {object} options
31
+ * @param {boolean} options.oneOfType Whether the given type is admitted once
32
+ */
33
+ export const toggleStyle = (
34
+ editor,
35
+ { cssClass, isBlock, oneOf, format, allowedChildren },
36
+ ) => {
37
+ if (isBlock) {
38
+ toggleBlockStyle(editor, cssClass, oneOf, format, allowedChildren);
39
+ } else {
40
+ toggleInlineStyle(editor, cssClass, oneOf);
41
+ }
42
+ };
43
+
44
+ export const toggleBlockStyle = (
45
+ editor,
46
+ style,
47
+ oneOf,
48
+ format,
49
+ allowedChildren,
50
+ ) => {
51
+ // We have 6 boolean variables which need to be accounted for.
52
+ // See https://docs.google.com/spreadsheets/d/1mVeMuqSTMABV2BhoHPrPAFjn7zUksbNgZ9AQK_dcd3U/edit?usp=sharing
53
+ const { slate } = config.settings;
54
+
55
+ const isListItem = isBlockActive(editor, slate.listItemType);
56
+ const isBlockquote = isBlockActive(editor, 'blockquote');
57
+
58
+ const isActive = isBlockStyleActive(editor, style);
59
+ const wantsList = false;
60
+ const wantsBlockquote = format === 'blockquote';
61
+
62
+ if (isListItem && wantsBlockquote && !isBlockquote) {
63
+ //wrap list with blockquote
64
+ Transforms.wrapNodes(
65
+ editor,
66
+ { type: format },
67
+ {
68
+ mode: 'highest',
69
+ split: false,
70
+ },
71
+ );
72
+ internalToggleBlockStyle(editor, style, oneOf, format);
73
+ } else if (isListItem && wantsBlockquote && isBlockquote) {
74
+ //remove blockquote wrap to list
75
+ //Transforms.unwrapNodes(editor, { mode: 'all', at: [0] });
76
+ const unwrap = true;
77
+ internalToggleBlockStyle(editor, style, oneOf, format, unwrap);
78
+ } else if (isListItem && !wantsList) {
79
+ toggleBlockStyleAsListItem(editor, style, oneOf);
80
+ } else if (isListItem && wantsList && !isActive) {
81
+ // switchListType(editor, format); // this will deconstruct to Volto blocks
82
+ } else if (!isListItem && wantsList) {
83
+ // changeBlockToList(editor, format);
84
+ } else if (!isListItem && !wantsList) {
85
+ //se ho rimosso tutti gli stili devo rimuoverre anche il format
86
+ const selectedChildren = editor.selection.focus.path[0];
87
+ if (format && editor.children?.[selectedChildren]?.type !== format) {
88
+ toggleFormat(editor, format, allowedChildren);
89
+ }
90
+ internalToggleBlockStyle(editor, style, oneOf, format);
91
+ } else {
92
+ console.warn('toggleBlockStyle case not covered, please examine:', {
93
+ wantsList,
94
+ isActive,
95
+ isListItem,
96
+ });
97
+ }
98
+ };
99
+
100
+ export const toggleInlineStyle = (editor, style, oneOf) => {
101
+ // We have 6 boolean variables which need to be accounted for.
102
+ // See https://docs.google.com/spreadsheets/d/1mVeMuqSTMABV2BhoHPrPAFjn7zUksbNgZ9AQK_dcd3U/edit?usp=sharing
103
+ const { slate } = config.settings;
104
+
105
+ const isListItem = isBlockActive(editor, slate.listItemType);
106
+ const isLinkItem = isBlockActive(editor, 'link');
107
+
108
+ const isActive = isInlineStyleActive(editor, style);
109
+ const wantsList = false;
110
+
111
+ if (isLinkItem) {
112
+ toggleLinkStyleInSelection(editor, style, oneOf);
113
+ } else if (isListItem && !wantsList) {
114
+ toggleInlineStyleAsListItem(editor, style);
115
+ } else if (isListItem && wantsList && !isActive) {
116
+ // switchListType(editor, format); // this will deconstruct to Volto blocks
117
+ } else if (!isListItem && wantsList) {
118
+ // changeBlockToList(editor, format);
119
+ } else if (!isListItem && !wantsList) {
120
+ internalToggleInlineStyle(editor, style);
121
+ } else {
122
+ console.warn('toggleInlineStyle case not covered, please examine:', {
123
+ wantsList,
124
+ isActive,
125
+ isListItem,
126
+ });
127
+ }
128
+ };
129
+
130
+ export const isBlockStyleActive = (editor, style, oneOf) => {
131
+ const keyName = `style-${style}`;
132
+ const sn = Array.from(
133
+ Editor.nodes(editor, {
134
+ match: (n) => {
135
+ const isStyle = typeof n.styleName === 'string' || n[keyName];
136
+ return !Editor.isEditor(n) && isStyle;
137
+ },
138
+ mode: 'all',
139
+ }),
140
+ );
141
+
142
+ if (oneOf) {
143
+ oneOf.sort((a, b) => {
144
+ const al = a.split(' ').length + a.split('-').length;
145
+ const bl = b.split(' ').length + b.split('-').length;
146
+ return al > bl ? -1 : al < bl ? 1 : 0;
147
+ });
148
+ }
149
+
150
+ for (const [n] of sn) {
151
+ if (typeof n.styleName === 'string') {
152
+ if (oneOf?.length > 0) {
153
+ let selected = false;
154
+ let foundOneOf = false;
155
+
156
+ for (var i = 0; i < oneOf.length; i++) {
157
+ const o = oneOf[i];
158
+
159
+ const si = n.styleName.indexOf(o);
160
+ if (si >= 0) {
161
+ if (!foundOneOf) {
162
+ foundOneOf = true;
163
+ if (o === style) {
164
+ selected = true;
165
+ }
166
+ }
167
+ }
168
+ }
169
+ return selected;
170
+ } else if (n.styleName.split(' ').filter((x) => x === style).length > 0) {
171
+ return true;
172
+ }
173
+ } else if (
174
+ n[keyName] &&
175
+ keyName.split('style-').filter((x) => x === style).length > 0
176
+ )
177
+ return true;
178
+ }
179
+ return false;
180
+ };
181
+
182
+ export const isInlineStyleActive = (editor, style) => {
183
+ const m = Editor.marks(editor);
184
+ const keyName = `style-${style}`;
185
+
186
+ if (m && m[keyName]) {
187
+ return true;
188
+ }
189
+ return false;
190
+ };
191
+
192
+ export const isLinkStyleActive = (editor, style) => {
193
+ const selection = editor.selection || editor.getSavedSelection();
194
+ let found;
195
+ try {
196
+ found = Array.from(
197
+ Editor.nodes(editor, {
198
+ match: (n) => n.type === 'link',
199
+ at: selection,
200
+ }) || [],
201
+ );
202
+ } catch (e) {
203
+ // eslint-disable-next-line
204
+ // console.warn('Error in finding active element', e);
205
+ return false;
206
+ }
207
+
208
+ if (found.length) {
209
+ for (const [n, p] of found) {
210
+ if (n?.styleName?.indexOf(style) >= 0) {
211
+ return true;
212
+ }
213
+ }
214
+ }
215
+
216
+ if (selection) {
217
+ const { path } = selection.anchor;
218
+ const isAtStart =
219
+ selection.anchor.offset === 0 && selection.focus.offset === 0;
220
+
221
+ if (isAtStart) {
222
+ try {
223
+ found = Editor.previous(editor, {
224
+ at: path,
225
+ // match: (n) => n.type === MENTION,
226
+ });
227
+ } catch (ex) {
228
+ found = [];
229
+ }
230
+ if (found && found[0] && found[0].type === 'link') {
231
+ if (found[0]?.styleName?.indexOf(style) >= 0) {
232
+ return true;
233
+ }
234
+ }
235
+ }
236
+ }
237
+
238
+ return false;
239
+ };
240
+
241
+ export const internalToggleBlockStyle = (
242
+ editor,
243
+ style,
244
+ oneOf,
245
+ format,
246
+ unwrap,
247
+ ) => {
248
+ return toggleBlockStyleInSelection(editor, style, oneOf, format, unwrap);
249
+ };
250
+
251
+ export const internalToggleInlineStyle = (editor, style) => {
252
+ toggleInlineStyleInSelection(editor, style);
253
+ };
254
+
255
+ /*
256
+ * Applies a block format unto a list item. Will split the list and deconstruct the
257
+ * block
258
+ */
259
+ export const toggleBlockStyleAsListItem = (editor, style, oneOf) => {
260
+ toggleBlockStyleInSelection(editor, style, oneOf);
261
+ };
262
+
263
+ /*
264
+ * Applies an inline style unto a list item.
265
+ */
266
+ export const toggleInlineStyleAsListItem = (editor, style) => {
267
+ toggleInlineStyleInSelection(editor, style);
268
+ };
269
+
270
+ function toggleInlineStyleInSelection(editor, style) {
271
+ const m = Editor.marks(editor);
272
+ const keyName = 'style-' + style;
273
+
274
+ if (m && m[keyName]) {
275
+ Editor.removeMark(editor, keyName);
276
+ } else {
277
+ Editor.addMark(editor, keyName, true);
278
+ }
279
+ }
280
+
281
+ function toggleLinkStyleInSelection(editor, style, oneOf) {
282
+ const sn = Array.from(
283
+ Editor.nodes(editor, {
284
+ mode: 'all',
285
+ match: (n) => {
286
+ return !Editor.isEditor(n) && n.type === 'link';
287
+ },
288
+ }),
289
+ );
290
+
291
+ //ordino mettendo prima le combinazioni di classi
292
+ if (oneOf) {
293
+ oneOf.sort((a, b) => {
294
+ const al = a.split(' ').length + a.split('-').length;
295
+ const bl = b.split(' ').length + b.split('-').length;
296
+ return al > bl ? -1 : al < bl ? 1 : 0;
297
+ });
298
+ }
299
+
300
+ for (const [n, p] of sn) {
301
+ let cn = n.styleName;
302
+
303
+ if (typeof n.styleName !== 'string') {
304
+ cn = style;
305
+ } else if (oneOf && oneOf.indexOf(style) >= 0) {
306
+ let stylename = n.styleName;
307
+ let addStyle = true;
308
+ oneOf.forEach((o) => {
309
+ const si = stylename.indexOf(o);
310
+ if (si >= 0) {
311
+ addStyle = o !== style;
312
+ stylename = stylename.replace(o, '');
313
+ }
314
+ });
315
+
316
+ //rimuovo gli stili oneof
317
+ cn = stylename.split(' ').filter((x) => x !== '');
318
+
319
+ if (addStyle) {
320
+ cn = cn.concat(style);
321
+ }
322
+ cn = cn.join(' ');
323
+ } else if (n.styleName.indexOf(style) >= 0) {
324
+ //rimuovo lo stile style
325
+ cn = n.styleName
326
+ .replace(style, '')
327
+ .split(' ')
328
+ .filter((x) => x !== '')
329
+ .join(' ');
330
+ } else {
331
+ if (oneOf?.length > 0) {
332
+ //tolgo tutti gli altri stili di oneOf, perchè ne voglio solo uno di quelli
333
+ cn = cn
334
+ .split(' ')
335
+ .filter((c) => !oneOf.includes(c))
336
+ .join(' ');
337
+ }
338
+
339
+ // the style is not set but other styles are set. Aggiungo lo stile
340
+ cn = cn
341
+ .split(' ')
342
+ .filter((c) => c !== '')
343
+ .concat(style)
344
+ .join(' ');
345
+ }
346
+ Transforms.setNodes(editor, { styleName: cn }, { at: p });
347
+ }
348
+ }
349
+
350
+ function toggleBlockStyleInSelection(editor, style, oneOf, format, unwrap) {
351
+ const sn = Array.from(
352
+ Editor.nodes(editor, {
353
+ mode: 'highest',
354
+ match: (n) => {
355
+ return !Editor.isEditor(n);
356
+ },
357
+ }),
358
+ );
359
+
360
+ //ordino mettendo prima le combinazioni di classi
361
+ if (oneOf) {
362
+ oneOf.sort((a, b) => {
363
+ const al = a.split(' ').length + a.split('-').length;
364
+ const bl = b.split(' ').length + b.split('-').length;
365
+ return al > bl ? -1 : al < bl ? 1 : 0;
366
+ });
367
+ }
368
+
369
+ for (const [n, p] of sn) {
370
+ let cn = n.styleName;
371
+
372
+ if (typeof n.styleName !== 'string') {
373
+ cn = style;
374
+ } else if (oneOf && oneOf.indexOf(style) >= 0) {
375
+ let stylename = n.styleName;
376
+ let addStyle = true;
377
+ oneOf.forEach((o) => {
378
+ const si = stylename.indexOf(o);
379
+ if (si >= 0) {
380
+ addStyle = o !== style;
381
+ stylename = stylename.replace(o, '');
382
+ }
383
+ });
384
+
385
+ //rimuovo gli stili oneof
386
+ cn = stylename.split(' ').filter((x) => x !== '');
387
+
388
+ if (addStyle) {
389
+ cn = cn.concat(style);
390
+ } else if (format) {
391
+ if (unwrap) {
392
+ Transforms.unwrapNodes(editor, { mode: 'all', at: [0] });
393
+ } else {
394
+ toggleFormat(editor, format);
395
+ }
396
+ }
397
+ cn = cn.join(' ');
398
+ } else if (n.styleName.split(' ').filter((x) => x === style).length > 0) {
399
+ //rimuovo lo stile style
400
+ cn = cn
401
+ .split(' ')
402
+ .filter((x) => x !== style && x !== '')
403
+ .join(' ');
404
+ } else {
405
+ if (oneOf?.length > 0) {
406
+ //tolgo tutti gli altri stili di oneOf, perchè ne voglio solo uno di quelli
407
+ cn = cn
408
+ .split(' ')
409
+ .filter((c) => !oneOf.includes(c))
410
+ .join(' ');
411
+ }
412
+
413
+ // the style is not set but other styles are set. Aggiungo lo stile
414
+ cn = cn
415
+ .split(' ')
416
+ .filter((c) => c !== '')
417
+ .concat(style)
418
+ .join(' ');
419
+ }
420
+ Transforms.setNodes(editor, { styleName: cn }, { at: p });
421
+ }
422
+ }
@@ -0,0 +1,91 @@
1
+ import { Editor, Range, Transforms } from 'slate';
2
+ import config from '@plone/volto/registry';
3
+ import {
4
+ isCursorAtBlockEnd,
5
+ getCurrentListItem,
6
+ createEmptyParagraph,
7
+ } from '@plone/volto-slate/utils';
8
+
9
+ export const breakList = (editor) => {
10
+ const { insertBreak } = editor;
11
+
12
+ editor.insertBreak = () => {
13
+ // If the selection does not exist or is expanded, handle with the default
14
+ // behavior.
15
+ if (!(editor.selection && Range.isCollapsed(editor.selection))) {
16
+ insertBreak();
17
+ return false;
18
+ }
19
+
20
+ const { slate } = config.settings;
21
+ const { anchor } = editor.selection;
22
+
23
+ const ref = Editor.rangeRef(editor, editor.selection, {
24
+ affinity: 'inward',
25
+ });
26
+
27
+ // If the selection is inside a LI and it starts at a non-0 offset, split
28
+ // the LI. (if one of the parents is a list item, break that list item)
29
+ const [listItem, listItemPath] = getCurrentListItem(editor);
30
+ if (listItem) {
31
+ // if there is text in the selection
32
+ if (Editor.string(editor, listItemPath)) {
33
+ Transforms.splitNodes(editor, {
34
+ at: editor.selection,
35
+ match: (node) => node.type === slate.listItemType,
36
+ always: true, // in case cursor is at end of line
37
+ });
38
+
39
+ return true;
40
+ }
41
+ }
42
+
43
+ // If the selection anchor is not in a LI or it is not at offset 0, handle
44
+ // with the default behavior.
45
+ const [parent] = Editor.parent(editor, anchor.path); // , parentPath
46
+
47
+ if (parent.type !== slate.listItemType || anchor.offset > 0) {
48
+ insertBreak();
49
+ return; // applies default behaviour, as defined in insertBreak.js extension
50
+ }
51
+
52
+ // if (parent) {
53
+ // const blockProps = editor.getBlockProps();
54
+ // const { data } = blockProps;
55
+ // // Don't add new block if not allowed
56
+ // if (data?.disableNewBlocks) {
57
+ // return insertBreak();
58
+ // }
59
+ // }
60
+
61
+ Editor.deleteBackward(editor, { unit: 'line' });
62
+ // also account for empty nodes [{text: ''}]
63
+ if (Editor.isEmpty(editor, parent)) {
64
+ Transforms.removeNodes(editor, { at: ref.current });
65
+
66
+ Transforms.insertNodes(editor, createEmptyParagraph(), {
67
+ at: [editor.children.length],
68
+ });
69
+ Transforms.select(editor, Editor.end(editor, []));
70
+
71
+ return true;
72
+ }
73
+
74
+ Transforms.removeNodes(editor, { at: ref.current });
75
+
76
+ if (isCursorAtBlockEnd(editor)) {
77
+ Editor.insertNode(editor, createEmptyParagraph());
78
+ return true;
79
+ }
80
+
81
+ //const [top, bottom] = splitEditorInTwoFragments(editor, ref.current);
82
+ //Editor.insertNode(editor, createEmptyParagraph());
83
+ //setEditorContent(editor, top);
84
+
85
+ //createAndSelectNewBlockAfter(editor, bottom);
86
+
87
+ return true;
88
+ };
89
+
90
+ return editor;
91
+ };