Type checking on some gutenberg blocks and removal of 'content' attribute.

This commit is contained in:
mateuswetah 2024-01-02 17:27:00 -03:00
parent abdbf2fb4e
commit 76833bc9d9
25 changed files with 445 additions and 194 deletions

View File

@ -8,17 +8,7 @@
"description": "A single item geocoordinate metadatum, containing location information.",
"textdomain": "tainacan",
"parent": [],
"example": {
"attributes": {
"content": "preview"
}
},
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"dataSource": {
"type": "string",
"default": "selection"

View File

@ -1 +1,32 @@
export default [];
export default [
{
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"dataSource": {
"type": "string",
"default": "selection"
},
"templateMode": {
"type": "boolean",
"default": false
},
"collectionId": {
"type": "integer"
},
"itemId": {
"type": "integer"
},
"metadatumId": {
"type": "integer"
},
"isModalOpen": {
"type": "boolean",
"default": false
}
}
}
];

View File

@ -11,7 +11,6 @@ import getCollectionIdFromPossibleTemplateEdition from '../../js/template/tainac
export default function ({ attributes, setAttributes, isSelected }) {
let {
content,
collectionId,
itemId,
metadatumId,
@ -43,14 +42,7 @@ export default function ({ attributes, setAttributes, isSelected }) {
}
}
return content == 'preview' ?
<div className={className}>
<img
width="100%"
src={ `${tainacan_blocks.base_url}/assets/images/related-carousel-items.png` } />
</div>
: (
<div { ...blockProps }>
return <div { ...blockProps }>
{ dataSource == 'selection' ? (
<BlockControls group="other">
{
@ -161,6 +153,5 @@ export default function ({ attributes, setAttributes, isSelected }) {
) : null
}
</div>
);
</div>;
};

View File

@ -7,21 +7,11 @@
"keywords": [ "item", "document", "carousel", "attachments", "zoom" ],
"description": "The media gallery of the item, displaying document, attachments and more.",
"textdomain": "tainacan",
"example": {
"attributes": {
"content": "preview"
}
},
"attributes": {
"blockId": {
"type": "string",
"default": ""
},
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"collectionId": {
"type": "string",
"default": ""

View File

@ -1 +1,114 @@
export default [];
export default [
{
"attributes": {
"blockId": {
"type": "string",
"default": ""
},
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"collectionId": {
"type": "string",
"default": ""
},
"itemId": {
"type": "string",
"default": ""
},
"isModalOpen": {
"type": "boolean",
"default": false
},
"layoutElements": {
"type": "object",
"default": {
"main": true,
"thumbnails": true
}
},
"mediaSources": {
"type": "object",
"default": {
"document": true,
"attachments": true,
"metadata": false
}
},
"hideFileNameMain": {
"type": "boolean",
"default": true
},
"hideFileCaptionMain": {
"type": "boolean",
"default": false
},
"hideFileDescriptionMain": {
"type": "boolean",
"default": true
},
"hideFileNameThumbnails": {
"type": "boolean",
"default": true
},
"hideFileCaptionThumbnails": {
"type": "boolean",
"default": true
},
"hideFileDescriptionThumbnails": {
"type": "boolean",
"default": true
},
"hideFileNameLightbox": {
"type": "boolean",
"default": false
},
"hideFileCaptionLightbox": {
"type": "boolean",
"default": false
},
"hideFileDescriptionLightbox": {
"type": "boolean",
"default": false
},
"openLightboxOnClick": {
"type": "boolean",
"default": true
},
"arrowsSize": {
"type": "integer",
"default": 44
},
"mainSliderHeight": {
"type": "integer",
"default": 60
},
"mainSliderWidth": {
"type": "integer",
"default": 100
},
"thumbnailsCarouselWidth": {
"type": "integer",
"default": 100
},
"thumbnailsCarouselItemSize": {
"type": "integer",
"default": 136
},
"showDownloadButtonMain": {
"type": "boolean",
"default": false
},
"lightboxHasLightBackground": {
"type": "boolean",
"default": false
},
"templateMode": {
"type": "boolean",
"default": false
}
}
}
];

View File

@ -11,7 +11,6 @@ import getCollectionIdFromPossibleTemplateEdition from '../../js/template/tainac
export default function ({ attributes, setAttributes, isSelected, clientId }) {
let {
content,
collectionId,
itemId,
isModalOpen,
@ -57,14 +56,7 @@ export default function ({ attributes, setAttributes, isSelected, clientId }) {
}
}
return content == 'preview' ?
<div className={className}>
<img
width="100%"
src={ `${tainacan_blocks.base_url}/assets/images/related-carousel-items.png` } />
</div>
: (
<div { ...blockProps }>
return <div { ...blockProps }>
<InspectorControls>
@ -401,6 +393,5 @@ export default function ({ attributes, setAttributes, isSelected, clientId }) {
) : null
}
</div>
);
</div>;
};

View File

@ -7,17 +7,7 @@
"keywords": [ "item", "metadata", "section", "regions", "fields" ],
"description": "A single metadata section, including its label and metadata whitin it.",
"textdomain": "tainacan",
"example": {
"attributes": {
"content": "preview"
}
},
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"dataSource": {
"type": "string",
"default": "selection"

View File

@ -1 +1,62 @@
export default [];
export default [
{
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"dataSource": {
"type": "string",
"default": "selection"
},
"templateMode": {
"type": "boolean",
"default": false
},
"isDynamic": {
"type": "boolean",
"default": false
},
"collectionId": {
"type": "integer"
},
"itemId": {
"type": "integer"
},
"isModalOpen": {
"type": "boolean",
"default": false
},
"isLoading": {
"type": "boolean",
"default": false
},
"metadataSectionRequestSource": {
"type": "object",
"default": ""
},
"metadataSectionTemplate": {
"type": "array",
"default": []
},
"sectionId": {
"type": "string",
"default": ""
},
"sectionName": {
"type": "string"
},
"sectionDescription": {
"type": "string"
},
"sectionMetadata": {
"type": "array",
"default": []
},
"textAlign": {
"type": "string"
}
}
}
];

View File

@ -1,5 +1,7 @@
const { __ } = wp.i18n;
const { useEffect } = wp.element;
const { Button, Spinner, Placeholder, ToggleControl, PanelBody } = wp.components;
const ServerSideRender = wp.serverSideRender;
@ -13,7 +15,6 @@ import axios from 'axios';
export default function ({ attributes, setAttributes, isSelected }) {
let {
content,
collectionId,
itemId,
isLoading,
@ -38,6 +39,10 @@ export default function ({ attributes, setAttributes, isSelected }) {
} );
const className = blockProps.className;
useEffect(() => {
setContent();
}, []);
function setContent() {
if ( sectionId && collectionId ) {
@ -153,20 +158,7 @@ export default function ({ attributes, setAttributes, isSelected }) {
}
}
// Executed only on the first load of page
if (content === undefined || (content && content.length && content[0].type)) {
setAttributes({ content: '' });
setContent();
}
return content == 'preview' ?
<div className={className}>
<img
width="100%"
src={ `${tainacan_blocks.base_url}/assets/images/related-carousel-items.png` } />
</div>
: (
<div { ...blockProps }>
return <div { ...blockProps }>
{ sectionId ?
<InspectorControls>
@ -214,7 +206,7 @@ export default function ({ attributes, setAttributes, isSelected }) {
});
}}
onSelectItem={ (selectedItemId) => {
itemId = selectedItemId;
itemId = Number(selectedItemId);
setAttributes({
itemId: itemId
});
@ -293,6 +285,5 @@ export default function ({ attributes, setAttributes, isSelected }) {
</div>
}
</div>
);
</div>;
};

View File

@ -7,17 +7,7 @@
"keywords": [ "item", "metadata", "sections", "regions", "fields" ],
"description": "The metadata sections, including their labels and metadata whitin it.",
"textdomain": "tainacan",
"example": {
"attributes": {
"content": "preview"
}
},
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"templateMode": {
"type": "boolean",
"default": false

View File

@ -1 +1,48 @@
export default [];
export default [
{
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"templateMode": {
"type": "boolean",
"default": false
},
"isDynamic": {
"type": "boolean",
"default": false
},
"collectionId": {
"type": "integer"
},
"itemId": {
"type": "integer"
},
"isModalOpen": {
"type": "boolean",
"default": false
},
"isLoading": {
"type": "boolean",
"default": false
},
"metadataSectionsRequestSource": {
"type": "object",
"default": ""
},
"metadataSections": {
"type": "array",
"default": []
},
"metadataSectionsTemplate": {
"type": "array",
"default": []
},
"textAlign": {
"type": "string"
}
}
}
];

View File

@ -1,5 +1,7 @@
const { __ } = wp.i18n;
const { useEffect } = wp.element;
const { Button, Spinner, Placeholder, ToggleControl, PanelBody } = wp.components;
const ServerSideRender = wp.serverSideRender;
@ -13,7 +15,6 @@ import axios from 'axios';
export default function ({ attributes, setAttributes, isSelected }) {
let {
content,
collectionId,
itemId,
isLoading,
@ -34,6 +35,10 @@ export default function ({ attributes, setAttributes, isSelected }) {
} );
const className = blockProps.className;
useEffect(() => {
setContent();
}, []);
function setContent() {
if (collectionId) {
@ -117,14 +122,7 @@ export default function ({ attributes, setAttributes, isSelected }) {
}
}
return content == 'preview' ?
<div className={className}>
<img
width="100%"
src={ `${tainacan_blocks.base_url}/assets/images/related-carousel-items.png` } />
</div>
: (
<div { ...blockProps }>
return <div { ...blockProps }>
<InspectorControls>
<PanelBody
@ -241,6 +239,5 @@ export default function ({ attributes, setAttributes, isSelected }) {
</div>
}
</div>
);
</div>;
};

View File

@ -7,17 +7,7 @@
"keywords": [ "item", "metadata", "fields", "values" ],
"description": "The item metadata, including their labels and values.",
"textdomain": "tainacan",
"example": {
"attributes": {
"content": "preview"
}
},
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"dataSource": {
"type": "string",
"default": "selection"

View File

@ -1 +1,60 @@
export default [];
export default [
{
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"dataSource": {
"type": "string",
"default": "selection"
},
"templateMode": {
"type": "boolean",
"default": false
},
"isDynamic": {
"type": "boolean",
"default": false
},
"collectionId": {
"type": "integer"
},
"itemId": {
"type": "integer"
},
"isModalOpen": {
"type": "boolean",
"default": false
},
"isLoading": {
"type": "boolean",
"default": false
},
"itemMetadataRequestSource": {
"type": "object",
"default": ""
},
"itemMetadata": {
"type": "array",
"default": []
},
"metadata": {
"type": "array",
"default": []
},
"itemMetadataTemplate": {
"type": "array",
"default": []
},
"sectionId": {
"type": "string",
"default": ""
},
"textAlign": {
"type": "string"
}
}
}
];

View File

@ -1,5 +1,7 @@
const { __ } = wp.i18n;
const { useEffect } = wp.element;
const { Button, Spinner, ToggleControl, Placeholder, PanelBody } = wp.components;
const ServerSideRender = wp.serverSideRender;
@ -13,7 +15,6 @@ import axios from 'axios';
export default function ({ attributes, setAttributes, isSelected }) {
let {
content,
collectionId,
itemId,
sectionId,
@ -37,6 +38,10 @@ export default function ({ attributes, setAttributes, isSelected }) {
} );
const className = blockProps.className;
useEffect(() => {
setContent();
}, []);
function setContent() {
if ( dataSource === 'parent' && templateMode) {
@ -192,20 +197,7 @@ export default function ({ attributes, setAttributes, isSelected }) {
}
}
// Executed only on the first load of page
if (content === undefined || (content && content.length && content[0].type)) {
setAttributes({ content: '' });
setContent();
}
return content == 'preview' ?
<div className={className}>
<img
width="100%"
src={ `${tainacan_blocks.base_url}/assets/images/related-carousel-items.png` } />
</div>
: (
<div { ...blockProps }>
return <div { ...blockProps }>
<InspectorControls>
<PanelBody
@ -323,6 +315,5 @@ export default function ({ attributes, setAttributes, isSelected }) {
</div>
}
</div>
);
</div>;
};

View File

@ -7,17 +7,7 @@
"keywords": [ "item", "metadatum", "field", "value" ],
"description": "A single item metadatum, including a label and its value.",
"textdomain": "tainacan",
"example": {
"attributes": {
"content": "preview"
}
},
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"dataSource": {
"type": "string",
"default": "selection"

View File

@ -1 +1,43 @@
export default [];
export default [
{
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"dataSource": {
"type": "string",
"default": "selection"
},
"templateMode": {
"type": "boolean",
"default": false
},
"collectionId": {
"type": "integer"
},
"itemId": {
"type": "integer"
},
"metadatumId": {
"type": "integer"
},
"metadatumType": {
"type": "string",
"default": ""
},
"isModalOpen": {
"type": "boolean",
"default": false
},
"labelLevel": {
"type": "number",
"default": 3
},
"textAlign": {
"type": "string"
}
}
}
];

View File

@ -20,7 +20,6 @@ const levelToPath = {
export default function ({ attributes, setAttributes, isSelected }) {
let {
content,
collectionId,
itemId,
metadatumId,
@ -53,14 +52,7 @@ export default function ({ attributes, setAttributes, isSelected }) {
}
}
return content == 'preview' ?
<div className={className}>
<img
width="100%"
src={ `${tainacan_blocks.base_url}/assets/images/related-carousel-items.png` } />
</div>
: (
<div { ...blockProps }>
return <div { ...blockProps }>
<BlockControls group="block">
<ToolbarDropdownMenu
@ -149,19 +141,19 @@ export default function ({ attributes, setAttributes, isSelected }) {
existingMetadatumId={ metadatumId }
isTemplateMode={ templateMode }
onSelectCollection={ (selectedCollectionId) => {
collectionId = selectedCollectionId;
collectionId = Number(selectedCollectionId);
setAttributes({
collectionId: collectionId
});
}}
onSelectItem={ (selectedItemId) => {
itemId = selectedItemId;
itemId = Number(selectedItemId);
setAttributes({
itemId: itemId
});
}}
onApplySelectedMetadatum={ (selectedMetadatum) => {
metadatumId = selectedMetadatum.metadatumId;
metadatumId = Number(selectedMetadatum.metadatumId);
metadatumType = selectedMetadatum.metadatumType;
setAttributes({
@ -224,6 +216,5 @@ export default function ({ attributes, setAttributes, isSelected }) {
) : null
}
</div>
);
</div>;
};

View File

@ -1,3 +1,3 @@
export default function() {
return null
};
}

View File

@ -8,17 +8,7 @@
"description": "A metadata section description, used to complement information about a metadata section.",
"textdomain": "tainacan",
"parent": [ "tainacan/item-metadata-section" ],
"example": {
"attributes": {
"content": "preview"
}
},
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"sectionId": {
"type": "string",
"default": ""

View File

@ -1 +1,22 @@
export default [];
export default [
{
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"sectionId": {
"type": "string",
"default": ""
},
"sectionDescription": {
"type": "string",
"default": ""
},
"textAlign": {
"type": "string"
}
}
}
];

View File

@ -5,7 +5,6 @@ const { useBlockProps, BlockControls, AlignmentControl } = wp.blockEditor;
export default function ({ attributes, setAttributes, context }) {
let {
content,
sectionId,
sectionDescription,
textAlign
@ -28,14 +27,7 @@ export default function ({ attributes, setAttributes, context }) {
if ( context['tainacan/metadataSectionId'] || context['tainacan/metadataSectionDescription'] )
setAttributes({ sectionId, sectionDescription });
return content == 'preview' ?
<div className={className}>
<img
width="100%"
src={ `${tainacan_blocks.base_url}/assets/images/related-carousel-items.png` } />
</div>
: (
<>
return <>
<BlockControls group="block">
<AlignmentControl
value={ textAlign }
@ -50,6 +42,5 @@ export default function ({ attributes, setAttributes, context }) {
id={ 'tainacan-metadata-section-description-block-id--' + sectionId }>
{ sectionDescription }
</p>
</>
);
</>;
};

View File

@ -8,17 +8,7 @@
"description": "A metadata section label, used to identify different metadata sections.",
"textdomain": "tainacan",
"parent": [ "tainacan/item-metadata-section" ],
"example": {
"attributes": {
"content": "preview"
}
},
"attributes": {
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"sectionId": {
"type": "string",
"default": ""

View File

@ -1 +1,24 @@
export default [];
export default [
{
"content": {
"type": "array",
"source": "query",
"selector": "div"
},
"sectionId": {
"type": "string",
"default": ""
},
"sectionName": {
"type": "string",
"default": ""
},
"labelLevel": {
"type": "number",
"default": 2
},
"textAlign": {
"type": "string"
}
}
];

View File

@ -15,7 +15,6 @@ const levelToPath = {
export default function ({ attributes, setAttributes, context }) {
let {
content,
sectionId,
sectionName,
labelLevel,
@ -39,14 +38,7 @@ export default function ({ attributes, setAttributes, context }) {
if ( context['tainacan/metadataSectionId'] || context['tainacan/metadataSectionName'] )
setAttributes({ sectionId, sectionName });
return content == 'preview' ?
<div className={className}>
<img
width="100%"
src={ `${tainacan_blocks.base_url}/assets/images/related-carousel-items.png` } />
</div>
: (
<>
return <>
<BlockControls group="block">
<ToolbarDropdownMenu
@ -105,6 +97,5 @@ export default function ({ attributes, setAttributes, context }) {
id={ 'tainacan-metadata-section-name-block-id--' + sectionId }>
{ sectionName }
</Heading>
</>
);
</>;
};