From 5cf5286e3c50b5f58f44eeeb48bbd3d635a30d5a Mon Sep 17 00:00:00 2001 From: Luca Bellenghi Date: Wed, 4 Sep 2024 15:48:37 +0200 Subject: [PATCH] why qubica block --- .../locales/en/LC_MESSAGES/volto.po | 4 +- .../locales/it/LC_MESSAGES/volto.po | 4 +- packages/volto-blocks/locales/volto.pot | 6 +- .../blocks/ImageAndTextBox/Edit.tsx | 81 +++++++++++++----- .../blocks/ImageAndTextBox/EditItem.tsx | 48 +++++++++-- .../blocks/ImageAndTextBox/View.tsx | 67 ++++++++++++--- .../blocks/ImageAndTextBox/ViewItem.tsx | 21 ++++- .../blocks/ImageAndTextBox/placeholder.png | Bin 0 -> 2809 bytes .../blocks/ImageAndTextBox/schema.ts | 2 +- .../blocks/ImageAndTextBox/styles.module.css | 43 +++++++--- 10 files changed, 220 insertions(+), 56 deletions(-) create mode 100644 packages/volto-blocks/src/components/blocks/ImageAndTextBox/placeholder.png diff --git a/packages/volto-blocks/locales/en/LC_MESSAGES/volto.po b/packages/volto-blocks/locales/en/LC_MESSAGES/volto.po index 665bd29..11fccaa 100644 --- a/packages/volto-blocks/locales/en/LC_MESSAGES/volto.po +++ b/packages/volto-blocks/locales/en/LC_MESSAGES/volto.po @@ -39,6 +39,7 @@ msgstr "" #. Default: "Text" #: components/blocks/Accordion/EditItem #: components/blocks/ImageAndTextBox/Edit +#: components/blocks/ImageAndTextBox/EditItem #: components/blocks/ImageAndTextBox/schema #: components/blocks/Testimonials/Edit #: components/blocks/Testimonials/schema @@ -54,6 +55,7 @@ msgstr "" #: components/blocks/Accordion/EditItem #: components/blocks/Accordion/schema #: components/blocks/ImageAndTextBox/Edit +#: components/blocks/ImageAndTextBox/EditItem #: components/blocks/ImageAndTextBox/schema #: components/blocks/Testimonials/Edit #: components/blocks/Testimonials/schema @@ -148,7 +150,7 @@ msgstr "" msgid "redturtle__volto-blocks__text7_img_column_width_title" msgstr "" -#. Default: "Text 7" +#. Default: "Image and Text Boxes" #: components/blocks/ImageAndTextBox/schema #: components/blocks/Text7/schema msgid "redturtle__volto-blocks__text7_title" diff --git a/packages/volto-blocks/locales/it/LC_MESSAGES/volto.po b/packages/volto-blocks/locales/it/LC_MESSAGES/volto.po index e457596..84a7276 100644 --- a/packages/volto-blocks/locales/it/LC_MESSAGES/volto.po +++ b/packages/volto-blocks/locales/it/LC_MESSAGES/volto.po @@ -39,6 +39,7 @@ msgstr "" #. Default: "Text" #: components/blocks/Accordion/EditItem #: components/blocks/ImageAndTextBox/Edit +#: components/blocks/ImageAndTextBox/EditItem #: components/blocks/ImageAndTextBox/schema #: components/blocks/Testimonials/Edit #: components/blocks/Testimonials/schema @@ -54,6 +55,7 @@ msgstr "Testo" #: components/blocks/Accordion/EditItem #: components/blocks/Accordion/schema #: components/blocks/ImageAndTextBox/Edit +#: components/blocks/ImageAndTextBox/EditItem #: components/blocks/ImageAndTextBox/schema #: components/blocks/Testimonials/Edit #: components/blocks/Testimonials/schema @@ -148,7 +150,7 @@ msgstr "" msgid "redturtle__volto-blocks__text7_img_column_width_title" msgstr "" -#. Default: "Text 7" +#. Default: "Image and Text Boxes" #: components/blocks/ImageAndTextBox/schema #: components/blocks/Text7/schema msgid "redturtle__volto-blocks__text7_title" diff --git a/packages/volto-blocks/locales/volto.pot b/packages/volto-blocks/locales/volto.pot index 1d4dc1a..1d269da 100644 --- a/packages/volto-blocks/locales/volto.pot +++ b/packages/volto-blocks/locales/volto.pot @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: Plone\n" -"POT-Creation-Date: 2024-09-04T09:08:41.235Z\n" +"POT-Creation-Date: 2024-09-04T13:48:23.392Z\n" "Last-Translator: Plone i18n \n" "Language-Team: Plone i18n \n" "Content-Type: text/plain; charset=utf-8\n" @@ -41,6 +41,7 @@ msgstr "" #. Default: "Text" #: components/blocks/Accordion/EditItem #: components/blocks/ImageAndTextBox/Edit +#: components/blocks/ImageAndTextBox/EditItem #: components/blocks/ImageAndTextBox/schema #: components/blocks/Testimonials/Edit #: components/blocks/Testimonials/schema @@ -56,6 +57,7 @@ msgstr "" #: components/blocks/Accordion/EditItem #: components/blocks/Accordion/schema #: components/blocks/ImageAndTextBox/Edit +#: components/blocks/ImageAndTextBox/EditItem #: components/blocks/ImageAndTextBox/schema #: components/blocks/Testimonials/Edit #: components/blocks/Testimonials/schema @@ -150,7 +152,7 @@ msgstr "" msgid "redturtle__volto-blocks__text7_img_column_width_title" msgstr "" -#. Default: "Text 7" +#. Default: "Image and Text Boxes" #: components/blocks/ImageAndTextBox/schema #: components/blocks/Text7/schema msgid "redturtle__volto-blocks__text7_title" diff --git a/packages/volto-blocks/src/components/blocks/ImageAndTextBox/Edit.tsx b/packages/volto-blocks/src/components/blocks/ImageAndTextBox/Edit.tsx index 866107f..220060e 100644 --- a/packages/volto-blocks/src/components/blocks/ImageAndTextBox/Edit.tsx +++ b/packages/volto-blocks/src/components/blocks/ImageAndTextBox/Edit.tsx @@ -1,9 +1,9 @@ -import { Icon, SidebarPortal } from '@plone/volto/components'; +import type { BlockEditProps } from '@plone/types'; +import { Icon, SidebarPortal, UniversalLink } from '@plone/volto/components'; import { BlockDataForm } from '@plone/volto/components/manage/Form'; import cx from 'classnames'; import { defineMessages, useIntl } from 'react-intl'; - -import type { BlockEditProps } from '@plone/types'; +import placeholder from './placeholder.png'; import type { ImageAndTextBoxData } from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/schema'; import styles from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/styles.module.css'; @@ -13,7 +13,7 @@ import { } from '@redturtle/volto-rt-slate'; import config from '@plone/registry'; -// import EditItem from './EditItem'; +import EditItem from './EditItem'; type ImageAndTextBoxEditProps = Omit & { data: ImageAndTextBoxData; @@ -55,23 +55,24 @@ export default function Edit(props: ImageAndTextBoxEditProps) { className={cx('block-imageandtextbox', styles.imageandtextbox)} aria-label={data.title} > - - {data.image ? ( - - ) : ( -
Upload image
- )} + {data.image ? ( + + ) : ( + + )} +
- {/* {data.boxes ? : ''} */} +
+ {data.boxes?.length > 0 && + data.boxes.map((item) => ( + { + onChangeBlock(block, { + ...data, + boxes: data.boxes.map((i) => + i['@id'] === id ? { ...i, [field]: value } : i, + ), + }); + }} + // @ts-expect-error TODO fix type in @plone/types + selected={selected} + /> + ))} +
+ {data.linkHref?.[0] && ( +
+ ) => { + e.preventDefault(); + }} + > + {data.linkTitle} + +
+ )}
diff --git a/packages/volto-blocks/src/components/blocks/ImageAndTextBox/EditItem.tsx b/packages/volto-blocks/src/components/blocks/ImageAndTextBox/EditItem.tsx index 261e75a..c5526e9 100644 --- a/packages/volto-blocks/src/components/blocks/ImageAndTextBox/EditItem.tsx +++ b/packages/volto-blocks/src/components/blocks/ImageAndTextBox/EditItem.tsx @@ -5,6 +5,7 @@ import type { ArrayElement } from '@plone/types'; import type { ImageAndTextBoxData } from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/schema'; import styles from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/styles.module.css'; +import { TextEditorWidget } from '@redturtle/volto-rt-slate'; type Props = { data: ArrayElement; @@ -23,11 +24,46 @@ export default function EditItem({ }: Props) { const intl = useIntl(); - if (__SERVER__) { - return
; - } - - return
BOX
; + return ( +
+ setFocusOn('title' + data['@id'])} + onChangeBlock={(id: string, value: { title: string }) => { + onChange(id, 'title', value.title); + }} + showToolbar={false} + placeholder={intl.formatMessage(messages.title)} + /> + setFocusOn('text' + data['@id'])} + onChangeBlock={(id: string, value: { text: string }) => { + onChange(id, 'text', value.text); + }} + placeholder={intl.formatMessage(messages.text)} + /> +
+ ); } -const messages = defineMessages({}); +const messages = defineMessages({ + title: { + id: 'Title', + defaultMessage: 'Title', + }, + text: { + id: 'Text', + defaultMessage: 'Text', + }, +}); diff --git a/packages/volto-blocks/src/components/blocks/ImageAndTextBox/View.tsx b/packages/volto-blocks/src/components/blocks/ImageAndTextBox/View.tsx index 4cbdf73..38397ab 100644 --- a/packages/volto-blocks/src/components/blocks/ImageAndTextBox/View.tsx +++ b/packages/volto-blocks/src/components/blocks/ImageAndTextBox/View.tsx @@ -1,9 +1,13 @@ import type { BlockViewProps } from '@plone/types'; +import { UniversalLink } from '@plone/volto/components'; +import { flattenToAppURL } from '@plone/volto/helpers'; import cx from 'classnames'; +import { TextBlockView } from '@plone/volto-slate/blocks/Text'; import type { ImageAndTextBoxData } from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/schema'; import styles from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/styles.module.css'; import ViewItem from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/ViewItem'; +import placeholder from './placeholder.png'; import config from '@plone/registry'; @@ -13,27 +17,68 @@ type Props = Omit & { export default function View({ data, className, style }: Props) { const Container = config.getComponent('Container').component || 'div'; + const Image = config.getComponent('Image').component; return (
- - {data.title && ( -

- {data.title} -

- )} -
+ {data.image ? ( + + ) : ( + + )} + +
+ {data.title && ( +

+ {data.title} +

+ )} + {data.text && ( +
+ +
+ )} +
+
{data.boxes?.length > 0 && data.boxes.map((item) => ( ))}
+ {data.linkHref?.[0] && ( +
+ + {data.linkTitle} + +
+ )}
); diff --git a/packages/volto-blocks/src/components/blocks/ImageAndTextBox/ViewItem.tsx b/packages/volto-blocks/src/components/blocks/ImageAndTextBox/ViewItem.tsx index d98d758..70cc768 100644 --- a/packages/volto-blocks/src/components/blocks/ImageAndTextBox/ViewItem.tsx +++ b/packages/volto-blocks/src/components/blocks/ImageAndTextBox/ViewItem.tsx @@ -1,7 +1,7 @@ import cx from 'classnames'; import type { ArrayElement } from '@plone/types'; - +import { TextBlockView } from '@plone/volto-slate/blocks/Text'; import type { ImageAndTextBoxData } from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/schema'; import styles from '@redturtle/volto-blocks/components/blocks/ImageAndTextBox/styles.module.css'; @@ -10,5 +10,22 @@ type Props = { }; export default function ViewItem({ data }: Props) { - return
BOX
; + return ( +
+ {data.title && ( +
+ {data.title && ( +

+ {data.title} +

+ )} +
+ )} + {data.text && ( +
+ +
+ )} +
+ ); } diff --git a/packages/volto-blocks/src/components/blocks/ImageAndTextBox/placeholder.png b/packages/volto-blocks/src/components/blocks/ImageAndTextBox/placeholder.png new file mode 100644 index 0000000000000000000000000000000000000000..d57c4b60dfb693054fd377afc7e94fe83c1e43e0 GIT binary patch literal 2809 zcmeHJX;hPE7Jez#D1}560fop`2!gVegw~WI2vlqg5t39}ktIq61pEXEh$bl=P=+9t zhzvS}MXE$vtA(R-?FV38va_Z8eIHZmBD?(XjU_wV!hd>W0Gm6e6Z<4a0P3JMBHBvL{` zLP$u6larIkR@wr9-a7%l-sI$=$9F%6djYIsHP3|ihW5BT37a3?{vz{%rpk~^S+=Bm zzPsiH&I~hl#j;T-lyDSsg%*ePEY!^V|G*jeLRUwNW2x!)CoLam{h#!_ioEqnkK;UI zP4$~9X9uHJ8W7k{X-2zBdgPk5CbiVUq~@+njAxEDzFN}zF;#mTua;4-d_^uO4K`^<%(OS)w$2*43JDiMvG!4mT$C9N>-n{}^Jx}};bUzQBHmIwkE>4$b%5q!K#nk?0b#k0)FliGWLX`KfhZIS!?o55?BJm8qDSlpl=)G9W zRmDFLl$K+A*Jg6q?qS1WM>HD5{V!RSE8e;@MN)1lmsHjN6T3Eh&&N_e-?6Ara-dCW zzlIJfr#=y3g>uKA7mplcmYYKeP{D8UETR_XyA#TOLQGzL*7j}!0tlR1L++KV}uB+|J4G$^C=sbg&0iT zzmid+2QucQjGgnBntg^J)zg&Gx453pGVj5yx*#Kjom!n|{Z+hM0}`E0 zzzR2!@HJtc-nHGK)$I;9R<7-C5$bozBdbuG+f_#8+(5UonI@xmCuTx6YqP|iUM)PjS#a~}SW?%Ch8lY_8ejC`Xpw11KM z*IOIrsyp02Jr_@tAc6mJDYvU^=W~L?_;tbGE&Hp=_O8K861y5) zlk;v7EFf8$0~mO^Sw6MWG4mml`r#mV>iR~1$DgT~u5l!Ytb)9p@}7k7zCN_!Y2u|0 z>DW8)MS-F#xEOyUs&9S&j-f6r^Lv35;?d$|&|0I};b zcKT-$K_RMQQfYTQ(RB4o%`$p;rWFE;b-kX#s)TAsJ}(z z!sH!~70uoymNs5Ho7&KF3NF*IROUK7$9Ml0YbD!k{!qTX9QRWlrLS5#7fM%ZIZGR@s*y6N(slV|*&MBB}`>oP4BCZUryAv7icuqn7G_dzX z#iTKvb-mee3f^2Oq2B_vDCif{b}Yy$jZxm zEvG>fdm$!e{>8iT>Oa*IFUunJC;?sxXC^&2lxINe?a6S3@j9(*0%a)Q0K-hm4 zA@HRp#-{w*vPJK=ci1_K`nBZ$ayS~jB#L#@=CnI(S=F>cjStr8WTY%{zf56;7W~(e z#nTV0;IZ}JaC!2)&;o3U