From a96ec820dbc99dbb3dd321e047751e55a818cca2 Mon Sep 17 00:00:00 2001 From: Michael Corkum Date: Tue, 23 Jul 2024 22:25:32 -0400 Subject: [PATCH 1/7] change: add a variable to switch post locking to warning --- block-accessibility-checks.php | 7 + build/block-checks-rtl.css | 43 ++- build/block-checks.asset.php | 2 +- build/block-checks.css | 45 ++- build/block-checks.js | 544 ++++++++++++++++++++++++++++++++- src/AssetEnqueuer.php | 12 +- src/scripts/registerPlugin.js | 11 +- 7 files changed, 655 insertions(+), 9 deletions(-) diff --git a/block-accessibility-checks.php b/block-accessibility-checks.php index c512248..7d996b3 100644 --- a/block-accessibility-checks.php +++ b/block-accessibility-checks.php @@ -16,9 +16,16 @@ // Setup autoloading require_once __DIR__ . '/vendor/autoload.php'; +// Set Constant +if (!defined('BLOCK_ACCESSIBILITY_MODE')) { + define('BLOCK_ACCESSIBILITY_MODE', 'DENY'); // Default value +} + // Include dependencies use BlockAccessibility\AssetEnqueuer; // Enqueue block editor assets $assetEnqueuer = new AssetEnqueuer(__FILE__); + +// WordPress Hooks add_action('enqueue_block_editor_assets', [$assetEnqueuer, 'enqueueAssets']); diff --git a/build/block-checks-rtl.css b/build/block-checks-rtl.css index cb16266..fa72a73 100644 --- a/build/block-checks-rtl.css +++ b/build/block-checks-rtl.css @@ -1 +1,42 @@ -.a11y-block-error{background-color:#f7edec;border:3px dashed #8b3122;display:flex;flex-direction:column;gap:18px;margin-right:-24px;padding:20px 24px;width:100%}.a11y-error-msg{background-color:#8b3122;color:#fff;font-size:16px;font-weight:600;line-height:24px;padding:5px 10px}.a11y-error-msg+*{margin-top:0}.a11y-block-error>:last-child{margin-bottom:0}.a11y-block-error.wp-block-heading{padding-bottom:0;padding-top:0} +/*!**************************************************************************************************************************************************************************!*\ + !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/styles/error.css ***! + \**************************************************************************************************************************************************************************/ +.a11y-block-error { + display: flex; + flex-direction: column; + gap: 18px; + width: 100%; + padding: 20px 24px; + margin-right: -24px; + background-color:#F7EDEC; + border: 3px dashed #8B3122; +} + +.a11y-error-msg { + /* display: flex; + gap: 6px; + align-items: center; */ + font-size: 16px; + line-height: 24px; + font-weight: 600; + color: white; + background-color: #8B3122; + padding: 5px 10px; +} + +/* Remove top spacing from block being wrapped */ +.a11y-error-msg + * { + margin-top: 0; +} + +/* Remove bottom spacing from block being wrapped */ +.a11y-block-error > *:last-child { + margin-bottom: 0; +} + +/* TODO: it's a mystery */ +.a11y-block-error.wp-block-heading { + padding-top: 0; + padding-bottom: 0; +} + diff --git a/build/block-checks.asset.php b/build/block-checks.asset.php index 6269cb3..713b4aa 100644 --- a/build/block-checks.asset.php +++ b/build/block-checks.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => '8d731575fd93004bcbf2'); + array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => '0867ab9a2a13e0ab1bbf'); diff --git a/build/block-checks.css b/build/block-checks.css index 8fedd65..208171a 100644 --- a/build/block-checks.css +++ b/build/block-checks.css @@ -1 +1,44 @@ -.a11y-block-error{background-color:#f7edec;border:3px dashed #8b3122;display:flex;flex-direction:column;gap:18px;margin-left:-24px;padding:20px 24px;width:100%}.a11y-error-msg{background-color:#8b3122;color:#fff;font-size:16px;font-weight:600;line-height:24px;padding:5px 10px}.a11y-error-msg+*{margin-top:0}.a11y-block-error>:last-child{margin-bottom:0}.a11y-block-error.wp-block-heading{padding-bottom:0;padding-top:0} +/*!**************************************************************************************************************************************************************************!*\ + !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/styles/error.css ***! + \**************************************************************************************************************************************************************************/ +.a11y-block-error { + display: flex; + flex-direction: column; + gap: 18px; + width: 100%; + padding: 20px 24px; + margin-left: -24px; + background-color:#F7EDEC; + border: 3px dashed #8B3122; +} + +.a11y-error-msg { + /* display: flex; + gap: 6px; + align-items: center; */ + font-size: 16px; + line-height: 24px; + font-weight: 600; + color: white; + background-color: #8B3122; + padding: 5px 10px; +} + +/* Remove top spacing from block being wrapped */ +.a11y-error-msg + * { + margin-top: 0; +} + +/* Remove bottom spacing from block being wrapped */ +.a11y-block-error > *:last-child { + margin-bottom: 0; +} + +/* TODO: it's a mystery */ +.a11y-block-error.wp-block-heading { + padding-top: 0; + padding-bottom: 0; +} + + +/*# sourceMappingURL=block-checks.css.map*/ \ No newline at end of file diff --git a/build/block-checks.js b/build/block-checks.js index d2ff744..453142f 100644 --- a/build/block-checks.js +++ b/build/block-checks.js @@ -1 +1,543 @@ -(()=>{"use strict";const e=window.wp.i18n,t=window.wp.hooks,n=window.wp.compose,r=window.wp.blockEditor,i=window.wp.components;(0,t.addFilter)("blocks.registerBlockType","block-accessibility-checks/add-image-attribute",(function(e){return"core/image"!==e.name||(e.attributes=Object.assign(e.attributes,{isDecorative:{type:"boolean",default:!1}})),e}));var a=(0,n.createHigherOrderComponent)((function(t){return function(n){if("core/image"!==n.name)return React.createElement(t,n);var a=n.attributes,c=n.setAttributes,o=a.isDecorative;return React.createElement(React.Fragment,null,React.createElement(r.InspectorControls,null,React.createElement(i.PanelBody,{title:(0,e.__)("Accessibility Settings","block-accessibility-checks"),initialOpen:!0},React.createElement(i.ToggleControl,{label:(0,e.__)("Please confirm this image is decorative","block-accessibility-checks"),checked:o,onChange:function(e){return c({isDecorative:e})}}))),React.createElement(t,n))}}),"addImageInspectorControls");(0,t.addFilter)("editor.BlockEdit","block-accessibility-checks/add-inspector-control",a);const c=window.wp.plugins,o=window.wp.data;function l(){return(0,o.useSelect)((function(e){return e("core/block-editor").getBlocks()}),[]).flatMap((function(e){return m.map((function(t){return t(e)}))})).filter((function(e){return!e.isValid}))}const s=window.wp.element;function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[_n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(n);try{for(a.s();!(i=a.n()).done;){var c=i.value;if("core/button"===c.name){var o=c.attributes,l=o.text,s=o.url;if(""===l||void 0===s)return{isValid:!1,message:(0,e.__)("Accessibility Error: Each button must have both text and URL.","block-accessibility-checks"),clientId:r}}if(c.innerBlocks.length>0){var u=t(c.innerBlocks,r);if(!u.isValid)return u}}}catch(e){a.e(e)}finally{a.f()}return{isValid:!0}}(t.innerBlocks,t.clientId)},function(t){return"core/heading"===t.name&&1===t.attributes.level?{isValid:!1,message:(0,e.__)("Accessibility Error: Level 1 headings are not allowed in your content area.","block-accessibility-checks"),clientId:t.clientId}:{isValid:!0}},function(t){return"core/image"!==t.name||t.attributes.alt||t.attributes.isDecorative?{isValid:!0}:{isValid:!1,message:(0,e.__)("Accessibility Error: Images are required to have alternative text.","block-accessibility-checks"),clientId:t.clientId}},function(t){return"core/table"===t.name&&0!==t.attributes.body.length&&0===t.attributes.head.length?{isValid:!1,message:(0,e.__)("Accessibility Error: Tables are required to have a header row.","block-accessibility-checks"),clientId:t.clientId}:{isValid:!0}}];(0,c.registerPlugin)("block-validation",{render:function(){var e=l(),t=(0,o.useDispatch)("core/editor"),n=t.lockPostSaving,r=t.unlockPostSaving,i=t.lockPostAutosaving,a=t.unlockPostAutosaving,c=t.disablePublishSidebar,u=t.enablePublishSidebar;return(0,s.useEffect)((function(){e.length>0?(n(),i(),c()):(r(),a(),u())}),[e,c,u,i,n,a,r]),null}})})(); \ No newline at end of file +/******/ (() => { // webpackBootstrap +/******/ "use strict"; +/******/ var __webpack_modules__ = ({ + +/***/ "./src/scripts/blockChecks/checkButton.js": +/*!************************************************!*\ + !*** ./src/scripts/blockChecks/checkButton.js ***! + \************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ checkButtonAttributes: () => (/* binding */ checkButtonAttributes) +/* harmony export */ }); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); +function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } +function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } +function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } + +function checkButtonAttributes(block) { + var checkButton = function checkButton(innerBlocks, parentClientId) { + var _iterator = _createForOfIteratorHelper(innerBlocks), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var innerBlock = _step.value; + if (innerBlock.name === 'core/button') { + var _innerBlock$attribute = innerBlock.attributes, + text = _innerBlock$attribute.text, + url = _innerBlock$attribute.url; + if (text === '' || url === undefined) { + return { + isValid: false, + message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Each button must have both text and URL.', 'block-accessibility-checks'), + clientId: parentClientId + }; + } + } + // Recursively check nested inner blocks + if (innerBlock.innerBlocks.length > 0) { + var result = checkButton(innerBlock.innerBlocks, parentClientId); + if (!result.isValid) { + return result; + } + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + return { + isValid: true + }; + }; + return checkButton(block.innerBlocks, block.clientId); +} + +/***/ }), + +/***/ "./src/scripts/blockChecks/checkHeading.js": +/*!*************************************************!*\ + !*** ./src/scripts/blockChecks/checkHeading.js ***! + \*************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ checkHeadingLevel: () => (/* binding */ checkHeadingLevel) +/* harmony export */ }); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); + +function checkHeadingLevel(block) { + if (block.name === 'core/heading' && block.attributes.level === 1) { + return { + isValid: false, + message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Level 1 headings are not allowed in your content area.', 'block-accessibility-checks'), + clientId: block.clientId + }; + } + return { + isValid: true + }; +} + +/***/ }), + +/***/ "./src/scripts/blockChecks/checkImage.js": +/*!***********************************************!*\ + !*** ./src/scripts/blockChecks/checkImage.js ***! + \***********************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ checkImageAlt: () => (/* binding */ checkImageAlt) +/* harmony export */ }); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); + +function checkImageAlt(block) { + if (block.name === 'core/image' && !block.attributes.alt && !block.attributes.isDecorative) { + return { + isValid: false, + message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Images are required to have alternative text.', 'block-accessibility-checks'), + clientId: block.clientId + }; + } + return { + isValid: true + }; +} + +/***/ }), + +/***/ "./src/scripts/blockChecks/checkTable.js": +/*!***********************************************!*\ + !*** ./src/scripts/blockChecks/checkTable.js ***! + \***********************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ checkTableHeaderRow: () => (/* binding */ checkTableHeaderRow) +/* harmony export */ }); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); + +function checkTableHeaderRow(block) { + if (block.name === 'core/table' && block.attributes.body.length !== 0 && block.attributes.head.length === 0) { + return { + isValid: false, + message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Tables are required to have a header row.', 'block-accessibility-checks'), + clientId: block.clientId + }; + } + return { + isValid: true + }; +} + +/***/ }), + +/***/ "./src/scripts/blockMods/imageAttr.js": +/*!********************************************!*\ + !*** ./src/scripts/blockMods/imageAttr.js ***! + \********************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks"); +/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); +/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__); + + + + + + +// Add image attribute to confirm decorative to bypass a11y block +var addImageAttribute = function addImageAttribute(settings) { + if (settings.name !== 'core/image') { + return settings; + } + settings.attributes = Object.assign(settings.attributes, { + isDecorative: { + type: 'boolean', + "default": false + } + }); + return settings; +}; +(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('blocks.registerBlockType', 'block-accessibility-checks/add-image-attribute', addImageAttribute); + +// Create a new block control for the attribute +var addImageInspectorControls = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__.createHigherOrderComponent)(function (BlockEdit) { + return function (props) { + if (props.name !== 'core/image') { + return /*#__PURE__*/React.createElement(BlockEdit, props); + } + var attributes = props.attributes, + setAttributes = props.setAttributes; + var isDecorative = attributes.isDecorative; + return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.InspectorControls, null, /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.PanelBody, { + title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Settings', 'block-accessibility-checks'), + initialOpen: true + }, /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToggleControl, { + label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Please confirm this image is decorative', 'block-accessibility-checks'), + checked: isDecorative, + onChange: function onChange(value) { + return setAttributes({ + isDecorative: value + }); + } + }))), /*#__PURE__*/React.createElement(BlockEdit, props)); + }; +}, 'addImageInspectorControls'); +(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('editor.BlockEdit', 'block-accessibility-checks/add-inspector-control', addImageInspectorControls); + +/***/ }), + +/***/ "./src/scripts/helpers/blockErrorComponent.js": +/*!****************************************************!*\ + !*** ./src/scripts/helpers/blockErrorComponent.js ***! + \****************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); +/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks"); +/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _getInvalidBlocks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./getInvalidBlocks */ "./src/scripts/helpers/getInvalidBlocks.js"); +function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } + + + +var blockErrorComponent = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__.createHigherOrderComponent)(function (BlockListBlock) { + var WrappedBlock = function WrappedBlock(props) { + var invalidBlock = (0,_getInvalidBlocks__WEBPACK_IMPORTED_MODULE_2__.GetInvalidBlocks)().find(function (obj) { + return obj.clientId === props.clientId; + }); + var messages = invalidBlock ? invalidBlock.message : ''; + return /*#__PURE__*/React.createElement(React.Fragment, null, invalidBlock ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", { + className: "a11y-block-error" + }, /*#__PURE__*/React.createElement("div", { + className: "a11y-error-msg" + }, messages), /*#__PURE__*/React.createElement(BlockListBlock, _extends({}, props, { + className: "".concat(props.className) + })))) : /*#__PURE__*/React.createElement(BlockListBlock, _extends({}, props, { + className: "".concat(props.className) + }))); + }; + + // Set the displayName for debugging purposes + WrappedBlock.displayName = "a11yCheck(".concat(BlockListBlock.displayName || BlockListBlock.name || 'Component', ")"); + return WrappedBlock; +}, 'blockErrorComponent'); +(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('editor.BlockListBlock', 'block-accessibilty-checks/with-client-id-class-name', blockErrorComponent); + +/***/ }), + +/***/ "./src/scripts/helpers/blockInvalidation.js": +/*!**************************************************!*\ + !*** ./src/scripts/helpers/blockInvalidation.js ***! + \**************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ BlockInvalidation: () => (/* binding */ BlockInvalidation) +/* harmony export */ }); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _getInvalidBlocks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./getInvalidBlocks */ "./src/scripts/helpers/getInvalidBlocks.js"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_2__); + + + +function BlockInvalidation() { + var invalidBlocks = (0,_getInvalidBlocks__WEBPACK_IMPORTED_MODULE_1__.GetInvalidBlocks)(); + var _useDispatch = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useDispatch)('core/editor'), + lockPostSaving = _useDispatch.lockPostSaving, + unlockPostSaving = _useDispatch.unlockPostSaving, + lockPostAutosaving = _useDispatch.lockPostAutosaving, + unlockPostAutosaving = _useDispatch.unlockPostAutosaving, + disablePublishSidebar = _useDispatch.disablePublishSidebar, + enablePublishSidebar = _useDispatch.enablePublishSidebar; + (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useEffect)(function () { + if (invalidBlocks.length > 0) { + lockPostSaving(); + lockPostAutosaving(); + disablePublishSidebar(); + } else { + unlockPostSaving(); + unlockPostAutosaving(); + enablePublishSidebar(); + } + }, [invalidBlocks, disablePublishSidebar, enablePublishSidebar, lockPostAutosaving, lockPostSaving, unlockPostAutosaving, unlockPostSaving]); + return null; +} + +/***/ }), + +/***/ "./src/scripts/helpers/getInvalidBlocks.js": +/*!*************************************************!*\ + !*** ./src/scripts/helpers/getInvalidBlocks.js ***! + \*************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ GetInvalidBlocks: () => (/* binding */ GetInvalidBlocks) +/* harmony export */ }); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _registerPlugin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../registerPlugin */ "./src/scripts/registerPlugin.js"); + + +function GetInvalidBlocks() { + var allBlocks = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useSelect)(function (select) { + return select('core/block-editor').getBlocks(); + }, []); + return allBlocks.flatMap(function (block) { + return _registerPlugin__WEBPACK_IMPORTED_MODULE_1__.blockChecksArray.map(function (check) { + return check(block); + }); + }).filter(function (result) { + return !result.isValid; + }); +} + +/***/ }), + +/***/ "./src/scripts/registerPlugin.js": +/*!***************************************!*\ + !*** ./src/scripts/registerPlugin.js ***! + \***************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ blockChecksArray: () => (/* binding */ blockChecksArray) +/* harmony export */ }); +/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/plugins */ "@wordpress/plugins"); +/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _helpers_blockInvalidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers/blockInvalidation */ "./src/scripts/helpers/blockInvalidation.js"); +/* harmony import */ var _helpers_blockErrorComponent__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helpers/blockErrorComponent */ "./src/scripts/helpers/blockErrorComponent.js"); +/* harmony import */ var _blockChecks_checkButton__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./blockChecks/checkButton */ "./src/scripts/blockChecks/checkButton.js"); +/* harmony import */ var _blockChecks_checkHeading__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./blockChecks/checkHeading */ "./src/scripts/blockChecks/checkHeading.js"); +/* harmony import */ var _blockChecks_checkImage__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./blockChecks/checkImage */ "./src/scripts/blockChecks/checkImage.js"); +/* harmony import */ var _blockChecks_checkTable__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./blockChecks/checkTable */ "./src/scripts/blockChecks/checkTable.js"); + + + + +// Import block check functions + + + + +var blockChecksArray = [_blockChecks_checkButton__WEBPACK_IMPORTED_MODULE_3__.checkButtonAttributes, _blockChecks_checkHeading__WEBPACK_IMPORTED_MODULE_4__.checkHeadingLevel, _blockChecks_checkImage__WEBPACK_IMPORTED_MODULE_5__.checkImageAlt, _blockChecks_checkTable__WEBPACK_IMPORTED_MODULE_6__.checkTableHeaderRow]; +(0,_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__.registerPlugin)('block-validation', { + render: _helpers_blockInvalidation__WEBPACK_IMPORTED_MODULE_1__.BlockInvalidation +}); + +// TODO: is this the right place? +if (blockAccessibilitySettings.mode === 'WARN') { + console.log('Warning: Accessibility issues detected!'); +} else if (blockAccessibilitySettings.mode === 'DENY') { + console.log('DENY!: Accessibility issues detected!'); +} + +/***/ }), + +/***/ "./src/styles/error.css": +/*!******************************!*\ + !*** ./src/styles/error.css ***! + \******************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +// extracted by mini-css-extract-plugin + + +/***/ }), + +/***/ "@wordpress/block-editor": +/*!*************************************!*\ + !*** external ["wp","blockEditor"] ***! + \*************************************/ +/***/ ((module) => { + +module.exports = window["wp"]["blockEditor"]; + +/***/ }), + +/***/ "@wordpress/components": +/*!************************************!*\ + !*** external ["wp","components"] ***! + \************************************/ +/***/ ((module) => { + +module.exports = window["wp"]["components"]; + +/***/ }), + +/***/ "@wordpress/compose": +/*!*********************************!*\ + !*** external ["wp","compose"] ***! + \*********************************/ +/***/ ((module) => { + +module.exports = window["wp"]["compose"]; + +/***/ }), + +/***/ "@wordpress/data": +/*!******************************!*\ + !*** external ["wp","data"] ***! + \******************************/ +/***/ ((module) => { + +module.exports = window["wp"]["data"]; + +/***/ }), + +/***/ "@wordpress/element": +/*!*********************************!*\ + !*** external ["wp","element"] ***! + \*********************************/ +/***/ ((module) => { + +module.exports = window["wp"]["element"]; + +/***/ }), + +/***/ "@wordpress/hooks": +/*!*******************************!*\ + !*** external ["wp","hooks"] ***! + \*******************************/ +/***/ ((module) => { + +module.exports = window["wp"]["hooks"]; + +/***/ }), + +/***/ "@wordpress/i18n": +/*!******************************!*\ + !*** external ["wp","i18n"] ***! + \******************************/ +/***/ ((module) => { + +module.exports = window["wp"]["i18n"]; + +/***/ }), + +/***/ "@wordpress/plugins": +/*!*********************************!*\ + !*** external ["wp","plugins"] ***! + \*********************************/ +/***/ ((module) => { + +module.exports = window["wp"]["plugins"]; + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __webpack_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __webpack_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __webpack_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ +/************************************************************************/ +var __webpack_exports__ = {}; +/*!***********************!*\ + !*** ./src/script.js ***! + \***********************/ +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _styles_error_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./styles/error.css */ "./src/styles/error.css"); +/* harmony import */ var _scripts_blockMods_imageAttr__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./scripts/blockMods/imageAttr */ "./src/scripts/blockMods/imageAttr.js"); +/* harmony import */ var _scripts_registerPlugin__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./scripts/registerPlugin */ "./src/scripts/registerPlugin.js"); + + +// Block Modifications + + +// Block Checks + +/******/ })() +; +//# sourceMappingURL=block-checks.js.map \ No newline at end of file diff --git a/src/AssetEnqueuer.php b/src/AssetEnqueuer.php index 1c0c539..1c539ea 100644 --- a/src/AssetEnqueuer.php +++ b/src/AssetEnqueuer.php @@ -12,9 +12,8 @@ public function __construct($pluginFile) { } public function enqueueAssets() { - $script_path = 'build/block-checks.js'; - $style_path = 'build/block-checks.css'; - + $script_path = 'build/block-checks.js'; + $style_path = 'build/block-checks.css'; $script_handle = 'block-accessibility-script'; wp_enqueue_script( @@ -31,6 +30,13 @@ public function enqueueAssets() { [], filemtime(plugin_dir_path($this->pluginFile) . $style_path) ); + + // Localize script with data from PHP + wp_localize_script( + $script_handle, + 'blockAccessibilitySettings', + ['mode' => BLOCK_ACCESSIBILITY_MODE] + ); // Load the text domain for the script wp_set_script_translations( diff --git a/src/scripts/registerPlugin.js b/src/scripts/registerPlugin.js index 63e2728..a20e7ea 100644 --- a/src/scripts/registerPlugin.js +++ b/src/scripts/registerPlugin.js @@ -15,6 +15,13 @@ export const blockChecksArray = [ checkTableHeaderRow, ]; -registerPlugin('block-validation', { +registerPlugin( 'block-validation', { render: BlockInvalidation, -}); +} ); + +// TODO: is this the right place? +if ( blockAccessibilitySettings.mode === 'WARN' ) { + console.log( 'Warning: Accessibility issues detected!' ); +} else if ( blockAccessibilitySettings.mode === 'DENY' ) { + console.log( 'DENY!: Accessibility issues detected!' ); +} From b4b2ebec6b78fa0d7935c50bfc3247867851aa64 Mon Sep 17 00:00:00 2001 From: Michael Corkum Date: Tue, 23 Jul 2024 22:36:34 -0400 Subject: [PATCH 2/7] change: add the check for the constant in the right place --- build/block-checks.asset.php | 2 +- build/block-checks.js | 9 +-------- src/scripts/helpers/blockInvalidation.js | 5 ++++- src/scripts/registerPlugin.js | 11 ++--------- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/build/block-checks.asset.php b/build/block-checks.asset.php index 713b4aa..e5d00ee 100644 --- a/build/block-checks.asset.php +++ b/build/block-checks.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => '0867ab9a2a13e0ab1bbf'); + array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => '6808926b1de680bc5c42'); diff --git a/build/block-checks.js b/build/block-checks.js index 453142f..0270cb2 100644 --- a/build/block-checks.js +++ b/build/block-checks.js @@ -277,7 +277,7 @@ function BlockInvalidation() { disablePublishSidebar = _useDispatch.disablePublishSidebar, enablePublishSidebar = _useDispatch.enablePublishSidebar; (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useEffect)(function () { - if (invalidBlocks.length > 0) { + if (invalidBlocks.length > 0 && blockAccessibilitySettings.mode === 'DENY') { lockPostSaving(); lockPostAutosaving(); disablePublishSidebar(); @@ -354,13 +354,6 @@ var blockChecksArray = [_blockChecks_checkButton__WEBPACK_IMPORTED_MODULE_3__.ch render: _helpers_blockInvalidation__WEBPACK_IMPORTED_MODULE_1__.BlockInvalidation }); -// TODO: is this the right place? -if (blockAccessibilitySettings.mode === 'WARN') { - console.log('Warning: Accessibility issues detected!'); -} else if (blockAccessibilitySettings.mode === 'DENY') { - console.log('DENY!: Accessibility issues detected!'); -} - /***/ }), /***/ "./src/styles/error.css": diff --git a/src/scripts/helpers/blockInvalidation.js b/src/scripts/helpers/blockInvalidation.js index 78e481b..f086aa7 100644 --- a/src/scripts/helpers/blockInvalidation.js +++ b/src/scripts/helpers/blockInvalidation.js @@ -15,7 +15,10 @@ export function BlockInvalidation() { } = useDispatch('core/editor'); useEffect(() => { - if (invalidBlocks.length > 0) { + if ( + invalidBlocks.length > 0 && + blockAccessibilitySettings.mode === 'DENY' + ) { lockPostSaving(); lockPostAutosaving(); disablePublishSidebar(); diff --git a/src/scripts/registerPlugin.js b/src/scripts/registerPlugin.js index a20e7ea..63e2728 100644 --- a/src/scripts/registerPlugin.js +++ b/src/scripts/registerPlugin.js @@ -15,13 +15,6 @@ export const blockChecksArray = [ checkTableHeaderRow, ]; -registerPlugin( 'block-validation', { +registerPlugin('block-validation', { render: BlockInvalidation, -} ); - -// TODO: is this the right place? -if ( blockAccessibilitySettings.mode === 'WARN' ) { - console.log( 'Warning: Accessibility issues detected!' ); -} else if ( blockAccessibilitySettings.mode === 'DENY' ) { - console.log( 'DENY!: Accessibility issues detected!' ); -} +}); From e39152b9d8aa73f244c8d2e76556be818f2be15e Mon Sep 17 00:00:00 2001 From: Michael Corkum Date: Tue, 23 Jul 2024 23:00:48 -0400 Subject: [PATCH 3/7] change: refactor php for more seperation --- block-accessibility-checks.php | 33 ++++++++--- ...AssetEnqueuer.php => ScriptsAndStyles.php} | 55 +++++++++++-------- src/Translations.php | 26 +++++++++ 3 files changed, 83 insertions(+), 31 deletions(-) rename src/{AssetEnqueuer.php => ScriptsAndStyles.php} (52%) create mode 100644 src/Translations.php diff --git a/block-accessibility-checks.php b/block-accessibility-checks.php index 7d996b3..8ec7d33 100644 --- a/block-accessibility-checks.php +++ b/block-accessibility-checks.php @@ -1,31 +1,46 @@ pluginFile = $pluginFile; + $this->translations = $translations; } - public function enqueueAssets() { - $script_path = 'build/block-checks.js'; - $style_path = 'build/block-checks.css'; + public function enqueueAssets() + { $script_handle = 'block-accessibility-script'; - + $this->translations->setupScriptTranslations($script_handle); + + $this->enqueueScripts(); + $this->enqueueStyles(); + } + + private function enqueueScripts() + { + $script_path = 'build/block-checks.js'; + $script_handle = 'block-accessibility-script'; + wp_enqueue_script( $script_handle, plugins_url($script_path, $this->pluginFile), @@ -23,26 +33,27 @@ public function enqueueAssets() { filemtime(plugin_dir_path($this->pluginFile) . $script_path), true ); - - wp_enqueue_style( - 'block-checks-style', - plugins_url($style_path, $this->pluginFile), - [], - filemtime(plugin_dir_path($this->pluginFile) . $style_path) - ); - // Localize script with data from PHP + $this->localizeScript($script_handle); + } + + private function localizeScript($handle) + { wp_localize_script( - $script_handle, + $handle, 'blockAccessibilitySettings', ['mode' => BLOCK_ACCESSIBILITY_MODE] ); - - // Load the text domain for the script - wp_set_script_translations( - $script_handle, - 'block-accessibility-checks', - plugin_dir_path($this->pluginFile) . 'languages' + } + + private function enqueueStyles() + { + $style_path = 'build/block-checks.css'; + wp_enqueue_style( + 'block-checks-style', + plugins_url($style_path, $this->pluginFile), + [], + filemtime(plugin_dir_path($this->pluginFile) . $style_path) ); } } diff --git a/src/Translations.php b/src/Translations.php new file mode 100644 index 0000000..491c6e6 --- /dev/null +++ b/src/Translations.php @@ -0,0 +1,26 @@ +pluginFile = $pluginFile; + $this->textDomain = $textDomain; + } + + public function loadTextDomain() { + load_plugin_textdomain($this->textDomain, false, dirname(plugin_basename($this->pluginFile)) . '/languages/'); + } + + public function setupScriptTranslations($scriptHandle) { + wp_set_script_translations( + $scriptHandle, + $this->textDomain, + plugin_dir_path($this->pluginFile) . 'languages' + ); + } +} From 4e3cf44a54e99df7731dbba601b0b0477789be9a Mon Sep 17 00:00:00 2001 From: Michael Corkum Date: Tue, 23 Jul 2024 23:03:27 -0400 Subject: [PATCH 4/7] change: eslint ignore because I have to --- build/block-checks-rtl.css | 43 +- build/block-checks.asset.php | 2 +- build/block-checks.css | 45 +- build/block-checks.js | 537 +---------------------- src/scripts/helpers/blockInvalidation.js | 1 + 5 files changed, 5 insertions(+), 623 deletions(-) diff --git a/build/block-checks-rtl.css b/build/block-checks-rtl.css index fa72a73..cb16266 100644 --- a/build/block-checks-rtl.css +++ b/build/block-checks-rtl.css @@ -1,42 +1 @@ -/*!**************************************************************************************************************************************************************************!*\ - !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/styles/error.css ***! - \**************************************************************************************************************************************************************************/ -.a11y-block-error { - display: flex; - flex-direction: column; - gap: 18px; - width: 100%; - padding: 20px 24px; - margin-right: -24px; - background-color:#F7EDEC; - border: 3px dashed #8B3122; -} - -.a11y-error-msg { - /* display: flex; - gap: 6px; - align-items: center; */ - font-size: 16px; - line-height: 24px; - font-weight: 600; - color: white; - background-color: #8B3122; - padding: 5px 10px; -} - -/* Remove top spacing from block being wrapped */ -.a11y-error-msg + * { - margin-top: 0; -} - -/* Remove bottom spacing from block being wrapped */ -.a11y-block-error > *:last-child { - margin-bottom: 0; -} - -/* TODO: it's a mystery */ -.a11y-block-error.wp-block-heading { - padding-top: 0; - padding-bottom: 0; -} - +.a11y-block-error{background-color:#f7edec;border:3px dashed #8b3122;display:flex;flex-direction:column;gap:18px;margin-right:-24px;padding:20px 24px;width:100%}.a11y-error-msg{background-color:#8b3122;color:#fff;font-size:16px;font-weight:600;line-height:24px;padding:5px 10px}.a11y-error-msg+*{margin-top:0}.a11y-block-error>:last-child{margin-bottom:0}.a11y-block-error.wp-block-heading{padding-bottom:0;padding-top:0} diff --git a/build/block-checks.asset.php b/build/block-checks.asset.php index e5d00ee..9f6d0ba 100644 --- a/build/block-checks.asset.php +++ b/build/block-checks.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => '6808926b1de680bc5c42'); + array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => 'b6bbeb5f881b8ca07b5a'); diff --git a/build/block-checks.css b/build/block-checks.css index 208171a..8fedd65 100644 --- a/build/block-checks.css +++ b/build/block-checks.css @@ -1,44 +1 @@ -/*!**************************************************************************************************************************************************************************!*\ - !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/styles/error.css ***! - \**************************************************************************************************************************************************************************/ -.a11y-block-error { - display: flex; - flex-direction: column; - gap: 18px; - width: 100%; - padding: 20px 24px; - margin-left: -24px; - background-color:#F7EDEC; - border: 3px dashed #8B3122; -} - -.a11y-error-msg { - /* display: flex; - gap: 6px; - align-items: center; */ - font-size: 16px; - line-height: 24px; - font-weight: 600; - color: white; - background-color: #8B3122; - padding: 5px 10px; -} - -/* Remove top spacing from block being wrapped */ -.a11y-error-msg + * { - margin-top: 0; -} - -/* Remove bottom spacing from block being wrapped */ -.a11y-block-error > *:last-child { - margin-bottom: 0; -} - -/* TODO: it's a mystery */ -.a11y-block-error.wp-block-heading { - padding-top: 0; - padding-bottom: 0; -} - - -/*# sourceMappingURL=block-checks.css.map*/ \ No newline at end of file +.a11y-block-error{background-color:#f7edec;border:3px dashed #8b3122;display:flex;flex-direction:column;gap:18px;margin-left:-24px;padding:20px 24px;width:100%}.a11y-error-msg{background-color:#8b3122;color:#fff;font-size:16px;font-weight:600;line-height:24px;padding:5px 10px}.a11y-error-msg+*{margin-top:0}.a11y-block-error>:last-child{margin-bottom:0}.a11y-block-error.wp-block-heading{padding-bottom:0;padding-top:0} diff --git a/build/block-checks.js b/build/block-checks.js index 0270cb2..d9d0f50 100644 --- a/build/block-checks.js +++ b/build/block-checks.js @@ -1,536 +1 @@ -/******/ (() => { // webpackBootstrap -/******/ "use strict"; -/******/ var __webpack_modules__ = ({ - -/***/ "./src/scripts/blockChecks/checkButton.js": -/*!************************************************!*\ - !*** ./src/scripts/blockChecks/checkButton.js ***! - \************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ checkButtonAttributes: () => (/* binding */ checkButtonAttributes) -/* harmony export */ }); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); -function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } -function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } -function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } - -function checkButtonAttributes(block) { - var checkButton = function checkButton(innerBlocks, parentClientId) { - var _iterator = _createForOfIteratorHelper(innerBlocks), - _step; - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var innerBlock = _step.value; - if (innerBlock.name === 'core/button') { - var _innerBlock$attribute = innerBlock.attributes, - text = _innerBlock$attribute.text, - url = _innerBlock$attribute.url; - if (text === '' || url === undefined) { - return { - isValid: false, - message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Each button must have both text and URL.', 'block-accessibility-checks'), - clientId: parentClientId - }; - } - } - // Recursively check nested inner blocks - if (innerBlock.innerBlocks.length > 0) { - var result = checkButton(innerBlock.innerBlocks, parentClientId); - if (!result.isValid) { - return result; - } - } - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - return { - isValid: true - }; - }; - return checkButton(block.innerBlocks, block.clientId); -} - -/***/ }), - -/***/ "./src/scripts/blockChecks/checkHeading.js": -/*!*************************************************!*\ - !*** ./src/scripts/blockChecks/checkHeading.js ***! - \*************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ checkHeadingLevel: () => (/* binding */ checkHeadingLevel) -/* harmony export */ }); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); - -function checkHeadingLevel(block) { - if (block.name === 'core/heading' && block.attributes.level === 1) { - return { - isValid: false, - message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Level 1 headings are not allowed in your content area.', 'block-accessibility-checks'), - clientId: block.clientId - }; - } - return { - isValid: true - }; -} - -/***/ }), - -/***/ "./src/scripts/blockChecks/checkImage.js": -/*!***********************************************!*\ - !*** ./src/scripts/blockChecks/checkImage.js ***! - \***********************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ checkImageAlt: () => (/* binding */ checkImageAlt) -/* harmony export */ }); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); - -function checkImageAlt(block) { - if (block.name === 'core/image' && !block.attributes.alt && !block.attributes.isDecorative) { - return { - isValid: false, - message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Images are required to have alternative text.', 'block-accessibility-checks'), - clientId: block.clientId - }; - } - return { - isValid: true - }; -} - -/***/ }), - -/***/ "./src/scripts/blockChecks/checkTable.js": -/*!***********************************************!*\ - !*** ./src/scripts/blockChecks/checkTable.js ***! - \***********************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ checkTableHeaderRow: () => (/* binding */ checkTableHeaderRow) -/* harmony export */ }); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); - -function checkTableHeaderRow(block) { - if (block.name === 'core/table' && block.attributes.body.length !== 0 && block.attributes.head.length === 0) { - return { - isValid: false, - message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Tables are required to have a header row.', 'block-accessibility-checks'), - clientId: block.clientId - }; - } - return { - isValid: true - }; -} - -/***/ }), - -/***/ "./src/scripts/blockMods/imageAttr.js": -/*!********************************************!*\ - !*** ./src/scripts/blockMods/imageAttr.js ***! - \********************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks"); -/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); -/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__); -/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); -/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__); -/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); -/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__); - - - - - - -// Add image attribute to confirm decorative to bypass a11y block -var addImageAttribute = function addImageAttribute(settings) { - if (settings.name !== 'core/image') { - return settings; - } - settings.attributes = Object.assign(settings.attributes, { - isDecorative: { - type: 'boolean', - "default": false - } - }); - return settings; -}; -(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('blocks.registerBlockType', 'block-accessibility-checks/add-image-attribute', addImageAttribute); - -// Create a new block control for the attribute -var addImageInspectorControls = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__.createHigherOrderComponent)(function (BlockEdit) { - return function (props) { - if (props.name !== 'core/image') { - return /*#__PURE__*/React.createElement(BlockEdit, props); - } - var attributes = props.attributes, - setAttributes = props.setAttributes; - var isDecorative = attributes.isDecorative; - return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.InspectorControls, null, /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.PanelBody, { - title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Settings', 'block-accessibility-checks'), - initialOpen: true - }, /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToggleControl, { - label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Please confirm this image is decorative', 'block-accessibility-checks'), - checked: isDecorative, - onChange: function onChange(value) { - return setAttributes({ - isDecorative: value - }); - } - }))), /*#__PURE__*/React.createElement(BlockEdit, props)); - }; -}, 'addImageInspectorControls'); -(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('editor.BlockEdit', 'block-accessibility-checks/add-inspector-control', addImageInspectorControls); - -/***/ }), - -/***/ "./src/scripts/helpers/blockErrorComponent.js": -/*!****************************************************!*\ - !*** ./src/scripts/helpers/blockErrorComponent.js ***! - \****************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); -/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks"); -/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */ var _getInvalidBlocks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./getInvalidBlocks */ "./src/scripts/helpers/getInvalidBlocks.js"); -function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } - - - -var blockErrorComponent = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__.createHigherOrderComponent)(function (BlockListBlock) { - var WrappedBlock = function WrappedBlock(props) { - var invalidBlock = (0,_getInvalidBlocks__WEBPACK_IMPORTED_MODULE_2__.GetInvalidBlocks)().find(function (obj) { - return obj.clientId === props.clientId; - }); - var messages = invalidBlock ? invalidBlock.message : ''; - return /*#__PURE__*/React.createElement(React.Fragment, null, invalidBlock ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", { - className: "a11y-block-error" - }, /*#__PURE__*/React.createElement("div", { - className: "a11y-error-msg" - }, messages), /*#__PURE__*/React.createElement(BlockListBlock, _extends({}, props, { - className: "".concat(props.className) - })))) : /*#__PURE__*/React.createElement(BlockListBlock, _extends({}, props, { - className: "".concat(props.className) - }))); - }; - - // Set the displayName for debugging purposes - WrappedBlock.displayName = "a11yCheck(".concat(BlockListBlock.displayName || BlockListBlock.name || 'Component', ")"); - return WrappedBlock; -}, 'blockErrorComponent'); -(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('editor.BlockListBlock', 'block-accessibilty-checks/with-client-id-class-name', blockErrorComponent); - -/***/ }), - -/***/ "./src/scripts/helpers/blockInvalidation.js": -/*!**************************************************!*\ - !*** ./src/scripts/helpers/blockInvalidation.js ***! - \**************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ BlockInvalidation: () => (/* binding */ BlockInvalidation) -/* harmony export */ }); -/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); -/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _getInvalidBlocks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./getInvalidBlocks */ "./src/scripts/helpers/getInvalidBlocks.js"); -/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); -/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_2__); - - - -function BlockInvalidation() { - var invalidBlocks = (0,_getInvalidBlocks__WEBPACK_IMPORTED_MODULE_1__.GetInvalidBlocks)(); - var _useDispatch = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useDispatch)('core/editor'), - lockPostSaving = _useDispatch.lockPostSaving, - unlockPostSaving = _useDispatch.unlockPostSaving, - lockPostAutosaving = _useDispatch.lockPostAutosaving, - unlockPostAutosaving = _useDispatch.unlockPostAutosaving, - disablePublishSidebar = _useDispatch.disablePublishSidebar, - enablePublishSidebar = _useDispatch.enablePublishSidebar; - (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useEffect)(function () { - if (invalidBlocks.length > 0 && blockAccessibilitySettings.mode === 'DENY') { - lockPostSaving(); - lockPostAutosaving(); - disablePublishSidebar(); - } else { - unlockPostSaving(); - unlockPostAutosaving(); - enablePublishSidebar(); - } - }, [invalidBlocks, disablePublishSidebar, enablePublishSidebar, lockPostAutosaving, lockPostSaving, unlockPostAutosaving, unlockPostSaving]); - return null; -} - -/***/ }), - -/***/ "./src/scripts/helpers/getInvalidBlocks.js": -/*!*************************************************!*\ - !*** ./src/scripts/helpers/getInvalidBlocks.js ***! - \*************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ GetInvalidBlocks: () => (/* binding */ GetInvalidBlocks) -/* harmony export */ }); -/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); -/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _registerPlugin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../registerPlugin */ "./src/scripts/registerPlugin.js"); - - -function GetInvalidBlocks() { - var allBlocks = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useSelect)(function (select) { - return select('core/block-editor').getBlocks(); - }, []); - return allBlocks.flatMap(function (block) { - return _registerPlugin__WEBPACK_IMPORTED_MODULE_1__.blockChecksArray.map(function (check) { - return check(block); - }); - }).filter(function (result) { - return !result.isValid; - }); -} - -/***/ }), - -/***/ "./src/scripts/registerPlugin.js": -/*!***************************************!*\ - !*** ./src/scripts/registerPlugin.js ***! - \***************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ blockChecksArray: () => (/* binding */ blockChecksArray) -/* harmony export */ }); -/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/plugins */ "@wordpress/plugins"); -/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _helpers_blockInvalidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers/blockInvalidation */ "./src/scripts/helpers/blockInvalidation.js"); -/* harmony import */ var _helpers_blockErrorComponent__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helpers/blockErrorComponent */ "./src/scripts/helpers/blockErrorComponent.js"); -/* harmony import */ var _blockChecks_checkButton__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./blockChecks/checkButton */ "./src/scripts/blockChecks/checkButton.js"); -/* harmony import */ var _blockChecks_checkHeading__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./blockChecks/checkHeading */ "./src/scripts/blockChecks/checkHeading.js"); -/* harmony import */ var _blockChecks_checkImage__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./blockChecks/checkImage */ "./src/scripts/blockChecks/checkImage.js"); -/* harmony import */ var _blockChecks_checkTable__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./blockChecks/checkTable */ "./src/scripts/blockChecks/checkTable.js"); - - - - -// Import block check functions - - - - -var blockChecksArray = [_blockChecks_checkButton__WEBPACK_IMPORTED_MODULE_3__.checkButtonAttributes, _blockChecks_checkHeading__WEBPACK_IMPORTED_MODULE_4__.checkHeadingLevel, _blockChecks_checkImage__WEBPACK_IMPORTED_MODULE_5__.checkImageAlt, _blockChecks_checkTable__WEBPACK_IMPORTED_MODULE_6__.checkTableHeaderRow]; -(0,_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__.registerPlugin)('block-validation', { - render: _helpers_blockInvalidation__WEBPACK_IMPORTED_MODULE_1__.BlockInvalidation -}); - -/***/ }), - -/***/ "./src/styles/error.css": -/*!******************************!*\ - !*** ./src/styles/error.css ***! - \******************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -// extracted by mini-css-extract-plugin - - -/***/ }), - -/***/ "@wordpress/block-editor": -/*!*************************************!*\ - !*** external ["wp","blockEditor"] ***! - \*************************************/ -/***/ ((module) => { - -module.exports = window["wp"]["blockEditor"]; - -/***/ }), - -/***/ "@wordpress/components": -/*!************************************!*\ - !*** external ["wp","components"] ***! - \************************************/ -/***/ ((module) => { - -module.exports = window["wp"]["components"]; - -/***/ }), - -/***/ "@wordpress/compose": -/*!*********************************!*\ - !*** external ["wp","compose"] ***! - \*********************************/ -/***/ ((module) => { - -module.exports = window["wp"]["compose"]; - -/***/ }), - -/***/ "@wordpress/data": -/*!******************************!*\ - !*** external ["wp","data"] ***! - \******************************/ -/***/ ((module) => { - -module.exports = window["wp"]["data"]; - -/***/ }), - -/***/ "@wordpress/element": -/*!*********************************!*\ - !*** external ["wp","element"] ***! - \*********************************/ -/***/ ((module) => { - -module.exports = window["wp"]["element"]; - -/***/ }), - -/***/ "@wordpress/hooks": -/*!*******************************!*\ - !*** external ["wp","hooks"] ***! - \*******************************/ -/***/ ((module) => { - -module.exports = window["wp"]["hooks"]; - -/***/ }), - -/***/ "@wordpress/i18n": -/*!******************************!*\ - !*** external ["wp","i18n"] ***! - \******************************/ -/***/ ((module) => { - -module.exports = window["wp"]["i18n"]; - -/***/ }), - -/***/ "@wordpress/plugins": -/*!*********************************!*\ - !*** external ["wp","plugins"] ***! - \*********************************/ -/***/ ((module) => { - -module.exports = window["wp"]["plugins"]; - -/***/ }) - -/******/ }); -/************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ // Check if module is in cache -/******/ var cachedModule = __webpack_module_cache__[moduleId]; -/******/ if (cachedModule !== undefined) { -/******/ return cachedModule.exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/************************************************************************/ -/******/ /* webpack/runtime/compat get default export */ -/******/ (() => { -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = (module) => { -/******/ var getter = module && module.__esModule ? -/******/ () => (module['default']) : -/******/ () => (module); -/******/ __webpack_require__.d(getter, { a: getter }); -/******/ return getter; -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/define property getters */ -/******/ (() => { -/******/ // define getter functions for harmony exports -/******/ __webpack_require__.d = (exports, definition) => { -/******/ for(var key in definition) { -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); -/******/ } -/******/ } -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/hasOwnProperty shorthand */ -/******/ (() => { -/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) -/******/ })(); -/******/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __webpack_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ })(); -/******/ -/************************************************************************/ -var __webpack_exports__ = {}; -/*!***********************!*\ - !*** ./src/script.js ***! - \***********************/ -__webpack_require__.r(__webpack_exports__); -/* harmony import */ var _styles_error_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./styles/error.css */ "./src/styles/error.css"); -/* harmony import */ var _scripts_blockMods_imageAttr__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./scripts/blockMods/imageAttr */ "./src/scripts/blockMods/imageAttr.js"); -/* harmony import */ var _scripts_registerPlugin__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./scripts/registerPlugin */ "./src/scripts/registerPlugin.js"); - - -// Block Modifications - - -// Block Checks - -/******/ })() -; -//# sourceMappingURL=block-checks.js.map \ No newline at end of file +(()=>{"use strict";const e=window.wp.i18n,t=window.wp.hooks,n=window.wp.compose,r=window.wp.blockEditor,i=window.wp.components;(0,t.addFilter)("blocks.registerBlockType","block-accessibility-checks/add-image-attribute",(function(e){return"core/image"!==e.name||(e.attributes=Object.assign(e.attributes,{isDecorative:{type:"boolean",default:!1}})),e}));var a=(0,n.createHigherOrderComponent)((function(t){return function(n){if("core/image"!==n.name)return React.createElement(t,n);var a=n.attributes,c=n.setAttributes,o=a.isDecorative;return React.createElement(React.Fragment,null,React.createElement(r.InspectorControls,null,React.createElement(i.PanelBody,{title:(0,e.__)("Accessibility Settings","block-accessibility-checks"),initialOpen:!0},React.createElement(i.ToggleControl,{label:(0,e.__)("Please confirm this image is decorative","block-accessibility-checks"),checked:o,onChange:function(e){return c({isDecorative:e})}}))),React.createElement(t,n))}}),"addImageInspectorControls");(0,t.addFilter)("editor.BlockEdit","block-accessibility-checks/add-inspector-control",a);const c=window.wp.plugins,o=window.wp.data;function l(){return(0,o.useSelect)((function(e){return e("core/block-editor").getBlocks()}),[]).flatMap((function(e){return m.map((function(t){return t(e)}))})).filter((function(e){return!e.isValid}))}const s=window.wp.element;function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[_n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(n);try{for(a.s();!(i=a.n()).done;){var c=i.value;if("core/button"===c.name){var o=c.attributes,l=o.text,s=o.url;if(""===l||void 0===s)return{isValid:!1,message:(0,e.__)("Accessibility Error: Each button must have both text and URL.","block-accessibility-checks"),clientId:r}}if(c.innerBlocks.length>0){var u=t(c.innerBlocks,r);if(!u.isValid)return u}}}catch(e){a.e(e)}finally{a.f()}return{isValid:!0}}(t.innerBlocks,t.clientId)},function(t){return"core/heading"===t.name&&1===t.attributes.level?{isValid:!1,message:(0,e.__)("Accessibility Error: Level 1 headings are not allowed in your content area.","block-accessibility-checks"),clientId:t.clientId}:{isValid:!0}},function(t){return"core/image"!==t.name||t.attributes.alt||t.attributes.isDecorative?{isValid:!0}:{isValid:!1,message:(0,e.__)("Accessibility Error: Images are required to have alternative text.","block-accessibility-checks"),clientId:t.clientId}},function(t){return"core/table"===t.name&&0!==t.attributes.body.length&&0===t.attributes.head.length?{isValid:!1,message:(0,e.__)("Accessibility Error: Tables are required to have a header row.","block-accessibility-checks"),clientId:t.clientId}:{isValid:!0}}];(0,c.registerPlugin)("block-validation",{render:function(){var e=l(),t=(0,o.useDispatch)("core/editor"),n=t.lockPostSaving,r=t.unlockPostSaving,i=t.lockPostAutosaving,a=t.unlockPostAutosaving,c=t.disablePublishSidebar,u=t.enablePublishSidebar;return(0,s.useEffect)((function(){e.length>0&&"DENY"===blockAccessibilitySettings.mode?(n(),i(),c()):(r(),a(),u())}),[e,c,u,i,n,a,r]),null}})})(); \ No newline at end of file diff --git a/src/scripts/helpers/blockInvalidation.js b/src/scripts/helpers/blockInvalidation.js index f086aa7..0f35b52 100644 --- a/src/scripts/helpers/blockInvalidation.js +++ b/src/scripts/helpers/blockInvalidation.js @@ -17,6 +17,7 @@ export function BlockInvalidation() { useEffect(() => { if ( invalidBlocks.length > 0 && + // eslint-disable-next-line no-undef -- blockAccessibilitySettings is defined in PHP blockAccessibilitySettings.mode === 'DENY' ) { lockPostSaving(); From 2b85ce8e24a8c49f6a51b081d73b92fef0c77783 Mon Sep 17 00:00:00 2001 From: Michael Corkum Date: Tue, 23 Jul 2024 23:08:53 -0400 Subject: [PATCH 5/7] change: language in a comment for clarity --- block-accessibility-checks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block-accessibility-checks.php b/block-accessibility-checks.php index 8ec7d33..cb56a14 100644 --- a/block-accessibility-checks.php +++ b/block-accessibility-checks.php @@ -26,7 +26,7 @@ // Define constants if (!defined('BLOCK_ACCESSIBILITY_MODE')) { - define('BLOCK_ACCESSIBILITY_MODE', 'DENY'); // Default value, can be overridden in wp-config.php + define('BLOCK_ACCESSIBILITY_MODE', 'DENY'); // Default value, can be overridden with WARN in wp-config.php } // Include dependencies From 676e701fe9bd116ab4451b29ead65484c006c34a Mon Sep 17 00:00:00 2001 From: Michael Corkum Date: Tue, 23 Jul 2024 23:15:38 -0400 Subject: [PATCH 6/7] change: try to add variable to eslint another way --- build/block-checks-rtl.css | 43 +- build/block-checks.asset.php | 2 +- build/block-checks.js | 538 ++++++++++++++++++++++- src/scripts/helpers/blockInvalidation.js | 2 +- 4 files changed, 581 insertions(+), 4 deletions(-) diff --git a/build/block-checks-rtl.css b/build/block-checks-rtl.css index cb16266..fa72a73 100644 --- a/build/block-checks-rtl.css +++ b/build/block-checks-rtl.css @@ -1 +1,42 @@ -.a11y-block-error{background-color:#f7edec;border:3px dashed #8b3122;display:flex;flex-direction:column;gap:18px;margin-right:-24px;padding:20px 24px;width:100%}.a11y-error-msg{background-color:#8b3122;color:#fff;font-size:16px;font-weight:600;line-height:24px;padding:5px 10px}.a11y-error-msg+*{margin-top:0}.a11y-block-error>:last-child{margin-bottom:0}.a11y-block-error.wp-block-heading{padding-bottom:0;padding-top:0} +/*!**************************************************************************************************************************************************************************!*\ + !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/styles/error.css ***! + \**************************************************************************************************************************************************************************/ +.a11y-block-error { + display: flex; + flex-direction: column; + gap: 18px; + width: 100%; + padding: 20px 24px; + margin-right: -24px; + background-color:#F7EDEC; + border: 3px dashed #8B3122; +} + +.a11y-error-msg { + /* display: flex; + gap: 6px; + align-items: center; */ + font-size: 16px; + line-height: 24px; + font-weight: 600; + color: white; + background-color: #8B3122; + padding: 5px 10px; +} + +/* Remove top spacing from block being wrapped */ +.a11y-error-msg + * { + margin-top: 0; +} + +/* Remove bottom spacing from block being wrapped */ +.a11y-block-error > *:last-child { + margin-bottom: 0; +} + +/* TODO: it's a mystery */ +.a11y-block-error.wp-block-heading { + padding-top: 0; + padding-bottom: 0; +} + diff --git a/build/block-checks.asset.php b/build/block-checks.asset.php index 9f6d0ba..e3749fe 100644 --- a/build/block-checks.asset.php +++ b/build/block-checks.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => 'b6bbeb5f881b8ca07b5a'); + array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => 'ca4a37ccd34c667a3ed6'); diff --git a/build/block-checks.js b/build/block-checks.js index d9d0f50..6e23db9 100644 --- a/build/block-checks.js +++ b/build/block-checks.js @@ -1 +1,537 @@ -(()=>{"use strict";const e=window.wp.i18n,t=window.wp.hooks,n=window.wp.compose,r=window.wp.blockEditor,i=window.wp.components;(0,t.addFilter)("blocks.registerBlockType","block-accessibility-checks/add-image-attribute",(function(e){return"core/image"!==e.name||(e.attributes=Object.assign(e.attributes,{isDecorative:{type:"boolean",default:!1}})),e}));var a=(0,n.createHigherOrderComponent)((function(t){return function(n){if("core/image"!==n.name)return React.createElement(t,n);var a=n.attributes,c=n.setAttributes,o=a.isDecorative;return React.createElement(React.Fragment,null,React.createElement(r.InspectorControls,null,React.createElement(i.PanelBody,{title:(0,e.__)("Accessibility Settings","block-accessibility-checks"),initialOpen:!0},React.createElement(i.ToggleControl,{label:(0,e.__)("Please confirm this image is decorative","block-accessibility-checks"),checked:o,onChange:function(e){return c({isDecorative:e})}}))),React.createElement(t,n))}}),"addImageInspectorControls");(0,t.addFilter)("editor.BlockEdit","block-accessibility-checks/add-inspector-control",a);const c=window.wp.plugins,o=window.wp.data;function l(){return(0,o.useSelect)((function(e){return e("core/block-editor").getBlocks()}),[]).flatMap((function(e){return m.map((function(t){return t(e)}))})).filter((function(e){return!e.isValid}))}const s=window.wp.element;function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[_n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(n);try{for(a.s();!(i=a.n()).done;){var c=i.value;if("core/button"===c.name){var o=c.attributes,l=o.text,s=o.url;if(""===l||void 0===s)return{isValid:!1,message:(0,e.__)("Accessibility Error: Each button must have both text and URL.","block-accessibility-checks"),clientId:r}}if(c.innerBlocks.length>0){var u=t(c.innerBlocks,r);if(!u.isValid)return u}}}catch(e){a.e(e)}finally{a.f()}return{isValid:!0}}(t.innerBlocks,t.clientId)},function(t){return"core/heading"===t.name&&1===t.attributes.level?{isValid:!1,message:(0,e.__)("Accessibility Error: Level 1 headings are not allowed in your content area.","block-accessibility-checks"),clientId:t.clientId}:{isValid:!0}},function(t){return"core/image"!==t.name||t.attributes.alt||t.attributes.isDecorative?{isValid:!0}:{isValid:!1,message:(0,e.__)("Accessibility Error: Images are required to have alternative text.","block-accessibility-checks"),clientId:t.clientId}},function(t){return"core/table"===t.name&&0!==t.attributes.body.length&&0===t.attributes.head.length?{isValid:!1,message:(0,e.__)("Accessibility Error: Tables are required to have a header row.","block-accessibility-checks"),clientId:t.clientId}:{isValid:!0}}];(0,c.registerPlugin)("block-validation",{render:function(){var e=l(),t=(0,o.useDispatch)("core/editor"),n=t.lockPostSaving,r=t.unlockPostSaving,i=t.lockPostAutosaving,a=t.unlockPostAutosaving,c=t.disablePublishSidebar,u=t.enablePublishSidebar;return(0,s.useEffect)((function(){e.length>0&&"DENY"===blockAccessibilitySettings.mode?(n(),i(),c()):(r(),a(),u())}),[e,c,u,i,n,a,r]),null}})})(); \ No newline at end of file +/******/ (() => { // webpackBootstrap +/******/ "use strict"; +/******/ var __webpack_modules__ = ({ + +/***/ "./src/scripts/blockChecks/checkButton.js": +/*!************************************************!*\ + !*** ./src/scripts/blockChecks/checkButton.js ***! + \************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ checkButtonAttributes: () => (/* binding */ checkButtonAttributes) +/* harmony export */ }); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); +function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } +function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } +function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } + +function checkButtonAttributes(block) { + var checkButton = function checkButton(innerBlocks, parentClientId) { + var _iterator = _createForOfIteratorHelper(innerBlocks), + _step; + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var innerBlock = _step.value; + if (innerBlock.name === 'core/button') { + var _innerBlock$attribute = innerBlock.attributes, + text = _innerBlock$attribute.text, + url = _innerBlock$attribute.url; + if (text === '' || url === undefined) { + return { + isValid: false, + message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Each button must have both text and URL.', 'block-accessibility-checks'), + clientId: parentClientId + }; + } + } + // Recursively check nested inner blocks + if (innerBlock.innerBlocks.length > 0) { + var result = checkButton(innerBlock.innerBlocks, parentClientId); + if (!result.isValid) { + return result; + } + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + return { + isValid: true + }; + }; + return checkButton(block.innerBlocks, block.clientId); +} + +/***/ }), + +/***/ "./src/scripts/blockChecks/checkHeading.js": +/*!*************************************************!*\ + !*** ./src/scripts/blockChecks/checkHeading.js ***! + \*************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ checkHeadingLevel: () => (/* binding */ checkHeadingLevel) +/* harmony export */ }); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); + +function checkHeadingLevel(block) { + if (block.name === 'core/heading' && block.attributes.level === 1) { + return { + isValid: false, + message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Level 1 headings are not allowed in your content area.', 'block-accessibility-checks'), + clientId: block.clientId + }; + } + return { + isValid: true + }; +} + +/***/ }), + +/***/ "./src/scripts/blockChecks/checkImage.js": +/*!***********************************************!*\ + !*** ./src/scripts/blockChecks/checkImage.js ***! + \***********************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ checkImageAlt: () => (/* binding */ checkImageAlt) +/* harmony export */ }); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); + +function checkImageAlt(block) { + if (block.name === 'core/image' && !block.attributes.alt && !block.attributes.isDecorative) { + return { + isValid: false, + message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Images are required to have alternative text.', 'block-accessibility-checks'), + clientId: block.clientId + }; + } + return { + isValid: true + }; +} + +/***/ }), + +/***/ "./src/scripts/blockChecks/checkTable.js": +/*!***********************************************!*\ + !*** ./src/scripts/blockChecks/checkTable.js ***! + \***********************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ checkTableHeaderRow: () => (/* binding */ checkTableHeaderRow) +/* harmony export */ }); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); + +function checkTableHeaderRow(block) { + if (block.name === 'core/table' && block.attributes.body.length !== 0 && block.attributes.head.length === 0) { + return { + isValid: false, + message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Tables are required to have a header row.', 'block-accessibility-checks'), + clientId: block.clientId + }; + } + return { + isValid: true + }; +} + +/***/ }), + +/***/ "./src/scripts/blockMods/imageAttr.js": +/*!********************************************!*\ + !*** ./src/scripts/blockMods/imageAttr.js ***! + \********************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); +/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks"); +/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); +/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); +/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); +/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__); + + + + + + +// Add image attribute to confirm decorative to bypass a11y block +var addImageAttribute = function addImageAttribute(settings) { + if (settings.name !== 'core/image') { + return settings; + } + settings.attributes = Object.assign(settings.attributes, { + isDecorative: { + type: 'boolean', + "default": false + } + }); + return settings; +}; +(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('blocks.registerBlockType', 'block-accessibility-checks/add-image-attribute', addImageAttribute); + +// Create a new block control for the attribute +var addImageInspectorControls = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__.createHigherOrderComponent)(function (BlockEdit) { + return function (props) { + if (props.name !== 'core/image') { + return /*#__PURE__*/React.createElement(BlockEdit, props); + } + var attributes = props.attributes, + setAttributes = props.setAttributes; + var isDecorative = attributes.isDecorative; + return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.InspectorControls, null, /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.PanelBody, { + title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Settings', 'block-accessibility-checks'), + initialOpen: true + }, /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToggleControl, { + label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Please confirm this image is decorative', 'block-accessibility-checks'), + checked: isDecorative, + onChange: function onChange(value) { + return setAttributes({ + isDecorative: value + }); + } + }))), /*#__PURE__*/React.createElement(BlockEdit, props)); + }; +}, 'addImageInspectorControls'); +(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('editor.BlockEdit', 'block-accessibility-checks/add-inspector-control', addImageInspectorControls); + +/***/ }), + +/***/ "./src/scripts/helpers/blockErrorComponent.js": +/*!****************************************************!*\ + !*** ./src/scripts/helpers/blockErrorComponent.js ***! + \****************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); +/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks"); +/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _getInvalidBlocks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./getInvalidBlocks */ "./src/scripts/helpers/getInvalidBlocks.js"); +function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } + + + +var blockErrorComponent = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__.createHigherOrderComponent)(function (BlockListBlock) { + var WrappedBlock = function WrappedBlock(props) { + var invalidBlock = (0,_getInvalidBlocks__WEBPACK_IMPORTED_MODULE_2__.GetInvalidBlocks)().find(function (obj) { + return obj.clientId === props.clientId; + }); + var messages = invalidBlock ? invalidBlock.message : ''; + return /*#__PURE__*/React.createElement(React.Fragment, null, invalidBlock ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", { + className: "a11y-block-error" + }, /*#__PURE__*/React.createElement("div", { + className: "a11y-error-msg" + }, messages), /*#__PURE__*/React.createElement(BlockListBlock, _extends({}, props, { + className: "".concat(props.className) + })))) : /*#__PURE__*/React.createElement(BlockListBlock, _extends({}, props, { + className: "".concat(props.className) + }))); + }; + + // Set the displayName for debugging purposes + WrappedBlock.displayName = "a11yCheck(".concat(BlockListBlock.displayName || BlockListBlock.name || 'Component', ")"); + return WrappedBlock; +}, 'blockErrorComponent'); +(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('editor.BlockListBlock', 'block-accessibilty-checks/with-client-id-class-name', blockErrorComponent); + +/***/ }), + +/***/ "./src/scripts/helpers/blockInvalidation.js": +/*!**************************************************!*\ + !*** ./src/scripts/helpers/blockInvalidation.js ***! + \**************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ BlockInvalidation: () => (/* binding */ BlockInvalidation) +/* harmony export */ }); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _getInvalidBlocks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./getInvalidBlocks */ "./src/scripts/helpers/getInvalidBlocks.js"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); +/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_2__); +/* global blockAccessibilitySettings */ + + + +function BlockInvalidation() { + var invalidBlocks = (0,_getInvalidBlocks__WEBPACK_IMPORTED_MODULE_1__.GetInvalidBlocks)(); + var _useDispatch = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useDispatch)('core/editor'), + lockPostSaving = _useDispatch.lockPostSaving, + unlockPostSaving = _useDispatch.unlockPostSaving, + lockPostAutosaving = _useDispatch.lockPostAutosaving, + unlockPostAutosaving = _useDispatch.unlockPostAutosaving, + disablePublishSidebar = _useDispatch.disablePublishSidebar, + enablePublishSidebar = _useDispatch.enablePublishSidebar; + (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useEffect)(function () { + if (invalidBlocks.length > 0 && blockAccessibilitySettings.mode === 'DENY') { + lockPostSaving(); + lockPostAutosaving(); + disablePublishSidebar(); + } else { + unlockPostSaving(); + unlockPostAutosaving(); + enablePublishSidebar(); + } + }, [invalidBlocks, disablePublishSidebar, enablePublishSidebar, lockPostAutosaving, lockPostSaving, unlockPostAutosaving, unlockPostSaving]); + return null; +} + +/***/ }), + +/***/ "./src/scripts/helpers/getInvalidBlocks.js": +/*!*************************************************!*\ + !*** ./src/scripts/helpers/getInvalidBlocks.js ***! + \*************************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ GetInvalidBlocks: () => (/* binding */ GetInvalidBlocks) +/* harmony export */ }); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); +/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _registerPlugin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../registerPlugin */ "./src/scripts/registerPlugin.js"); + + +function GetInvalidBlocks() { + var allBlocks = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useSelect)(function (select) { + return select('core/block-editor').getBlocks(); + }, []); + return allBlocks.flatMap(function (block) { + return _registerPlugin__WEBPACK_IMPORTED_MODULE_1__.blockChecksArray.map(function (check) { + return check(block); + }); + }).filter(function (result) { + return !result.isValid; + }); +} + +/***/ }), + +/***/ "./src/scripts/registerPlugin.js": +/*!***************************************!*\ + !*** ./src/scripts/registerPlugin.js ***! + \***************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ blockChecksArray: () => (/* binding */ blockChecksArray) +/* harmony export */ }); +/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/plugins */ "@wordpress/plugins"); +/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _helpers_blockInvalidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers/blockInvalidation */ "./src/scripts/helpers/blockInvalidation.js"); +/* harmony import */ var _helpers_blockErrorComponent__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helpers/blockErrorComponent */ "./src/scripts/helpers/blockErrorComponent.js"); +/* harmony import */ var _blockChecks_checkButton__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./blockChecks/checkButton */ "./src/scripts/blockChecks/checkButton.js"); +/* harmony import */ var _blockChecks_checkHeading__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./blockChecks/checkHeading */ "./src/scripts/blockChecks/checkHeading.js"); +/* harmony import */ var _blockChecks_checkImage__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./blockChecks/checkImage */ "./src/scripts/blockChecks/checkImage.js"); +/* harmony import */ var _blockChecks_checkTable__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./blockChecks/checkTable */ "./src/scripts/blockChecks/checkTable.js"); + + + + +// Import block check functions + + + + +var blockChecksArray = [_blockChecks_checkButton__WEBPACK_IMPORTED_MODULE_3__.checkButtonAttributes, _blockChecks_checkHeading__WEBPACK_IMPORTED_MODULE_4__.checkHeadingLevel, _blockChecks_checkImage__WEBPACK_IMPORTED_MODULE_5__.checkImageAlt, _blockChecks_checkTable__WEBPACK_IMPORTED_MODULE_6__.checkTableHeaderRow]; +(0,_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__.registerPlugin)('block-validation', { + render: _helpers_blockInvalidation__WEBPACK_IMPORTED_MODULE_1__.BlockInvalidation +}); + +/***/ }), + +/***/ "./src/styles/error.css": +/*!******************************!*\ + !*** ./src/styles/error.css ***! + \******************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +// extracted by mini-css-extract-plugin + + +/***/ }), + +/***/ "@wordpress/block-editor": +/*!*************************************!*\ + !*** external ["wp","blockEditor"] ***! + \*************************************/ +/***/ ((module) => { + +module.exports = window["wp"]["blockEditor"]; + +/***/ }), + +/***/ "@wordpress/components": +/*!************************************!*\ + !*** external ["wp","components"] ***! + \************************************/ +/***/ ((module) => { + +module.exports = window["wp"]["components"]; + +/***/ }), + +/***/ "@wordpress/compose": +/*!*********************************!*\ + !*** external ["wp","compose"] ***! + \*********************************/ +/***/ ((module) => { + +module.exports = window["wp"]["compose"]; + +/***/ }), + +/***/ "@wordpress/data": +/*!******************************!*\ + !*** external ["wp","data"] ***! + \******************************/ +/***/ ((module) => { + +module.exports = window["wp"]["data"]; + +/***/ }), + +/***/ "@wordpress/element": +/*!*********************************!*\ + !*** external ["wp","element"] ***! + \*********************************/ +/***/ ((module) => { + +module.exports = window["wp"]["element"]; + +/***/ }), + +/***/ "@wordpress/hooks": +/*!*******************************!*\ + !*** external ["wp","hooks"] ***! + \*******************************/ +/***/ ((module) => { + +module.exports = window["wp"]["hooks"]; + +/***/ }), + +/***/ "@wordpress/i18n": +/*!******************************!*\ + !*** external ["wp","i18n"] ***! + \******************************/ +/***/ ((module) => { + +module.exports = window["wp"]["i18n"]; + +/***/ }), + +/***/ "@wordpress/plugins": +/*!*********************************!*\ + !*** external ["wp","plugins"] ***! + \*********************************/ +/***/ ((module) => { + +module.exports = window["wp"]["plugins"]; + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __webpack_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __webpack_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __webpack_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ +/************************************************************************/ +var __webpack_exports__ = {}; +/*!***********************!*\ + !*** ./src/script.js ***! + \***********************/ +__webpack_require__.r(__webpack_exports__); +/* harmony import */ var _styles_error_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./styles/error.css */ "./src/styles/error.css"); +/* harmony import */ var _scripts_blockMods_imageAttr__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./scripts/blockMods/imageAttr */ "./src/scripts/blockMods/imageAttr.js"); +/* harmony import */ var _scripts_registerPlugin__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./scripts/registerPlugin */ "./src/scripts/registerPlugin.js"); + + +// Block Modifications + + +// Block Checks + +/******/ })() +; +//# sourceMappingURL=block-checks.js.map \ No newline at end of file diff --git a/src/scripts/helpers/blockInvalidation.js b/src/scripts/helpers/blockInvalidation.js index 0f35b52..498a673 100644 --- a/src/scripts/helpers/blockInvalidation.js +++ b/src/scripts/helpers/blockInvalidation.js @@ -1,3 +1,4 @@ +/* global blockAccessibilitySettings */ import { useDispatch } from '@wordpress/data'; import { GetInvalidBlocks } from './getInvalidBlocks'; import { useEffect } from '@wordpress/element'; @@ -17,7 +18,6 @@ export function BlockInvalidation() { useEffect(() => { if ( invalidBlocks.length > 0 && - // eslint-disable-next-line no-undef -- blockAccessibilitySettings is defined in PHP blockAccessibilitySettings.mode === 'DENY' ) { lockPostSaving(); From 179b72a1fd1afbf5299757f090ddf2cd13f8119a Mon Sep 17 00:00:00 2001 From: Michael Corkum Date: Tue, 23 Jul 2024 23:16:58 -0400 Subject: [PATCH 7/7] change: add build --- build/block-checks-rtl.css | 43 +-- build/block-checks.asset.php | 2 +- build/block-checks.js | 538 +---------------------------------- 3 files changed, 3 insertions(+), 580 deletions(-) diff --git a/build/block-checks-rtl.css b/build/block-checks-rtl.css index fa72a73..cb16266 100644 --- a/build/block-checks-rtl.css +++ b/build/block-checks-rtl.css @@ -1,42 +1 @@ -/*!**************************************************************************************************************************************************************************!*\ - !*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[2].use[2]!./src/styles/error.css ***! - \**************************************************************************************************************************************************************************/ -.a11y-block-error { - display: flex; - flex-direction: column; - gap: 18px; - width: 100%; - padding: 20px 24px; - margin-right: -24px; - background-color:#F7EDEC; - border: 3px dashed #8B3122; -} - -.a11y-error-msg { - /* display: flex; - gap: 6px; - align-items: center; */ - font-size: 16px; - line-height: 24px; - font-weight: 600; - color: white; - background-color: #8B3122; - padding: 5px 10px; -} - -/* Remove top spacing from block being wrapped */ -.a11y-error-msg + * { - margin-top: 0; -} - -/* Remove bottom spacing from block being wrapped */ -.a11y-block-error > *:last-child { - margin-bottom: 0; -} - -/* TODO: it's a mystery */ -.a11y-block-error.wp-block-heading { - padding-top: 0; - padding-bottom: 0; -} - +.a11y-block-error{background-color:#f7edec;border:3px dashed #8b3122;display:flex;flex-direction:column;gap:18px;margin-right:-24px;padding:20px 24px;width:100%}.a11y-error-msg{background-color:#8b3122;color:#fff;font-size:16px;font-weight:600;line-height:24px;padding:5px 10px}.a11y-error-msg+*{margin-top:0}.a11y-block-error>:last-child{margin-bottom:0}.a11y-block-error.wp-block-heading{padding-bottom:0;padding-top:0} diff --git a/build/block-checks.asset.php b/build/block-checks.asset.php index e3749fe..9f6d0ba 100644 --- a/build/block-checks.asset.php +++ b/build/block-checks.asset.php @@ -1 +1 @@ - array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => 'ca4a37ccd34c667a3ed6'); + array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => 'b6bbeb5f881b8ca07b5a'); diff --git a/build/block-checks.js b/build/block-checks.js index 6e23db9..d9d0f50 100644 --- a/build/block-checks.js +++ b/build/block-checks.js @@ -1,537 +1 @@ -/******/ (() => { // webpackBootstrap -/******/ "use strict"; -/******/ var __webpack_modules__ = ({ - -/***/ "./src/scripts/blockChecks/checkButton.js": -/*!************************************************!*\ - !*** ./src/scripts/blockChecks/checkButton.js ***! - \************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ checkButtonAttributes: () => (/* binding */ checkButtonAttributes) -/* harmony export */ }); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); -function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } -function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } -function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } - -function checkButtonAttributes(block) { - var checkButton = function checkButton(innerBlocks, parentClientId) { - var _iterator = _createForOfIteratorHelper(innerBlocks), - _step; - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - var innerBlock = _step.value; - if (innerBlock.name === 'core/button') { - var _innerBlock$attribute = innerBlock.attributes, - text = _innerBlock$attribute.text, - url = _innerBlock$attribute.url; - if (text === '' || url === undefined) { - return { - isValid: false, - message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Each button must have both text and URL.', 'block-accessibility-checks'), - clientId: parentClientId - }; - } - } - // Recursively check nested inner blocks - if (innerBlock.innerBlocks.length > 0) { - var result = checkButton(innerBlock.innerBlocks, parentClientId); - if (!result.isValid) { - return result; - } - } - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - return { - isValid: true - }; - }; - return checkButton(block.innerBlocks, block.clientId); -} - -/***/ }), - -/***/ "./src/scripts/blockChecks/checkHeading.js": -/*!*************************************************!*\ - !*** ./src/scripts/blockChecks/checkHeading.js ***! - \*************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ checkHeadingLevel: () => (/* binding */ checkHeadingLevel) -/* harmony export */ }); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); - -function checkHeadingLevel(block) { - if (block.name === 'core/heading' && block.attributes.level === 1) { - return { - isValid: false, - message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Level 1 headings are not allowed in your content area.', 'block-accessibility-checks'), - clientId: block.clientId - }; - } - return { - isValid: true - }; -} - -/***/ }), - -/***/ "./src/scripts/blockChecks/checkImage.js": -/*!***********************************************!*\ - !*** ./src/scripts/blockChecks/checkImage.js ***! - \***********************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ checkImageAlt: () => (/* binding */ checkImageAlt) -/* harmony export */ }); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); - -function checkImageAlt(block) { - if (block.name === 'core/image' && !block.attributes.alt && !block.attributes.isDecorative) { - return { - isValid: false, - message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Images are required to have alternative text.', 'block-accessibility-checks'), - clientId: block.clientId - }; - } - return { - isValid: true - }; -} - -/***/ }), - -/***/ "./src/scripts/blockChecks/checkTable.js": -/*!***********************************************!*\ - !*** ./src/scripts/blockChecks/checkTable.js ***! - \***********************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ checkTableHeaderRow: () => (/* binding */ checkTableHeaderRow) -/* harmony export */ }); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); - -function checkTableHeaderRow(block) { - if (block.name === 'core/table' && block.attributes.body.length !== 0 && block.attributes.head.length === 0) { - return { - isValid: false, - message: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Error: Tables are required to have a header row.', 'block-accessibility-checks'), - clientId: block.clientId - }; - } - return { - isValid: true - }; -} - -/***/ }), - -/***/ "./src/scripts/blockMods/imageAttr.js": -/*!********************************************!*\ - !*** ./src/scripts/blockMods/imageAttr.js ***! - \********************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); -/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks"); -/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); -/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__); -/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); -/* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__); -/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); -/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__); - - - - - - -// Add image attribute to confirm decorative to bypass a11y block -var addImageAttribute = function addImageAttribute(settings) { - if (settings.name !== 'core/image') { - return settings; - } - settings.attributes = Object.assign(settings.attributes, { - isDecorative: { - type: 'boolean', - "default": false - } - }); - return settings; -}; -(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('blocks.registerBlockType', 'block-accessibility-checks/add-image-attribute', addImageAttribute); - -// Create a new block control for the attribute -var addImageInspectorControls = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__.createHigherOrderComponent)(function (BlockEdit) { - return function (props) { - if (props.name !== 'core/image') { - return /*#__PURE__*/React.createElement(BlockEdit, props); - } - var attributes = props.attributes, - setAttributes = props.setAttributes; - var isDecorative = attributes.isDecorative; - return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.InspectorControls, null, /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.PanelBody, { - title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Accessibility Settings', 'block-accessibility-checks'), - initialOpen: true - }, /*#__PURE__*/React.createElement(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ToggleControl, { - label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Please confirm this image is decorative', 'block-accessibility-checks'), - checked: isDecorative, - onChange: function onChange(value) { - return setAttributes({ - isDecorative: value - }); - } - }))), /*#__PURE__*/React.createElement(BlockEdit, props)); - }; -}, 'addImageInspectorControls'); -(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('editor.BlockEdit', 'block-accessibility-checks/add-inspector-control', addImageInspectorControls); - -/***/ }), - -/***/ "./src/scripts/helpers/blockErrorComponent.js": -/*!****************************************************!*\ - !*** ./src/scripts/helpers/blockErrorComponent.js ***! - \****************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); -/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks"); -/* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */ var _getInvalidBlocks__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./getInvalidBlocks */ "./src/scripts/helpers/getInvalidBlocks.js"); -function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } - - - -var blockErrorComponent = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_0__.createHigherOrderComponent)(function (BlockListBlock) { - var WrappedBlock = function WrappedBlock(props) { - var invalidBlock = (0,_getInvalidBlocks__WEBPACK_IMPORTED_MODULE_2__.GetInvalidBlocks)().find(function (obj) { - return obj.clientId === props.clientId; - }); - var messages = invalidBlock ? invalidBlock.message : ''; - return /*#__PURE__*/React.createElement(React.Fragment, null, invalidBlock ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", { - className: "a11y-block-error" - }, /*#__PURE__*/React.createElement("div", { - className: "a11y-error-msg" - }, messages), /*#__PURE__*/React.createElement(BlockListBlock, _extends({}, props, { - className: "".concat(props.className) - })))) : /*#__PURE__*/React.createElement(BlockListBlock, _extends({}, props, { - className: "".concat(props.className) - }))); - }; - - // Set the displayName for debugging purposes - WrappedBlock.displayName = "a11yCheck(".concat(BlockListBlock.displayName || BlockListBlock.name || 'Component', ")"); - return WrappedBlock; -}, 'blockErrorComponent'); -(0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('editor.BlockListBlock', 'block-accessibilty-checks/with-client-id-class-name', blockErrorComponent); - -/***/ }), - -/***/ "./src/scripts/helpers/blockInvalidation.js": -/*!**************************************************!*\ - !*** ./src/scripts/helpers/blockInvalidation.js ***! - \**************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ BlockInvalidation: () => (/* binding */ BlockInvalidation) -/* harmony export */ }); -/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); -/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _getInvalidBlocks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./getInvalidBlocks */ "./src/scripts/helpers/getInvalidBlocks.js"); -/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); -/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_2__); -/* global blockAccessibilitySettings */ - - - -function BlockInvalidation() { - var invalidBlocks = (0,_getInvalidBlocks__WEBPACK_IMPORTED_MODULE_1__.GetInvalidBlocks)(); - var _useDispatch = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useDispatch)('core/editor'), - lockPostSaving = _useDispatch.lockPostSaving, - unlockPostSaving = _useDispatch.unlockPostSaving, - lockPostAutosaving = _useDispatch.lockPostAutosaving, - unlockPostAutosaving = _useDispatch.unlockPostAutosaving, - disablePublishSidebar = _useDispatch.disablePublishSidebar, - enablePublishSidebar = _useDispatch.enablePublishSidebar; - (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_2__.useEffect)(function () { - if (invalidBlocks.length > 0 && blockAccessibilitySettings.mode === 'DENY') { - lockPostSaving(); - lockPostAutosaving(); - disablePublishSidebar(); - } else { - unlockPostSaving(); - unlockPostAutosaving(); - enablePublishSidebar(); - } - }, [invalidBlocks, disablePublishSidebar, enablePublishSidebar, lockPostAutosaving, lockPostSaving, unlockPostAutosaving, unlockPostSaving]); - return null; -} - -/***/ }), - -/***/ "./src/scripts/helpers/getInvalidBlocks.js": -/*!*************************************************!*\ - !*** ./src/scripts/helpers/getInvalidBlocks.js ***! - \*************************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ GetInvalidBlocks: () => (/* binding */ GetInvalidBlocks) -/* harmony export */ }); -/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); -/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _registerPlugin__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../registerPlugin */ "./src/scripts/registerPlugin.js"); - - -function GetInvalidBlocks() { - var allBlocks = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useSelect)(function (select) { - return select('core/block-editor').getBlocks(); - }, []); - return allBlocks.flatMap(function (block) { - return _registerPlugin__WEBPACK_IMPORTED_MODULE_1__.blockChecksArray.map(function (check) { - return check(block); - }); - }).filter(function (result) { - return !result.isValid; - }); -} - -/***/ }), - -/***/ "./src/scripts/registerPlugin.js": -/*!***************************************!*\ - !*** ./src/scripts/registerPlugin.js ***! - \***************************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ blockChecksArray: () => (/* binding */ blockChecksArray) -/* harmony export */ }); -/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/plugins */ "@wordpress/plugins"); -/* harmony import */ var _wordpress_plugins__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _helpers_blockInvalidation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers/blockInvalidation */ "./src/scripts/helpers/blockInvalidation.js"); -/* harmony import */ var _helpers_blockErrorComponent__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./helpers/blockErrorComponent */ "./src/scripts/helpers/blockErrorComponent.js"); -/* harmony import */ var _blockChecks_checkButton__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./blockChecks/checkButton */ "./src/scripts/blockChecks/checkButton.js"); -/* harmony import */ var _blockChecks_checkHeading__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./blockChecks/checkHeading */ "./src/scripts/blockChecks/checkHeading.js"); -/* harmony import */ var _blockChecks_checkImage__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./blockChecks/checkImage */ "./src/scripts/blockChecks/checkImage.js"); -/* harmony import */ var _blockChecks_checkTable__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./blockChecks/checkTable */ "./src/scripts/blockChecks/checkTable.js"); - - - - -// Import block check functions - - - - -var blockChecksArray = [_blockChecks_checkButton__WEBPACK_IMPORTED_MODULE_3__.checkButtonAttributes, _blockChecks_checkHeading__WEBPACK_IMPORTED_MODULE_4__.checkHeadingLevel, _blockChecks_checkImage__WEBPACK_IMPORTED_MODULE_5__.checkImageAlt, _blockChecks_checkTable__WEBPACK_IMPORTED_MODULE_6__.checkTableHeaderRow]; -(0,_wordpress_plugins__WEBPACK_IMPORTED_MODULE_0__.registerPlugin)('block-validation', { - render: _helpers_blockInvalidation__WEBPACK_IMPORTED_MODULE_1__.BlockInvalidation -}); - -/***/ }), - -/***/ "./src/styles/error.css": -/*!******************************!*\ - !*** ./src/styles/error.css ***! - \******************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -// extracted by mini-css-extract-plugin - - -/***/ }), - -/***/ "@wordpress/block-editor": -/*!*************************************!*\ - !*** external ["wp","blockEditor"] ***! - \*************************************/ -/***/ ((module) => { - -module.exports = window["wp"]["blockEditor"]; - -/***/ }), - -/***/ "@wordpress/components": -/*!************************************!*\ - !*** external ["wp","components"] ***! - \************************************/ -/***/ ((module) => { - -module.exports = window["wp"]["components"]; - -/***/ }), - -/***/ "@wordpress/compose": -/*!*********************************!*\ - !*** external ["wp","compose"] ***! - \*********************************/ -/***/ ((module) => { - -module.exports = window["wp"]["compose"]; - -/***/ }), - -/***/ "@wordpress/data": -/*!******************************!*\ - !*** external ["wp","data"] ***! - \******************************/ -/***/ ((module) => { - -module.exports = window["wp"]["data"]; - -/***/ }), - -/***/ "@wordpress/element": -/*!*********************************!*\ - !*** external ["wp","element"] ***! - \*********************************/ -/***/ ((module) => { - -module.exports = window["wp"]["element"]; - -/***/ }), - -/***/ "@wordpress/hooks": -/*!*******************************!*\ - !*** external ["wp","hooks"] ***! - \*******************************/ -/***/ ((module) => { - -module.exports = window["wp"]["hooks"]; - -/***/ }), - -/***/ "@wordpress/i18n": -/*!******************************!*\ - !*** external ["wp","i18n"] ***! - \******************************/ -/***/ ((module) => { - -module.exports = window["wp"]["i18n"]; - -/***/ }), - -/***/ "@wordpress/plugins": -/*!*********************************!*\ - !*** external ["wp","plugins"] ***! - \*********************************/ -/***/ ((module) => { - -module.exports = window["wp"]["plugins"]; - -/***/ }) - -/******/ }); -/************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ // Check if module is in cache -/******/ var cachedModule = __webpack_module_cache__[moduleId]; -/******/ if (cachedModule !== undefined) { -/******/ return cachedModule.exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/************************************************************************/ -/******/ /* webpack/runtime/compat get default export */ -/******/ (() => { -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = (module) => { -/******/ var getter = module && module.__esModule ? -/******/ () => (module['default']) : -/******/ () => (module); -/******/ __webpack_require__.d(getter, { a: getter }); -/******/ return getter; -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/define property getters */ -/******/ (() => { -/******/ // define getter functions for harmony exports -/******/ __webpack_require__.d = (exports, definition) => { -/******/ for(var key in definition) { -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); -/******/ } -/******/ } -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/hasOwnProperty shorthand */ -/******/ (() => { -/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) -/******/ })(); -/******/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __webpack_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ })(); -/******/ -/************************************************************************/ -var __webpack_exports__ = {}; -/*!***********************!*\ - !*** ./src/script.js ***! - \***********************/ -__webpack_require__.r(__webpack_exports__); -/* harmony import */ var _styles_error_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./styles/error.css */ "./src/styles/error.css"); -/* harmony import */ var _scripts_blockMods_imageAttr__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./scripts/blockMods/imageAttr */ "./src/scripts/blockMods/imageAttr.js"); -/* harmony import */ var _scripts_registerPlugin__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./scripts/registerPlugin */ "./src/scripts/registerPlugin.js"); - - -// Block Modifications - - -// Block Checks - -/******/ })() -; -//# sourceMappingURL=block-checks.js.map \ No newline at end of file +(()=>{"use strict";const e=window.wp.i18n,t=window.wp.hooks,n=window.wp.compose,r=window.wp.blockEditor,i=window.wp.components;(0,t.addFilter)("blocks.registerBlockType","block-accessibility-checks/add-image-attribute",(function(e){return"core/image"!==e.name||(e.attributes=Object.assign(e.attributes,{isDecorative:{type:"boolean",default:!1}})),e}));var a=(0,n.createHigherOrderComponent)((function(t){return function(n){if("core/image"!==n.name)return React.createElement(t,n);var a=n.attributes,c=n.setAttributes,o=a.isDecorative;return React.createElement(React.Fragment,null,React.createElement(r.InspectorControls,null,React.createElement(i.PanelBody,{title:(0,e.__)("Accessibility Settings","block-accessibility-checks"),initialOpen:!0},React.createElement(i.ToggleControl,{label:(0,e.__)("Please confirm this image is decorative","block-accessibility-checks"),checked:o,onChange:function(e){return c({isDecorative:e})}}))),React.createElement(t,n))}}),"addImageInspectorControls");(0,t.addFilter)("editor.BlockEdit","block-accessibility-checks/add-inspector-control",a);const c=window.wp.plugins,o=window.wp.data;function l(){return(0,o.useSelect)((function(e){return e("core/block-editor").getBlocks()}),[]).flatMap((function(e){return m.map((function(t){return t(e)}))})).filter((function(e){return!e.isValid}))}const s=window.wp.element;function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,r=Array(t);n=e.length?{done:!0}:{done:!1,value:e[_n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}(n);try{for(a.s();!(i=a.n()).done;){var c=i.value;if("core/button"===c.name){var o=c.attributes,l=o.text,s=o.url;if(""===l||void 0===s)return{isValid:!1,message:(0,e.__)("Accessibility Error: Each button must have both text and URL.","block-accessibility-checks"),clientId:r}}if(c.innerBlocks.length>0){var u=t(c.innerBlocks,r);if(!u.isValid)return u}}}catch(e){a.e(e)}finally{a.f()}return{isValid:!0}}(t.innerBlocks,t.clientId)},function(t){return"core/heading"===t.name&&1===t.attributes.level?{isValid:!1,message:(0,e.__)("Accessibility Error: Level 1 headings are not allowed in your content area.","block-accessibility-checks"),clientId:t.clientId}:{isValid:!0}},function(t){return"core/image"!==t.name||t.attributes.alt||t.attributes.isDecorative?{isValid:!0}:{isValid:!1,message:(0,e.__)("Accessibility Error: Images are required to have alternative text.","block-accessibility-checks"),clientId:t.clientId}},function(t){return"core/table"===t.name&&0!==t.attributes.body.length&&0===t.attributes.head.length?{isValid:!1,message:(0,e.__)("Accessibility Error: Tables are required to have a header row.","block-accessibility-checks"),clientId:t.clientId}:{isValid:!0}}];(0,c.registerPlugin)("block-validation",{render:function(){var e=l(),t=(0,o.useDispatch)("core/editor"),n=t.lockPostSaving,r=t.unlockPostSaving,i=t.lockPostAutosaving,a=t.unlockPostAutosaving,c=t.disablePublishSidebar,u=t.enablePublishSidebar;return(0,s.useEffect)((function(){e.length>0&&"DENY"===blockAccessibilitySettings.mode?(n(),i(),c()):(r(),a(),u())}),[e,c,u,i,n,a,r]),null}})})(); \ No newline at end of file