Changeset 3402104
- Timestamp:
- 11/24/2025 10:13:13 PM (4 months ago)
- Location:
- content-area-block/trunk
- Files:
-
- 7 edited
-
build/block.json (modified) (1 diff)
-
build/index.asset.php (modified) (1 diff)
-
build/index.js (modified) (1 diff)
-
content-area-block.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
-
src/edit.js (modified) (1 diff)
-
src/hooks.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
content-area-block/trunk/build/block.json
r3336929 r3402104 18 18 "metaKey": { 19 19 "type": "string", 20 "default": " "20 "default": "extra_content_area" 21 21 }, 22 22 "allowedBlocks": { -
content-area-block/trunk/build/index.asset.php
r3336929 r3402104 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' => ' 19161ae0ff48fd6afbba');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' => '7e0b176223b22e53e510'); -
content-area-block/trunk/build/index.js
r3336929 r3402104 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); return(0,l.useEffect)((()=>{k?.[p]&&b&&y(null)}),[k,p,b]),{blocks:x,onChange:(0,l.useCallback)((t=>{const o=(0,e.__unstableSerializeAndClean)(t);if(_===o)return g("postType",s,i);y(t);const n={[p]:t,meta:{...w,[d]:o}};m("postType",s,i,n)}),[p,_,m,w,d,i,s,g]),onInput:(0,l.useCallback)((t=>{y(t);const o=(0,e.__unstableSerializeAndClean)(t),n={[p]:t,meta:{...w,[d]:o}};m("postType",s,i,n)}),[p,m,w,d,i,s])}}({attributes:a,context:n}),m=(0,l.useMemo)((()=>{const t=(0,e.getBlockTypes)(),o="allow"===p?i:t.map((({name:e})=>e));return"disallow"===p?o.filter((e=>!d.includes(e))):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,defaultBlock:[i?.[0]||"core/paragraph"]});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)(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)(),o="allow"===p?i:t.map((({name:e})=>e));return"disallow"===p?o.filter((e=>!d.includes(e))):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"]]});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 2 // Translators: %s is the metaKey attribute value. 3 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: B,editingMode:C}=(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&&B&&f)return(0,c.jsx)(b,{});const P="default"===C;return(0,c.jsxs)(j,{children:[T&&B?(0,c.jsx)(w,{context:r,layout:g,attributes:u,postId:h,postType:B}):(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})})();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})})(); -
content-area-block/trunk/content-area-block.php
r3336929 r3402104 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: 0.1.05 * Version: 1.0.0 6 6 * Requires at least: 6.7 7 7 * Requires PHP: 7.4 -
content-area-block/trunk/readme.txt
r3336931 r3402104 8 8 Repository URI: https://github.com/iansvo/content-area-block 9 9 10 == Description == 11 12 This block allows you to add an additional block content area to a site-editor template and store the block output inside a meta field. By default, the plugin will add a new meta field called `extra_content_area` for all post types which you can use to store the block markup. 10 Adds a block content area to a site editor template and stores the blocks in a specified meta field. By default, the plugin will add a new meta field called `extra_content_area` for all post types which you can use to store the block markup. 13 11 14 12 If you want to disable this meta key's registration, add the following to your theme or plugin: … … 18 16 add_filter( 'content_area_block_register_default_meta', '__return_false' ); 19 17 ` 18 19 == Description == 20 21 This block allows you to add an additional block content area to a site-editor template and store the block output inside a meta field. 20 22 21 23 Note: Using this plugin requires you to enable template previews (which will let you visually see the new content area you're adding). This can be enabled on any given post or page, but you can optionally set it on by default using a filter. … … 38 40 == Changelog == 39 41 42 = 1.0.0 = 43 * Fixed issues with undo, paste, and default block display. 44 40 45 = 0.1.0 = 41 46 * Release -
content-area-block/trunk/src/edit.js
r3336929 r3402104 135 135 allowedBlocks: 136 136 allowedBlocksList.length > 0 ? allowedBlocksList : undefined, 137 defaultBlock: [ allowedBlocks?.[ 0 ] || 'core/paragraph' ],137 template: ! blocks?.length ? [ [ 'core/paragraph' ] ] : undefined, 138 138 } ); 139 139 -
content-area-block/trunk/src/hooks.js
r3336929 r3402104 147 147 const onChange = useCallback( 148 148 ( newBlocks ) => { 149 const serializedContent = __unstableSerializeAndClean( newBlocks ); 150 151 if ( content === serializedContent ) { 149 const noChange = blocks === newBlocks; 150 if ( noChange ) { 152 151 return __unstableCreateUndoLevel( 153 152 'postType', … … 156 155 ); 157 156 } 157 158 const serializedContent = __unstableSerializeAndClean( newBlocks ); 158 159 159 160 // Set local blocks immediately for UI responsiveness … … 168 169 }; 169 170 170 editEntityRecord( 'postType', postType, postId, edits );171 editEntityRecord( 'postType', postType, postId, edits, { isCached: false } ); 171 172 }, 172 173 [ 173 174 BLOCKS_KEY, 174 content,175 blocks, 175 176 editEntityRecord, 176 177 meta, … … 197 198 }; 198 199 199 editEntityRecord( 'postType', postType, postId, edits );200 editEntityRecord( 'postType', postType, postId, edits, { isCached: true } ); 200 201 }, 201 202 [ BLOCKS_KEY, editEntityRecord, meta, metaKey, postId, postType ]
Note: See TracChangeset
for help on using the changeset viewer.