From a702252e706ce1c16446a38c4ca424bebee9a31c Mon Sep 17 00:00:00 2001 From: Ajay D'Souza Date: Thu, 19 Dec 2024 19:06:47 +0000 Subject: [PATCH] Updated blocks --- includes/blocks/build/alerts/block.json | 4 +- includes/blocks/build/alerts/index.asset.php | 2 +- includes/blocks/build/alerts/index.js | 2 +- includes/blocks/build/breadcrumb/block.json | 3 +- includes/blocks/build/kb/block.json | 4 +- includes/blocks/build/kb/index.asset.php | 2 +- includes/blocks/build/kb/index.js | 2 +- includes/blocks/src/alerts/block.json | 2 +- includes/blocks/src/kb/block.json | 2 +- includes/blocks/src/kb/edit.js | 379 +++++++++---------- 10 files changed, 186 insertions(+), 216 deletions(-) diff --git a/includes/blocks/build/alerts/block.json b/includes/blocks/build/alerts/block.json index 1a30618..03e8f6d 100644 --- a/includes/blocks/build/alerts/block.json +++ b/includes/blocks/build/alerts/block.json @@ -1,8 +1,8 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, + "apiVersion": 3, "name": "knowledgebase/alerts", - "version": "1.0.0", + "version": "2.3.0", "title": "Knowledge Base Alerts", "category": "design", "icon": "book", diff --git a/includes/blocks/build/alerts/index.asset.php b/includes/blocks/build/alerts/index.asset.php index 99d4879..51c5519 100644 --- a/includes/blocks/build/alerts/index.asset.php +++ b/includes/blocks/build/alerts/index.asset.php @@ -1 +1 @@ - array('react', 'wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => '2d1ba7f66d29cf290099'); + array('react', 'wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => 'df6a61d80bfbef1bfd2f'); diff --git a/includes/blocks/build/alerts/index.js b/includes/blocks/build/alerts/index.js index bb391e7..cb826d6 100644 --- a/includes/blocks/build/alerts/index.js +++ b/includes/blocks/build/alerts/index.js @@ -1 +1 @@ -(()=>{"use strict";var e,t={462:()=>{const e=window.wp.blocks,t=window.React,n=window.wp.i18n,r=window.wp.blockEditor;(0,e.registerBlockType)("knowledgebase/alerts",{edit:function({attributes:e,setAttributes:o}){const a=(0,r.useBlockProps)({className:"wzkb-alert"}),{content:l,align:s}=e;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.BlockControls,null,(0,t.createElement)(r.AlignmentControl,{value:s,onChange:e=>{o({align:void 0===e?"none":e})}})),(0,t.createElement)(r.RichText,{...a,tagName:"div",value:l,onChange:e=>{o({content:e})},placeholder:(0,n.__)("Enter the alert text...","knowledgebase"),style:{textAlign:s}}))},save:function({attributes:e}){const n=r.useBlockProps.save({className:"wzkb-alert"}),{content:o,align:a}=e,l=n.className;return(0,t.createElement)(r.RichText.Content,{...n,className:l,tagName:"div",value:o,style:{textAlign:a}})}})}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=(t,n,o,a)=>{if(!n){var l=1/0;for(u=0;u=a)&&Object.keys(r.O).every((e=>r.O[e](n[i])))?n.splice(i--,1):(s=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={539:0,267:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var o,a,l=n[0],s=n[1],i=n[2],c=0;if(l.some((t=>0!==e[t]))){for(o in s)r.o(s,o)&&(r.m[o]=s[o]);if(i)var u=i(r)}for(t&&t(n);cr(462)));o=r.O(o)})(); \ No newline at end of file +(()=>{"use strict";var e,t={462:()=>{const e=window.wp.blocks,t=window.React,n=window.wp.i18n,r=window.wp.blockEditor;(0,e.registerBlockType)("knowledgebase/alerts",{edit:function({attributes:e,setAttributes:o}){const a=(0,r.useBlockProps)({className:"wzkb-alert"}),{content:l,align:s}=e;return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.BlockControls,null,(0,t.createElement)(r.AlignmentControl,{value:s,onChange:e=>{o({align:void 0===e?"none":e})}})),(0,t.createElement)(r.RichText,{...a,tagName:"div",value:l,onChange:e=>{o({content:e})},placeholder:(0,n.__)("Enter the alert text...","knowledgebase"),style:{textAlign:s}}))},save:function({attributes:e}){const n=r.useBlockProps.save({className:"wzkb-alert"}),{content:o,align:a}=e,l=n.className;return(0,t.createElement)(r.RichText.Content,{...n,className:l,tagName:"div",value:o,style:{textAlign:a}})}})}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=(t,n,o,a)=>{if(!n){var l=1/0;for(u=0;u=a)&&Object.keys(r.O).every((e=>r.O[e](n[i])))?n.splice(i--,1):(s=!1,a0&&e[u-1][2]>a;u--)e[u]=e[u-1];e[u]=[n,o,a]},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={539:0,267:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var o,a,[l,s,i]=n,c=0;if(l.some((t=>0!==e[t]))){for(o in s)r.o(s,o)&&(r.m[o]=s[o]);if(i)var u=i(r)}for(t&&t(n);cr(462)));o=r.O(o)})(); \ No newline at end of file diff --git a/includes/blocks/build/breadcrumb/block.json b/includes/blocks/build/breadcrumb/block.json index 0247521..36009bc 100644 --- a/includes/blocks/build/breadcrumb/block.json +++ b/includes/blocks/build/breadcrumb/block.json @@ -30,6 +30,5 @@ "example": {}, "textdomain": "knowledgebase", "editorScript": "file:./index.js", - "editorStyle": "file:./index.css", - "style": "file:./style-index.css" + "editorStyle": "file:./index.css" } \ No newline at end of file diff --git a/includes/blocks/build/kb/block.json b/includes/blocks/build/kb/block.json index c8cc685..15fb8e8 100644 --- a/includes/blocks/build/kb/block.json +++ b/includes/blocks/build/kb/block.json @@ -1,8 +1,8 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 2, + "apiVersion": 3, "name": "knowledgebase/knowledgebase", - "version": "2.0.0", + "version": "2.3.0", "title": "Knowledge Base", "category": "design", "icon": "book", diff --git a/includes/blocks/build/kb/index.asset.php b/includes/blocks/build/kb/index.asset.php index c3de9c0..ce0a3b4 100644 --- a/includes/blocks/build/kb/index.asset.php +++ b/includes/blocks/build/kb/index.asset.php @@ -1 +1 @@ - array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n', 'wp-server-side-render'), 'version' => '10ba162f0a0eb6c91f2f'); + array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n', 'wp-server-side-render'), 'version' => '9d0f780ce17c9a1667d6'); diff --git a/includes/blocks/build/kb/index.js b/includes/blocks/build/kb/index.js index e31ce37..ae3b1dc 100644 --- a/includes/blocks/build/kb/index.js +++ b/includes/blocks/build/kb/index.js @@ -1 +1 @@ -(()=>{"use strict";var e={n:l=>{var t=l&&l.__esModule?()=>l.default:()=>l;return e.d(t,{a:t}),t},d:(l,t)=>{for(var n in t)e.o(t,n)&&!e.o(l,n)&&Object.defineProperty(l,n,{enumerable:!0,get:t[n]})},o:(e,l)=>Object.prototype.hasOwnProperty.call(e,l)};const l=window.wp.blocks,t=window.React,n=window.wp.i18n,o=window.wp.serverSideRender;var a=e.n(o);const r=window.wp.blockEditor,s=window.wp.components;(0,l.registerBlockType)("knowledgebase/knowledgebase",{edit:function({attributes:e,setAttributes:l}){function o(e){return void 0===e||0===e||""===e||isNaN(e)?"":parseInt(e)}const{category:c,limit:i,showArticleCount:d,showExcerpt:w,hasClickableSection:g,showEmptySections:b,columns:u,other_attributes:h}=e,m=(0,r.useBlockProps)();return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.InspectorControls,null,(0,t.createElement)(s.PanelBody,{title:(0,n.__)("Knowledge Base Settings","knowledgebase"),initialOpen:!0},(0,t.createElement)(s.PanelRow,null,(0,t.createElement)("fieldset",null,(0,t.createElement)(s.TextControl,{label:(0,n.__)("Category ID","knowledgebase"),value:c,onChange:e=>{l({category:void 0===e?"":e})},help:(0,n.__)("Enter a single category/section ID to display its knowledge base or leave back to display the full knowledge base. You can find this under Knowledge Base > Sections.","knowledgebase")}))),(0,t.createElement)(s.PanelRow,null,(0,t.createElement)("fieldset",null,(0,t.createElement)(s.TextControl,{label:(0,n.__)("Max articles per section","knowledgebase"),value:i,onChange:e=>{l({limit:o(e)})},help:(0,n.__)("After this limit is reached, the footer is displayed with the more link to view the category.","knowledgebase")}))),(0,t.createElement)(s.PanelRow,null,(0,t.createElement)("fieldset",null,(0,t.createElement)(s.ToggleControl,{label:(0,n.__)("Show article count","knowledgebase"),help:d?(0,n.__)("Article count displayed","knowledgebase"):(0,n.__)("No article count displayed","knowledgebase"),checked:d,onChange:()=>{l({showArticleCount:!d})}}))),(0,t.createElement)(s.PanelRow,null,(0,t.createElement)("fieldset",null,(0,t.createElement)(s.ToggleControl,{label:(0,n.__)("Show excerpt","knowledgebase"),help:w?(0,n.__)("Excerpt displayed","knowledgebase"):(0,n.__)("No excerpt","knowledgebase"),checked:w,onChange:()=>{l({showExcerpt:!w})}}))),(0,t.createElement)(s.PanelRow,null,(0,t.createElement)("fieldset",null,(0,t.createElement)(s.ToggleControl,{label:(0,n.__)("Show clickable section","knowledgebase"),help:g?(0,n.__)("Section headers are linked","knowledgebase"):(0,n.__)("Section headers not linked","knowledgebase"),checked:g,onChange:()=>{l({hasClickableSection:!g})}}))),(0,t.createElement)(s.PanelRow,null,(0,t.createElement)("fieldset",null,(0,t.createElement)(s.ToggleControl,{label:(0,n.__)("Show empty sections","knowledgebase"),help:b?(0,n.__)("Empty sections displayed","knowledgebase"):(0,n.__)("Empty sections hidden","knowledgebase"),checked:b,onChange:()=>{l({showEmptySections:!b})}}))),(0,t.createElement)(s.PanelRow,null,(0,t.createElement)("fieldset",null,(0,t.createElement)(s.TextControl,{label:(0,n.__)("Number of columns","knowledgebase"),value:u,onChange:e=>{l({columns:o(e)})},help:(0,n.__)("Only works when inbuilt styles are enabled in the Settings page","knowledgebase")}))),(0,t.createElement)(s.PanelRow,null,(0,t.createElement)("fieldset",null,(0,t.createElement)(s.TextareaControl,{label:(0,n.__)("Other attributes","knowledgebase"),value:h,onChange:e=>{l({other_attributes:void 0===e?"":e})},help:(0,n.__)("Enter other attributes in a URL-style string-query.","knowledgebase")}))))),(0,t.createElement)("div",{...m},(0,t.createElement)(s.Disabled,null,(0,t.createElement)(a(),{block:"knowledgebase/knowledgebase",attributes:e}))))},save:()=>null})})(); \ No newline at end of file +(()=>{"use strict";var e={n:t=>{var l=t&&t.__esModule?()=>t.default:()=>t;return e.d(l,{a:l}),l},d:(t,l)=>{for(var n in l)e.o(l,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:l[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,l=window.React,n=window.wp.i18n,o=window.wp.serverSideRender;var a=e.n(o);const r=window.wp.blockEditor,s=window.wp.components,i=({attributes:e,onUpdateAttribute:t,onToggleAttribute:o,processNumber:a})=>{const{category:r,limit:i,showArticleCount:c,showExcerpt:d,hasClickableSection:b,showEmptySections:w,columns:g,other_attributes:u}=e;return(0,l.createElement)(s.PanelBody,{title:(0,n.__)("Knowledge Base Settings","knowledgebase"),initialOpen:!0},(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.TextControl,{label:(0,n.__)("Category ID","knowledgebase"),value:r,onChange:e=>t("category",e||""),help:(0,n.__)("Enter a single category/section ID to display its knowledge base or leave blank to display the full knowledge base. You can find this under Knowledge Base > Sections.","knowledgebase")})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.TextControl,{label:(0,n.__)("Max articles per section","knowledgebase"),value:i,onChange:e=>t("limit",a(e)),help:(0,n.__)("After this limit is reached, the footer is displayed with the more link to view the category.","knowledgebase")})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.ToggleControl,{label:(0,n.__)("Show article count","knowledgebase"),help:c?(0,n.__)("Article count displayed","knowledgebase"):(0,n.__)("No article count displayed","knowledgebase"),checked:c,onChange:()=>o("showArticleCount")})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.ToggleControl,{label:(0,n.__)("Show excerpt","knowledgebase"),help:d?(0,n.__)("Excerpt displayed","knowledgebase"):(0,n.__)("No excerpt","knowledgebase"),checked:d,onChange:()=>o("showExcerpt")})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.ToggleControl,{label:(0,n.__)("Show clickable section","knowledgebase"),help:b?(0,n.__)("Section headers are linked","knowledgebase"):(0,n.__)("Section headers not linked","knowledgebase"),checked:b,onChange:()=>o("hasClickableSection")})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.ToggleControl,{label:(0,n.__)("Show empty sections","knowledgebase"),help:w?(0,n.__)("Empty sections displayed","knowledgebase"):(0,n.__)("Empty sections hidden","knowledgebase"),checked:w,onChange:()=>o("showEmptySections")})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.TextControl,{label:(0,n.__)("Number of columns","knowledgebase"),value:g,onChange:e=>t("columns",a(e)),help:(0,n.__)("Only works when inbuilt styles are enabled in the Settings page","knowledgebase")})),(0,l.createElement)(s.PanelRow,null,(0,l.createElement)(s.TextareaControl,{label:(0,n.__)("Other attributes","knowledgebase"),value:u,onChange:e=>t("other_attributes",e||""),help:(0,n.__)("Enter other attributes in a URL-style string-query.","knowledgebase")})))};(0,t.registerBlockType)("knowledgebase/knowledgebase",{edit:function({attributes:e,setAttributes:t}){const n=(0,r.useBlockProps)(),{processNumber:o,updateAttribute:c,toggleAttribute:d}=((e,t)=>({processNumber:e=>void 0===e||0===e||""===e||isNaN(e)?"":parseInt(e),updateAttribute:(e,l)=>{t({[e]:l})},toggleAttribute:l=>{t({[l]:!e[l]})}}))(e,t);return(0,l.createElement)(l.Fragment,null,(0,l.createElement)(r.InspectorControls,null,(0,l.createElement)(i,{attributes:e,onUpdateAttribute:c,onToggleAttribute:d,processNumber:o})),(0,l.createElement)("div",{...n},(0,l.createElement)(s.Disabled,null,(0,l.createElement)(a(),{block:"knowledgebase/knowledgebase",attributes:e}))))},save:()=>null})})(); \ No newline at end of file diff --git a/includes/blocks/src/alerts/block.json b/includes/blocks/src/alerts/block.json index 50147b1..f60a319 100644 --- a/includes/blocks/src/alerts/block.json +++ b/includes/blocks/src/alerts/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "knowledgebase/alerts", - "version": "1.0.0", + "version": "2.3.0", "title": "Knowledge Base Alerts", "category": "design", "icon": "book", diff --git a/includes/blocks/src/kb/block.json b/includes/blocks/src/kb/block.json index ca9cdc1..26e47c4 100644 --- a/includes/blocks/src/kb/block.json +++ b/includes/blocks/src/kb/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "knowledgebase/knowledgebase", - "version": "2.0.0", + "version": "2.3.0", "title": "Knowledge Base", "category": "design", "icon": "book", diff --git a/includes/blocks/src/kb/edit.js b/includes/blocks/src/kb/edit.js index cfc8d20..94ca4f0 100644 --- a/includes/blocks/src/kb/edit.js +++ b/includes/blocks/src/kb/edit.js @@ -1,20 +1,9 @@ /** - * Retrieves the translation of text. - * - * @see https://developer.wordpress.org/block-editor/packages/packages-i18n/ + * WordPress dependencies */ import { __ } from '@wordpress/i18n'; - import ServerSideRender from '@wordpress/server-side-render'; - -/** - * React hook that is used to mark the block wrapper element. - * It provides all the necessary props like the class name. - * - * @see https://developer.wordpress.org/block-editor/packages/packages-block-editor/#useBlockProps - */ import { useBlockProps, InspectorControls } from '@wordpress/block-editor'; - import { Disabled, TextControl, @@ -25,30 +14,56 @@ import { } from '@wordpress/components'; /** - * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. - * Those files can contain any CSS code that gets applied to the editor. - * - * @see https://www.npmjs.com/package/@wordpress/scripts#using-css + * Internal dependencies */ import './editor.scss'; /** - * The edit function describes the structure of your block in the context of the - * editor. This represents what the editor will render when the block is used. - * - * @see https://developer.wordpress.org/block-editor/developers/block-api/block-edit-save/#edit + * Custom hook for handling knowledge base settings * - * @return {WPElement} Element to render. + * @param {Object} attributes - The block's attributes. + * @param {Function} setAttributes - The function to update the attributes. */ -export default function Edit({ attributes, setAttributes }) { - function processNumber(input) { - const output = - undefined === input || 0 === input || '' === input || isNaN(input) - ? '' - : parseInt(input); - return output; - } +const useKnowledgeBaseSettings = (attributes, setAttributes) => { + const processNumber = (input) => { + return input === undefined || + input === 0 || + input === '' || + isNaN(input) + ? '' + : parseInt(input); + }; + const updateAttribute = (name, value) => { + setAttributes({ [name]: value }); + }; + + const toggleAttribute = (name) => { + setAttributes({ [name]: !attributes[name] }); + }; + + return { + processNumber, + updateAttribute, + toggleAttribute, + }; +}; + +/** + * Settings Panel Component + * + * @param {Object} props - The component props. + * @param {Object} props.attributes - The block's attributes. + * @param {Function} props.onUpdateAttribute - The function to update the attributes. + * @param {Function} props.onToggleAttribute - The function to toggle the attributes. + * @param {Function} props.processNumber - The function to process the number. + */ +const KnowledgeBaseSettings = ({ + attributes, + onUpdateAttribute, + onToggleAttribute, + processNumber, +}) => { const { category, limit, @@ -60,186 +75,142 @@ export default function Edit({ attributes, setAttributes }) { other_attributes, } = attributes; + return ( + + + + onUpdateAttribute('category', value || '') + } + help={__( + 'Enter a single category/section ID to display its knowledge base or leave blank to display the full knowledge base. You can find this under Knowledge Base > Sections.', + 'knowledgebase' + )} + /> + + + + + onUpdateAttribute('limit', processNumber(value)) + } + help={__( + 'After this limit is reached, the footer is displayed with the more link to view the category.', + 'knowledgebase' + )} + /> + + + + onToggleAttribute('showArticleCount')} + /> + + + + onToggleAttribute('showExcerpt')} + /> + + + + onToggleAttribute('hasClickableSection')} + /> + + + + onToggleAttribute('showEmptySections')} + /> + + + + + onUpdateAttribute('columns', processNumber(value)) + } + help={__( + 'Only works when inbuilt styles are enabled in the Settings page', + 'knowledgebase' + )} + /> + + + + + onUpdateAttribute('other_attributes', value || '') + } + help={__( + 'Enter other attributes in a URL-style string-query.', + 'knowledgebase' + )} + /> + + + ); +}; + +/** + * Edit component for the Knowledge Base block + * + * @param {Object} attributes - The block's attributes. + * @param {Function} setAttributes - The function to update the attributes. + */ +export default function Edit({ attributes, setAttributes }) { const blockProps = useBlockProps(); - const onChangeCategory = (newCategory) => { - setAttributes({ - category: undefined === newCategory ? '' : newCategory, - }); - }; - const onChangeLimit = (newLimit) => { - setAttributes({ limit: processNumber(newLimit) }); - }; - const toggleShowArticleCount = () => { - setAttributes({ showArticleCount: !showArticleCount }); - }; - const toggleShowExcerpt = () => { - setAttributes({ showExcerpt: !showExcerpt }); - }; - const toggleClickableSection = () => { - setAttributes({ hasClickableSection: !hasClickableSection }); - }; - const toggleShowEmptySections = () => { - setAttributes({ showEmptySections: !showEmptySections }); - }; - const onChangeColumns = (newColumns) => { - setAttributes({ columns: processNumber(newColumns) }); - }; - const onChangeOtherAttributes = (newOtherAttributes) => { - setAttributes({ - other_attributes: - undefined === newOtherAttributes ? '' : newOtherAttributes, - }); - }; + const { processNumber, updateAttribute, toggleAttribute } = + useKnowledgeBaseSettings(attributes, setAttributes); return ( <> - - -
- Sections.', - 'knowledgebase' - )} - /> -
-
- -
- -
-
- -
- -
-
- -
- -
-
- -
- -
-
- -
- -
-
- -
- -
-
- -
- -
-
-
+