| 1 |
(()=>{"use strict";var e={10490:(e,t,n)=>{n.d(t,{Yv:()=>r,f:()=>a,iw:()=>l,t3:()=>i});const a=[{label:"H2",value:"h2"},{label:"H3",value:"h3"},{label:"H4",value:"h4"},{label:"Paragraph",value:"p"}],l=[{label:"Bulleted",value:"disc"},{label:"Numbered",value:"decimal"},{label:"Plain",value:"none"}];function r(e){return e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9\s-]/g,"").trim().replace(/[\s-]+/g,"-").replace(/^-+|-+$/g,"")}function i(e){var t;return{marginBottom:`${null!==(t=e.itemSpacing)&&void 0!==t?t:6}px`,color:e.linkColor||void 0}}},24454:()=>{},27034:(e,t,n)=>{n.d(t,{A:()=>i});var a=n(51609),l=n(94715),r=n(10490);function i({attributes:e}){const{heading:t,headingTag:n,headings:i,listStyle:o}=e,s=(i||[]).filter(e=>e.content&&e.anchor);if(0===s.length)return null;const c=l.useBlockProps.save({className:"thinkrank-toc"}),h=n||"h2";return(0,a.createElement)("div",{...c},t?(0,a.createElement)(l.RichText.Content,{tagName:h,className:"thinkrank-toc__heading",value:t}):null,(0,a.createElement)("nav",{"aria-label":"Table of contents"},(0,a.createElement)("ul",{className:`thinkrank-toc__list thinkrank-toc__list--${o}`},s.map((t,n)=>(0,a.createElement)("li",{key:n,className:`thinkrank-toc__item thinkrank-toc__item--level-${t.level}`,style:(0,r.t3)(e)},(0,a.createElement)("a",{href:`#${t.anchor}`},t.content))))))}},27723:e=>{e.exports=window.wp.i18n},35271:(e,t,n)=>{n.d(t,{A:()=>h});var a=n(51609),l=n(27723),r=n(47143),i=n(86087),o=n(94715),s=n(56427),c=n(10490);function h({attributes:e,setAttributes:t}){const{heading:n,headingTag:h,headings:k,maxLevel:u,listStyle:d,outputSchema:m,linkColor:p,itemSpacing:g}=e,_=(0,o.useBlockProps)({className:"thinkrank-toc"}),v=h||"h2",{updateBlockAttributes:b,__unstableMarkNextChangeAsNotPersistent:f}=(0,r.useDispatch)("core/block-editor"),y=(0,r.useSelect)(e=>{const t=e("core/block-editor");return t.getClientIdsWithDescendants().map(e=>t.getBlock(e)).filter(e=>e&&"core/heading"===e.name)},[]);(0,i.useEffect)(()=>{const e=new Set,n=[];y.forEach(t=>{var a;const l=null!==(a=t.attributes.level)&&void 0!==a?a:2,r=(t.attributes.content||"").toString().replace(/<[^>]+>/g,"").trim();if(!r||l<2||l>u)return;let i=t.attributes.anchor||"";if(!i){const n=(0,c.Yv)(r)||"section";i=n;let a=2;for(;e.has(i);)i=`${n}-${a++}`;b(t.clientId,{anchor:i})}e.add(i),n.push({content:r,level:l,anchor:i})}),JSON.stringify(n)!==JSON.stringify(k||[])&&(f(),t({headings:n}))},[y,u]);const w=Array.isArray(k)?k:[];return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(o.InspectorControls,null,(0,a.createElement)(s.TabPanel,{className:"thinkrank-toc-tabs",activeClass:"is-active",tabs:[{name:"general",title:(0,l.__)("General","thinkrank")},{name:"style",title:(0,l.__)("Style","thinkrank")}]},e=>"general"===e.name?(0,a.createElement)(s.PanelBody,{title:(0,l.__)("Content","thinkrank"),initialOpen:!0},(0,a.createElement)(s.SelectControl,{label:(0,l.__)("Heading tag","thinkrank"),value:h,options:c.f,onChange:e=>t({headingTag:e})}),(0,a.createElement)(s.SelectControl,{label:(0,l.__)("Include headings up to","thinkrank"),value:String(u),options:[{label:"H2",value:"2"},{label:"H3",value:"3"},{label:"H4",value:"4"}],onChange:e=>t({maxLevel:parseInt(e,10)})}),(0,a.createElement)(s.SelectControl,{label:(0,l.__)("List style","thinkrank"),value:d,options:c.iw,onChange:e=>t({listStyle:e})}),(0,a.createElement)(s.ToggleControl,{label:(0,l.__)("Output TOC schema (JSON-LD)","thinkrank"),help:(0,l.__)("Adds SiteNavigationElement structured data for the listed sections.","thinkrank"),checked:!!m,onChange:e=>t({outputSchema:e})})):(0,a.createElement)(a.Fragment,null,(0,a.createElement)(o.PanelColorSettings,{title:(0,l.__)("Colors","thinkrank"),initialOpen:!0,colorSettings:[{value:p,onChange:e=>t({linkColor:e}),label:(0,l.__)("Links","thinkrank")}]}),(0,a.createElement)(s.PanelBody,{title:(0,l.__)("Spacing","thinkrank"),initialOpen:!1},(0,a.createElement)(s.RangeControl,{label:(0,l.__)("Space between items (px)","thinkrank"),value:g,onChange:e=>t({itemSpacing:e}),min:0,max:24}))))),(0,a.createElement)("div",{..._},(0,a.createElement)(o.RichText,{tagName:v,className:"thinkrank-toc__heading",value:n,onChange:e=>t({heading:e}),placeholder:(0,l.__)("Table of Contents","thinkrank"),allowedFormats:[]}),0===w.length?(0,a.createElement)(s.Notice,{status:"info",isDismissible:!1},(0,l.__)("Add headings (H2 and below) to the post and they will appear here automatically.","thinkrank")):(0,a.createElement)("ul",{className:`thinkrank-toc__list thinkrank-toc__list--${d}`},w.map((t,n)=>(0,a.createElement)("li",{key:n,className:`thinkrank-toc__item thinkrank-toc__item--level-${t.level}`,style:(0,c.t3)(e)},(0,a.createElement)("a",{href:`#${t.anchor}`},t.content))))))}},47143:e=>{e.exports=window.wp.data},51609:e=>{e.exports=window.React},56427:e=>{e.exports=window.wp.components},74997:e=>{e.exports=window.wp.blocks},86087:e=>{e.exports=window.wp.element},94715:e=>{e.exports=window.wp.blockEditor}},t={};function n(a){var l=t[a];if(void 0!==l)return l.exports;var r=t[a]={exports:{}};return e[a](r,r.exports,n),r.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var a in t)n.o(t,a)&&!n.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var a=n(74997),l=n(27723),r=n(35271),i=n(27034);n(24454),(0,a.registerBlockType)("thinkrank/toc",{apiVersion:3,title:(0,l.__)("Table of Contents (ThinkRank)","thinkrank"),description:(0,l.__)("A linked table of contents generated from your headings.","thinkrank"),category:"widgets",icon:"list-view",keywords:[(0,l.__)("table of contents","thinkrank"),(0,l.__)("toc","thinkrank"),(0,l.__)("index","thinkrank"),(0,l.__)("anchor","thinkrank")],supports:{html:!1,anchor:!0},attributes:{heading:{type:"string",default:"Table of Contents"},headingTag:{type:"string",default:"h2"},headings:{type:"array",default:[]},maxLevel:{type:"number",default:3},listStyle:{type:"string",default:"disc"},outputSchema:{type:"boolean",default:!0},linkColor:{type:"string"},itemSpacing:{type:"number",default:6}},edit:r.A,save:i.A})})(); |