Skip to content

Commit

Permalink
Merge pull request #8 from kitconcept/helperAdditions
Browse files Browse the repository at this point in the history
Helper additions
  • Loading branch information
jnptk authored Feb 26, 2025
2 parents 03be731 + 17458bf commit cdb57a6
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 49 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ backend-docker-start: ## Starts a Docker-based backend for development
@echo "$(GREEN)==> Start Docker-based Plone Backend$(RESET)"
docker run -it --rm --name=backend -p 8080:8080 -e SITE=Plone $(DOCKER_IMAGE)

.PHONY: backend-docker-detached-start
backend-docker-detached-start: ## Starts a Docker-based backend for development
@echo "$(GREEN)==> Start Docker-based Plone Backend$(RESET)"
docker run -d -it --rm --name=backend -p 8080:8080 -e SITE=Plone $(DOCKER_IMAGE)

## Storybook
.PHONY: storybook-start
storybook-start: ## Start Storybook server on port 6006
Expand Down
9 changes: 5 additions & 4 deletions packages/volto-iframe-block/locales/de/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ msgstr "Beschreibung"

#. Default: "Error"
#: components/Edit
#: helpers/isValidUrl
msgid "Error"
msgstr "Fehler"

Expand All @@ -38,7 +39,7 @@ msgid "Iframe"
msgstr "Iframe"

#. Default: "Invalid url"
#: components/Edit
#: helpers/isValidUrl
msgid "Invalid url"
msgstr "Ungültige Url"

Expand Down Expand Up @@ -72,10 +73,10 @@ msgstr "Titel"
msgid "Type a Iframe URL"
msgstr "Geben Sie eine URL ein"

#. Default: "Values are in Pixels"
#. Default: "Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)"
#: components/schema
msgid "Values are in Pixels"
msgstr "Werte werden in Pixeln angegeben"
msgid "Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)"
msgstr "Die Werte werden in Pixeln (z.B. 100 oder 100px) oder Prozent (z.B. 100%) angegeben."

#. Default: "Width"
#: components/schema
Expand Down
7 changes: 4 additions & 3 deletions packages/volto-iframe-block/locales/en/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ msgstr ""

#. Default: "Error"
#: components/Edit
#: helpers/isValidUrl
msgid "Error"
msgstr ""

Expand All @@ -38,7 +39,7 @@ msgid "Iframe"
msgstr ""

#. Default: "Invalid url"
#: components/Edit
#: helpers/isValidUrl
msgid "Invalid url"
msgstr ""

Expand Down Expand Up @@ -72,9 +73,9 @@ msgstr ""
msgid "Type a Iframe URL"
msgstr ""

#. Default: "Values are in Pixels"
#. Default: "Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)"
#: components/schema
msgid "Values are in Pixels"
msgid "Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)"
msgstr ""

#. Default: "Width"
Expand Down
7 changes: 4 additions & 3 deletions packages/volto-iframe-block/locales/es/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ msgstr ""

#. Default: "Error"
#: components/Edit
#: helpers/isValidUrl
msgid "Error"
msgstr ""

Expand All @@ -45,7 +46,7 @@ msgid "Iframe"
msgstr ""

#. Default: "Invalid url"
#: components/Edit
#: helpers/isValidUrl
msgid "Invalid url"
msgstr ""

Expand Down Expand Up @@ -79,9 +80,9 @@ msgstr ""
msgid "Type a Iframe URL"
msgstr ""

#. Default: "Values are in Pixels"
#. Default: "Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)"
#: components/schema
msgid "Values are in Pixels"
msgid "Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)"
msgstr ""

#. Default: "Width"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ msgstr ""

#. Default: "Error"
#: components/Edit
#: helpers/isValidUrl
msgid "Error"
msgstr ""

Expand All @@ -43,7 +44,7 @@ msgid "Iframe"
msgstr ""

#. Default: "Invalid url"
#: components/Edit
#: helpers/isValidUrl
msgid "Invalid url"
msgstr ""

Expand Down Expand Up @@ -77,9 +78,9 @@ msgstr ""
msgid "Type a Iframe URL"
msgstr ""

#. Default: "Values are in Pixels"
#. Default: "Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)"
#: components/schema
msgid "Values are in Pixels"
msgid "Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)"
msgstr ""

#. Default: "Width"
Expand Down
9 changes: 5 additions & 4 deletions packages/volto-iframe-block/locales/volto.pot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
"POT-Creation-Date: 2025-02-18T09:54:00.232Z\n"
"POT-Creation-Date: 2025-02-25T10:06:06.493Z\n"
"Last-Translator: Plone i18n <[email protected]>\n"
"Language-Team: Plone i18n <[email protected]>\n"
"Content-Type: text/plain; charset=utf-8\n"
Expand All @@ -25,6 +25,7 @@ msgstr ""

#. Default: "Error"
#: components/Edit
#: helpers/isValidUrl
msgid "Error"
msgstr ""

Expand All @@ -40,7 +41,7 @@ msgid "Iframe"
msgstr ""

#. Default: "Invalid url"
#: components/Edit
#: helpers/isValidUrl
msgid "Invalid url"
msgstr ""

Expand Down Expand Up @@ -74,9 +75,9 @@ msgstr ""
msgid "Type a Iframe URL"
msgstr ""

