Plugin Directory

Changeset 3402104


Ignore:
Timestamp:
11/24/2025 10:13:13 PM (4 months ago)
Author:
iansvo
Message:

1.0.0 release

Location:
content-area-block/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • content-area-block/trunk/build/block.json

    r3336929 r3402104  
    1818    "metaKey": {
    1919      "type": "string",
    20       "default": ""
     20      "default": "extra_content_area"
    2121    },
    2222    "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)(
    22// Translators: %s is the metaKey attribute value.
    33// 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  
    33 * Plugin Name:       Content Area Block
    44 * Description:       Add an outlet for blocks in a template that stores block data in a meta field.
    5  * Version:           0.1.0
     5 * Version:           1.0.0
    66 * Requires at least: 6.7
    77 * Requires PHP:      7.4
  • content-area-block/trunk/readme.txt

    r3336931 r3402104  
    88Repository URI:    https://github.com/iansvo/content-area-block
    99
    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.
     10Adds 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.
    1311
    1412If you want to disable this meta key's registration, add the following to your theme or plugin:
     
    1816add_filter( 'content_area_block_register_default_meta', '__return_false' );
    1917`
     18
     19== Description ==
     20
     21This block allows you to add an additional block content area to a site-editor template and store the block output inside a meta field.
    2022
    2123Note: 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.
     
    3840== Changelog ==
    3941
     42= 1.0.0 =
     43* Fixed issues with undo, paste, and default block display.
     44
    4045= 0.1.0 =
    4146* Release
  • content-area-block/trunk/src/edit.js

    r3336929 r3402104  
    135135        allowedBlocks:
    136136            allowedBlocksList.length > 0 ? allowedBlocksList : undefined,
    137         defaultBlock: [ allowedBlocks?.[ 0 ] || 'core/paragraph' ],
     137        template: ! blocks?.length ? [ [ 'core/paragraph' ] ] : undefined,
    138138    } );
    139139
  • content-area-block/trunk/src/hooks.js

    r3336929 r3402104  
    147147    const onChange = useCallback(
    148148        ( newBlocks ) => {
    149             const serializedContent = __unstableSerializeAndClean( newBlocks );
    150 
    151             if ( content === serializedContent ) {
     149            const noChange = blocks === newBlocks;
     150            if ( noChange ) {
    152151                return __unstableCreateUndoLevel(
    153152                    'postType',
     
    156155                );
    157156            }
     157
     158            const serializedContent = __unstableSerializeAndClean( newBlocks );
    158159
    159160            // Set local blocks immediately for UI responsiveness
     
    168169            };
    169170
    170             editEntityRecord( 'postType', postType, postId, edits );
     171            editEntityRecord( 'postType', postType, postId, edits, { isCached: false } );
    171172        },
    172173        [
    173174            BLOCKS_KEY,
    174             content,
     175            blocks,
    175176            editEntityRecord,
    176177            meta,
     
    197198            };
    198199
    199             editEntityRecord( 'postType', postType, postId, edits );
     200            editEntityRecord( 'postType', postType, postId, edits, { isCached: true } );
    200201        },
    201202        [ BLOCKS_KEY, editEntityRecord, meta, metaKey, postId, postType ]
Note: See TracChangeset for help on using the changeset viewer.