From f9958980a6a99b7c00bef774db4f63ac325d36d3 Mon Sep 17 00:00:00 2001 From: Marc Toensing Date: Fri, 2 Feb 2024 13:15:51 +0100 Subject: [PATCH] fix for new installation with autorefresh --- build/index.asset.php | 2 +- build/index.js | 2 +- package-lock.json | 4 ++-- simpletoc-admin-settings.php | 15 +++++---------- src/edit.js | 7 +++++-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/build/index.asset.php b/build/index.asset.php index a1cac22..30187ae 100644 --- a/build/index.asset.php +++ b/build/index.asset.php @@ -1 +1 @@ - array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-server-side-render'), 'version' => '83a72e27f0da141aa26b'); + array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-server-side-render'), 'version' => '94f22d7c390e2dee9f8b'); diff --git a/build/index.js b/build/index.js index 5c32bae..06883cb 100644 --- a/build/index.js +++ b/build/index.js @@ -1 +1 @@ -(()=>{"use strict";var e={n:t=>{var l=t&&t.__esModule?()=>t.default:()=>t;return e.d(l,{a:l}),l},d:(t,l)=>{for(var o in l)e.o(l,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:l[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,l=window.wp.blocks,o=JSON.parse('{"$schema":"https://json.schemastore.org/block.json","apiVersion":2,"name":"simpletoc/toc","version":"6.3.0","title":"SimpleTOC","category":"layout","icon":"","keywords":["TOC","Table of Contents","SimpleTOC","Index"],"supports":{"align":["wide","full"]},"description":"Adds a Table of Contents.","attributes":{"no_title":{"type":"boolean","default":false},"title_level":{"type":"integer","default":2},"title_text":{"type":"string"},"use_ol":{"type":"boolean","default":false},"remove_indent":{"type":"boolean","default":false},"add_smooth":{"type":"boolean","default":false},"use_absolute_urls":{"type":"boolean","default":false},"max_level":{"type":"integer","default":6},"min_level":{"type":"integer","default":1},"updated":{"type":"integer"},"accordion":{"type":"boolean","default":false},"wrapper":{"type":"boolean","default":false},"autoupdate":{"type":"boolean","default":true}},"textdomain":"simpletoc","editorScript":"file:index.js","editorStyle":"file:index.css"}'),n=window.React,a=window.wp.i18n,i=window.wp.blockEditor,c=window.wp.editor,r=window.wp.serverSideRender;var s=e.n(r);const m=window.wp.primitives,d=(0,n.createElement)(m.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(m.Path,{d:"M11.1 15.8H20v-1.5h-8.9v1.5zm0-8.6v1.5H20V7.2h-8.9zM6 13c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-7c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"})),v=(0,n.createElement)(m.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(m.Path,{d:"M11.1 15.8H20v-1.5h-8.9v1.5zm0-8.6v1.5H20V7.2h-8.9zM5 6.7V10h1V5.3L3.8 6l.4 1 .8-.3zm-.4 5.7c-.3.1-.5.2-.7.3l.1 1.1c.2-.2.5-.4.8-.5.3-.1.6 0 .7.1.2.3 0 .8-.2 1.1-.5.8-.9 1.6-1.4 2.5h2.7v-1h-1c.3-.6.8-1.4.9-2.1.1-.3 0-.8-.2-1.1-.5-.6-1.3-.5-1.7-.4z"})),h=(0,n.createElement)(m.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(m.Path,{d:"M4 7.2v1.5h16V7.2H4zm8 8.6h8v-1.5h-8v1.5zm-4-4.6l-4 4 4 4 1-1-3-3 3-3-1-1z"})),u=(0,n.createElement)(m.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(m.Path,{d:"M4 7.2v1.5h16V7.2H4zm8 8.6h8v-1.5h-8v1.5zm-8-3.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2.5-.2.9-.2 1.4.4-.3.8-.6 1.2-.8.4-.2.8-.3 1.3-.3.4 0 .8 0 1.2.2.4.1.7.3 1 .6.3.3.5.6.7.9.2.4.3.8.3 1.3s-.1.9-.3 1.4c-.2.4-.5.7-.8 1-.4.3-.8.5-1.2.6-1 .3-2 .3-3 0-.5-.2-1-.5-1.4-.9-.4-.4-.8-.9-1-1.5-.2-.6-.3-1.3-.3-2.1s.1-1.6.4-2.3c.2-.6.6-1.2 1-1.6.4-.4.9-.7 1.4-.9.6-.3 1.1-.4 1.7-.4.7 0 1.4.1 2 .3.5.2 1 .5 1.4.8 0 .1-1.3 1.4-1.3 1.4zm-2.4 5.8c.2 0 .4 0 .6-.1.2 0 .4-.1.5-.2.1-.1.3-.3.4-.5.1-.2.1-.5.1-.7 0-.4-.1-.8-.4-1.1-.3-.2-.7-.3-1.1-.3-.3 0-.7.1-1 .2-.4.2-.7.4-1 .7 0 .3.1.7.3 1 .1.2.3.4.4.6.2.1.3.3.5.3.2.1.5.2.7.1z"};return o.hasOwnProperty(e)?(0,t.createElement)(_.SVG,{width:"24",height:"24",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",isPressed:l},(0,t.createElement)(_.Path,{d:o[e]})):null}const w=[0,1,2,3,4,5,6],b={className:"block-library-heading-level-dropdown"};function E({selectedLevel:e,onChange:l}){return(0,t.createElement)(_.ToolbarDropdownMenu,{popoverProps:b,icon:(0,t.createElement)(g,{level:e}),label:(0,a.__)("Change heading level tag"),controls:w.map((o=>{{const n=o===e;return{icon:(0,t.createElement)(g,{level:o,isPressed:n}),isActive:n,onClick(){l(o)}}}}))})}const f=window.wp.data,z=(0,t.createElement)("svg",{clipRule:"evenodd",fillRule:"evenodd",strokeLinejoin:"round",strokeMiterlimit:"2",viewBox:"0 0 500 500",xmlns:"http://www.w3.org/2000/svg"},(0,t.createElement)("path",{d:"m365.983 78.248c2.72-32.415 29.921-57.908 63.029-57.908 34.91 0 63.253 28.342 63.253 63.252s-28.343 63.252-63.253 63.252v269.582c0 25.232-20.485 45.718-45.718 45.718h-313.62c-25.233 0-45.719-20.486-45.719-45.718v-292.46c0-25.233 20.486-45.718 45.719-45.718zm-245.943 324.857c-16.883 0-30.511-13.719-30.511-30.714 0-16.79 13.628-30.714 30.511-30.714 16.679 0 30.511 13.924 30.511 30.714 0 16.995-13.832 30.714-30.511 30.714zm50.851-40.952h183.063v20.476h-183.063zm-50.851-61.428c-16.883 0-30.511-13.719-30.511-30.714 0-16.79 13.628-30.714 30.511-30.714 16.679 0 30.511 13.924 30.511 30.714 0 16.995-13.832 30.714-30.511 30.714zm50.851-40.952h183.063v20.476h-183.063zm-50.851-61.428c-16.883 0-30.511-13.719-30.511-30.714 0-16.791 13.628-30.714 30.511-30.714 16.679 0 30.511 13.923 30.511 30.714 0 16.995-13.832 30.714-30.511 30.714zm50.851-40.952h183.063v20.476h-183.063zm253.007-44.649v-24.188h-24.008v-10.108h24.008v-24.008h10.229v24.008h24.008v10.108h-24.008v24.188z"}));(0,l.registerBlockType)(o,{icon:z,edit:function({attributes:e,setAttributes:t}){const l=(0,i.useBlockProps)(),o=(0,f.useSelect)((e=>{const t=e("core").getSite()?.simpletoc_autoupdate_enabled;return Boolean(t)}),[]),{autoupdate:r}=e,{returnisSaving:m,returnisSavingNonPostEntityChanges:g}=(0,f.useSelect)((e=>{const{isSavingPost:t,isSavingNonPostEntityChanges:l}=e(c.store);return{returnisSaving:t(),returnisSavingNonPostEntityChanges:l()}})),w=(0,n.createElement)(i.BlockControls,{group:"block"},!(e.no_title||e.accordion)&&(0,n.createElement)(E,{selectedLevel:e.title_level,onChange:e=>t({title_level:Number(e)})}),(0,n.createElement)(_.ToolbarButton,{icon:d,title:(0,a.__)("Convert to unordered list","simpletoc"),describedBy:(0,a.__)("Convert to unordered list","simpletoc"),isActive:!1===e.use_ol,onClick:()=>{t({use_ol:!1})}}),(0,n.createElement)(_.ToolbarButton,{icon:v,title:(0,a.__)("Convert to ordered list","simpletoc"),describedBy:(0,a.__)("Convert to ordered list","simpletoc"),isActive:!0===e.use_ol,onClick:()=>{t({use_ol:!0})}}),(0,n.createElement)(_.ToolbarButton,{icon:h,title:(0,a.__)("Indent list","simpletoc"),describedBy:(0,a.__)("Indent list","simpletoc"),isActive:!0===e.remove_indent,onClick:()=>{t({remove_indent:!0})}}),(0,n.createElement)(_.ToolbarButton,{icon:u,title:(0,a.__)("Outdent list","simpletoc"),describedBy:(0,a.__)("Outdent list","simpletoc"),isActive:!1===e.remove_indent,onClick:()=>{t({remove_indent:!1})}}),!e.autoupdate||!o&&(0,n.createElement)(_.ToolbarButton,{icon:p,label:(0,a.__)("Update table of contents","simpletoc"),onClick:()=>t({updated:Date.now()})})),b=(0,n.createElement)(i.InspectorControls,null,(0,n.createElement)(_.Panel,null,(0,n.createElement)(_.PanelBody,null,!e.no_title&&(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.TextControl,{label:(0,a.__)("Heading Text","simpletoc"),help:(0,a.__)("Set the heading text of the block.","simpletoc")+" "+(0,a.__)("Default value","simpletoc")+": "+(0,a.__)("Table of Contents","simpletoc"),value:e.title_text,onChange:e=>t({title_text:e||(0,a.__)("Table of Contents","simpletoc")})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Remove heading","simpletoc"),checked:e.no_title,onChange:()=>t({no_title:!e.no_title})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.SelectControl,{label:(0,a.__)("Minimum level","simpletoc"),help:(0,a.__)("Minimum depth of the headings.","simpletoc"),value:e.min_level,options:[{label:(0,a.__)("Including","simpletoc")+" H6",value:"6"},{label:(0,a.__)("Including","simpletoc")+" H5",value:"5"},{label:(0,a.__)("Including","simpletoc")+" H4",value:"4"},{label:(0,a.__)("Including","simpletoc")+" H3",value:"3"},{label:(0,a.__)("Including","simpletoc")+" H2",value:"2"},{label:(0,a.__)("Including","simpletoc")+" H1 ("+(0,a.__)("default","simpletoc")+")",value:"1"}],onChange:e=>t({min_level:Number(e)})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.SelectControl,{label:(0,a.__)("Maximum level","simpletoc"),help:(0,a.__)("Maximum depth of the headings.","simpletoc"),value:e.max_level,options:[{label:(0,a.__)("Including","simpletoc")+" H6 ("+(0,a.__)("default","simpletoc")+")",value:"6"},{label:(0,a.__)("Including","simpletoc")+" H5",value:"5"},{label:(0,a.__)("Including","simpletoc")+" H4",value:"4"},{label:(0,a.__)("Including","simpletoc")+" H3",value:"3"},{label:(0,a.__)("Including","simpletoc")+" H2",value:"2"},{label:(0,a.__)("Including","simpletoc")+" H1",value:"1"}],onChange:e=>t({max_level:Number(e)})})))),(0,n.createElement)(_.Panel,null,(0,n.createElement)(_.PanelBody,{title:(0,a.__)("Advanced Features","simpletoc"),icon:"settings",initialOpen:!1},(0,n.createElement)(_.PanelRow,null,(0,n.createElement)("div",{style:{marginBottom:"1em",border:"1px solid rgba(0, 0, 0, 0.05)",padding:"0.5em",backgroundColor:"#f7f7f7"}},(0,n.createElement)("p",null,(0,n.createElement)("strong",null,(0,a.__)("Think about making a donation if you use any of these features.","simpletoc"))),(0,n.createElement)(_.ExternalLink,{href:"https://marc.tv/out/donate"},(0,a.__)("Donate here!","simpletoc")))),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Hide in accordion menu","simpletoc"),help:(0,a.__)("Adds minimal JavaScript and css styles.","simpletoc"),checked:e.accordion,onChange:()=>t({accordion:!e.accordion})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Smooth scrolling support","simpletoc"),help:(0,a.__)('Adds the following CSS to the HTML element: "scroll-behavior: smooth;"',"simpletoc"),checked:e.add_smooth,onChange:()=>t({add_smooth:!e.add_smooth})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Use absolute urls","simpletoc"),help:(0,a.__)("Adds the permalink url to the fragment.","simpletoc"),checked:e.use_absolute_urls,onChange:()=>t({use_absolute_urls:!e.use_absolute_urls})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Wrapper div","simpletoc"),help:(0,a.__)('Additionally adds the role "navigation" and ARIA attributes.',"simpletoc"),checked:e.wrapper,onChange:()=>t({wrapper:!e.wrapper})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Automatic refresh","simpletoc"),help:(0,a.__)("Automatic updating of the table of contents.","simpletoc"),checked:e.autoupdate,onChange:()=>t({autoupdate:!e.autoupdate})})))));return(0,n.createElement)("div",{...l},w,b,o&&r&&(m||g)?(0,n.createElement)(_.Spinner,null):(0,n.createElement)(s(),{block:"simpletoc/toc",attributes:e}))},save:function(){return null}})})(); \ No newline at end of file +(()=>{"use strict";var e={n:t=>{var l=t&&t.__esModule?()=>t.default:()=>t;return e.d(l,{a:l}),l},d:(t,l)=>{for(var o in l)e.o(l,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:l[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,l=window.wp.blocks,o=JSON.parse('{"$schema":"https://json.schemastore.org/block.json","apiVersion":2,"name":"simpletoc/toc","version":"6.3.0","title":"SimpleTOC","category":"layout","icon":"","keywords":["TOC","Table of Contents","SimpleTOC","Index"],"supports":{"align":["wide","full"]},"description":"Adds a Table of Contents.","attributes":{"no_title":{"type":"boolean","default":false},"title_level":{"type":"integer","default":2},"title_text":{"type":"string"},"use_ol":{"type":"boolean","default":false},"remove_indent":{"type":"boolean","default":false},"add_smooth":{"type":"boolean","default":false},"use_absolute_urls":{"type":"boolean","default":false},"max_level":{"type":"integer","default":6},"min_level":{"type":"integer","default":1},"updated":{"type":"integer"},"accordion":{"type":"boolean","default":false},"wrapper":{"type":"boolean","default":false},"autoupdate":{"type":"boolean","default":true}},"textdomain":"simpletoc","editorScript":"file:index.js","editorStyle":"file:index.css"}'),n=window.React,a=window.wp.i18n,i=window.wp.blockEditor,c=window.wp.editor,r=window.wp.serverSideRender;var s=e.n(r);const m=window.wp.primitives,d=(0,n.createElement)(m.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(m.Path,{d:"M11.1 15.8H20v-1.5h-8.9v1.5zm0-8.6v1.5H20V7.2h-8.9zM6 13c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-7c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"})),v=(0,n.createElement)(m.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(m.Path,{d:"M11.1 15.8H20v-1.5h-8.9v1.5zm0-8.6v1.5H20V7.2h-8.9zM5 6.7V10h1V5.3L3.8 6l.4 1 .8-.3zm-.4 5.7c-.3.1-.5.2-.7.3l.1 1.1c.2-.2.5-.4.8-.5.3-.1.6 0 .7.1.2.3 0 .8-.2 1.1-.5.8-.9 1.6-1.4 2.5h2.7v-1h-1c.3-.6.8-1.4.9-2.1.1-.3 0-.8-.2-1.1-.5-.6-1.3-.5-1.7-.4z"})),h=(0,n.createElement)(m.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(m.Path,{d:"M4 7.2v1.5h16V7.2H4zm8 8.6h8v-1.5h-8v1.5zm-4-4.6l-4 4 4 4 1-1-3-3 3-3-1-1z"})),u=(0,n.createElement)(m.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(m.Path,{d:"M4 7.2v1.5h16V7.2H4zm8 8.6h8v-1.5h-8v1.5zm-8-3.5l3 3-3 3 1 1 4-4-4-4-1 1z"})),p=(0,n.createElement)(m.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,n.createElement)(m.Path,{d:"m11.3 17.2-5-5c-.1-.1-.1-.3 0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 1-.4.3-.8.5-1.2.6-1 .3-2 .3-3 0-.5-.2-1-.5-1.4-.9-.4-.4-.8-.9-1-1.5-.2-.6-.3-1.3-.3-2.1s.1-1.6.4-2.3c.2-.6.6-1.2 1-1.6.4-.4.9-.7 1.4-.9.6-.3 1.1-.4 1.7-.4.7 0 1.4.1 2 .3.5.2 1 .5 1.4.8 0 .1-1.3 1.4-1.3 1.4zm-2.4 5.8c.2 0 .4 0 .6-.1.2 0 .4-.1.5-.2.1-.1.3-.3.4-.5.1-.2.1-.5.1-.7 0-.4-.1-.8-.4-1.1-.3-.2-.7-.3-1.1-.3-.3 0-.7.1-1 .2-.4.2-.7.4-1 .7 0 .3.1.7.3 1 .1.2.3.4.4.6.2.1.3.3.5.3.2.1.5.2.7.1z"};return o.hasOwnProperty(e)?(0,t.createElement)(_.SVG,{width:"24",height:"24",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",isPressed:l},(0,t.createElement)(_.Path,{d:o[e]})):null}const w=[0,1,2,3,4,5,6],b={className:"block-library-heading-level-dropdown"};function E({selectedLevel:e,onChange:l}){return(0,t.createElement)(_.ToolbarDropdownMenu,{popoverProps:b,icon:(0,t.createElement)(g,{level:e}),label:(0,a.__)("Change heading level tag"),controls:w.map((o=>{{const n=o===e;return{icon:(0,t.createElement)(g,{level:o,isPressed:n}),isActive:n,onClick(){l(o)}}}}))})}const f=window.wp.data,z=(0,t.createElement)("svg",{clipRule:"evenodd",fillRule:"evenodd",strokeLinejoin:"round",strokeMiterlimit:"2",viewBox:"0 0 500 500",xmlns:"http://www.w3.org/2000/svg"},(0,t.createElement)("path",{d:"m365.983 78.248c2.72-32.415 29.921-57.908 63.029-57.908 34.91 0 63.253 28.342 63.253 63.252s-28.343 63.252-63.253 63.252v269.582c0 25.232-20.485 45.718-45.718 45.718h-313.62c-25.233 0-45.719-20.486-45.719-45.718v-292.46c0-25.233 20.486-45.718 45.719-45.718zm-245.943 324.857c-16.883 0-30.511-13.719-30.511-30.714 0-16.79 13.628-30.714 30.511-30.714 16.679 0 30.511 13.924 30.511 30.714 0 16.995-13.832 30.714-30.511 30.714zm50.851-40.952h183.063v20.476h-183.063zm-50.851-61.428c-16.883 0-30.511-13.719-30.511-30.714 0-16.79 13.628-30.714 30.511-30.714 16.679 0 30.511 13.924 30.511 30.714 0 16.995-13.832 30.714-30.511 30.714zm50.851-40.952h183.063v20.476h-183.063zm-50.851-61.428c-16.883 0-30.511-13.719-30.511-30.714 0-16.791 13.628-30.714 30.511-30.714 16.679 0 30.511 13.923 30.511 30.714 0 16.995-13.832 30.714-30.511 30.714zm50.851-40.952h183.063v20.476h-183.063zm253.007-44.649v-24.188h-24.008v-10.108h24.008v-24.008h10.229v24.008h24.008v10.108h-24.008v24.188z"}));(0,l.registerBlockType)(o,{icon:z,edit:function({attributes:e,setAttributes:t}){const l=(0,i.useBlockProps)(),o=(0,f.useSelect)((e=>{const t=e("core").getSite()?.simpletoc_autoupdate_enabled;return 1!==t}),[]),{autoupdate:r}=e,{returnisSaving:m,returnisSavingNonPostEntityChanges:g}=(0,f.useSelect)((e=>{const{isSavingPost:t,isSavingNonPostEntityChanges:l}=e(c.store);return{returnisSaving:t(),returnisSavingNonPostEntityChanges:l()}})),w=(0,n.createElement)(i.BlockControls,{group:"block"},!(e.no_title||e.accordion)&&(0,n.createElement)(E,{selectedLevel:e.title_level,onChange:e=>t({title_level:Number(e)})}),(0,n.createElement)(_.ToolbarButton,{icon:d,title:(0,a.__)("Convert to unordered list","simpletoc"),describedBy:(0,a.__)("Convert to unordered list","simpletoc"),isActive:!1===e.use_ol,onClick:()=>{t({use_ol:!1})}}),(0,n.createElement)(_.ToolbarButton,{icon:v,title:(0,a.__)("Convert to ordered list","simpletoc"),describedBy:(0,a.__)("Convert to ordered list","simpletoc"),isActive:!0===e.use_ol,onClick:()=>{t({use_ol:!0})}}),(0,n.createElement)(_.ToolbarButton,{icon:h,title:(0,a.__)("Indent list","simpletoc"),describedBy:(0,a.__)("Indent list","simpletoc"),isActive:!0===e.remove_indent,onClick:()=>{t({remove_indent:!0})}}),(0,n.createElement)(_.ToolbarButton,{icon:u,title:(0,a.__)("Outdent list","simpletoc"),describedBy:(0,a.__)("Outdent list","simpletoc"),isActive:!1===e.remove_indent,onClick:()=>{t({remove_indent:!1})}}),!e.autoupdate||!o&&(0,n.createElement)(_.ToolbarButton,{icon:p,label:(0,a.__)("Update table of contents","simpletoc"),onClick:()=>t({updated:Date.now()})})),b=(0,n.createElement)(i.InspectorControls,null,(0,n.createElement)(_.Panel,null,(0,n.createElement)(_.PanelBody,null,!e.no_title&&(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.TextControl,{label:(0,a.__)("Heading Text","simpletoc"),help:(0,a.__)("Set the heading text of the block.","simpletoc")+" "+(0,a.__)("Default value","simpletoc")+": "+(0,a.__)("Table of Contents","simpletoc"),value:e.title_text,onChange:e=>t({title_text:e||(0,a.__)("Table of Contents","simpletoc")})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Remove heading","simpletoc"),checked:e.no_title,onChange:()=>t({no_title:!e.no_title})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.SelectControl,{label:(0,a.__)("Minimum level","simpletoc"),help:(0,a.__)("Minimum depth of the headings.","simpletoc"),value:e.min_level,options:[{label:(0,a.__)("Including","simpletoc")+" H6",value:"6"},{label:(0,a.__)("Including","simpletoc")+" H5",value:"5"},{label:(0,a.__)("Including","simpletoc")+" H4",value:"4"},{label:(0,a.__)("Including","simpletoc")+" H3",value:"3"},{label:(0,a.__)("Including","simpletoc")+" H2",value:"2"},{label:(0,a.__)("Including","simpletoc")+" H1 ("+(0,a.__)("default","simpletoc")+")",value:"1"}],onChange:e=>t({min_level:Number(e)})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.SelectControl,{label:(0,a.__)("Maximum level","simpletoc"),help:(0,a.__)("Maximum depth of the headings.","simpletoc"),value:e.max_level,options:[{label:(0,a.__)("Including","simpletoc")+" H6 ("+(0,a.__)("default","simpletoc")+")",value:"6"},{label:(0,a.__)("Including","simpletoc")+" H5",value:"5"},{label:(0,a.__)("Including","simpletoc")+" H4",value:"4"},{label:(0,a.__)("Including","simpletoc")+" H3",value:"3"},{label:(0,a.__)("Including","simpletoc")+" H2",value:"2"},{label:(0,a.__)("Including","simpletoc")+" H1",value:"1"}],onChange:e=>t({max_level:Number(e)})})))),(0,n.createElement)(_.Panel,null,(0,n.createElement)(_.PanelBody,{title:(0,a.__)("Advanced Features","simpletoc"),icon:"settings",initialOpen:!1},(0,n.createElement)(_.PanelRow,null,(0,n.createElement)("div",{style:{marginBottom:"1em",border:"1px solid rgba(0, 0, 0, 0.05)",padding:"0.5em",backgroundColor:"#f7f7f7"}},(0,n.createElement)("p",null,(0,n.createElement)("strong",null,(0,a.__)("Think about making a donation if you use any of these features.","simpletoc"))),(0,n.createElement)(_.ExternalLink,{href:"https://marc.tv/out/donate"},(0,a.__)("Donate here!","simpletoc")))),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Hide in accordion menu","simpletoc"),help:(0,a.__)("Adds minimal JavaScript and css styles.","simpletoc"),checked:e.accordion,onChange:()=>t({accordion:!e.accordion})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Smooth scrolling support","simpletoc"),help:(0,a.__)('Adds the following CSS to the HTML element: "scroll-behavior: smooth;"',"simpletoc"),checked:e.add_smooth,onChange:()=>t({add_smooth:!e.add_smooth})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Use absolute urls","simpletoc"),help:(0,a.__)("Adds the permalink url to the fragment.","simpletoc"),checked:e.use_absolute_urls,onChange:()=>t({use_absolute_urls:!e.use_absolute_urls})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Wrapper div","simpletoc"),help:(0,a.__)('Additionally adds the role "navigation" and ARIA attributes.',"simpletoc"),checked:e.wrapper,onChange:()=>t({wrapper:!e.wrapper})})),(0,n.createElement)(_.PanelRow,null,(0,n.createElement)(_.ToggleControl,{label:(0,a.__)("Automatic refresh","simpletoc"),help:(0,a.__)("Automatic updating of the table of contents.","simpletoc"),checked:e.autoupdate,onChange:()=>t({autoupdate:!e.autoupdate})})))));return(0,n.createElement)("div",{...l},w,b,o&&r&&(m||g)?(0,n.createElement)(_.Spinner,null):(0,n.createElement)(s(),{block:"simpletoc/toc",attributes:e}))},save:function(){return null}})})(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 78b8aa5..49feab4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "simpletoc", - "version": "6.1.1", + "version": "6.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "simpletoc", - "version": "6.1.1", + "version": "6.3.0", "license": "GPL-2.0-or-later", "dependencies": { "@wordpress/i18n": "^4.50.0", diff --git a/simpletoc-admin-settings.php b/simpletoc-admin-settings.php index 4adc94b..cee1963 100644 --- a/simpletoc-admin-settings.php +++ b/simpletoc-admin-settings.php @@ -39,6 +39,7 @@ function simpletoc_register_settings() { $accordion_enabled_filter = apply_filters('simpletoc_accordion_enabled', null); $smooth_enabled_filter = apply_filters('simpletoc_smooth_enabled', null); $absolute_urls_enabled_filter = apply_filters('simpletoc_absolute_urls_enabled', null); + $autoupdate_enabled_filter = apply_filters('simpletoc_autoupdate_enabled', null); if ($wrapper_enabled_filter === null) { register_setting('simpletoc_settings', 'simpletoc_wrapper_enabled'); @@ -56,14 +57,8 @@ function simpletoc_register_settings() { register_setting('simpletoc_settings', 'simpletoc_absolute_urls_enabled'); } - // Register setting for autoupdate feature - $autoupdate_enabled_filter = apply_filters('simpletoc_autoupdate_enabled', null); if ($autoupdate_enabled_filter === null) { - $defaults = array( - 'show_in_rest' => true, - 'default' => true - ); - register_setting('simpletoc_settings', 'simpletoc_autoupdate_enabled', $defaults ); + register_setting('simpletoc_settings', 'simpletoc_autoupdate_enabled', array( 'show_in_rest' => true ) ); } // Add settings sections and fields @@ -109,7 +104,7 @@ function simpletoc_register_settings() { // Add the autoupdate settings field add_settings_field( 'simpletoc_autoupdate_enabled', - __('Enable TOC Autoupdate', 'simpletoc'), + __('Force no auto refresh', 'simpletoc'), 'simpletoc_autoupdate_enabled_callback', 'simpletoc', 'simpletoc_wrapper_section' @@ -168,7 +163,7 @@ function simpletoc_absolute_urls_enabled_callback() function simpletoc_autoupdate_enabled_callback() { - $autoupdate_enabled = get_option('simpletoc_autoupdate_enabled', true); + $autoupdate_enabled = get_option('simpletoc_autoupdate_enabled', false); echo ''; - echo ''; + echo ''; } diff --git a/src/edit.js b/src/edit.js index 344e50f..d21700d 100644 --- a/src/edit.js +++ b/src/edit.js @@ -32,11 +32,14 @@ import './accordion.css'; export default function Edit( { attributes, setAttributes } ) { const blockProps = useBlockProps(); - // Get the current option value. + // Get the autoupdate option from WordPress php. const autoupdateOption = useSelect( ( select ) => { const optionValue = select( 'core' ).getSite()?.simpletoc_autoupdate_enabled; - return Boolean( optionValue ); // or use !!optionValue + if ( optionValue !== 1 ) { + return true; + } + return false; }, [] ); const { autoupdate } = attributes;