#. Default: "Values are in Pixels"
#. Default: "Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)"
#: components/schema
msgid "Values are in Pixels"
msgid "Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)"
msgstr ""

#. Default: "Width"
Expand Down
1 change: 1 addition & 0 deletions packages/volto-iframe-block/news/8.bugfix.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
We now only show the whole `figure` if a url is set & valid [@jnptk]
1 change: 1 addition & 0 deletions packages/volto-iframe-block/news/8.bugfix.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Moved the `width` to the `figure` element to ensure that title, description etc. are the same width as the `iframe` [@jnptk]
1 change: 1 addition & 0 deletions packages/volto-iframe-block/news/8.feature.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move toast error messages to isValidUrl.js file so that if you want to shadow the `isValidUrl` function you can change the error message as well [@jnptk]
1 change: 1 addition & 0 deletions packages/volto-iframe-block/news/8.feature.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed the `height` field to use a `text` input field for pixel and percentage value support (e.g. 100px, 50%) [@jnptk]
1 change: 1 addition & 0 deletions packages/volto-iframe-block/news/8.internal.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `backend-docker-detached-start` make command to start backend in daemon mode [@jnptk]
13 changes: 6 additions & 7 deletions packages/volto-iframe-block/src/components/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import React, { useState } from 'react';
import { defineMessages } from 'react-intl';
import { toast } from 'react-toastify';

import { isValidUrl } from '@kitconcept/volto-iframe-block/helpers/isValidUrl';
import {
isValidUrl,
toastError,
} from '@kitconcept/volto-iframe-block/helpers/isValidUrl';
import IframeSidebar from '@kitconcept/volto-iframe-block/components/Data';
import IframeView from '@kitconcept/volto-iframe-block/components/View';

Expand All @@ -17,10 +20,6 @@ const messages = defineMessages({
id: 'Type a Iframe URL',
defaultMessage: 'Type a Iframe URL',
},
IncorrectUrl: {
id: 'Invalid url',
defaultMessage: 'Invalid url',
},
Error: {
id: 'Error',
defaultMessage: 'Error',
Expand Down Expand Up @@ -51,8 +50,8 @@ const IframeEdit = (props) => {
toast.error(
<Toast
error
title={intl.formatMessage(messages.Error)}
content={intl.formatMessage(messages.IncorrectUrl)}
title={intl.formatMessage(toastError.Title)}
content={intl.formatMessage(toastError.Content)}
/>,
);
};
Expand Down
39 changes: 17 additions & 22 deletions packages/volto-iframe-block/src/components/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,23 @@ const IframeView = (props) => {
return (
<div className={cx('block iframe align', data.align, className)}>
<div className="block-container">
<figure>
{data.src && isValidUrl(data.src) && (
<iframe
src={data.src}
title={data.title}
width={width}
height={data.height}
/>
)}
<figcaption>
{data.title && <div className="title">{data.title}</div>}
{data.description && (
<div className="description">{data.description}</div>
)}
{data.credit && (
<div className="credit">
Credit:{' '}
<div dangerouslySetInnerHTML={{ __html: data.credit.data }} />
</div>
)}
</figcaption>
</figure>
{data.src && isValidUrl(data.src) && (
<figure style={{ width: width }}>
<iframe src={data.src} title={data.title} height={data.height} />
<figcaption>
{data.title && <div className="title">{data.title}</div>}
{data.description && (
<div className="description">{data.description}</div>
)}
{data.credit && (
<div className="credit">
Credit:{' '}
<div dangerouslySetInnerHTML={{ __html: data.credit.data }} />
</div>
)}
</figcaption>
</figure>
)}
</div>
</div>
);
Expand Down
7 changes: 4 additions & 3 deletions packages/volto-iframe-block/src/components/schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ const messages = defineMessages({
defaultMessage: 'Open in a new tab',
},
TextHintPixels: {
id: 'Values are in Pixels',
defaultMessage: 'Values are in Pixels',
id: 'Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)',
defaultMessage:
'Values are in Pixels (e.g. 100 or 100px) or Percent (e.g. 100%)',
},
});

Expand Down Expand Up @@ -97,7 +98,7 @@ export const IframeBlockSchema = (props) => ({
},
height: {
title: props.intl.formatMessage(messages.Height),
type: 'number',
widget: 'text',
description: props.intl.formatMessage(messages.TextHintPixels),
},
},
Expand Down
16 changes: 16 additions & 0 deletions packages/volto-iframe-block/src/helpers/isValidUrl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import config from '@plone/volto/registry';
import { isEmpty } from 'lodash';
import { defineMessages } from 'react-intl';

/**
* Error messages for displaying toast notifications when an invalid URL
* is submitted.
*/
export const toastError = defineMessages({
Title: {
id: 'Error',
defaultMessage: 'Error',
},
Content: {
id: 'Invalid url',
defaultMessage: 'Invalid url',
},
});

export function isValidUrl(url) {
const patterns = config.blocks.blocksConfig.iframe.validUrls;
Expand Down
4 changes: 4 additions & 0 deletions packages/volto-iframe-block/src/theme/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@
}
}
}

.block.iframe iframe {
width: 100%;
}

0 comments on commit cdb57a6

Please sign in to comment.