Changeset 3431152
- Timestamp:
- 01/02/2026 04:56:44 PM (3 months ago)
- Location:
- content-area-block
- Files:
-
- 2 deleted
- 8 edited
- 11 copied
-
tags/1.0.2 (copied) (copied from content-area-block/trunk)
-
tags/1.0.2/build/block.json (copied) (copied from content-area-block/trunk/build/block.json) (2 diffs)
-
tags/1.0.2/build/index.asset.php (copied) (copied from content-area-block/trunk/build/index.asset.php) (1 diff)
-
tags/1.0.2/build/index.js (copied) (copied from content-area-block/trunk/build/index.js) (1 diff)
-
tags/1.0.2/build/render.php (copied) (copied from content-area-block/trunk/build/render.php)
-
tags/1.0.2/content-area-block.php (copied) (copied from content-area-block/trunk/content-area-block.php) (1 diff)
-
tags/1.0.2/content-area-block.zip (deleted)
-
tags/1.0.2/package-lock.json (deleted)
-
tags/1.0.2/package.json (copied) (copied from content-area-block/trunk/package.json)
-
tags/1.0.2/readme.txt (copied) (copied from content-area-block/trunk/readme.txt) (1 diff)
-
tags/1.0.2/src/block.json (modified) (2 diffs)
-
tags/1.0.2/src/edit.js (copied) (copied from content-area-block/trunk/src/edit.js) (4 diffs)
-
tags/1.0.2/src/hooks.js (copied) (copied from content-area-block/trunk/src/hooks.js)
-
tags/1.0.2/src/render.php (copied) (copied from content-area-block/trunk/src/render.php)
-
trunk/build/block.json (modified) (2 diffs)
-
trunk/build/index.asset.php (modified) (1 diff)
-
trunk/build/index.js (modified) (1 diff)
-
trunk/content-area-block.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/src/block.json (modified) (2 diffs)
-
trunk/src/edit.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
content-area-block/tags/1.0.2/build/block.json
r3402104 r3431152 20 20 "default": "extra_content_area" 21 21 }, 22 "allowedBlocks": {23 "type": "array",24 "default": [],25 "items": {26 "type": "string"27 }28 },29 22 "disallowedBlocks": { 30 23 "type": "array", … … 44 37 }, 45 38 "supports": { 46 "html": false 39 "html": false, 40 "allowedBlocks": true, 41 "lock": false, 42 "contentRole": true 47 43 }, 48 44 "usesContext": [ 49 45 "postId", 50 "postType" 46 "postType", 47 "queryId" 51 48 ], 52 49 "textdomain": "content-area-block", -
content-area-block/tags/1.0.2/build/index.asset.php
r3406218 r3431152 1 <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => ' 3ce08443ee2ecb3af289');1 <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '093018c4ccc5fa6f3ef1'); -
content-area-block/tags/1.0.2/build/index.js
r3406218 r3431152 1 (()=>{"use strict";const e=window.wp.blocks,t=window.wp.i18n,o=window.wp.data,n=window.wp.editor,s=window.wp.blockEditor,l=window.wp.element,a=window.wp.components,r=window.wp.coreData,c=window.ReactJSXRuntime,i=(0,l.createContext)({});const u=[],d=[{value:"allow",label:(0,t.__)("Allow","content-area-block")},{value:"disallow",label:(0,t.__)("Disallow","content-area-block")}];function p({parentLayout:o,layoutClassNames:n,userCanEdit:a,postType:i,postId:u,tagName:d="div"}){const[,,p]=(0,r.useEntityProp)("postType",i,"content",u),k=(0,s.useBlockProps)({className:n}),w=(0,l.useMemo)((()=>p?.raw?(0,e.parse)(p.raw):[]),[p?.raw]),_=(0,s.__experimentalUseBlockPreview)({blocks:w,props:k,layout:o});return a?(0,c.jsx)("div",{..._}):p?.protected?(0,c.jsx)(d,{...k,children:(0,c.jsx)(s.Warning,{children:(0,t.__)("This content is password protected.","content-area-block")})}):(0,c.jsx)(d,{...k,dangerouslySetInnerHTML:{__html:p?.rendered}})}function k({layout:t,context:n={},attributes:a={}}){const{allowedBlocks:i=[],disallowedBlocks:d=[],blockFilter:p="allow"}=a,k=(0,o.useSelect)((e=>{const{getSettings:t}=e(s.store);return t()?.supportsLayout}),[]),w=(0,s.useSettings)(["layout"])[0]||{},_=t&&t.inherit?w:t,{blocks:b,onChange:y,onInput:x}=function({attributes:t,context:n}){const{postType:s,postId:a}=n,c=(0,r.useEntityId)("postType",s),i=null!=a?a:c,{metaKey:d}=t,p=`${d}_blocks`,k=(0,o.useSelect)((e=>{const{getEditedEntityRecord:t}=e("core");return t("postType",s,i)}),[s,i]),{meta:w}=k,_=(0,l.useMemo)((()=>w?.[d]||""),[w,d]),[b,y]=(0,l.useState)((()=>k?.[p])),x=(0,l.useMemo)((()=>b||(k?.[p]?k[p]:_?(0,e.parse)(_):u)),[b,k,p,_]),{editEntityRecord:m,__unstableCreateUndoLevel:g}=(0,o.useDispatch)(r.store);(0,l.useEffect)((()=>{k?.[p]&&b&&y(null)}),[k,p,b]);const h=(0,l.useCallback)((t=>{if(x===t)return g("postType",s,i);const o=(0,e.__unstableSerializeAndClean)(t);y(t);const n={[p]:t,meta:{...w,[d]:o}};m("postType",s,i,n,{isCached:!1})}),[p,x,m,w,d,i,s,g]),C=(0,l.useCallback)((t=>{y(t);const o=(0,e.__unstableSerializeAndClean)(t),n={[p]:t,meta:{...w,[d]:o}};m("postType",s,i,n,{isCached:!0})}),[p,m,w,d,i,s]);return{blocks:x,onChange:h,onInput:C}}({attributes:a,context:n}),m=(0,l.useMemo)((()=>{const t=(0,e.getBlockTypes)();let o="allow"===p?i:t.map((({name:e})=>e));return o="disallow"===p?o.filter((e=>!d.includes(e))):o,o.length>0&&!o.includes("core/paragraph")&&(o=["core/paragraph",...o]),o}),[p,i,d]),g=(0,s.useBlockProps)(),h=(0,s.useInnerBlocksProps)(g,{value:b,onInput:x,onChange:y,__experimentalLayout:k?_:void 0,allowedBlocks:m.length>0?m:void 0,template:b?.length?void 0:[["core/paragraph"]],__experimentalDefaultBlock:{name:"core/paragraph"},__experimentalDirectInsert:!0});return(0,c.jsx)("div",{...h})}function w(e){const{context:{queryId:t,postType:n,postId:s}={}}=e,l=Number.isFinite(t),a=(i="postType",u=n,d=s,(0,o.useSelect)((e=>e(r.store).canUser("update",{kind:i,name:u,id:d})),[i,u,d]));var i,u,d;return a&&!l?(0,c.jsx)(k,{...e}):(0,c.jsx)(p,{userCanEdit:a,postType:n,postId:s})}function _({metaKey:e=""}){const o=(0,s.useBlockProps)();return(0,c.jsx)("div",{...o,children:(0,c.jsx)("p",{children:e?(0,t.sprintf)( 2 // Translators: %s is the metaKey attribute value. 3 // Translators: %s is the metaKey attribute value. 4 (0,t.__)("Post Content from meta_key: %s","content-area-block"),e):(0,t.__)("Set a meta key to pull blocks from.","content-area-block")})})}function b(){const e=(0,s.useBlockProps)();return(0,c.jsx)("div",{...e,children:(0,c.jsx)(s.Warning,{children:(0,t.__)("Block cannot be rendered inside itself.","content-area-block")})})}const y=JSON.parse('{"UU":"iansvo/content-area"}');(0,window.wp.hooks.addFilter)("editor.postContentBlockTypes","iansvo/content-area/post-content-block-types",(function(e){return[...e,"iansvo/content-area"]})),(0,e.registerBlockType)(y.UU,{edit:function({context:r,attributes:u,setAttributes:p}){const{metaKey:k,allowedBlocks:y=[],disallowedBlocks:x=[],blockFilter:m="allow"}=u,{layout:g={}}=u,{postId:h,postType:C,editingMode:B}=(0,o.useSelect)((e=>({postId:e(n.store).getCurrentPostId(),postType:e(n.store).getCurrentPostType(),editingMode:e(s.store).getBlockEditingMode()}))),[f,j]=function(e,t=""){const o=(0,l.useContext)(i),{name:n}=(0,s.useBlockEditContext)();t=t||n;const a=Boolean(o[t]?.has(e)),r=(0,l.useMemo)((()=>function(e,t,o){const n={...e,[t]:e[t]?new Set(e[t]):new Set};return n[t].add(o),n}(o,t,e)),[o,t,e]);return[a,(0,l.useCallback)((({children:e})=>(0,c.jsx)(i.Provider,{value:r,children:e})),[r])]}(h),T="number"==typeof h&&h,v=(0,l.useCallback)((function(e){p({metaKey:e})}),[p]),S=(0,l.useCallback)((function(e){p({allowedBlocks:e})}),[p]),I=(0,l.useCallback)((function(e){p({disallowedBlocks:e})}),[p]),M=(0,l.useMemo)((()=>(0,e.getBlockTypes)().map((e=>e.name))),[]);if(T&&C&&f)return(0,c.jsx)(b,{});const P="default"===B;return(0,c.jsxs)(j,{children:[T&&C?(0,c.jsx)(w,{context:r,layout:g,attributes:u,postId:h,postType:C}):(0,c.jsx)(_,{metaKey:k}),(0,c.jsx)(s.InspectorControls,{children:P?(0,c.jsxs)(a.PanelBody,{title:(0,t.__)("Content Area Settings","content-area-block"),children:[(0,c.jsx)(a.TextControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,value:k,onChange:v,label:(0,t.__)("Meta Key","content-area-block")}),(0,c.jsx)(a.SelectControl,{value:m,onChange:e=>p({blockFilter:e}),label:(0,t.__)("Block Filter Type","content-area-block"),options:d}),"allow"===m&&(0,c.jsx)(a.FormTokenField,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,value:y,onChange:S,suggestions:M,label:(0,t.__)("Allowed Blocks","content-area-block")}),"disallow"===m&&(0,c.jsx)(a.FormTokenField,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,value:x,onChange:I,suggestions:M,label:(0,t.__)("Disallowed Blocks","content-area-block")})]}):(0,c.jsx)(a.PanelBody,{opened:!0,children:(0,c.jsxs)(a.Notice,{isDismissible:!1,status:"warning",children:[(0,c.jsx)("h2",{style:{marginBlockStart:0},children:(0,t.__)("Content Only Mode","content-area-block")}),(0,t.__)("Edit the template to change settings for this block.","content-area-block")]})})})]})},save:()=>null})})(); 1 /******/ (() => { // webpackBootstrap 2 /******/ "use strict"; 3 /******/ var __webpack_modules__ = ({ 4 5 /***/ "./src/block.json": 6 /*!************************!*\ 7 !*** ./src/block.json ***! 8 \************************/ 9 /***/ ((module) => { 10 11 module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"iansvo/content-area","version":"0.1.0","title":"Content Area","category":"theme","icon":"layout","description":"Adds a block content area to a site editor template.","keywords":["content","area","meta","template","fse"],"attributes":{"metaKey":{"type":"string","default":"extra_content_area"},"disallowedBlocks":{"type":"array","default":[],"items":{"type":"string"}},"blockFilter":{"type":"string","enum":["allow","disallow"],"default":"allow"}},"supports":{"html":false,"allowedBlocks":true,"lock":false,"contentRole":true},"usesContext":["postId","postType","queryId"],"textdomain":"content-area-block","editorScript":"file:./index.js","render":"file:./render.php"}'); 12 13 /***/ }), 14 15 /***/ "./src/edit.js": 16 /*!*********************!*\ 17 !*** ./src/edit.js ***! 18 \*********************/ 19 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 20 21 __webpack_require__.r(__webpack_exports__); 22 /* harmony export */ __webpack_require__.d(__webpack_exports__, { 23 /* harmony export */ "default": () => (/* binding */ ContentAreaEdit) 24 /* harmony export */ }); 25 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); 26 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); 27 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); 28 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__); 29 /* harmony import */ var _wordpress_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/editor */ "@wordpress/editor"); 30 /* harmony import */ var _wordpress_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__); 31 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks"); 32 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__); 33 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); 34 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__); 35 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); 36 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_5__); 37 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); 38 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__); 39 /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @wordpress/core-data */ "@wordpress/core-data"); 40 /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_7__); 41 /* harmony import */ var _hooks__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./hooks */ "./src/hooks.js"); 42 /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime"); 43 /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__); 44 /** 45 * WordPress dependencies 46 */ 47 48 49 50 51 52 53 54 55 56 57 const blockFilterTypes = [{ 58 value: 'allow', 59 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Allow', 'content-area-block') 60 }, { 61 value: 'disallow', 62 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Disallow', 'content-area-block') 63 }]; 64 function ReadOnlyContent({ 65 parentLayout, 66 layoutClassNames, 67 userCanEdit, 68 postType, 69 postId, 70 tagName: TagName = 'div' 71 }) { 72 const [,, content] = (0,_wordpress_core_data__WEBPACK_IMPORTED_MODULE_7__.useEntityProp)('postType', postType, 'content', postId); 73 const blockProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.useBlockProps)({ 74 className: layoutClassNames 75 }); 76 const blocks = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useMemo)(() => { 77 return content?.raw ? (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__.parse)(content.raw) : []; 78 }, [content?.raw]); 79 const blockPreviewProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.__experimentalUseBlockPreview)({ 80 blocks, 81 props: blockProps, 82 layout: parentLayout 83 }); 84 if (userCanEdit) { 85 /* 86 * Rendering the block preview using the raw content blocks allows for 87 * block support styles to be generated and applied by the editor. 88 * 89 * The preview using the raw blocks can only be presented to users with 90 * edit permissions for the post to prevent potential exposure of private 91 * block content. 92 */ 93 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", { 94 ...blockPreviewProps 95 }); 96 } 97 return content?.protected ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(TagName, { 98 ...blockProps, 99 children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.Warning, { 100 children: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('This content is password protected.', 'content-area-block') 101 }) 102 }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(TagName, { 103 ...blockProps, 104 dangerouslySetInnerHTML: { 105 __html: content?.rendered 106 } 107 }); 108 } 109 function EditableContent({ 110 layout, 111 context = {}, 112 attributes = {} 113 }) { 114 const { 115 allowedBlocks = [], 116 disallowedBlocks = [], 117 blockFilter = 'allow' 118 } = attributes; 119 const { 120 blocks, 121 onChange, 122 onInput 123 } = (0,_hooks__WEBPACK_IMPORTED_MODULE_8__.useMetaBlockEditor)({ 124 attributes, 125 context 126 }); 127 const allowedBlocksList = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useMemo)(() => { 128 const blockTypes = (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__.getBlockTypes)(); 129 const filterMode = blockFilter === 'allow' && Array.isArray(allowedBlocks) ? 'allow' : 'disallow'; 130 let list = filterMode === 'allow' ? allowedBlocks : blockTypes.map(({ 131 name 132 }) => name); 133 list = blockFilter === 'disallow' ? list.filter(blockType => !disallowedBlocks.includes(blockType)) : list; 134 135 // Always ensure paragraph is available 136 if (list.length > 0 && !list.includes('core/paragraph')) { 137 list = ['core/paragraph', ...list]; 138 } 139 return list; 140 }, [blockFilter, allowedBlocks, disallowedBlocks]); 141 const blockProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.useBlockProps)(); 142 const innerBlocksProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.useInnerBlocksProps)(blockProps, { 143 value: blocks, 144 onInput, 145 onChange, 146 allowedBlocks: allowedBlocksList.length > 0 ? allowedBlocksList : undefined, 147 template: !blocks?.length ? [['core/paragraph']] : undefined 148 }); 149 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", { 150 ...innerBlocksProps 151 }); 152 } 153 function Content(props) { 154 const { 155 context: { 156 queryId, 157 postType, 158 postId 159 } = {} 160 } = props; 161 const isDescendentOfQueryLoop = Number.isFinite(queryId); 162 const userCanEdit = (0,_hooks__WEBPACK_IMPORTED_MODULE_8__.useCanEditEntity)('postType', postType, postId); 163 const isEditable = userCanEdit && !isDescendentOfQueryLoop; 164 return isEditable ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(EditableContent, { 165 ...props 166 }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(ReadOnlyContent, { 167 userCanEdit: userCanEdit, 168 postType: postType, 169 postId: postId 170 }); 171 } 172 function Placeholder({ 173 metaKey = '' 174 }) { 175 const blockProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.useBlockProps)(); 176 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", { 177 ...blockProps, 178 children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("p", { 179 children: metaKey ? (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.sprintf)( 180 // Translators: %s is the metaKey attribute value. 181 (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Post Content from meta_key: %s', 'content-area-block'), metaKey) : (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Set a meta key to pull blocks from.', 'content-area-block') 182 }) 183 }); 184 } 185 function RecursionError() { 186 const blockProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.useBlockProps)(); 187 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", { 188 ...blockProps, 189 children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.Warning, { 190 children: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Block cannot be rendered inside itself.', 'content-area-block') 191 }) 192 }); 193 } 194 function ContentAreaEdit({ 195 context, 196 attributes, 197 setAttributes 198 }) { 199 const { 200 metaKey, 201 allowedBlocks = [], 202 disallowedBlocks = [], 203 blockFilter = 'allow' 204 } = attributes; 205 const { 206 layout = {} 207 } = attributes; 208 const { 209 postId, 210 postType, 211 editingMode 212 } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.useSelect)(select => { 213 return { 214 postId: select(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__.store).getCurrentPostId(), 215 postType: select(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__.store).getCurrentPostType(), 216 editingMode: select(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.store).getBlockEditingMode() 217 }; 218 }); 219 const [hasAlreadyRendered, RecursionProvider] = (0,_hooks__WEBPACK_IMPORTED_MODULE_8__.useNoRecursiveRenders)(postId); 220 const isValidPostId = 'number' === typeof postId && postId; 221 const handleMetaKeyChange = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useCallback)(function handleMetaKeyChange(value) { 222 setAttributes({ 223 metaKey: value 224 }); 225 }, [setAttributes]); 226 const handleAllowedBlocksChange = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useCallback)(function handleAllowedBlocksChange(value) { 227 setAttributes({ 228 allowedBlocks: value 229 }); 230 }, [setAttributes]); 231 const handleDisallowedBlocksChange = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useCallback)(function handleDisallowedBlocksChange(value) { 232 setAttributes({ 233 disallowedBlocks: value 234 }); 235 }, [setAttributes]); 236 const blockSuggestions = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useMemo)(() => { 237 const blockTypes = (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__.getBlockTypes)(); 238 return blockTypes.map(block => block.name); 239 }, []); 240 if (isValidPostId && postType && hasAlreadyRendered) { 241 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(RecursionError, {}); 242 } 243 const showControls = editingMode === 'default'; 244 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)(RecursionProvider, { 245 children: [isValidPostId && postType ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(Content, { 246 context: context, 247 layout: layout, 248 attributes: attributes, 249 postId: postId, 250 postType: postType 251 }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(Placeholder, { 252 metaKey: metaKey 253 }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.InspectorControls, { 254 children: showControls ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.PanelBody, { 255 title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Content Area Settings', 'content-area-block'), 256 children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.TextControl, { 257 __next40pxDefaultSize: true, 258 __nextHasNoMarginBottom: true, 259 value: metaKey, 260 onChange: handleMetaKeyChange, 261 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Meta Key', 'content-area-block') 262 }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.SelectControl, { 263 value: blockFilter, 264 onChange: newValue => setAttributes({ 265 blockFilter: newValue 266 }), 267 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Block Filter Type', 'content-area-block'), 268 options: blockFilterTypes 269 }), blockFilter === 'allow' && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.FormTokenField, { 270 __next40pxDefaultSize: true, 271 __nextHasNoMarginBottom: true, 272 value: allowedBlocks, 273 onChange: handleAllowedBlocksChange, 274 suggestions: blockSuggestions, 275 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Allowed Blocks', 'content-area-block') 276 }), blockFilter === 'disallow' && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.FormTokenField, { 277 __next40pxDefaultSize: true, 278 __nextHasNoMarginBottom: true, 279 value: disallowedBlocks, 280 onChange: handleDisallowedBlocksChange, 281 suggestions: blockSuggestions, 282 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Disallowed Blocks', 'content-area-block') 283 })] 284 }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.PanelBody, { 285 opened: true, 286 children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.Notice, { 287 isDismissible: false, 288 status: "warning", 289 children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("h2", { 290 style: { 291 marginBlockStart: 0 292 }, 293 children: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Content Only Mode', 'content-area-block') 294 }), (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Edit the template to change settings for this block.', 'content-area-block')] 295 }) 296 }) 297 })] 298 }); 299 } 300 301 /***/ }), 302 303 /***/ "./src/filters.js": 304 /*!************************!*\ 305 !*** ./src/filters.js ***! 306 \************************/ 307 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 308 309 __webpack_require__.r(__webpack_exports__); 310 /* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks"); 311 /* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_hooks__WEBPACK_IMPORTED_MODULE_0__); 312 313 314 // 315 function addCustomPostContentBlockTypes(blockTypes) { 316 return [...blockTypes, 'iansvo/content-area']; 317 } 318 (0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_0__.addFilter)('editor.postContentBlockTypes', 'iansvo/content-area/post-content-block-types', addCustomPostContentBlockTypes); 319 320 /***/ }), 321 322 /***/ "./src/hooks.js": 323 /*!**********************!*\ 324 !*** ./src/hooks.js ***! 325 \**********************/ 326 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 327 328 __webpack_require__.r(__webpack_exports__); 329 /* harmony export */ __webpack_require__.d(__webpack_exports__, { 330 /* harmony export */ useCanEditEntity: () => (/* binding */ useCanEditEntity), 331 /* harmony export */ useMetaBlockEditor: () => (/* binding */ useMetaBlockEditor), 332 /* harmony export */ useNoRecursiveRenders: () => (/* binding */ useNoRecursiveRenders) 333 /* harmony export */ }); 334 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); 335 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); 336 /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/core-data */ "@wordpress/core-data"); 337 /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__); 338 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); 339 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__); 340 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); 341 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_3__); 342 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks"); 343 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__); 344 /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime"); 345 /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__); 346 /** 347 * WordPress dependencies 348 */ 349 350 351 352 353 354 355 const RenderedRefsContext = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.createContext)({}); 356 357 /** 358 * Returns whether the current user can edit the given entity. 359 * 360 * @param {string} kind Entity kind. 361 * @param {string} name Entity name. 362 * @param {string} recordId Record's id. 363 */ 364 function useCanEditEntity(kind, name, recordId) { 365 return (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useSelect)(select => select(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__.store).canUser('update', { 366 kind, 367 name, 368 id: recordId 369 }), [kind, name, recordId]); 370 } 371 372 /** 373 * Immutably adds an unique identifier to a set scoped for a given block type. 374 * 375 * @param {Object} renderedBlocks Rendered blocks grouped by block name 376 * @param {string} blockName Name of the block. 377 * @param {*} uniqueId Any value that acts as a unique identifier for a block instance. 378 * 379 * @return {Object} The list of rendered blocks grouped by block name. 380 */ 381 function addToBlockType(renderedBlocks, blockName, uniqueId) { 382 const result = { 383 ...renderedBlocks, 384 [blockName]: renderedBlocks[blockName] ? new Set(renderedBlocks[blockName]) : new Set() 385 }; 386 result[blockName].add(uniqueId); 387 return result; 388 } 389 390 /** 391 * A React hook for keeping track of blocks previously rendered up in the block 392 * tree. Blocks susceptible to recursion can use this hook in their `Edit` 393 * function to prevent said recursion. 394 * 395 * @see https://github.com/iansvo/gutenberg/blob/a7e2895829c16ecd77a5ba22d84f1dee1cfb0977/packages/block-editor/src/components/use-no-recursive-renders/index.js 396 * 397 * @param {*} uniqueId Any value that acts as a unique identifier for a block instance. 398 * @param {string} blockName Optional block name. 399 * 400 * @return {[boolean, Function]} A tuple of: 401 * - a boolean describing whether the provided id 402 * has already been rendered; 403 * - a React context provider to be used to wrap 404 * other elements. 405 */ 406 function useNoRecursiveRenders(uniqueId, blockName = '') { 407 const previouslyRenderedBlocks = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useContext)(RenderedRefsContext); 408 const { 409 name 410 } = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.useBlockEditContext)(); 411 blockName = blockName || name; 412 const hasAlreadyRendered = Boolean(previouslyRenderedBlocks[blockName]?.has(uniqueId)); 413 const newRenderedBlocks = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useMemo)(() => addToBlockType(previouslyRenderedBlocks, blockName, uniqueId), [previouslyRenderedBlocks, blockName, uniqueId]); 414 const Provider = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useCallback)(({ 415 children 416 }) => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsx)(RenderedRefsContext.Provider, { 417 value: newRenderedBlocks, 418 children: children 419 }), [newRenderedBlocks]); 420 return [hasAlreadyRendered, Provider]; 421 } 422 const EMPTY_ARRAY = []; 423 function useMetaBlockEditor({ 424 attributes, 425 context 426 }) { 427 const { 428 postType, 429 postId: contextPostId 430 } = context; 431 const providerId = (0,_wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__.useEntityId)('postType', postType); 432 const postId = contextPostId !== null && contextPostId !== void 0 ? contextPostId : providerId; 433 const { 434 metaKey 435 } = attributes; 436 const BLOCKS_KEY = `${metaKey}_blocks`; 437 const editedRecord = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useSelect)(select => { 438 const { 439 getEditedEntityRecord 440 } = select('core'); 441 return getEditedEntityRecord('postType', postType, postId); 442 }, [postType, postId]); 443 const { 444 meta 445 } = editedRecord; 446 const content = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useMemo)(() => meta?.[metaKey] || '', [meta, metaKey]); 447 const [localBlocks, setLocalBlocks] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useState)(() => editedRecord?.[BLOCKS_KEY]); 448 const blocks = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useMemo)(() => { 449 // If we have local blocks from a recent edit, use those 450 if (localBlocks) { 451 return localBlocks; 452 } 453 // Otherwise use stored blocks 454 if (editedRecord?.[BLOCKS_KEY]) { 455 return editedRecord[BLOCKS_KEY]; 456 } 457 if (content) { 458 return (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__.parse)(content); 459 } 460 return EMPTY_ARRAY; 461 }, [localBlocks, editedRecord, BLOCKS_KEY, content]); 462 const { 463 editEntityRecord, 464 __unstableCreateUndoLevel 465 } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useDispatch)(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__.store); 466 467 // Clear local blocks when content is successfully saved 468 (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useEffect)(() => { 469 if (editedRecord?.[BLOCKS_KEY] && localBlocks) { 470 setLocalBlocks(null); 471 } 472 }, [editedRecord, BLOCKS_KEY, localBlocks]); 473 const onChange = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useCallback)(newBlocks => { 474 const noChange = blocks === newBlocks; 475 if (noChange) { 476 return __unstableCreateUndoLevel('postType', postType, postId); 477 } 478 const serializedContent = (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__.__unstableSerializeAndClean)(newBlocks); 479 480 // Set local blocks immediately for UI responsiveness 481 setLocalBlocks(newBlocks); 482 const edits = { 483 [BLOCKS_KEY]: newBlocks, 484 meta: { 485 ...meta, 486 [metaKey]: serializedContent 487 } 488 }; 489 editEntityRecord('postType', postType, postId, edits, { 490 isCached: false 491 }); 492 }, [BLOCKS_KEY, blocks, editEntityRecord, meta, metaKey, postId, postType, __unstableCreateUndoLevel]); 493 const onInput = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useCallback)(newBlocks => { 494 // Set local blocks immediately for UI responsiveness 495 setLocalBlocks(newBlocks); 496 const serializedContent = (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__.__unstableSerializeAndClean)(newBlocks); 497 const edits = { 498 [BLOCKS_KEY]: newBlocks, 499 meta: { 500 ...meta, 501 [metaKey]: serializedContent 502 } 503 }; 504 editEntityRecord('postType', postType, postId, edits, { 505 isCached: true 506 }); 507 }, [BLOCKS_KEY, editEntityRecord, meta, metaKey, postId, postType]); 508 return { 509 blocks, 510 onChange, 511 onInput 512 }; 513 } 514 515 /***/ }), 516 517 /***/ "@wordpress/block-editor": 518 /*!*************************************!*\ 519 !*** external ["wp","blockEditor"] ***! 520 \*************************************/ 521 /***/ ((module) => { 522 523 module.exports = window["wp"]["blockEditor"]; 524 525 /***/ }), 526 527 /***/ "@wordpress/blocks": 528 /*!********************************!*\ 529 !*** external ["wp","blocks"] ***! 530 \********************************/ 531 /***/ ((module) => { 532 533 module.exports = window["wp"]["blocks"]; 534 535 /***/ }), 536 537 /***/ "@wordpress/components": 538 /*!************************************!*\ 539 !*** external ["wp","components"] ***! 540 \************************************/ 541 /***/ ((module) => { 542 543 module.exports = window["wp"]["components"]; 544 545 /***/ }), 546 547 /***/ "@wordpress/core-data": 548 /*!**********************************!*\ 549 !*** external ["wp","coreData"] ***! 550 \**********************************/ 551 /***/ ((module) => { 552 553 module.exports = window["wp"]["coreData"]; 554 555 /***/ }), 556 557 /***/ "@wordpress/data": 558 /*!******************************!*\ 559 !*** external ["wp","data"] ***! 560 \******************************/ 561 /***/ ((module) => { 562 563 module.exports = window["wp"]["data"]; 564 565 /***/ }), 566 567 /***/ "@wordpress/editor": 568 /*!********************************!*\ 569 !*** external ["wp","editor"] ***! 570 \********************************/ 571 /***/ ((module) => { 572 573 module.exports = window["wp"]["editor"]; 574 575 /***/ }), 576 577 /***/ "@wordpress/element": 578 /*!*********************************!*\ 579 !*** external ["wp","element"] ***! 580 \*********************************/ 581 /***/ ((module) => { 582 583 module.exports = window["wp"]["element"]; 584 585 /***/ }), 586 587 /***/ "@wordpress/hooks": 588 /*!*******************************!*\ 589 !*** external ["wp","hooks"] ***! 590 \*******************************/ 591 /***/ ((module) => { 592 593 module.exports = window["wp"]["hooks"]; 594 595 /***/ }), 596 597 /***/ "@wordpress/i18n": 598 /*!******************************!*\ 599 !*** external ["wp","i18n"] ***! 600 \******************************/ 601 /***/ ((module) => { 602 603 module.exports = window["wp"]["i18n"]; 604 605 /***/ }), 606 607 /***/ "react/jsx-runtime": 608 /*!**********************************!*\ 609 !*** external "ReactJSXRuntime" ***! 610 \**********************************/ 611 /***/ ((module) => { 612 613 module.exports = window["ReactJSXRuntime"]; 614 615 /***/ }) 616 617 /******/ }); 618 /************************************************************************/ 619 /******/ // The module cache 620 /******/ var __webpack_module_cache__ = {}; 621 /******/ 622 /******/ // The require function 623 /******/ function __webpack_require__(moduleId) { 624 /******/ // Check if module is in cache 625 /******/ var cachedModule = __webpack_module_cache__[moduleId]; 626 /******/ if (cachedModule !== undefined) { 627 /******/ return cachedModule.exports; 628 /******/ } 629 /******/ // Create a new module (and put it into the cache) 630 /******/ var module = __webpack_module_cache__[moduleId] = { 631 /******/ // no module.id needed 632 /******/ // no module.loaded needed 633 /******/ exports: {} 634 /******/ }; 635 /******/ 636 /******/ // Execute the module function 637 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 638 /******/ 639 /******/ // Return the exports of the module 640 /******/ return module.exports; 641 /******/ } 642 /******/ 643 /************************************************************************/ 644 /******/ /* webpack/runtime/compat get default export */ 645 /******/ (() => { 646 /******/ // getDefaultExport function for compatibility with non-harmony modules 647 /******/ __webpack_require__.n = (module) => { 648 /******/ var getter = module && module.__esModule ? 649 /******/ () => (module['default']) : 650 /******/ () => (module); 651 /******/ __webpack_require__.d(getter, { a: getter }); 652 /******/ return getter; 653 /******/ }; 654 /******/ })(); 655 /******/ 656 /******/ /* webpack/runtime/define property getters */ 657 /******/ (() => { 658 /******/ // define getter functions for harmony exports 659 /******/ __webpack_require__.d = (exports, definition) => { 660 /******/ for(var key in definition) { 661 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 662 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 663 /******/ } 664 /******/ } 665 /******/ }; 666 /******/ })(); 667 /******/ 668 /******/ /* webpack/runtime/hasOwnProperty shorthand */ 669 /******/ (() => { 670 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 671 /******/ })(); 672 /******/ 673 /******/ /* webpack/runtime/make namespace object */ 674 /******/ (() => { 675 /******/ // define __esModule on exports 676 /******/ __webpack_require__.r = (exports) => { 677 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 678 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 679 /******/ } 680 /******/ Object.defineProperty(exports, '__esModule', { value: true }); 681 /******/ }; 682 /******/ })(); 683 /******/ 684 /************************************************************************/ 685 var __webpack_exports__ = {}; 686 // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. 687 (() => { 688 /*!**********************!*\ 689 !*** ./src/index.js ***! 690 \**********************/ 691 __webpack_require__.r(__webpack_exports__); 692 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks"); 693 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__); 694 /* harmony import */ var _edit__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./edit */ "./src/edit.js"); 695 /* harmony import */ var _block_json__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./block.json */ "./src/block.json"); 696 /* harmony import */ var _filters__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./filters */ "./src/filters.js"); 697 698 699 700 701 (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__.registerBlockType)(_block_json__WEBPACK_IMPORTED_MODULE_2__.name, { 702 edit: _edit__WEBPACK_IMPORTED_MODULE_1__["default"], 703 save: () => null 704 }); 705 })(); 706 707 /******/ })() 708 ; 709 //# sourceMappingURL=index.js.map -
content-area-block/tags/1.0.2/content-area-block.php
r3406218 r3431152 3 3 * Plugin Name: Content Area Block 4 4 * Description: Add an outlet for blocks in a template that stores block data in a meta field. 5 * Version: 1.0. 15 * Version: 1.0.2 6 6 * Requires at least: 6.7 7 7 * Requires PHP: 7.4 -
content-area-block/tags/1.0.2/readme.txt
r3406218 r3431152 2 2 Contributors: iansvo 3 3 Tags: block, fse, site-editor, content, template 4 Tested up to: 6. 85 Stable tag: 1.0. 14 Tested up to: 6.9 5 Stable tag: 1.0.2 6 6 License: GPL-2.0-or-later 7 7 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
content-area-block/tags/1.0.2/src/block.json
r3336929 r3431152 14 14 "default": "extra_content_area" 15 15 }, 16 "allowedBlocks": {17 "type": "array",18 "default": [],19 "items": {20 "type": "string"21 }22 },23 16 "disallowedBlocks": { 24 17 "type": "array", … … 35 28 }, 36 29 "supports": { 37 "html": false 30 "html": false, 31 "allowedBlocks": true, 32 "lock": false, 33 "contentRole": true 38 34 }, 39 "usesContext": [ "postId", "postType" ],35 "usesContext": [ "postId", "postType", "queryId" ], 40 36 "textdomain": "content-area-block", 41 37 "editorScript": "file:./index.js", -
content-area-block/tags/1.0.2/src/edit.js
r3406218 r3431152 10 10 useInnerBlocksProps, 11 11 useSettings, 12 useBlockEditingMode, 12 13 store as blockEditorStore, 13 14 Warning, … … 101 102 blockFilter = 'allow', 102 103 } = attributes; 103 const themeSupportsLayout = useSelect( ( select ) => {104 const { getSettings } = select( blockEditorStore );105 return getSettings()?.supportsLayout;106 }, [] );107 const defaultLayout = useSettings( [ 'layout' ] )[ 0 ] || {};108 const usedLayout = !! layout && layout.inherit ? defaultLayout : layout;109 104 const { blocks, onChange, onInput } = useMetaBlockEditor( { 110 105 attributes, … … 114 109 const allowedBlocksList = useMemo( () => { 115 110 const blockTypes = getBlockTypes(); 111 const filterMode = blockFilter === 'allow' && Array.isArray( allowedBlocks ) ? 'allow' : 'disallow'; 116 112 117 113 let list = 118 blockFilter=== 'allow'114 filterMode === 'allow' 119 115 ? allowedBlocks 120 116 : blockTypes.map( ( { name } ) => name ); … … 136 132 137 133 const blockProps = useBlockProps(); 138 const props = useInnerBlocksProps( blockProps, {134 const innerBlocksProps = useInnerBlocksProps( blockProps, { 139 135 value: blocks, 140 136 onInput, 141 137 onChange, 142 __experimentalLayout: themeSupportsLayout ? usedLayout : undefined,143 138 allowedBlocks: 144 139 allowedBlocksList.length > 0 ? allowedBlocksList : undefined, 145 140 template: ! blocks?.length ? [ [ 'core/paragraph' ] ] : undefined, 146 __experimentalDefaultBlock: { name: 'core/paragraph' },147 __experimentalDirectInsert: true,148 141 } ); 149 142 150 return <div { ... props } />;143 return <div { ...innerBlocksProps } />; 151 144 } 152 145 -
content-area-block/trunk/build/block.json
r3402104 r3431152 20 20 "default": "extra_content_area" 21 21 }, 22 "allowedBlocks": {23 "type": "array",24 "default": [],25 "items": {26 "type": "string"27 }28 },29 22 "disallowedBlocks": { 30 23 "type": "array", … … 44 37 }, 45 38 "supports": { 46 "html": false 39 "html": false, 40 "allowedBlocks": true, 41 "lock": false, 42 "contentRole": true 47 43 }, 48 44 "usesContext": [ 49 45 "postId", 50 "postType" 46 "postType", 47 "queryId" 51 48 ], 52 49 "textdomain": "content-area-block", -
content-area-block/trunk/build/index.asset.php
r3406218 r3431152 1 <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => ' 3ce08443ee2ecb3af289');1 <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '093018c4ccc5fa6f3ef1'); -
content-area-block/trunk/build/index.js
r3406218 r3431152 1 (()=>{"use strict";const e=window.wp.blocks,t=window.wp.i18n,o=window.wp.data,n=window.wp.editor,s=window.wp.blockEditor,l=window.wp.element,a=window.wp.components,r=window.wp.coreData,c=window.ReactJSXRuntime,i=(0,l.createContext)({});const u=[],d=[{value:"allow",label:(0,t.__)("Allow","content-area-block")},{value:"disallow",label:(0,t.__)("Disallow","content-area-block")}];function p({parentLayout:o,layoutClassNames:n,userCanEdit:a,postType:i,postId:u,tagName:d="div"}){const[,,p]=(0,r.useEntityProp)("postType",i,"content",u),k=(0,s.useBlockProps)({className:n}),w=(0,l.useMemo)((()=>p?.raw?(0,e.parse)(p.raw):[]),[p?.raw]),_=(0,s.__experimentalUseBlockPreview)({blocks:w,props:k,layout:o});return a?(0,c.jsx)("div",{..._}):p?.protected?(0,c.jsx)(d,{...k,children:(0,c.jsx)(s.Warning,{children:(0,t.__)("This content is password protected.","content-area-block")})}):(0,c.jsx)(d,{...k,dangerouslySetInnerHTML:{__html:p?.rendered}})}function k({layout:t,context:n={},attributes:a={}}){const{allowedBlocks:i=[],disallowedBlocks:d=[],blockFilter:p="allow"}=a,k=(0,o.useSelect)((e=>{const{getSettings:t}=e(s.store);return t()?.supportsLayout}),[]),w=(0,s.useSettings)(["layout"])[0]||{},_=t&&t.inherit?w:t,{blocks:b,onChange:y,onInput:x}=function({attributes:t,context:n}){const{postType:s,postId:a}=n,c=(0,r.useEntityId)("postType",s),i=null!=a?a:c,{metaKey:d}=t,p=`${d}_blocks`,k=(0,o.useSelect)((e=>{const{getEditedEntityRecord:t}=e("core");return t("postType",s,i)}),[s,i]),{meta:w}=k,_=(0,l.useMemo)((()=>w?.[d]||""),[w,d]),[b,y]=(0,l.useState)((()=>k?.[p])),x=(0,l.useMemo)((()=>b||(k?.[p]?k[p]:_?(0,e.parse)(_):u)),[b,k,p,_]),{editEntityRecord:m,__unstableCreateUndoLevel:g}=(0,o.useDispatch)(r.store);(0,l.useEffect)((()=>{k?.[p]&&b&&y(null)}),[k,p,b]);const h=(0,l.useCallback)((t=>{if(x===t)return g("postType",s,i);const o=(0,e.__unstableSerializeAndClean)(t);y(t);const n={[p]:t,meta:{...w,[d]:o}};m("postType",s,i,n,{isCached:!1})}),[p,x,m,w,d,i,s,g]),C=(0,l.useCallback)((t=>{y(t);const o=(0,e.__unstableSerializeAndClean)(t),n={[p]:t,meta:{...w,[d]:o}};m("postType",s,i,n,{isCached:!0})}),[p,m,w,d,i,s]);return{blocks:x,onChange:h,onInput:C}}({attributes:a,context:n}),m=(0,l.useMemo)((()=>{const t=(0,e.getBlockTypes)();let o="allow"===p?i:t.map((({name:e})=>e));return o="disallow"===p?o.filter((e=>!d.includes(e))):o,o.length>0&&!o.includes("core/paragraph")&&(o=["core/paragraph",...o]),o}),[p,i,d]),g=(0,s.useBlockProps)(),h=(0,s.useInnerBlocksProps)(g,{value:b,onInput:x,onChange:y,__experimentalLayout:k?_:void 0,allowedBlocks:m.length>0?m:void 0,template:b?.length?void 0:[["core/paragraph"]],__experimentalDefaultBlock:{name:"core/paragraph"},__experimentalDirectInsert:!0});return(0,c.jsx)("div",{...h})}function w(e){const{context:{queryId:t,postType:n,postId:s}={}}=e,l=Number.isFinite(t),a=(i="postType",u=n,d=s,(0,o.useSelect)((e=>e(r.store).canUser("update",{kind:i,name:u,id:d})),[i,u,d]));var i,u,d;return a&&!l?(0,c.jsx)(k,{...e}):(0,c.jsx)(p,{userCanEdit:a,postType:n,postId:s})}function _({metaKey:e=""}){const o=(0,s.useBlockProps)();return(0,c.jsx)("div",{...o,children:(0,c.jsx)("p",{children:e?(0,t.sprintf)( 2 // Translators: %s is the metaKey attribute value. 3 // Translators: %s is the metaKey attribute value. 4 (0,t.__)("Post Content from meta_key: %s","content-area-block"),e):(0,t.__)("Set a meta key to pull blocks from.","content-area-block")})})}function b(){const e=(0,s.useBlockProps)();return(0,c.jsx)("div",{...e,children:(0,c.jsx)(s.Warning,{children:(0,t.__)("Block cannot be rendered inside itself.","content-area-block")})})}const y=JSON.parse('{"UU":"iansvo/content-area"}');(0,window.wp.hooks.addFilter)("editor.postContentBlockTypes","iansvo/content-area/post-content-block-types",(function(e){return[...e,"iansvo/content-area"]})),(0,e.registerBlockType)(y.UU,{edit:function({context:r,attributes:u,setAttributes:p}){const{metaKey:k,allowedBlocks:y=[],disallowedBlocks:x=[],blockFilter:m="allow"}=u,{layout:g={}}=u,{postId:h,postType:C,editingMode:B}=(0,o.useSelect)((e=>({postId:e(n.store).getCurrentPostId(),postType:e(n.store).getCurrentPostType(),editingMode:e(s.store).getBlockEditingMode()}))),[f,j]=function(e,t=""){const o=(0,l.useContext)(i),{name:n}=(0,s.useBlockEditContext)();t=t||n;const a=Boolean(o[t]?.has(e)),r=(0,l.useMemo)((()=>function(e,t,o){const n={...e,[t]:e[t]?new Set(e[t]):new Set};return n[t].add(o),n}(o,t,e)),[o,t,e]);return[a,(0,l.useCallback)((({children:e})=>(0,c.jsx)(i.Provider,{value:r,children:e})),[r])]}(h),T="number"==typeof h&&h,v=(0,l.useCallback)((function(e){p({metaKey:e})}),[p]),S=(0,l.useCallback)((function(e){p({allowedBlocks:e})}),[p]),I=(0,l.useCallback)((function(e){p({disallowedBlocks:e})}),[p]),M=(0,l.useMemo)((()=>(0,e.getBlockTypes)().map((e=>e.name))),[]);if(T&&C&&f)return(0,c.jsx)(b,{});const P="default"===B;return(0,c.jsxs)(j,{children:[T&&C?(0,c.jsx)(w,{context:r,layout:g,attributes:u,postId:h,postType:C}):(0,c.jsx)(_,{metaKey:k}),(0,c.jsx)(s.InspectorControls,{children:P?(0,c.jsxs)(a.PanelBody,{title:(0,t.__)("Content Area Settings","content-area-block"),children:[(0,c.jsx)(a.TextControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,value:k,onChange:v,label:(0,t.__)("Meta Key","content-area-block")}),(0,c.jsx)(a.SelectControl,{value:m,onChange:e=>p({blockFilter:e}),label:(0,t.__)("Block Filter Type","content-area-block"),options:d}),"allow"===m&&(0,c.jsx)(a.FormTokenField,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,value:y,onChange:S,suggestions:M,label:(0,t.__)("Allowed Blocks","content-area-block")}),"disallow"===m&&(0,c.jsx)(a.FormTokenField,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,value:x,onChange:I,suggestions:M,label:(0,t.__)("Disallowed Blocks","content-area-block")})]}):(0,c.jsx)(a.PanelBody,{opened:!0,children:(0,c.jsxs)(a.Notice,{isDismissible:!1,status:"warning",children:[(0,c.jsx)("h2",{style:{marginBlockStart:0},children:(0,t.__)("Content Only Mode","content-area-block")}),(0,t.__)("Edit the template to change settings for this block.","content-area-block")]})})})]})},save:()=>null})})(); 1 /******/ (() => { // webpackBootstrap 2 /******/ "use strict"; 3 /******/ var __webpack_modules__ = ({ 4 5 /***/ "./src/block.json": 6 /*!************************!*\ 7 !*** ./src/block.json ***! 8 \************************/ 9 /***/ ((module) => { 10 11 module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"iansvo/content-area","version":"0.1.0","title":"Content Area","category":"theme","icon":"layout","description":"Adds a block content area to a site editor template.","keywords":["content","area","meta","template","fse"],"attributes":{"metaKey":{"type":"string","default":"extra_content_area"},"disallowedBlocks":{"type":"array","default":[],"items":{"type":"string"}},"blockFilter":{"type":"string","enum":["allow","disallow"],"default":"allow"}},"supports":{"html":false,"allowedBlocks":true,"lock":false,"contentRole":true},"usesContext":["postId","postType","queryId"],"textdomain":"content-area-block","editorScript":"file:./index.js","render":"file:./render.php"}'); 12 13 /***/ }), 14 15 /***/ "./src/edit.js": 16 /*!*********************!*\ 17 !*** ./src/edit.js ***! 18 \*********************/ 19 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 20 21 __webpack_require__.r(__webpack_exports__); 22 /* harmony export */ __webpack_require__.d(__webpack_exports__, { 23 /* harmony export */ "default": () => (/* binding */ ContentAreaEdit) 24 /* harmony export */ }); 25 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); 26 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__); 27 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); 28 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__); 29 /* harmony import */ var _wordpress_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/editor */ "@wordpress/editor"); 30 /* harmony import */ var _wordpress_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__); 31 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks"); 32 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__); 33 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); 34 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__); 35 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); 36 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_5__); 37 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); 38 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__); 39 /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @wordpress/core-data */ "@wordpress/core-data"); 40 /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_7__); 41 /* harmony import */ var _hooks__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./hooks */ "./src/hooks.js"); 42 /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime"); 43 /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__); 44 /** 45 * WordPress dependencies 46 */ 47 48 49 50 51 52 53 54 55 56 57 const blockFilterTypes = [{ 58 value: 'allow', 59 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Allow', 'content-area-block') 60 }, { 61 value: 'disallow', 62 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Disallow', 'content-area-block') 63 }]; 64 function ReadOnlyContent({ 65 parentLayout, 66 layoutClassNames, 67 userCanEdit, 68 postType, 69 postId, 70 tagName: TagName = 'div' 71 }) { 72 const [,, content] = (0,_wordpress_core_data__WEBPACK_IMPORTED_MODULE_7__.useEntityProp)('postType', postType, 'content', postId); 73 const blockProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.useBlockProps)({ 74 className: layoutClassNames 75 }); 76 const blocks = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useMemo)(() => { 77 return content?.raw ? (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__.parse)(content.raw) : []; 78 }, [content?.raw]); 79 const blockPreviewProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.__experimentalUseBlockPreview)({ 80 blocks, 81 props: blockProps, 82 layout: parentLayout 83 }); 84 if (userCanEdit) { 85 /* 86 * Rendering the block preview using the raw content blocks allows for 87 * block support styles to be generated and applied by the editor. 88 * 89 * The preview using the raw blocks can only be presented to users with 90 * edit permissions for the post to prevent potential exposure of private 91 * block content. 92 */ 93 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", { 94 ...blockPreviewProps 95 }); 96 } 97 return content?.protected ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(TagName, { 98 ...blockProps, 99 children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.Warning, { 100 children: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('This content is password protected.', 'content-area-block') 101 }) 102 }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(TagName, { 103 ...blockProps, 104 dangerouslySetInnerHTML: { 105 __html: content?.rendered 106 } 107 }); 108 } 109 function EditableContent({ 110 layout, 111 context = {}, 112 attributes = {} 113 }) { 114 const { 115 allowedBlocks = [], 116 disallowedBlocks = [], 117 blockFilter = 'allow' 118 } = attributes; 119 const { 120 blocks, 121 onChange, 122 onInput 123 } = (0,_hooks__WEBPACK_IMPORTED_MODULE_8__.useMetaBlockEditor)({ 124 attributes, 125 context 126 }); 127 const allowedBlocksList = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useMemo)(() => { 128 const blockTypes = (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__.getBlockTypes)(); 129 const filterMode = blockFilter === 'allow' && Array.isArray(allowedBlocks) ? 'allow' : 'disallow'; 130 let list = filterMode === 'allow' ? allowedBlocks : blockTypes.map(({ 131 name 132 }) => name); 133 list = blockFilter === 'disallow' ? list.filter(blockType => !disallowedBlocks.includes(blockType)) : list; 134 135 // Always ensure paragraph is available 136 if (list.length > 0 && !list.includes('core/paragraph')) { 137 list = ['core/paragraph', ...list]; 138 } 139 return list; 140 }, [blockFilter, allowedBlocks, disallowedBlocks]); 141 const blockProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.useBlockProps)(); 142 const innerBlocksProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.useInnerBlocksProps)(blockProps, { 143 value: blocks, 144 onInput, 145 onChange, 146 allowedBlocks: allowedBlocksList.length > 0 ? allowedBlocksList : undefined, 147 template: !blocks?.length ? [['core/paragraph']] : undefined 148 }); 149 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", { 150 ...innerBlocksProps 151 }); 152 } 153 function Content(props) { 154 const { 155 context: { 156 queryId, 157 postType, 158 postId 159 } = {} 160 } = props; 161 const isDescendentOfQueryLoop = Number.isFinite(queryId); 162 const userCanEdit = (0,_hooks__WEBPACK_IMPORTED_MODULE_8__.useCanEditEntity)('postType', postType, postId); 163 const isEditable = userCanEdit && !isDescendentOfQueryLoop; 164 return isEditable ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(EditableContent, { 165 ...props 166 }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(ReadOnlyContent, { 167 userCanEdit: userCanEdit, 168 postType: postType, 169 postId: postId 170 }); 171 } 172 function Placeholder({ 173 metaKey = '' 174 }) { 175 const blockProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.useBlockProps)(); 176 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", { 177 ...blockProps, 178 children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("p", { 179 children: metaKey ? (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.sprintf)( 180 // Translators: %s is the metaKey attribute value. 181 (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Post Content from meta_key: %s', 'content-area-block'), metaKey) : (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Set a meta key to pull blocks from.', 'content-area-block') 182 }) 183 }); 184 } 185 function RecursionError() { 186 const blockProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.useBlockProps)(); 187 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("div", { 188 ...blockProps, 189 children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.Warning, { 190 children: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Block cannot be rendered inside itself.', 'content-area-block') 191 }) 192 }); 193 } 194 function ContentAreaEdit({ 195 context, 196 attributes, 197 setAttributes 198 }) { 199 const { 200 metaKey, 201 allowedBlocks = [], 202 disallowedBlocks = [], 203 blockFilter = 'allow' 204 } = attributes; 205 const { 206 layout = {} 207 } = attributes; 208 const { 209 postId, 210 postType, 211 editingMode 212 } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.useSelect)(select => { 213 return { 214 postId: select(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__.store).getCurrentPostId(), 215 postType: select(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__.store).getCurrentPostType(), 216 editingMode: select(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.store).getBlockEditingMode() 217 }; 218 }); 219 const [hasAlreadyRendered, RecursionProvider] = (0,_hooks__WEBPACK_IMPORTED_MODULE_8__.useNoRecursiveRenders)(postId); 220 const isValidPostId = 'number' === typeof postId && postId; 221 const handleMetaKeyChange = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useCallback)(function handleMetaKeyChange(value) { 222 setAttributes({ 223 metaKey: value 224 }); 225 }, [setAttributes]); 226 const handleAllowedBlocksChange = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useCallback)(function handleAllowedBlocksChange(value) { 227 setAttributes({ 228 allowedBlocks: value 229 }); 230 }, [setAttributes]); 231 const handleDisallowedBlocksChange = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useCallback)(function handleDisallowedBlocksChange(value) { 232 setAttributes({ 233 disallowedBlocks: value 234 }); 235 }, [setAttributes]); 236 const blockSuggestions = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useMemo)(() => { 237 const blockTypes = (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__.getBlockTypes)(); 238 return blockTypes.map(block => block.name); 239 }, []); 240 if (isValidPostId && postType && hasAlreadyRendered) { 241 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(RecursionError, {}); 242 } 243 const showControls = editingMode === 'default'; 244 return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)(RecursionProvider, { 245 children: [isValidPostId && postType ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(Content, { 246 context: context, 247 layout: layout, 248 attributes: attributes, 249 postId: postId, 250 postType: postType 251 }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(Placeholder, { 252 metaKey: metaKey 253 }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_4__.InspectorControls, { 254 children: showControls ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.PanelBody, { 255 title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Content Area Settings', 'content-area-block'), 256 children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.TextControl, { 257 __next40pxDefaultSize: true, 258 __nextHasNoMarginBottom: true, 259 value: metaKey, 260 onChange: handleMetaKeyChange, 261 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Meta Key', 'content-area-block') 262 }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.SelectControl, { 263 value: blockFilter, 264 onChange: newValue => setAttributes({ 265 blockFilter: newValue 266 }), 267 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Block Filter Type', 'content-area-block'), 268 options: blockFilterTypes 269 }), blockFilter === 'allow' && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.FormTokenField, { 270 __next40pxDefaultSize: true, 271 __nextHasNoMarginBottom: true, 272 value: allowedBlocks, 273 onChange: handleAllowedBlocksChange, 274 suggestions: blockSuggestions, 275 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Allowed Blocks', 'content-area-block') 276 }), blockFilter === 'disallow' && /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.FormTokenField, { 277 __next40pxDefaultSize: true, 278 __nextHasNoMarginBottom: true, 279 value: disallowedBlocks, 280 onChange: handleDisallowedBlocksChange, 281 suggestions: blockSuggestions, 282 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Disallowed Blocks', 'content-area-block') 283 })] 284 }) : /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.PanelBody, { 285 opened: true, 286 children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)(_wordpress_components__WEBPACK_IMPORTED_MODULE_6__.Notice, { 287 isDismissible: false, 288 status: "warning", 289 children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)("h2", { 290 style: { 291 marginBlockStart: 0 292 }, 293 children: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Content Only Mode', 'content-area-block') 294 }), (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_0__.__)('Edit the template to change settings for this block.', 'content-area-block')] 295 }) 296 }) 297 })] 298 }); 299 } 300 301 /***/ }), 302 303 /***/ "./src/filters.js": 304 /*!************************!*\ 305 !*** ./src/filters.js ***! 306 \************************/ 307 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 308 309 __webpack_require__.r(__webpack_exports__); 310 /* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks"); 311 /* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_hooks__WEBPACK_IMPORTED_MODULE_0__); 312 313 314 // 315 function addCustomPostContentBlockTypes(blockTypes) { 316 return [...blockTypes, 'iansvo/content-area']; 317 } 318 (0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_0__.addFilter)('editor.postContentBlockTypes', 'iansvo/content-area/post-content-block-types', addCustomPostContentBlockTypes); 319 320 /***/ }), 321 322 /***/ "./src/hooks.js": 323 /*!**********************!*\ 324 !*** ./src/hooks.js ***! 325 \**********************/ 326 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 327 328 __webpack_require__.r(__webpack_exports__); 329 /* harmony export */ __webpack_require__.d(__webpack_exports__, { 330 /* harmony export */ useCanEditEntity: () => (/* binding */ useCanEditEntity), 331 /* harmony export */ useMetaBlockEditor: () => (/* binding */ useMetaBlockEditor), 332 /* harmony export */ useNoRecursiveRenders: () => (/* binding */ useNoRecursiveRenders) 333 /* harmony export */ }); 334 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); 335 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); 336 /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/core-data */ "@wordpress/core-data"); 337 /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__); 338 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); 339 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__); 340 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); 341 /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_3__); 342 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks"); 343 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__); 344 /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime"); 345 /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__); 346 /** 347 * WordPress dependencies 348 */ 349 350 351 352 353 354 355 const RenderedRefsContext = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.createContext)({}); 356 357 /** 358 * Returns whether the current user can edit the given entity. 359 * 360 * @param {string} kind Entity kind. 361 * @param {string} name Entity name. 362 * @param {string} recordId Record's id. 363 */ 364 function useCanEditEntity(kind, name, recordId) { 365 return (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useSelect)(select => select(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__.store).canUser('update', { 366 kind, 367 name, 368 id: recordId 369 }), [kind, name, recordId]); 370 } 371 372 /** 373 * Immutably adds an unique identifier to a set scoped for a given block type. 374 * 375 * @param {Object} renderedBlocks Rendered blocks grouped by block name 376 * @param {string} blockName Name of the block. 377 * @param {*} uniqueId Any value that acts as a unique identifier for a block instance. 378 * 379 * @return {Object} The list of rendered blocks grouped by block name. 380 */ 381 function addToBlockType(renderedBlocks, blockName, uniqueId) { 382 const result = { 383 ...renderedBlocks, 384 [blockName]: renderedBlocks[blockName] ? new Set(renderedBlocks[blockName]) : new Set() 385 }; 386 result[blockName].add(uniqueId); 387 return result; 388 } 389 390 /** 391 * A React hook for keeping track of blocks previously rendered up in the block 392 * tree. Blocks susceptible to recursion can use this hook in their `Edit` 393 * function to prevent said recursion. 394 * 395 * @see https://github.com/iansvo/gutenberg/blob/a7e2895829c16ecd77a5ba22d84f1dee1cfb0977/packages/block-editor/src/components/use-no-recursive-renders/index.js 396 * 397 * @param {*} uniqueId Any value that acts as a unique identifier for a block instance. 398 * @param {string} blockName Optional block name. 399 * 400 * @return {[boolean, Function]} A tuple of: 401 * - a boolean describing whether the provided id 402 * has already been rendered; 403 * - a React context provider to be used to wrap 404 * other elements. 405 */ 406 function useNoRecursiveRenders(uniqueId, blockName = '') { 407 const previouslyRenderedBlocks = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useContext)(RenderedRefsContext); 408 const { 409 name 410 } = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.useBlockEditContext)(); 411 blockName = blockName || name; 412 const hasAlreadyRendered = Boolean(previouslyRenderedBlocks[blockName]?.has(uniqueId)); 413 const newRenderedBlocks = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useMemo)(() => addToBlockType(previouslyRenderedBlocks, blockName, uniqueId), [previouslyRenderedBlocks, blockName, uniqueId]); 414 const Provider = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useCallback)(({ 415 children 416 }) => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_5__.jsx)(RenderedRefsContext.Provider, { 417 value: newRenderedBlocks, 418 children: children 419 }), [newRenderedBlocks]); 420 return [hasAlreadyRendered, Provider]; 421 } 422 const EMPTY_ARRAY = []; 423 function useMetaBlockEditor({ 424 attributes, 425 context 426 }) { 427 const { 428 postType, 429 postId: contextPostId 430 } = context; 431 const providerId = (0,_wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__.useEntityId)('postType', postType); 432 const postId = contextPostId !== null && contextPostId !== void 0 ? contextPostId : providerId; 433 const { 434 metaKey 435 } = attributes; 436 const BLOCKS_KEY = `${metaKey}_blocks`; 437 const editedRecord = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useSelect)(select => { 438 const { 439 getEditedEntityRecord 440 } = select('core'); 441 return getEditedEntityRecord('postType', postType, postId); 442 }, [postType, postId]); 443 const { 444 meta 445 } = editedRecord; 446 const content = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useMemo)(() => meta?.[metaKey] || '', [meta, metaKey]); 447 const [localBlocks, setLocalBlocks] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useState)(() => editedRecord?.[BLOCKS_KEY]); 448 const blocks = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useMemo)(() => { 449 // If we have local blocks from a recent edit, use those 450 if (localBlocks) { 451 return localBlocks; 452 } 453 // Otherwise use stored blocks 454 if (editedRecord?.[BLOCKS_KEY]) { 455 return editedRecord[BLOCKS_KEY]; 456 } 457 if (content) { 458 return (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__.parse)(content); 459 } 460 return EMPTY_ARRAY; 461 }, [localBlocks, editedRecord, BLOCKS_KEY, content]); 462 const { 463 editEntityRecord, 464 __unstableCreateUndoLevel 465 } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.useDispatch)(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__.store); 466 467 // Clear local blocks when content is successfully saved 468 (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useEffect)(() => { 469 if (editedRecord?.[BLOCKS_KEY] && localBlocks) { 470 setLocalBlocks(null); 471 } 472 }, [editedRecord, BLOCKS_KEY, localBlocks]); 473 const onChange = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useCallback)(newBlocks => { 474 const noChange = blocks === newBlocks; 475 if (noChange) { 476 return __unstableCreateUndoLevel('postType', postType, postId); 477 } 478 const serializedContent = (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__.__unstableSerializeAndClean)(newBlocks); 479 480 // Set local blocks immediately for UI responsiveness 481 setLocalBlocks(newBlocks); 482 const edits = { 483 [BLOCKS_KEY]: newBlocks, 484 meta: { 485 ...meta, 486 [metaKey]: serializedContent 487 } 488 }; 489 editEntityRecord('postType', postType, postId, edits, { 490 isCached: false 491 }); 492 }, [BLOCKS_KEY, blocks, editEntityRecord, meta, metaKey, postId, postType, __unstableCreateUndoLevel]); 493 const onInput = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_3__.useCallback)(newBlocks => { 494 // Set local blocks immediately for UI responsiveness 495 setLocalBlocks(newBlocks); 496 const serializedContent = (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_4__.__unstableSerializeAndClean)(newBlocks); 497 const edits = { 498 [BLOCKS_KEY]: newBlocks, 499 meta: { 500 ...meta, 501 [metaKey]: serializedContent 502 } 503 }; 504 editEntityRecord('postType', postType, postId, edits, { 505 isCached: true 506 }); 507 }, [BLOCKS_KEY, editEntityRecord, meta, metaKey, postId, postType]); 508 return { 509 blocks, 510 onChange, 511 onInput 512 }; 513 } 514 515 /***/ }), 516 517 /***/ "@wordpress/block-editor": 518 /*!*************************************!*\ 519 !*** external ["wp","blockEditor"] ***! 520 \*************************************/ 521 /***/ ((module) => { 522 523 module.exports = window["wp"]["blockEditor"]; 524 525 /***/ }), 526 527 /***/ "@wordpress/blocks": 528 /*!********************************!*\ 529 !*** external ["wp","blocks"] ***! 530 \********************************/ 531 /***/ ((module) => { 532 533 module.exports = window["wp"]["blocks"]; 534 535 /***/ }), 536 537 /***/ "@wordpress/components": 538 /*!************************************!*\ 539 !*** external ["wp","components"] ***! 540 \************************************/ 541 /***/ ((module) => { 542 543 module.exports = window["wp"]["components"]; 544 545 /***/ }), 546 547 /***/ "@wordpress/core-data": 548 /*!**********************************!*\ 549 !*** external ["wp","coreData"] ***! 550 \**********************************/ 551 /***/ ((module) => { 552 553 module.exports = window["wp"]["coreData"]; 554 555 /***/ }), 556 557 /***/ "@wordpress/data": 558 /*!******************************!*\ 559 !*** external ["wp","data"] ***! 560 \******************************/ 561 /***/ ((module) => { 562 563 module.exports = window["wp"]["data"]; 564 565 /***/ }), 566 567 /***/ "@wordpress/editor": 568 /*!********************************!*\ 569 !*** external ["wp","editor"] ***! 570 \********************************/ 571 /***/ ((module) => { 572 573 module.exports = window["wp"]["editor"]; 574 575 /***/ }), 576 577 /***/ "@wordpress/element": 578 /*!*********************************!*\ 579 !*** external ["wp","element"] ***! 580 \*********************************/ 581 /***/ ((module) => { 582 583 module.exports = window["wp"]["element"]; 584 585 /***/ }), 586 587 /***/ "@wordpress/hooks": 588 /*!*******************************!*\ 589 !*** external ["wp","hooks"] ***! 590 \*******************************/ 591 /***/ ((module) => { 592 593 module.exports = window["wp"]["hooks"]; 594 595 /***/ }), 596 597 /***/ "@wordpress/i18n": 598 /*!******************************!*\ 599 !*** external ["wp","i18n"] ***! 600 \******************************/ 601 /***/ ((module) => { 602 603 module.exports = window["wp"]["i18n"]; 604 605 /***/ }), 606 607 /***/ "react/jsx-runtime": 608 /*!**********************************!*\ 609 !*** external "ReactJSXRuntime" ***! 610 \**********************************/ 611 /***/ ((module) => { 612 613 module.exports = window["ReactJSXRuntime"]; 614 615 /***/ }) 616 617 /******/ }); 618 /************************************************************************/ 619 /******/ // The module cache 620 /******/ var __webpack_module_cache__ = {}; 621 /******/ 622 /******/ // The require function 623 /******/ function __webpack_require__(moduleId) { 624 /******/ // Check if module is in cache 625 /******/ var cachedModule = __webpack_module_cache__[moduleId]; 626 /******/ if (cachedModule !== undefined) { 627 /******/ return cachedModule.exports; 628 /******/ } 629 /******/ // Create a new module (and put it into the cache) 630 /******/ var module = __webpack_module_cache__[moduleId] = { 631 /******/ // no module.id needed 632 /******/ // no module.loaded needed 633 /******/ exports: {} 634 /******/ }; 635 /******/ 636 /******/ // Execute the module function 637 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 638 /******/ 639 /******/ // Return the exports of the module 640 /******/ return module.exports; 641 /******/ } 642 /******/ 643 /************************************************************************/ 644 /******/ /* webpack/runtime/compat get default export */ 645 /******/ (() => { 646 /******/ // getDefaultExport function for compatibility with non-harmony modules 647 /******/ __webpack_require__.n = (module) => { 648 /******/ var getter = module && module.__esModule ? 649 /******/ () => (module['default']) : 650 /******/ () => (module); 651 /******/ __webpack_require__.d(getter, { a: getter }); 652 /******/ return getter; 653 /******/ }; 654 /******/ })(); 655 /******/ 656 /******/ /* webpack/runtime/define property getters */ 657 /******/ (() => { 658 /******/ // define getter functions for harmony exports 659 /******/ __webpack_require__.d = (exports, definition) => { 660 /******/ for(var key in definition) { 661 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 662 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 663 /******/ } 664 /******/ } 665 /******/ }; 666 /******/ })(); 667 /******/ 668 /******/ /* webpack/runtime/hasOwnProperty shorthand */ 669 /******/ (() => { 670 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 671 /******/ })(); 672 /******/ 673 /******/ /* webpack/runtime/make namespace object */ 674 /******/ (() => { 675 /******/ // define __esModule on exports 676 /******/ __webpack_require__.r = (exports) => { 677 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 678 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 679 /******/ } 680 /******/ Object.defineProperty(exports, '__esModule', { value: true }); 681 /******/ }; 682 /******/ })(); 683 /******/ 684 /************************************************************************/ 685 var __webpack_exports__ = {}; 686 // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. 687 (() => { 688 /*!**********************!*\ 689 !*** ./src/index.js ***! 690 \**********************/ 691 __webpack_require__.r(__webpack_exports__); 692 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks"); 693 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__); 694 /* harmony import */ var _edit__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./edit */ "./src/edit.js"); 695 /* harmony import */ var _block_json__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./block.json */ "./src/block.json"); 696 /* harmony import */ var _filters__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./filters */ "./src/filters.js"); 697 698 699 700 701 (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__.registerBlockType)(_block_json__WEBPACK_IMPORTED_MODULE_2__.name, { 702 edit: _edit__WEBPACK_IMPORTED_MODULE_1__["default"], 703 save: () => null 704 }); 705 })(); 706 707 /******/ })() 708 ; 709 //# sourceMappingURL=index.js.map -
content-area-block/trunk/content-area-block.php
r3406218 r3431152 3 3 * Plugin Name: Content Area Block 4 4 * Description: Add an outlet for blocks in a template that stores block data in a meta field. 5 * Version: 1.0. 15 * Version: 1.0.2 6 6 * Requires at least: 6.7 7 7 * Requires PHP: 7.4 -
content-area-block/trunk/readme.txt
r3406218 r3431152 2 2 Contributors: iansvo 3 3 Tags: block, fse, site-editor, content, template 4 Tested up to: 6. 85 Stable tag: 1.0. 14 Tested up to: 6.9 5 Stable tag: 1.0.2 6 6 License: GPL-2.0-or-later 7 7 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
content-area-block/trunk/src/block.json
r3336929 r3431152 14 14 "default": "extra_content_area" 15 15 }, 16 "allowedBlocks": {17 "type": "array",18 "default": [],19 "items": {20 "type": "string"21 }22 },23 16 "disallowedBlocks": { 24 17 "type": "array", … … 35 28 }, 36 29 "supports": { 37 "html": false 30 "html": false, 31 "allowedBlocks": true, 32 "lock": false, 33 "contentRole": true 38 34 }, 39 "usesContext": [ "postId", "postType" ],35 "usesContext": [ "postId", "postType", "queryId" ], 40 36 "textdomain": "content-area-block", 41 37 "editorScript": "file:./index.js", -
content-area-block/trunk/src/edit.js
r3406218 r3431152 10 10 useInnerBlocksProps, 11 11 useSettings, 12 useBlockEditingMode, 12 13 store as blockEditorStore, 13 14 Warning, … … 101 102 blockFilter = 'allow', 102 103 } = attributes; 103 const themeSupportsLayout = useSelect( ( select ) => {104 const { getSettings } = select( blockEditorStore );105 return getSettings()?.supportsLayout;106 }, [] );107 const defaultLayout = useSettings( [ 'layout' ] )[ 0 ] || {};108 const usedLayout = !! layout && layout.inherit ? defaultLayout : layout;109 104 const { blocks, onChange, onInput } = useMetaBlockEditor( { 110 105 attributes, … … 114 109 const allowedBlocksList = useMemo( () => { 115 110 const blockTypes = getBlockTypes(); 111 const filterMode = blockFilter === 'allow' && Array.isArray( allowedBlocks ) ? 'allow' : 'disallow'; 116 112 117 113 let list = 118 blockFilter=== 'allow'114 filterMode === 'allow' 119 115 ? allowedBlocks 120 116 : blockTypes.map( ( { name } ) => name ); … … 136 132 137 133 const blockProps = useBlockProps(); 138 const props = useInnerBlocksProps( blockProps, {134 const innerBlocksProps = useInnerBlocksProps( blockProps, { 139 135 value: blocks, 140 136 onInput, 141 137 onChange, 142 __experimentalLayout: themeSupportsLayout ? usedLayout : undefined,143 138 allowedBlocks: 144 139 allowedBlocksList.length > 0 ? allowedBlocksList : undefined, 145 140 template: ! blocks?.length ? [ [ 'core/paragraph' ] ] : undefined, 146 __experimentalDefaultBlock: { name: 'core/paragraph' },147 __experimentalDirectInsert: true,148 141 } ); 149 142 150 return <div { ... props } />;143 return <div { ...innerBlocksProps } />; 151 144 } 152 145
Note: See TracChangeset
for help on using the changeset viewer.