Plugin Directory

Changeset 3182831


Ignore:
Timestamp:
11/06/2024 05:30:52 AM (17 months ago)
Author:
happyprime
Message:

Update to version 3.0.0 from GitHub

Location:
show-hide-section-block
Files:
34 added
2 deleted
34 edited
1 copied

Legend:

Unmodified
Added
Removed
  • show-hide-section-block/tags/3.0.0/LICENSE

    r2874431 r3182831  
    11Show/Hide Section Block - a plugin for WordPress
    22
    3 Copyright 2020-2023 by Happy Prime
     3Copyright 2020-2024 by Happy Prime
    44
    55This program is free software; you can redistribute it and/or modify
  • show-hide-section-block/tags/3.0.0/build/show-hide-group/block.json

    r2905297 r3182831  
    11{
    2   "$schema": "https://json.schemastore.org/block.json",
    3   "apiVersion": 2,
    4   "name": "happyprime/show-hide-group",
    5   "title": "Show Hide Group",
    6   "textdomain": "show-hide-section-block",
    7   "category": "widgets",
    8   "description": "A group of accessible summaries that can be toggled to show or hide additional details.",
    9   "icon": "hidden",
    10   "attributes": {
    11     "hasToggle": {
    12       "type": "boolean",
    13       "default": false
    14     }
    15   },
    16   "supports": {
    17     "align": true,
    18     "alignWide": true,
    19     "anchor": true,
    20     "color": {
    21       "background": true,
    22       "enableContrastChecker": true,
    23       "text": true,
    24       "link": true,
    25       "gradients": true
    26     },
    27     "defaultStylePicker": true,
    28     "dimensions": {
    29       "minHeight": true
    30     },
    31     "html": false,
    32     "position": {
    33       "sticky": false
    34     },
    35     "spacing": {
    36       "margin": true,
    37       "padding": true
    38     },
    39     "typography": {
    40       "fontSize": true,
    41       "lineHeight": true
    42     }
    43   },
    44   "editorScript": "file:index.js",
    45   "viewScript": "file:view.js"
     2    "$schema": "https://json.schemastore.org/block.json",
     3    "apiVersion": 3,
     4    "name": "happyprime/show-hide-group",
     5    "title": "Show Hide Group",
     6    "textdomain": "show-hide-section-block",
     7    "category": "widgets",
     8    "description": "A group of accessible summaries that can be toggled to show or hide additional details.",
     9    "icon": "hidden",
     10    "attributes": {
     11        "hasToggle": {
     12            "type": "boolean",
     13            "default": false
     14        }
     15    },
     16    "supports": {
     17        "align": true,
     18        "alignWide": true,
     19        "anchor": true,
     20        "color": {
     21            "background": true,
     22            "enableContrastChecker": true,
     23            "text": true,
     24            "link": true,
     25            "gradients": true
     26        },
     27        "defaultStylePicker": true,
     28        "dimensions": {
     29            "minHeight": true
     30        },
     31        "html": false,
     32        "position": {
     33            "sticky": false
     34        },
     35        "spacing": {
     36            "margin": true,
     37            "padding": true
     38        },
     39        "typography": {
     40            "fontSize": true,
     41            "lineHeight": true
     42        }
     43    },
     44    "editorScript": "file:index.js",
     45    "viewScript": "file:view.js"
    4646}
  • show-hide-section-block/tags/3.0.0/build/show-hide-group/index.asset.php

    r2905297 r3182831  
    1 <?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '9821368a8f1930a9690c');
     1<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-i18n'), 'version' => '70bf254dd1647cf40738');
  • show-hide-section-block/tags/3.0.0/build/show-hide-group/index.js

    r2905297 r3182831  
    1 !function(){"use strict";var e=window.wp.element,t=window.wp.blocks,o=window.wp.blockEditor,l=window.wp.components,a=window.wp.data,i=window.wp.i18n,n=JSON.parse('{"$schema":"https://json.schemastore.org/block.json","apiVersion":2,"name":"happyprime/show-hide-group","title":"Show Hide Group","textdomain":"show-hide-section-block","category":"widgets","description":"A group of accessible summaries that can be toggled to show or hide additional details.","icon":"hidden","attributes":{"hasToggle":{"type":"boolean","default":false}},"supports":{"align":true,"alignWide":true,"anchor":true,"color":{"background":true,"enableContrastChecker":true,"text":true,"link":true,"gradients":true},"defaultStylePicker":true,"dimensions":{"minHeight":true},"html":false,"position":{"sticky":false},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true}},"editorScript":"file:index.js","viewScript":"file:view.js"}');(0,t.registerBlockType)(n,{edit:t=>{const{attributes:{hasToggle:n},setAttributes:r}=t,s=(0,a.useSelect)((e=>e("core/block-editor").getBlocks(t.clientId)));return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(o.InspectorControls,null,(0,e.createElement)(l.PanelBody,null,(0,e.createElement)(l.ToggleControl,{label:(0,i.__)("Has open/close all toggle","show-hide-section-block"),help:n?(0,i.__)("Open/close all toggle will display.","show-hide-section-block"):(0,i.__)("Open/close all toggle will not display.","show-hide-section-block"),checked:n,onChange:e=>{r({hasToggle:e})}}))),(0,e.createElement)("div",(0,o.useBlockProps)(),n&&(0,e.createElement)("button",{className:"toggle-all","aria-expanded":"false",onClick:e=>{!1===e.target.ariaExpanded?(s.forEach((e=>{(0,a.dispatch)("core/block-editor").updateBlockAttributes(e.clientId,{isOpen:!0})})),e.target.innerText=(0,i.__)("Close all","show-hide-section-block"),e.target.ariaExpanded=!0):(s.forEach((e=>{(0,a.dispatch)("core/block-editor").updateBlockAttributes(e.clientId,{isOpen:!1})})),e.target.innerText=(0,i.__)("Open all","show-hide-section-block"),e.target.ariaExpanded=!1)}},(0,i.__)("Open all","show-hide-section-block")),(0,e.createElement)(o.InnerBlocks,{allowedBlocks:["happyprime/show-hide-section"],template:[["happyprime/show-hide-section",{},[["core/paragraph",{}]]],["happyprime/show-hide-section",{},[["core/paragraph",{}]]]],templateLock:!1})))},save:t=>{const{attributes:{hasToggle:l}}=t;return(0,e.createElement)("div",o.useBlockProps.save(),l&&(0,e.createElement)("button",{className:"toggle-all","aria-expanded":"false"},(0,i.__)("Open all","show-hide-section-block")),(0,e.createElement)(o.InnerBlocks.Content,null))}})}();
     1(()=>{"use strict";const e=window.wp.blocks,t=window.wp.blockEditor,o=window.wp.components,l=window.wp.data,a=window.wp.i18n,i=JSON.parse('{"$schema":"https://json.schemastore.org/block.json","apiVersion":3,"name":"happyprime/show-hide-group","title":"Show Hide Group","textdomain":"show-hide-section-block","category":"widgets","description":"A group of accessible summaries that can be toggled to show or hide additional details.","icon":"hidden","attributes":{"hasToggle":{"type":"boolean","default":false}},"supports":{"align":true,"alignWide":true,"anchor":true,"color":{"background":true,"enableContrastChecker":true,"text":true,"link":true,"gradients":true},"defaultStylePicker":true,"dimensions":{"minHeight":true},"html":false,"position":{"sticky":false},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true}},"editorScript":"file:index.js","viewScript":"file:view.js"}');(0,e.registerBlockType)(i,{edit:e=>{const{attributes:{hasToggle:i},setAttributes:n}=e,s=(0,l.useSelect)((t=>t("core/block-editor").getBlocks(e.clientId)));return React.createElement(React.Fragment,null,React.createElement(t.InspectorControls,null,React.createElement(o.PanelBody,null,React.createElement(o.ToggleControl,{label:(0,a.__)("Has open/close all toggle","show-hide-section-block"),help:i?(0,a.__)("Open/close all toggle will display.","show-hide-section-block"):(0,a.__)("Open/close all toggle will not display.","show-hide-section-block"),checked:i,onChange:e=>{n({hasToggle:e})}}))),React.createElement("div",(0,t.useBlockProps)(),i&&React.createElement("button",{className:"toggle-all","aria-expanded":"false",onClick:e=>{!1===e.target.ariaExpanded?(s.forEach((e=>{(0,l.dispatch)("core/block-editor").updateBlockAttributes(e.clientId,{isOpen:!0})})),e.target.innerText=(0,a.__)("Close all","show-hide-section-block"),e.target.ariaExpanded=!0):(s.forEach((e=>{(0,l.dispatch)("core/block-editor").updateBlockAttributes(e.clientId,{isOpen:!1})})),e.target.innerText=(0,a.__)("Open all","show-hide-section-block"),e.target.ariaExpanded=!1)}},(0,a.__)("Open all","show-hide-section-block")),React.createElement(t.InnerBlocks,{allowedBlocks:["happyprime/show-hide-section"],template:[["happyprime/show-hide-section",{}]],templateLock:!1})))},save:e=>{const{attributes:{hasToggle:o}}=e;return React.createElement("div",t.useBlockProps.save(),o&&React.createElement("button",{className:"toggle-all","aria-expanded":"false"},(0,a.__)("Open all","show-hide-section-block")),React.createElement(t.InnerBlocks.Content,null))}})})();
  • show-hide-section-block/tags/3.0.0/build/show-hide-group/view.asset.php

    r2905297 r3182831  
    1 <?php return array('dependencies' => array(), 'version' => 'c1c493ae492c636904dd');
     1<?php return array('dependencies' => array(), 'version' => 'fbf381460e85f307651f');
  • show-hide-section-block/tags/3.0.0/build/show-hide-group/view.js

    r2905297 r3182831  
    1 !function(){{const e=()=>{const e=document.querySelectorAll(".wp-block-happyprime-show-hide-group .toggle-all");e.length>0&&e.forEach((e=>e.addEventListener("click",(()=>{const t=e.parentElement.querySelectorAll("details.wp-block-happyprime-show-hide-section");"true"!==e.ariaExpanded?(t.forEach((e=>{e.setAttribute("open","true")})),e.innerText="Close All",e.ariaExpanded="true"):(t.forEach((e=>{e.removeAttribute("open")})),e.innerText="Open All",e.ariaExpanded="false")}))))};document.addEventListener("DOMContentLoaded",e)}}();
     1(()=>{{const e=()=>{const e=document.querySelectorAll(".wp-block-happyprime-show-hide-group .toggle-all");e.length>0&&e.forEach((e=>e.addEventListener("click",(()=>{const t=e.parentElement.querySelectorAll("details.wp-block-happyprime-show-hide-section");"true"!==e.ariaExpanded?(t.forEach((e=>{e.setAttribute("open","true")})),e.innerText="Close All",e.ariaExpanded="true"):(t.forEach((e=>{e.removeAttribute("open")})),e.innerText="Open All",e.ariaExpanded="false")}))))};document.addEventListener("DOMContentLoaded",e)}})();
  • show-hide-section-block/tags/3.0.0/build/show-hide-section/block.json

    r2905297 r3182831  
    11{
    2   "$schema": "https://json.schemastore.org/block.json",
    3   "apiVersion": 2,
    4   "name": "happyprime/show-hide-section",
    5   "title": "Show Hide Section",
    6   "textdomain": "show-hide-section-block",
    7   "category": "widgets",
    8   "description": "A section of collapsible content contained in a details element with a summary.",
    9   "icon": "media-document",
    10   "parent": [
    11     "happyprime/show-hide-group"
    12   ],
    13   "attributes": {
    14     "isOpen": {
    15       "type": "boolean",
    16       "default": false
    17     },
    18     "summary": {
    19       "type": "string",
    20       "source": "html",
    21       "selector": "summary"
    22     }
    23   },
    24   "supports": {
    25     "anchor": true,
    26     "align": true,
    27     "alignWide": true,
    28     "color": {
    29       "background": true,
    30       "enableContrastChecker": true,
    31       "text": true,
    32       "link": true,
    33       "gradients": true
    34     },
    35     "defaultStylePicker": true,
    36     "dimensions": {
    37       "minHeight": true
    38     },
    39     "html": false,
    40     "multiple": true,
    41     "position": {
    42       "sticky": false
    43     },
    44     "spacing": {
    45       "margin": true,
    46       "padding": true
    47     },
    48     "typography": {
    49       "fontSize": true,
    50       "lineHeight": true
    51     }
    52   },
    53   "editorScript": "file:index.js"
     2    "$schema": "https://json.schemastore.org/block.json",
     3    "apiVersion": 3,
     4    "name": "happyprime/show-hide-section",
     5    "title": "Show Hide Section",
     6    "textdomain": "show-hide-section-block",
     7    "category": "widgets",
     8    "description": "A section of collapsible content contained in a details element with a summary.",
     9    "icon": "media-document",
     10    "parent": [ "happyprime/show-hide-group" ],
     11    "attributes": {
     12        "isOpen": {
     13            "type": "boolean",
     14            "default": false
     15        }
     16    },
     17    "supports": {
     18        "anchor": true,
     19        "align": true,
     20        "alignWide": true,
     21        "color": {
     22            "background": true,
     23            "enableContrastChecker": true,
     24            "text": true,
     25            "link": true,
     26            "gradients": true
     27        },
     28        "defaultStylePicker": true,
     29        "dimensions": {
     30            "minHeight": true
     31        },
     32        "html": false,
     33        "multiple": true,
     34        "position": {
     35            "sticky": false
     36        },
     37        "spacing": {
     38            "margin": true,
     39            "padding": true
     40        },
     41        "typography": {
     42            "fontSize": true,
     43            "lineHeight": true
     44        }
     45    },
     46    "editorScript": "file:index.js"
    5447}
  • show-hide-section-block/tags/3.0.0/build/show-hide-section/index.asset.php

    r2905297 r3182831  
    1 <?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-element', 'wp-i18n'), 'version' => 'b7962f8806702068f778');
     1<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => 'beb08742a35f54543878');
  • show-hide-section-block/tags/3.0.0/build/show-hide-section/index.js

    r2905297 r3182831  
    1 !function(){"use strict";function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},e.apply(this,arguments)}var t=window.wp.element,n=window.wp.blocks,r=window.wp.blockEditor,o=window.wp.i18n,i=JSON.parse('{"$schema":"https://json.schemastore.org/block.json","apiVersion":2,"name":"happyprime/show-hide-section","title":"Show Hide Section","textdomain":"show-hide-section-block","category":"widgets","description":"A section of collapsible content contained in a details element with a summary.","icon":"media-document","parent":["happyprime/show-hide-group"],"attributes":{"isOpen":{"type":"boolean","default":false},"summary":{"type":"string","source":"html","selector":"summary"}},"supports":{"anchor":true,"align":true,"alignWide":true,"color":{"background":true,"enableContrastChecker":true,"text":true,"link":true,"gradients":true},"defaultStylePicker":true,"dimensions":{"minHeight":true},"html":false,"multiple":true,"position":{"sticky":false},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true}},"editorScript":"file:index.js"}');(0,n.registerBlockType)(i,{edit:n=>{const{attributes:{isOpen:i,summary:a},setAttributes:s}=n;return(0,t.createElement)("details",e({},(0,r.useBlockProps)(),{open:i}),(0,t.createElement)(r.RichText,{tagName:"summary",label:(0,o.__)("Summary","show-hide-section-block"),placeholder:(0,o.__)("Summary","show-hide-section-block"),value:a,allowedFormats:["core/bold","core/italic"],onChange:e=>{s({summary:e})},onKeyUp:e=>{" "===e.key&&(e.preventDefault(),(e=>{const{ownerDocument:t}=e,{defaultView:n}=t,r=n.getSelection().getRangeAt(0),o=document.createTextNode(" ");r.deleteContents(),r.insertNode(o),r.setStartAfter(o)})(e.target))}}),(0,t.createElement)(r.InnerBlocks,null))},save:e=>{const{attributes:{summary:n}}=e;return(0,t.createElement)("details",r.useBlockProps.save(),(0,t.createElement)("summary",null,(0,t.createElement)(r.RichText.Content,{tag:"summary",value:n})),(0,t.createElement)(r.InnerBlocks.Content,null))}})}();
     1(()=>{"use strict";const e=window.wp.blocks,t=window.wp.blockEditor,s=window.wp.i18n,i=JSON.parse('{"$schema":"https://json.schemastore.org/block.json","apiVersion":3,"name":"happyprime/show-hide-section","title":"Show Hide Section","textdomain":"show-hide-section-block","category":"widgets","description":"A section of collapsible content contained in a details element with a summary.","icon":"media-document","parent":["happyprime/show-hide-group"],"attributes":{"isOpen":{"type":"boolean","default":false}},"supports":{"anchor":true,"align":true,"alignWide":true,"color":{"background":true,"enableContrastChecker":true,"text":true,"link":true,"gradients":true},"defaultStylePicker":true,"dimensions":{"minHeight":true},"html":false,"multiple":true,"position":{"sticky":false},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true}},"editorScript":"file:index.js"}'),a=[{attributes:{summary:{type:"string",source:"html",selector:"summary"}},save:({attributes:e})=>React.createElement("details",t.useBlockProps.save(),React.createElement("summary",null,e.summary),React.createElement(t.InnerBlocks.Content,null)),migrate:(t,s)=>[{},[(0,e.createBlock)("happyprime/show-hide-summary",{summary:t.summary}),(0,e.createBlock)("happyprime/show-hide-details",{},s)]],supports:{html:!0,anchor:!0},isEligible:({summary:e})=>"string"==typeof e&&e.length>0}];(0,e.registerBlockType)(i,{edit:e=>{const{attributes:{isOpen:i},setAttributes:a,isSelected:r}=e,o=[["happyprime/show-hide-summary",{summary:(0,s.__)("Summary","show-hide-section-block")}],["happyprime/show-hide-details",{details:(0,s.__)("Details","show-hide-section-block")}]];return React.createElement("div",(0,t.useBlockProps)(),React.createElement(t.InnerBlocks,{template:o,allowedBlocks:["happyprime/show-hide-summary","happyprime/show-hide-details"],templateLock:"all"}))},save:()=>React.createElement("details",t.useBlockProps.save(),React.createElement(t.InnerBlocks.Content,null)),deprecated:a})})();
  • show-hide-section-block/tags/3.0.0/languages/show-hide-section-block.pot

    r2874431 r3182831  
    1 # Copyright (C) 2023 Happy Prime
     1# Copyright (C) 2024 Happy Prime
    22# This file is distributed under the same license as the Show / Hide Section Block plugin.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Show / Hide Section Block 2.0.0\n"
     5"Project-Id-Version: Show / Hide Section Block 3.0.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/show-hide-section-block\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2023-03-03T16:41:52+00:00\n"
     12"POT-Creation-Date: 2024-11-06T05:29:22+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    14 "X-Generator: WP-CLI 2.6.0\n"
     14"X-Generator: WP-CLI 2.10.0\n"
    1515"X-Domain: show-hide-section-block\n"
    1616
    1717#. Plugin Name of the plugin
     18#: plugin.php
    1819msgid "Show / Hide Section Block"
    1920msgstr ""
    2021
    2122#. Plugin URI of the plugin
    22 msgid "https://github.com/happyprime/show-hide-section"
     23#: plugin.php
     24msgid "https://wordpress.org/plugins/show-hide-section-block/"
    2325msgstr ""
    2426
    2527#. Description of the plugin
     28#: plugin.php
    2629msgid "Display an accessible show/hide interface with details and summary elements."
    2730msgstr ""
    2831
    2932#. Author of the plugin
     33#: plugin.php
    3034msgid "Happy Prime"
    3135msgstr ""
    3236
    3337#. Author URI of the plugin
     38#: plugin.php
    3439msgid "https://happyprime.co/"
    3540msgstr ""
    3641
    37 #: blocks/show-hide-group/index.js:37
    38 #: build/show-hide-group.js:1
     42#: build/show-hide-details/index.js:1
     43#: src/show-hide-details/index.js:12
     44msgid "Remaining"
     45msgstr ""
     46
     47#: build/show-hide-group/index.js:1
     48#: src/show-hide-group/index.js:57
     49msgid "Has open/close all toggle"
     50msgstr ""
     51
     52#: build/show-hide-group/index.js:1
     53#: src/show-hide-group/index.js:63
     54msgid "Open/close all toggle will display."
     55msgstr ""
     56
     57#: build/show-hide-group/index.js:1
     58#: src/show-hide-group/index.js:67
     59msgid "Open/close all toggle will not display."
     60msgstr ""
     61
     62#: build/show-hide-group/index.js:1
     63#: src/show-hide-group/index.js:37
    3964msgid "Close all"
    4065msgstr ""
    4166
    42 #: blocks/show-hide-group/index.js:47
    43 #: blocks/show-hide-group/index.js:86
    44 #: blocks/show-hide-group/index.js:119
    45 #: build/show-hide-group.js:1
     67#: build/show-hide-group/index.js:1
     68#: src/show-hide-group/index.js:47
     69#: src/show-hide-group/index.js:86
     70#: src/show-hide-group/index.js:108
    4671msgid "Open all"
    4772msgstr ""
    4873
    49 #: blocks/show-hide-group/index.js:57
    50 #: build/show-hide-group.js:1
    51 msgid "Has open/close all toggle"
    52 msgstr ""
    53 
    54 #: blocks/show-hide-group/index.js:63
    55 #: build/show-hide-group.js:1
    56 msgid "Open/close all toggle will display."
    57 msgstr ""
    58 
    59 #: blocks/show-hide-group/index.js:67
    60 #: build/show-hide-group.js:1
    61 msgid "Open/close all toggle will not display."
    62 msgstr ""
    63 
    64 #: blocks/show-hide-section/index.js:37
    65 #: blocks/show-hide-section/index.js:38
    66 #: build/show-hide-section.js:1
     74#: build/show-hide-section/index.js:1
     75#: build/show-hide-summary/index.js:1
     76#: src/show-hide-section/index.js:20
     77#: src/show-hide-summary/index.js:18
     78#: src/show-hide-summary/index.js:19
    6779msgid "Summary"
    6880msgstr ""
    6981
    70 #: blocks/show-hide-group/block.json
     82#: build/show-hide-section/index.js:1
     83#: src/show-hide-section/index.js:24
     84msgid "Details"
     85msgstr ""
     86
     87#: build/show-hide-details/block.json
     88#: src/show-hide-details/block.json
     89msgctxt "block title"
     90msgid "Show Hide Details"
     91msgstr ""
     92
     93#: build/show-hide-details/block.json
     94#: src/show-hide-details/block.json
     95msgctxt "block description"
     96msgid "The remaining content in a details section."
     97msgstr ""
     98
     99#: build/show-hide-group/block.json
     100#: src/show-hide-group/block.json
    71101msgctxt "block title"
    72102msgid "Show Hide Group"
    73103msgstr ""
    74104
    75 #: blocks/show-hide-group/block.json
     105#: build/show-hide-group/block.json
     106#: src/show-hide-group/block.json
    76107msgctxt "block description"
    77108msgid "A group of accessible summaries that can be toggled to show or hide additional details."
    78109msgstr ""
    79110
    80 #: blocks/show-hide-section/block.json
     111#: build/show-hide-section/block.json
     112#: src/show-hide-section/block.json
    81113msgctxt "block title"
    82114msgid "Show Hide Section"
    83115msgstr ""
    84116
    85 #: blocks/show-hide-section/block.json
     117#: build/show-hide-section/block.json
     118#: src/show-hide-section/block.json
    86119msgctxt "block description"
    87120msgid "A section of collapsible content contained in a details element with a summary."
    88121msgstr ""
     122
     123#: build/show-hide-summary/block.json
     124#: src/show-hide-summary/block.json
     125msgctxt "block title"
     126msgid "Show Hide Summary"
     127msgstr ""
     128
     129#: build/show-hide-summary/block.json
     130#: src/show-hide-summary/block.json
     131msgctxt "block description"
     132msgid "The summary element in a details section."
     133msgstr ""
  • show-hide-section-block/tags/3.0.0/plugin.php

    r2905805 r3182831  
    33 * Plugin Name: Show / Hide Section Block
    44 * Description: Display an accessible show/hide interface with details and summary elements.
    5  * Version: 2.0.3
     5 * Version: 3.0.0
    66 * Plugin URI: https://wordpress.org/plugins/show-hide-section-block/
    77 * Author: Happy Prime
     
    99 * Text Domain: show-hide-section-block
    1010 * Domain Path: /languages
    11  * Requires at least: 6.1
     11 * Requires at least: 6.4
    1212 * Requires PHP: 7.4
    1313 *
     
    3333define( 'HP_SHS_PLUGIN_FILE', __FILE__ );
    3434
     35require_once __DIR__ . '/src/show-hide-details/index.php';
    3536require_once __DIR__ . '/src/show-hide-group/index.php';
    3637require_once __DIR__ . '/src/show-hide-section/index.php';
     38require_once __DIR__ . '/src/show-hide-summary/index.php';
  • show-hide-section-block/tags/3.0.0/readme.txt

    r2905805 r3182831  
    22Contributors: happyprime, jeremyfelt, slocker, philcable
    33Tags: collapsible, details, summary
    4 Requires at least: 6.1
    5 Tested up to: 6.2
    6 Stable tag: 2.0.3
     4Requires at least: 6.4
     5Tested up to: 6.7
     6Stable tag: 3.0.0
    77License: GPLv2 or later
    88Requires PHP: 7.4
     
    1212## Description
    1313
    14 Show / Hide Section Block provides two blocks: a Show / Hide Group block that is populated with one or more Show / Hide Section blocks.
     14Show / Hide Section Block provides four blocks that are used to display a group of `<details>` elements that each contain a `<summary>` and an arbitrary number of additional blocks.
     15
     16* The Show Hide Group block is a wrapping `<div>`.
     17* The Show Hide Section block is a wrapping `<details>`. One or more of these blocks is added to a Show Hide Group block.
     18* The Show Hide Summary block contains the content for a `<summary>` tag. One of these blocks is inside each Show Hide Section block.
     19* The Show Hide Details block contains arbitrary content. One of these blocks is added inside each Show Hide Section block.
    1520
    1621The HTML output for an individual section is:
    1722
    1823    <!-- Each section block has a details element. -->
    19     <details>
     24    <details class="wp-block-happyprime-show-hide-section">
    2025        <!-- Each details element has a summary and additional, collapsible content. -->
    21         <summary>Summary text</summary>
     26        <summary class="wp-block-happyprime-show-hide-summary">Summary text</summary>
    2227        <!-- Additional inner blocks of any type are populated here. -->
    2328    </details>
     
    2530The HTML output for the group is:
    2631
    27     <div>
    28         <details>
    29             <summary></summary>
     32    <div class="wp-block-happyprime-show-hide-group">
     33        <!-- Optional based on attribute -->
     34        <button class="toggle-all" aria-expanded="false">Open all</button>
     35        <details class="wp-block-happyprime-show-hide-section">
     36            <summary class="wp-block-happyprime-show-hide-summary"></summary>
    3037            <!-- Additional blocks to be shown/hidden -->
    3138        </details>
    32         <details>
    33             <summary></summary>
     39        <details class="wp-block-happyprime-show-hide-section">
     40            <summary class="wp-block-happyprime-show-hide-summary"></summary>
    3441            <!-- Additional blocks to be shown hidden -->
    3542        </details>
     
    3946An option is provided in the block's side panel to toggle an "Open all"/"Close all" button. If this is toggled on for a block, an additional `<button>` element will be inserted and JavaScript will be used on the front-end to control the show/hide behavior of all `<details>` elements in the group at once.
    4047
    41 If the toggle is off, no JavaScript is loaded on the front end.
     48If the toggle is off, no JavaScript is loaded on the front end and only the browser's default behavior is used for opening and closing `<details>` elements.
    4249
    4350## Changelog
     51
     52### 3.0.0
     53
     54* Refactor block markup to improve editorial experience and formatting options.
     55* Introduce `happyprime/show-hide-summary` block to manage `<summary>` content.
     56* Introduce `happyprime/show-hide-details` block to manage remaningin `<details>` content.
     57* Upgrade `happyprime/show-hide-group` and `happyprime/show-hide-section` blocks to API v3.
     58* Add a deprecation routine to transform 2.0.x block markup into the new format.
     59* Replace `@wordpress/scripts` with slimmer build configuration.
     60* Bump minimum WordPress version to 6.4; confirm compatibility with 6.7.
    4461
    4562### 2.0.3
  • show-hide-section-block/tags/3.0.0/src/show-hide-group/block.json

    r2905297 r3182831  
    11{
    22    "$schema": "https://json.schemastore.org/block.json",
    3     "apiVersion": 2,
     3    "apiVersion": 3,
    44    "name": "happyprime/show-hide-group",
    55    "title": "Show Hide Group",
  • show-hide-section-block/tags/3.0.0/src/show-hide-group/index.js

    r2905297 r3182831  
    1212import metadata from './block.json';
    1313
    14 const Edit = ( props ) => {
     14const Edit = (props) => {
    1515    const {
    1616        attributes: { hasToggle },
     
    1818    } = props;
    1919
    20     const details = useSelect( ( select ) => {
    21         const currentBlocks = select( 'core/block-editor' ).getBlocks(
     20    const details = useSelect((select) => {
     21        const currentBlocks = select('core/block-editor').getBlocks(
    2222            props.clientId
    2323        );
    2424
    2525        return currentBlocks;
    26     } );
     26    });
    2727
    28     const toggleAllSections = ( evt ) => {
    29         if ( false === evt.target.ariaExpanded ) {
    30             details.forEach( ( detail ) => {
    31                 dispatch( 'core/block-editor' ).updateBlockAttributes(
     28    const toggleAllSections = (evt) => {
     29        if (false === evt.target.ariaExpanded) {
     30            details.forEach((detail) => {
     31                dispatch('core/block-editor').updateBlockAttributes(
    3232                    detail.clientId,
    3333                    { isOpen: true }
    3434                );
    35             } );
     35            });
    3636
    37             evt.target.innerText = __( 'Close all', 'show-hide-section-block' );
     37            evt.target.innerText = __('Close all', 'show-hide-section-block');
    3838            evt.target.ariaExpanded = true;
    3939        } else {
    40             details.forEach( ( detail ) => {
    41                 dispatch( 'core/block-editor' ).updateBlockAttributes(
     40            details.forEach((detail) => {
     41                dispatch('core/block-editor').updateBlockAttributes(
    4242                    detail.clientId,
    4343                    { isOpen: false }
    4444                );
    45             } );
     45            });
    4646
    47             evt.target.innerText = __( 'Open all', 'show-hide-section-block' );
     47            evt.target.innerText = __('Open all', 'show-hide-section-block');
    4848            evt.target.ariaExpanded = false;
    4949        }
     
    5555                <PanelBody>
    5656                    <ToggleControl
    57                         label={ __(
     57                        label={__(
    5858                            'Has open/close all toggle',
    5959                            'show-hide-section-block'
    60                         ) }
     60                        )}
    6161                        help={
    6262                            hasToggle
     
    6464                                        'Open/close all toggle will display.',
    6565                                        'show-hide-section-block'
    66                                   )
     66                                    )
    6767                                : __(
    6868                                        'Open/close all toggle will not display.',
    6969                                        'show-hide-section-block'
    70                                   )
     70                                    )
    7171                        }
    72                         checked={ hasToggle }
    73                         onChange={ ( value ) => {
    74                             setAttributes( { hasToggle: value } );
    75                         } }
     72                        checked={hasToggle}
     73                        onChange={(value) => {
     74                            setAttributes({ hasToggle: value });
     75                        }}
    7676                    />
    7777                </PanelBody>
    7878            </InspectorControls>
    79             <div { ...useBlockProps() }>
    80                 { hasToggle && (
     79            <div {...useBlockProps()}>
     80                {hasToggle && (
    8181                    <button
    8282                        className="toggle-all"
    8383                        aria-expanded="false"
    84                         onClick={ toggleAllSections }
     84                        onClick={toggleAllSections}
    8585                    >
    86                         { __( 'Open all', 'show-hide-section-block' ) }
     86                        {__('Open all', 'show-hide-section-block')}
    8787                    </button>
    88                 ) }
     88                )}
    8989                <InnerBlocks
    90                     allowedBlocks={ [ 'happyprime/show-hide-section' ] }
    91                     template={ [
    92                         [
    93                             'happyprime/show-hide-section',
    94                             {},
    95                             [ [ 'core/paragraph', {} ] ],
    96                         ],
    97                         [
    98                             'happyprime/show-hide-section',
    99                             {},
    100                             [ [ 'core/paragraph', {} ] ],
    101                         ],
    102                     ] }
    103                     templateLock={ false }
     90                    allowedBlocks={['happyprime/show-hide-section']}
     91                    template={[['happyprime/show-hide-section', {}]]}
     92                    templateLock={false}
    10493                />
    10594            </div>
     
    10897};
    10998
    110 const Save = ( props ) => {
     99const Save = (props) => {
    111100    const {
    112101        attributes: { hasToggle },
     
    114103
    115104    return (
    116         <div { ...useBlockProps.save() }>
    117             { hasToggle && (
     105        <div {...useBlockProps.save()}>
     106            {hasToggle && (
    118107                <button className="toggle-all" aria-expanded="false">
    119                     { __( 'Open all', 'show-hide-section-block' ) }
     108                    {__('Open all', 'show-hide-section-block')}
    120109                </button>
    121             ) }
     110            )}
    122111            <InnerBlocks.Content />
    123112        </div>
     
    126115
    127116// Register the block.
    128 registerBlockType( metadata, {
     117registerBlockType(metadata, {
    129118    edit: Edit,
    130119    save: Save,
    131 } );
     120});
  • show-hide-section-block/tags/3.0.0/src/show-hide-group/view.js

    r2905297 r3182831  
    55        );
    66
    7         if ( toggleAll.length > 0 ) {
    8             toggleAll.forEach( ( toggle ) =>
    9                 toggle.addEventListener( 'click', () => {
     7        if (toggleAll.length > 0) {
     8            toggleAll.forEach((toggle) =>
     9                toggle.addEventListener('click', () => {
    1010                    const details = toggle.parentElement.querySelectorAll(
    1111                        'details.wp-block-happyprime-show-hide-section'
    1212                    );
    1313
    14                     if ( 'true' !== toggle.ariaExpanded ) {
    15                         details.forEach( ( detail ) => {
    16                             detail.setAttribute( 'open', 'true' );
    17                         } );
     14                    if ('true' !== toggle.ariaExpanded) {
     15                        details.forEach((detail) => {
     16                            detail.setAttribute('open', 'true');
     17                        });
    1818
    1919                        toggle.innerText = 'Close All';
    2020                        toggle.ariaExpanded = 'true';
    2121                    } else {
    22                         details.forEach( ( detail ) => {
    23                             detail.removeAttribute( 'open' );
    24                         } );
     22                        details.forEach((detail) => {
     23                            detail.removeAttribute('open');
     24                        });
    2525
    2626                        toggle.innerText = 'Open All';
    2727                        toggle.ariaExpanded = 'false';
    2828                    }
    29                 } )
     29                })
    3030            );
    3131        }
    3232    };
    3333
    34     document.addEventListener( 'DOMContentLoaded', handleToggleButton );
     34    document.addEventListener('DOMContentLoaded', handleToggleButton);
    3535}
  • show-hide-section-block/tags/3.0.0/src/show-hide-section/block.json

    r2905297 r3182831  
    11{
    22    "$schema": "https://json.schemastore.org/block.json",
    3     "apiVersion": 2,
     3    "apiVersion": 3,
    44    "name": "happyprime/show-hide-section",
    55    "title": "Show Hide Section",
     
    1313            "type": "boolean",
    1414            "default": false
    15         },
    16         "summary": {
    17             "type": "string",
    18             "source": "html",
    19             "selector": "summary"
    2015        }
    2116    },
  • show-hide-section-block/tags/3.0.0/src/show-hide-section/index.js

    r2905297 r3182831  
    11import { registerBlockType } from '@wordpress/blocks';
    2 import { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';
     2import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
    33import { __ } from '@wordpress/i18n';
    44
    55// Internal dependencies.
    66import metadata from './block.json';
     7import deprecated from './deprecated';
    78
    8 const Edit = ( props ) => {
     9const Edit = (props) => {
    910    const {
    10         attributes: { isOpen, summary },
     11        attributes: { isOpen },
    1112        setAttributes,
     13        isSelected,
    1214    } = props;
    1315
    14     /**
    15      * Insert a space at the current position of the cursor and then adjust
    16      * the cursor position, accounting for any selection it has made.
    17      *
    18      * @param {Node} node
    19      */
    20     const insertSpace = ( node ) => {
    21         const { ownerDocument } = node;
    22         const { defaultView } = ownerDocument;
    23 
    24         const sel = defaultView.getSelection();
    25         const range = sel.getRangeAt( 0 );
    26         const textNode = document.createTextNode( ' ' );
    27 
    28         range.deleteContents();
    29         range.insertNode( textNode );
    30         range.setStartAfter( textNode );
    31     };
     16    // Create an inner blocks template for the content.
     17    const TEMPLATE = [
     18        [
     19            'happyprime/show-hide-summary',
     20            { summary: __('Summary', 'show-hide-section-block') },
     21        ],
     22        [
     23            'happyprime/show-hide-details',
     24            { details: __('Details', 'show-hide-section-block') },
     25        ],
     26    ];
    3227
    3328    return (
    34         <details { ...useBlockProps() } open={ isOpen }>
    35             <RichText
    36                 tagName="summary"
    37                 label={ __( 'Summary', 'show-hide-section-block' ) }
    38                 placeholder={ __( 'Summary', 'show-hide-section-block' ) }
    39                 value={ summary }
    40                 allowedFormats={ [ 'core/bold', 'core/italic' ] }
    41                 onChange={ ( value ) => {
    42                     setAttributes( { summary: value } );
    43                 } }
    44                 onKeyUp={ ( evt ) => {
    45                     if ( ' ' === evt.key ) {
    46                         evt.preventDefault(); // Stop the details element from toggling.
    47                         insertSpace( evt.target ); // But make sure the space character is added.
    48                     }
    49                 } }
     29        <div {...useBlockProps()}>
     30            <InnerBlocks
     31                template={TEMPLATE}
     32                allowedBlocks={[
     33                    'happyprime/show-hide-summary',
     34                    'happyprime/show-hide-details',
     35                ]}
     36                templateLock="all"
    5037            />
    51             <InnerBlocks />
    52         </details>
     38        </div>
    5339    );
    5440};
    5541
    56 const Save = ( props ) => {
    57     const {
    58         attributes: { summary },
    59     } = props;
    60 
     42const Save = () => {
    6143    return (
    62         <details { ...useBlockProps.save() }>
    63             <summary>
    64                 <RichText.Content tag={ 'summary' } value={ summary } />
    65             </summary>
     44        <details {...useBlockProps.save()}>
    6645            <InnerBlocks.Content />
    6746        </details>
     
    7049
    7150// Register the block.
    72 registerBlockType( metadata, {
     51registerBlockType(metadata, {
    7352    edit: Edit,
    7453    save: Save,
    75 } );
     54    deprecated,
     55});
  • show-hide-section-block/trunk/LICENSE

    r2874431 r3182831  
    11Show/Hide Section Block - a plugin for WordPress
    22
    3 Copyright 2020-2023 by Happy Prime
     3Copyright 2020-2024 by Happy Prime
    44
    55This program is free software; you can redistribute it and/or modify
  • show-hide-section-block/trunk/build/show-hide-group/block.json

    r2905297 r3182831  
    11{
    2   "$schema": "https://json.schemastore.org/block.json",
    3   "apiVersion": 2,
    4   "name": "happyprime/show-hide-group",
    5   "title": "Show Hide Group",
    6   "textdomain": "show-hide-section-block",
    7   "category": "widgets",
    8   "description": "A group of accessible summaries that can be toggled to show or hide additional details.",
    9   "icon": "hidden",
    10   "attributes": {
    11     "hasToggle": {
    12       "type": "boolean",
    13       "default": false
    14     }
    15   },
    16   "supports": {
    17     "align": true,
    18     "alignWide": true,
    19     "anchor": true,
    20     "color": {
    21       "background": true,
    22       "enableContrastChecker": true,
    23       "text": true,
    24       "link": true,
    25       "gradients": true
    26     },
    27     "defaultStylePicker": true,
    28     "dimensions": {
    29       "minHeight": true
    30     },
    31     "html": false,
    32     "position": {
    33       "sticky": false
    34     },
    35     "spacing": {
    36       "margin": true,
    37       "padding": true
    38     },
    39     "typography": {
    40       "fontSize": true,
    41       "lineHeight": true
    42     }
    43   },
    44   "editorScript": "file:index.js",
    45   "viewScript": "file:view.js"
     2    "$schema": "https://json.schemastore.org/block.json",
     3    "apiVersion": 3,
     4    "name": "happyprime/show-hide-group",
     5    "title": "Show Hide Group",
     6    "textdomain": "show-hide-section-block",
     7    "category": "widgets",
     8    "description": "A group of accessible summaries that can be toggled to show or hide additional details.",
     9    "icon": "hidden",
     10    "attributes": {
     11        "hasToggle": {
     12            "type": "boolean",
     13            "default": false
     14        }
     15    },
     16    "supports": {
     17        "align": true,
     18        "alignWide": true,
     19        "anchor": true,
     20        "color": {
     21            "background": true,
     22            "enableContrastChecker": true,
     23            "text": true,
     24            "link": true,
     25            "gradients": true
     26        },
     27        "defaultStylePicker": true,
     28        "dimensions": {
     29            "minHeight": true
     30        },
     31        "html": false,
     32        "position": {
     33            "sticky": false
     34        },
     35        "spacing": {
     36            "margin": true,
     37            "padding": true
     38        },
     39        "typography": {
     40            "fontSize": true,
     41            "lineHeight": true
     42        }
     43    },
     44    "editorScript": "file:index.js",
     45    "viewScript": "file:view.js"
    4646}
  • show-hide-section-block/trunk/build/show-hide-group/index.asset.php

    r2905297 r3182831  
    1 <?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '9821368a8f1930a9690c');
     1<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-i18n'), 'version' => '70bf254dd1647cf40738');
  • show-hide-section-block/trunk/build/show-hide-group/index.js

    r2905297 r3182831  
    1 !function(){"use strict";var e=window.wp.element,t=window.wp.blocks,o=window.wp.blockEditor,l=window.wp.components,a=window.wp.data,i=window.wp.i18n,n=JSON.parse('{"$schema":"https://json.schemastore.org/block.json","apiVersion":2,"name":"happyprime/show-hide-group","title":"Show Hide Group","textdomain":"show-hide-section-block","category":"widgets","description":"A group of accessible summaries that can be toggled to show or hide additional details.","icon":"hidden","attributes":{"hasToggle":{"type":"boolean","default":false}},"supports":{"align":true,"alignWide":true,"anchor":true,"color":{"background":true,"enableContrastChecker":true,"text":true,"link":true,"gradients":true},"defaultStylePicker":true,"dimensions":{"minHeight":true},"html":false,"position":{"sticky":false},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true}},"editorScript":"file:index.js","viewScript":"file:view.js"}');(0,t.registerBlockType)(n,{edit:t=>{const{attributes:{hasToggle:n},setAttributes:r}=t,s=(0,a.useSelect)((e=>e("core/block-editor").getBlocks(t.clientId)));return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(o.InspectorControls,null,(0,e.createElement)(l.PanelBody,null,(0,e.createElement)(l.ToggleControl,{label:(0,i.__)("Has open/close all toggle","show-hide-section-block"),help:n?(0,i.__)("Open/close all toggle will display.","show-hide-section-block"):(0,i.__)("Open/close all toggle will not display.","show-hide-section-block"),checked:n,onChange:e=>{r({hasToggle:e})}}))),(0,e.createElement)("div",(0,o.useBlockProps)(),n&&(0,e.createElement)("button",{className:"toggle-all","aria-expanded":"false",onClick:e=>{!1===e.target.ariaExpanded?(s.forEach((e=>{(0,a.dispatch)("core/block-editor").updateBlockAttributes(e.clientId,{isOpen:!0})})),e.target.innerText=(0,i.__)("Close all","show-hide-section-block"),e.target.ariaExpanded=!0):(s.forEach((e=>{(0,a.dispatch)("core/block-editor").updateBlockAttributes(e.clientId,{isOpen:!1})})),e.target.innerText=(0,i.__)("Open all","show-hide-section-block"),e.target.ariaExpanded=!1)}},(0,i.__)("Open all","show-hide-section-block")),(0,e.createElement)(o.InnerBlocks,{allowedBlocks:["happyprime/show-hide-section"],template:[["happyprime/show-hide-section",{},[["core/paragraph",{}]]],["happyprime/show-hide-section",{},[["core/paragraph",{}]]]],templateLock:!1})))},save:t=>{const{attributes:{hasToggle:l}}=t;return(0,e.createElement)("div",o.useBlockProps.save(),l&&(0,e.createElement)("button",{className:"toggle-all","aria-expanded":"false"},(0,i.__)("Open all","show-hide-section-block")),(0,e.createElement)(o.InnerBlocks.Content,null))}})}();
     1(()=>{"use strict";const e=window.wp.blocks,t=window.wp.blockEditor,o=window.wp.components,l=window.wp.data,a=window.wp.i18n,i=JSON.parse('{"$schema":"https://json.schemastore.org/block.json","apiVersion":3,"name":"happyprime/show-hide-group","title":"Show Hide Group","textdomain":"show-hide-section-block","category":"widgets","description":"A group of accessible summaries that can be toggled to show or hide additional details.","icon":"hidden","attributes":{"hasToggle":{"type":"boolean","default":false}},"supports":{"align":true,"alignWide":true,"anchor":true,"color":{"background":true,"enableContrastChecker":true,"text":true,"link":true,"gradients":true},"defaultStylePicker":true,"dimensions":{"minHeight":true},"html":false,"position":{"sticky":false},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true}},"editorScript":"file:index.js","viewScript":"file:view.js"}');(0,e.registerBlockType)(i,{edit:e=>{const{attributes:{hasToggle:i},setAttributes:n}=e,s=(0,l.useSelect)((t=>t("core/block-editor").getBlocks(e.clientId)));return React.createElement(React.Fragment,null,React.createElement(t.InspectorControls,null,React.createElement(o.PanelBody,null,React.createElement(o.ToggleControl,{label:(0,a.__)("Has open/close all toggle","show-hide-section-block"),help:i?(0,a.__)("Open/close all toggle will display.","show-hide-section-block"):(0,a.__)("Open/close all toggle will not display.","show-hide-section-block"),checked:i,onChange:e=>{n({hasToggle:e})}}))),React.createElement("div",(0,t.useBlockProps)(),i&&React.createElement("button",{className:"toggle-all","aria-expanded":"false",onClick:e=>{!1===e.target.ariaExpanded?(s.forEach((e=>{(0,l.dispatch)("core/block-editor").updateBlockAttributes(e.clientId,{isOpen:!0})})),e.target.innerText=(0,a.__)("Close all","show-hide-section-block"),e.target.ariaExpanded=!0):(s.forEach((e=>{(0,l.dispatch)("core/block-editor").updateBlockAttributes(e.clientId,{isOpen:!1})})),e.target.innerText=(0,a.__)("Open all","show-hide-section-block"),e.target.ariaExpanded=!1)}},(0,a.__)("Open all","show-hide-section-block")),React.createElement(t.InnerBlocks,{allowedBlocks:["happyprime/show-hide-section"],template:[["happyprime/show-hide-section",{}]],templateLock:!1})))},save:e=>{const{attributes:{hasToggle:o}}=e;return React.createElement("div",t.useBlockProps.save(),o&&React.createElement("button",{className:"toggle-all","aria-expanded":"false"},(0,a.__)("Open all","show-hide-section-block")),React.createElement(t.InnerBlocks.Content,null))}})})();
  • show-hide-section-block/trunk/build/show-hide-group/view.asset.php

    r2905297 r3182831  
    1 <?php return array('dependencies' => array(), 'version' => 'c1c493ae492c636904dd');
     1<?php return array('dependencies' => array(), 'version' => 'fbf381460e85f307651f');
  • show-hide-section-block/trunk/build/show-hide-group/view.js

    r2905297 r3182831  
    1 !function(){{const e=()=>{const e=document.querySelectorAll(".wp-block-happyprime-show-hide-group .toggle-all");e.length>0&&e.forEach((e=>e.addEventListener("click",(()=>{const t=e.parentElement.querySelectorAll("details.wp-block-happyprime-show-hide-section");"true"!==e.ariaExpanded?(t.forEach((e=>{e.setAttribute("open","true")})),e.innerText="Close All",e.ariaExpanded="true"):(t.forEach((e=>{e.removeAttribute("open")})),e.innerText="Open All",e.ariaExpanded="false")}))))};document.addEventListener("DOMContentLoaded",e)}}();
     1(()=>{{const e=()=>{const e=document.querySelectorAll(".wp-block-happyprime-show-hide-group .toggle-all");e.length>0&&e.forEach((e=>e.addEventListener("click",(()=>{const t=e.parentElement.querySelectorAll("details.wp-block-happyprime-show-hide-section");"true"!==e.ariaExpanded?(t.forEach((e=>{e.setAttribute("open","true")})),e.innerText="Close All",e.ariaExpanded="true"):(t.forEach((e=>{e.removeAttribute("open")})),e.innerText="Open All",e.ariaExpanded="false")}))))};document.addEventListener("DOMContentLoaded",e)}})();
  • show-hide-section-block/trunk/build/show-hide-section/block.json

    r2905297 r3182831  
    11{
    2   "$schema": "https://json.schemastore.org/block.json",
    3   "apiVersion": 2,
    4   "name": "happyprime/show-hide-section",
    5   "title": "Show Hide Section",
    6   "textdomain": "show-hide-section-block",
    7   "category": "widgets",
    8   "description": "A section of collapsible content contained in a details element with a summary.",
    9   "icon": "media-document",
    10   "parent": [
    11     "happyprime/show-hide-group"
    12   ],
    13   "attributes": {
    14     "isOpen": {
    15       "type": "boolean",
    16       "default": false
    17     },
    18     "summary": {
    19       "type": "string",
    20       "source": "html",
    21       "selector": "summary"
    22     }
    23   },
    24   "supports": {
    25     "anchor": true,
    26     "align": true,
    27     "alignWide": true,
    28     "color": {
    29       "background": true,
    30       "enableContrastChecker": true,
    31       "text": true,
    32       "link": true,
    33       "gradients": true
    34     },
    35     "defaultStylePicker": true,
    36     "dimensions": {
    37       "minHeight": true
    38     },
    39     "html": false,
    40     "multiple": true,
    41     "position": {
    42       "sticky": false
    43     },
    44     "spacing": {
    45       "margin": true,
    46       "padding": true
    47     },
    48     "typography": {
    49       "fontSize": true,
    50       "lineHeight": true
    51     }
    52   },
    53   "editorScript": "file:index.js"
     2    "$schema": "https://json.schemastore.org/block.json",
     3    "apiVersion": 3,
     4    "name": "happyprime/show-hide-section",
     5    "title": "Show Hide Section",
     6    "textdomain": "show-hide-section-block",
     7    "category": "widgets",
     8    "description": "A section of collapsible content contained in a details element with a summary.",
     9    "icon": "media-document",
     10    "parent": [ "happyprime/show-hide-group" ],
     11    "attributes": {
     12        "isOpen": {
     13            "type": "boolean",
     14            "default": false
     15        }
     16    },
     17    "supports": {
     18        "anchor": true,
     19        "align": true,
     20        "alignWide": true,
     21        "color": {
     22            "background": true,
     23            "enableContrastChecker": true,
     24            "text": true,
     25            "link": true,
     26            "gradients": true
     27        },
     28        "defaultStylePicker": true,
     29        "dimensions": {
     30            "minHeight": true
     31        },
     32        "html": false,
     33        "multiple": true,
     34        "position": {
     35            "sticky": false
     36        },
     37        "spacing": {
     38            "margin": true,
     39            "padding": true
     40        },
     41        "typography": {
     42            "fontSize": true,
     43            "lineHeight": true
     44        }
     45    },
     46    "editorScript": "file:index.js"
    5447}
  • show-hide-section-block/trunk/build/show-hide-section/index.asset.php

    r2905297 r3182831  
    1 <?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-element', 'wp-i18n'), 'version' => 'b7962f8806702068f778');
     1<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => 'beb08742a35f54543878');
  • show-hide-section-block/trunk/build/show-hide-section/index.js

    r2905297 r3182831  
    1 !function(){"use strict";function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},e.apply(this,arguments)}var t=window.wp.element,n=window.wp.blocks,r=window.wp.blockEditor,o=window.wp.i18n,i=JSON.parse('{"$schema":"https://json.schemastore.org/block.json","apiVersion":2,"name":"happyprime/show-hide-section","title":"Show Hide Section","textdomain":"show-hide-section-block","category":"widgets","description":"A section of collapsible content contained in a details element with a summary.","icon":"media-document","parent":["happyprime/show-hide-group"],"attributes":{"isOpen":{"type":"boolean","default":false},"summary":{"type":"string","source":"html","selector":"summary"}},"supports":{"anchor":true,"align":true,"alignWide":true,"color":{"background":true,"enableContrastChecker":true,"text":true,"link":true,"gradients":true},"defaultStylePicker":true,"dimensions":{"minHeight":true},"html":false,"multiple":true,"position":{"sticky":false},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true}},"editorScript":"file:index.js"}');(0,n.registerBlockType)(i,{edit:n=>{const{attributes:{isOpen:i,summary:a},setAttributes:s}=n;return(0,t.createElement)("details",e({},(0,r.useBlockProps)(),{open:i}),(0,t.createElement)(r.RichText,{tagName:"summary",label:(0,o.__)("Summary","show-hide-section-block"),placeholder:(0,o.__)("Summary","show-hide-section-block"),value:a,allowedFormats:["core/bold","core/italic"],onChange:e=>{s({summary:e})},onKeyUp:e=>{" "===e.key&&(e.preventDefault(),(e=>{const{ownerDocument:t}=e,{defaultView:n}=t,r=n.getSelection().getRangeAt(0),o=document.createTextNode(" ");r.deleteContents(),r.insertNode(o),r.setStartAfter(o)})(e.target))}}),(0,t.createElement)(r.InnerBlocks,null))},save:e=>{const{attributes:{summary:n}}=e;return(0,t.createElement)("details",r.useBlockProps.save(),(0,t.createElement)("summary",null,(0,t.createElement)(r.RichText.Content,{tag:"summary",value:n})),(0,t.createElement)(r.InnerBlocks.Content,null))}})}();
     1(()=>{"use strict";const e=window.wp.blocks,t=window.wp.blockEditor,s=window.wp.i18n,i=JSON.parse('{"$schema":"https://json.schemastore.org/block.json","apiVersion":3,"name":"happyprime/show-hide-section","title":"Show Hide Section","textdomain":"show-hide-section-block","category":"widgets","description":"A section of collapsible content contained in a details element with a summary.","icon":"media-document","parent":["happyprime/show-hide-group"],"attributes":{"isOpen":{"type":"boolean","default":false}},"supports":{"anchor":true,"align":true,"alignWide":true,"color":{"background":true,"enableContrastChecker":true,"text":true,"link":true,"gradients":true},"defaultStylePicker":true,"dimensions":{"minHeight":true},"html":false,"multiple":true,"position":{"sticky":false},"spacing":{"margin":true,"padding":true},"typography":{"fontSize":true,"lineHeight":true}},"editorScript":"file:index.js"}'),a=[{attributes:{summary:{type:"string",source:"html",selector:"summary"}},save:({attributes:e})=>React.createElement("details",t.useBlockProps.save(),React.createElement("summary",null,e.summary),React.createElement(t.InnerBlocks.Content,null)),migrate:(t,s)=>[{},[(0,e.createBlock)("happyprime/show-hide-summary",{summary:t.summary}),(0,e.createBlock)("happyprime/show-hide-details",{},s)]],supports:{html:!0,anchor:!0},isEligible:({summary:e})=>"string"==typeof e&&e.length>0}];(0,e.registerBlockType)(i,{edit:e=>{const{attributes:{isOpen:i},setAttributes:a,isSelected:r}=e,o=[["happyprime/show-hide-summary",{summary:(0,s.__)("Summary","show-hide-section-block")}],["happyprime/show-hide-details",{details:(0,s.__)("Details","show-hide-section-block")}]];return React.createElement("div",(0,t.useBlockProps)(),React.createElement(t.InnerBlocks,{template:o,allowedBlocks:["happyprime/show-hide-summary","happyprime/show-hide-details"],templateLock:"all"}))},save:()=>React.createElement("details",t.useBlockProps.save(),React.createElement(t.InnerBlocks.Content,null)),deprecated:a})})();
  • show-hide-section-block/trunk/languages/show-hide-section-block.pot

    r2874431 r3182831  
    1 # Copyright (C) 2023 Happy Prime
     1# Copyright (C) 2024 Happy Prime
    22# This file is distributed under the same license as the Show / Hide Section Block plugin.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Show / Hide Section Block 2.0.0\n"
     5"Project-Id-Version: Show / Hide Section Block 3.0.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/show-hide-section-block\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2023-03-03T16:41:52+00:00\n"
     12"POT-Creation-Date: 2024-11-06T05:29:22+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    14 "X-Generator: WP-CLI 2.6.0\n"
     14"X-Generator: WP-CLI 2.10.0\n"
    1515"X-Domain: show-hide-section-block\n"
    1616
    1717#. Plugin Name of the plugin
     18#: plugin.php
    1819msgid "Show / Hide Section Block"
    1920msgstr ""
    2021
    2122#. Plugin URI of the plugin
    22 msgid "https://github.com/happyprime/show-hide-section"
     23#: plugin.php
     24msgid "https://wordpress.org/plugins/show-hide-section-block/"
    2325msgstr ""
    2426
    2527#. Description of the plugin
     28#: plugin.php
    2629msgid "Display an accessible show/hide interface with details and summary elements."
    2730msgstr ""
    2831
    2932#. Author of the plugin
     33#: plugin.php
    3034msgid "Happy Prime"
    3135msgstr ""
    3236
    3337#. Author URI of the plugin
     38#: plugin.php
    3439msgid "https://happyprime.co/"
    3540msgstr ""
    3641
    37 #: blocks/show-hide-group/index.js:37
    38 #: build/show-hide-group.js:1
     42#: build/show-hide-details/index.js:1
     43#: src/show-hide-details/index.js:12
     44msgid "Remaining"
     45msgstr ""
     46
     47#: build/show-hide-group/index.js:1
     48#: src/show-hide-group/index.js:57
     49msgid "Has open/close all toggle"
     50msgstr ""
     51
     52#: build/show-hide-group/index.js:1
     53#: src/show-hide-group/index.js:63
     54msgid "Open/close all toggle will display."
     55msgstr ""
     56
     57#: build/show-hide-group/index.js:1
     58#: src/show-hide-group/index.js:67
     59msgid "Open/close all toggle will not display."
     60msgstr ""
     61
     62#: build/show-hide-group/index.js:1
     63#: src/show-hide-group/index.js:37
    3964msgid "Close all"
    4065msgstr ""
    4166
    42 #: blocks/show-hide-group/index.js:47
    43 #: blocks/show-hide-group/index.js:86
    44 #: blocks/show-hide-group/index.js:119
    45 #: build/show-hide-group.js:1
     67#: build/show-hide-group/index.js:1
     68#: src/show-hide-group/index.js:47
     69#: src/show-hide-group/index.js:86
     70#: src/show-hide-group/index.js:108
    4671msgid "Open all"
    4772msgstr ""
    4873
    49 #: blocks/show-hide-group/index.js:57
    50 #: build/show-hide-group.js:1
    51 msgid "Has open/close all toggle"
    52 msgstr ""
    53 
    54 #: blocks/show-hide-group/index.js:63
    55 #: build/show-hide-group.js:1
    56 msgid "Open/close all toggle will display."
    57 msgstr ""
    58 
    59 #: blocks/show-hide-group/index.js:67
    60 #: build/show-hide-group.js:1
    61 msgid "Open/close all toggle will not display."
    62 msgstr ""
    63 
    64 #: blocks/show-hide-section/index.js:37
    65 #: blocks/show-hide-section/index.js:38
    66 #: build/show-hide-section.js:1
     74#: build/show-hide-section/index.js:1
     75#: build/show-hide-summary/index.js:1
     76#: src/show-hide-section/index.js:20
     77#: src/show-hide-summary/index.js:18
     78#: src/show-hide-summary/index.js:19
    6779msgid "Summary"
    6880msgstr ""
    6981
    70 #: blocks/show-hide-group/block.json
     82#: build/show-hide-section/index.js:1
     83#: src/show-hide-section/index.js:24
     84msgid "Details"
     85msgstr ""
     86
     87#: build/show-hide-details/block.json
     88#: src/show-hide-details/block.json
     89msgctxt "block title"
     90msgid "Show Hide Details"
     91msgstr ""
     92
     93#: build/show-hide-details/block.json
     94#: src/show-hide-details/block.json
     95msgctxt "block description"
     96msgid "The remaining content in a details section."
     97msgstr ""
     98
     99#: build/show-hide-group/block.json
     100#: src/show-hide-group/block.json
    71101msgctxt "block title"
    72102msgid "Show Hide Group"
    73103msgstr ""
    74104
    75 #: blocks/show-hide-group/block.json
     105#: build/show-hide-group/block.json
     106#: src/show-hide-group/block.json
    76107msgctxt "block description"
    77108msgid "A group of accessible summaries that can be toggled to show or hide additional details."
    78109msgstr ""
    79110
    80 #: blocks/show-hide-section/block.json
     111#: build/show-hide-section/block.json
     112#: src/show-hide-section/block.json
    81113msgctxt "block title"
    82114msgid "Show Hide Section"
    83115msgstr ""
    84116
    85 #: blocks/show-hide-section/block.json
     117#: build/show-hide-section/block.json
     118#: src/show-hide-section/block.json
    86119msgctxt "block description"
    87120msgid "A section of collapsible content contained in a details element with a summary."
    88121msgstr ""
     122
     123#: build/show-hide-summary/block.json
     124#: src/show-hide-summary/block.json
     125msgctxt "block title"
     126msgid "Show Hide Summary"
     127msgstr ""
     128
     129#: build/show-hide-summary/block.json
     130#: src/show-hide-summary/block.json
     131msgctxt "block description"
     132msgid "The summary element in a details section."
     133msgstr ""
  • show-hide-section-block/trunk/plugin.php

    r2905805 r3182831  
    33 * Plugin Name: Show / Hide Section Block
    44 * Description: Display an accessible show/hide interface with details and summary elements.
    5  * Version: 2.0.3
     5 * Version: 3.0.0
    66 * Plugin URI: https://wordpress.org/plugins/show-hide-section-block/
    77 * Author: Happy Prime
     
    99 * Text Domain: show-hide-section-block
    1010 * Domain Path: /languages
    11  * Requires at least: 6.1
     11 * Requires at least: 6.4
    1212 * Requires PHP: 7.4
    1313 *
     
    3333define( 'HP_SHS_PLUGIN_FILE', __FILE__ );
    3434
     35require_once __DIR__ . '/src/show-hide-details/index.php';
    3536require_once __DIR__ . '/src/show-hide-group/index.php';
    3637require_once __DIR__ . '/src/show-hide-section/index.php';
     38require_once __DIR__ . '/src/show-hide-summary/index.php';
  • show-hide-section-block/trunk/readme.txt

    r2905805 r3182831  
    22Contributors: happyprime, jeremyfelt, slocker, philcable
    33Tags: collapsible, details, summary
    4 Requires at least: 6.1
    5 Tested up to: 6.2
    6 Stable tag: 2.0.3
     4Requires at least: 6.4
     5Tested up to: 6.7
     6Stable tag: 3.0.0
    77License: GPLv2 or later
    88Requires PHP: 7.4
     
    1212## Description
    1313
    14 Show / Hide Section Block provides two blocks: a Show / Hide Group block that is populated with one or more Show / Hide Section blocks.
     14Show / Hide Section Block provides four blocks that are used to display a group of `<details>` elements that each contain a `<summary>` and an arbitrary number of additional blocks.
     15
     16* The Show Hide Group block is a wrapping `<div>`.
     17* The Show Hide Section block is a wrapping `<details>`. One or more of these blocks is added to a Show Hide Group block.
     18* The Show Hide Summary block contains the content for a `<summary>` tag. One of these blocks is inside each Show Hide Section block.
     19* The Show Hide Details block contains arbitrary content. One of these blocks is added inside each Show Hide Section block.
    1520
    1621The HTML output for an individual section is:
    1722
    1823    <!-- Each section block has a details element. -->
    19     <details>
     24    <details class="wp-block-happyprime-show-hide-section">
    2025        <!-- Each details element has a summary and additional, collapsible content. -->
    21         <summary>Summary text</summary>
     26        <summary class="wp-block-happyprime-show-hide-summary">Summary text</summary>
    2227        <!-- Additional inner blocks of any type are populated here. -->
    2328    </details>
     
    2530The HTML output for the group is:
    2631
    27     <div>
    28         <details>
    29             <summary></summary>
     32    <div class="wp-block-happyprime-show-hide-group">
     33        <!-- Optional based on attribute -->
     34        <button class="toggle-all" aria-expanded="false">Open all</button>
     35        <details class="wp-block-happyprime-show-hide-section">
     36            <summary class="wp-block-happyprime-show-hide-summary"></summary>
    3037            <!-- Additional blocks to be shown/hidden -->
    3138        </details>
    32         <details>
    33             <summary></summary>
     39        <details class="wp-block-happyprime-show-hide-section">
     40            <summary class="wp-block-happyprime-show-hide-summary"></summary>
    3441            <!-- Additional blocks to be shown hidden -->
    3542        </details>
     
    3946An option is provided in the block's side panel to toggle an "Open all"/"Close all" button. If this is toggled on for a block, an additional `<button>` element will be inserted and JavaScript will be used on the front-end to control the show/hide behavior of all `<details>` elements in the group at once.
    4047
    41 If the toggle is off, no JavaScript is loaded on the front end.
     48If the toggle is off, no JavaScript is loaded on the front end and only the browser's default behavior is used for opening and closing `<details>` elements.
    4249
    4350## Changelog
     51
     52### 3.0.0
     53
     54* Refactor block markup to improve editorial experience and formatting options.
     55* Introduce `happyprime/show-hide-summary` block to manage `<summary>` content.
     56* Introduce `happyprime/show-hide-details` block to manage remaningin `<details>` content.
     57* Upgrade `happyprime/show-hide-group` and `happyprime/show-hide-section` blocks to API v3.
     58* Add a deprecation routine to transform 2.0.x block markup into the new format.
     59* Replace `@wordpress/scripts` with slimmer build configuration.
     60* Bump minimum WordPress version to 6.4; confirm compatibility with 6.7.
    4461
    4562### 2.0.3
  • show-hide-section-block/trunk/src/show-hide-group/block.json

    r2905297 r3182831  
    11{
    22    "$schema": "https://json.schemastore.org/block.json",
    3     "apiVersion": 2,
     3    "apiVersion": 3,
    44    "name": "happyprime/show-hide-group",
    55    "title": "Show Hide Group",
  • show-hide-section-block/trunk/src/show-hide-group/index.js

    r2905297 r3182831  
    1212import metadata from './block.json';
    1313
    14 const Edit = ( props ) => {
     14const Edit = (props) => {
    1515    const {
    1616        attributes: { hasToggle },
     
    1818    } = props;
    1919
    20     const details = useSelect( ( select ) => {
    21         const currentBlocks = select( 'core/block-editor' ).getBlocks(
     20    const details = useSelect((select) => {
     21        const currentBlocks = select('core/block-editor').getBlocks(
    2222            props.clientId
    2323        );
    2424
    2525        return currentBlocks;
    26     } );
     26    });
    2727
    28     const toggleAllSections = ( evt ) => {
    29         if ( false === evt.target.ariaExpanded ) {
    30             details.forEach( ( detail ) => {
    31                 dispatch( 'core/block-editor' ).updateBlockAttributes(
     28    const toggleAllSections = (evt) => {
     29        if (false === evt.target.ariaExpanded) {
     30            details.forEach((detail) => {
     31                dispatch('core/block-editor').updateBlockAttributes(
    3232                    detail.clientId,
    3333                    { isOpen: true }
    3434                );
    35             } );
     35            });
    3636
    37             evt.target.innerText = __( 'Close all', 'show-hide-section-block' );
     37            evt.target.innerText = __('Close all', 'show-hide-section-block');
    3838            evt.target.ariaExpanded = true;
    3939        } else {
    40             details.forEach( ( detail ) => {
    41                 dispatch( 'core/block-editor' ).updateBlockAttributes(
     40            details.forEach((detail) => {
     41                dispatch('core/block-editor').updateBlockAttributes(
    4242                    detail.clientId,
    4343                    { isOpen: false }
    4444                );
    45             } );
     45            });
    4646
    47             evt.target.innerText = __( 'Open all', 'show-hide-section-block' );
     47            evt.target.innerText = __('Open all', 'show-hide-section-block');
    4848            evt.target.ariaExpanded = false;
    4949        }
     
    5555                <PanelBody>
    5656                    <ToggleControl
    57                         label={ __(
     57                        label={__(
    5858                            'Has open/close all toggle',
    5959                            'show-hide-section-block'
    60                         ) }
     60                        )}
    6161                        help={
    6262                            hasToggle
     
    6464                                        'Open/close all toggle will display.',
    6565                                        'show-hide-section-block'
    66                                   )
     66                                    )
    6767                                : __(
    6868                                        'Open/close all toggle will not display.',
    6969                                        'show-hide-section-block'
    70                                   )
     70                                    )
    7171                        }
    72                         checked={ hasToggle }
    73                         onChange={ ( value ) => {
    74                             setAttributes( { hasToggle: value } );
    75                         } }
     72                        checked={hasToggle}
     73                        onChange={(value) => {
     74                            setAttributes({ hasToggle: value });
     75                        }}
    7676                    />
    7777                </PanelBody>
    7878            </InspectorControls>
    79             <div { ...useBlockProps() }>
    80                 { hasToggle && (
     79            <div {...useBlockProps()}>
     80                {hasToggle && (
    8181                    <button
    8282                        className="toggle-all"
    8383                        aria-expanded="false"
    84                         onClick={ toggleAllSections }
     84                        onClick={toggleAllSections}
    8585                    >
    86                         { __( 'Open all', 'show-hide-section-block' ) }
     86                        {__('Open all', 'show-hide-section-block')}
    8787                    </button>
    88                 ) }
     88                )}
    8989                <InnerBlocks
    90                     allowedBlocks={ [ 'happyprime/show-hide-section' ] }
    91                     template={ [
    92                         [
    93                             'happyprime/show-hide-section',
    94                             {},
    95                             [ [ 'core/paragraph', {} ] ],
    96                         ],
    97                         [
    98                             'happyprime/show-hide-section',
    99                             {},
    100                             [ [ 'core/paragraph', {} ] ],
    101                         ],
    102                     ] }
    103                     templateLock={ false }
     90                    allowedBlocks={['happyprime/show-hide-section']}
     91                    template={[['happyprime/show-hide-section', {}]]}
     92                    templateLock={false}
    10493                />
    10594            </div>
     
    10897};
    10998
    110 const Save = ( props ) => {
     99const Save = (props) => {
    111100    const {
    112101        attributes: { hasToggle },
     
    114103
    115104    return (
    116         <div { ...useBlockProps.save() }>
    117             { hasToggle && (
     105        <div {...useBlockProps.save()}>
     106            {hasToggle && (
    118107                <button className="toggle-all" aria-expanded="false">
    119                     { __( 'Open all', 'show-hide-section-block' ) }
     108                    {__('Open all', 'show-hide-section-block')}
    120109                </button>
    121             ) }
     110            )}
    122111            <InnerBlocks.Content />
    123112        </div>
     
    126115
    127116// Register the block.
    128 registerBlockType( metadata, {
     117registerBlockType(metadata, {
    129118    edit: Edit,
    130119    save: Save,
    131 } );
     120});
  • show-hide-section-block/trunk/src/show-hide-group/view.js

    r2905297 r3182831  
    55        );
    66
    7         if ( toggleAll.length > 0 ) {
    8             toggleAll.forEach( ( toggle ) =>
    9                 toggle.addEventListener( 'click', () => {
     7        if (toggleAll.length > 0) {
     8            toggleAll.forEach((toggle) =>
     9                toggle.addEventListener('click', () => {
    1010                    const details = toggle.parentElement.querySelectorAll(
    1111                        'details.wp-block-happyprime-show-hide-section'
    1212                    );
    1313
    14                     if ( 'true' !== toggle.ariaExpanded ) {
    15                         details.forEach( ( detail ) => {
    16                             detail.setAttribute( 'open', 'true' );
    17                         } );
     14                    if ('true' !== toggle.ariaExpanded) {
     15                        details.forEach((detail) => {
     16                            detail.setAttribute('open', 'true');
     17                        });
    1818
    1919                        toggle.innerText = 'Close All';
    2020                        toggle.ariaExpanded = 'true';
    2121                    } else {
    22                         details.forEach( ( detail ) => {
    23                             detail.removeAttribute( 'open' );
    24                         } );
     22                        details.forEach((detail) => {
     23                            detail.removeAttribute('open');
     24                        });
    2525
    2626                        toggle.innerText = 'Open All';
    2727                        toggle.ariaExpanded = 'false';
    2828                    }
    29                 } )
     29                })
    3030            );
    3131        }
    3232    };
    3333
    34     document.addEventListener( 'DOMContentLoaded', handleToggleButton );
     34    document.addEventListener('DOMContentLoaded', handleToggleButton);
    3535}
  • show-hide-section-block/trunk/src/show-hide-section/block.json

    r2905297 r3182831  
    11{
    22    "$schema": "https://json.schemastore.org/block.json",
    3     "apiVersion": 2,
     3    "apiVersion": 3,
    44    "name": "happyprime/show-hide-section",
    55    "title": "Show Hide Section",
     
    1313            "type": "boolean",
    1414            "default": false
    15         },
    16         "summary": {
    17             "type": "string",
    18             "source": "html",
    19             "selector": "summary"
    2015        }
    2116    },
  • show-hide-section-block/trunk/src/show-hide-section/index.js

    r2905297 r3182831  
    11import { registerBlockType } from '@wordpress/blocks';
    2 import { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';
     2import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
    33import { __ } from '@wordpress/i18n';
    44
    55// Internal dependencies.
    66import metadata from './block.json';
     7import deprecated from './deprecated';
    78
    8 const Edit = ( props ) => {
     9const Edit = (props) => {
    910    const {
    10         attributes: { isOpen, summary },
     11        attributes: { isOpen },
    1112        setAttributes,
     13        isSelected,
    1214    } = props;
    1315
    14     /**
    15      * Insert a space at the current position of the cursor and then adjust
    16      * the cursor position, accounting for any selection it has made.
    17      *
    18      * @param {Node} node
    19      */
    20     const insertSpace = ( node ) => {
    21         const { ownerDocument } = node;
    22         const { defaultView } = ownerDocument;
    23 
    24         const sel = defaultView.getSelection();
    25         const range = sel.getRangeAt( 0 );
    26         const textNode = document.createTextNode( ' ' );
    27 
    28         range.deleteContents();
    29         range.insertNode( textNode );
    30         range.setStartAfter( textNode );
    31     };
     16    // Create an inner blocks template for the content.
     17    const TEMPLATE = [
     18        [
     19            'happyprime/show-hide-summary',
     20            { summary: __('Summary', 'show-hide-section-block') },
     21        ],
     22        [
     23            'happyprime/show-hide-details',
     24            { details: __('Details', 'show-hide-section-block') },
     25        ],
     26    ];
    3227
    3328    return (
    34         <details { ...useBlockProps() } open={ isOpen }>
    35             <RichText
    36                 tagName="summary"
    37                 label={ __( 'Summary', 'show-hide-section-block' ) }
    38                 placeholder={ __( 'Summary', 'show-hide-section-block' ) }
    39                 value={ summary }
    40                 allowedFormats={ [ 'core/bold', 'core/italic' ] }
    41                 onChange={ ( value ) => {
    42                     setAttributes( { summary: value } );
    43                 } }
    44                 onKeyUp={ ( evt ) => {
    45                     if ( ' ' === evt.key ) {
    46                         evt.preventDefault(); // Stop the details element from toggling.
    47                         insertSpace( evt.target ); // But make sure the space character is added.
    48                     }
    49                 } }
     29        <div {...useBlockProps()}>
     30            <InnerBlocks
     31                template={TEMPLATE}
     32                allowedBlocks={[
     33                    'happyprime/show-hide-summary',
     34                    'happyprime/show-hide-details',
     35                ]}
     36                templateLock="all"
    5037            />
    51             <InnerBlocks />
    52         </details>
     38        </div>
    5339    );
    5440};
    5541
    56 const Save = ( props ) => {
    57     const {
    58         attributes: { summary },
    59     } = props;
    60 
     42const Save = () => {
    6143    return (
    62         <details { ...useBlockProps.save() }>
    63             <summary>
    64                 <RichText.Content tag={ 'summary' } value={ summary } />
    65             </summary>
     44        <details {...useBlockProps.save()}>
    6645            <InnerBlocks.Content />
    6746        </details>
     
    7049
    7150// Register the block.
    72 registerBlockType( metadata, {
     51registerBlockType(metadata, {
    7352    edit: Edit,
    7453    save: Save,
    75 } );
     54    deprecated,
     55});
Note: See TracChangeset for help on using the changeset viewer.