diff --git a/build/taxonomy/block.json b/build/taxonomy/block.json index 6cdb93d..a08d616 100644 --- a/build/taxonomy/block.json +++ b/build/taxonomy/block.json @@ -59,6 +59,10 @@ "showLabel": { "type": "boolean", "default": true + }, + "useCheckboxes": { + "type": "boolean", + "default": false } }, "textdomain": "query-filter", diff --git a/build/taxonomy/index.asset.php b/build/taxonomy/index.asset.php index 4b3ef34..2c646d8 100644 --- a/build/taxonomy/index.asset.php +++ b/build/taxonomy/index.asset.php @@ -1 +1 @@ - array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-i18n'), 'version' => 'f1456d24ac8e3da497aa'); + array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-i18n'), 'version' => '67725197dbfd061bc1c5'); diff --git a/build/taxonomy/index.js b/build/taxonomy/index.js index 5868836..111578f 100644 --- a/build/taxonomy/index.js +++ b/build/taxonomy/index.js @@ -1 +1 @@ -(()=>{"use strict";const e=window.wp.blocks,l=window.wp.i18n,t=window.wp.blockEditor,o=window.wp.components,n=window.wp.data,r=window.ReactJSXRuntime,a=JSON.parse('{"UU":"query-filter/taxonomy"}');(0,e.registerBlockType)(a.UU,{edit:function({attributes:e,setAttributes:a}){const{taxonomy:i,emptyLabel:s,label:c,showLabel:u}=e,b=(0,n.useSelect)((e=>{const l=(e("core").getTaxonomies({per_page:100})||[]).filter((e=>e.visibility.publicly_queryable));return l&&l.length>0&&!i&&a({taxonomy:l[0].slug,label:l[0].name}),l}),[i]),y=(0,n.useSelect)((e=>e("core").getEntityRecords("taxonomy",i,{number:50})||[]),[i]);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.InspectorControls,{children:(0,r.jsxs)(o.PanelBody,{title:(0,l.__)("Taxonomy Settings","query-filter"),children:[(0,r.jsx)(o.SelectControl,{label:(0,l.__)("Select Taxonomy","query-filter"),value:i,options:(b||[]).map((e=>({label:e.name,value:e.slug}))),onChange:e=>a({taxonomy:e,label:b.find((l=>l.slug===e)).name})}),(0,r.jsx)(o.TextControl,{label:(0,l.__)("Label","query-filter"),value:c,help:(0,l.__)("If empty then no label will be shown","query-filter"),onChange:e=>a({label:e})}),(0,r.jsx)(o.ToggleControl,{label:(0,l.__)("Show Label","query-filter"),checked:u,onChange:e=>a({showLabel:e})}),(0,r.jsx)(o.TextControl,{label:(0,l.__)("Empty Choice Label","query-filter"),value:s,placeholder:(0,l.__)("All","query-filter"),onChange:e=>a({emptyLabel:e})})]})}),(0,r.jsxs)("div",{...(0,t.useBlockProps)({className:"wp-block-query-filter"}),children:[u&&(0,r.jsx)("label",{className:"wp-block-query-filter-taxonomy__label wp-block-query-filter__label",children:c}),(0,r.jsxs)("select",{className:"wp-block-query-filter-taxonomy__select wp-block-query-filter__select",inert:!0,children:[(0,r.jsx)("option",{children:s||(0,l.__)("All","query-filter")}),y.map((e=>(0,r.jsx)("option",{children:e.name},e.slug)))]})]})]})}})})(); \ No newline at end of file +(()=>{"use strict";const e=window.wp.blocks,l=window.wp.i18n,o=window.wp.blockEditor,t=window.wp.components,r=window.wp.data,s=window.ReactJSXRuntime,n=JSON.parse('{"UU":"query-filter/taxonomy"}');(0,e.registerBlockType)(n.UU,{edit:function({attributes:e,setAttributes:n}){const{taxonomy:a,emptyLabel:i,label:c,showLabel:u,useCheckboxes:b}=e,y=(0,r.useSelect)((e=>{const l=(e("core").getTaxonomies({per_page:100})||[]).filter((e=>e.visibility.publicly_queryable));return l&&l.length>0&&!a&&n({taxonomy:l[0].slug,label:l[0].name}),l}),[a]),p=(0,r.useSelect)((e=>e("core").getEntityRecords("taxonomy",a,{number:50})||[]),[a]);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(o.InspectorControls,{children:(0,s.jsxs)(t.PanelBody,{title:(0,l.__)("Taxonomy Settings","query-filter"),children:[(0,s.jsx)(t.SelectControl,{label:(0,l.__)("Select Taxonomy","query-filter"),value:a,options:(y||[]).map((e=>({label:e.name,value:e.slug}))),onChange:e=>n({taxonomy:e,label:y.find((l=>l.slug===e)).name})}),(0,s.jsx)(t.TextControl,{label:(0,l.__)("Label","query-filter"),value:c,help:(0,l.__)("If empty then no label will be shown","query-filter"),onChange:e=>n({label:e})}),(0,s.jsx)(t.ToggleControl,{label:(0,l.__)("Show Label","query-filter"),checked:u,onChange:e=>n({showLabel:e})}),(0,s.jsx)(t.TextControl,{label:(0,l.__)("Empty Choice Label","query-filter"),value:i,placeholder:(0,l.__)("All","query-filter"),onChange:e=>n({emptyLabel:e})}),(0,s.jsx)(t.ToggleControl,{label:(0,l.__)("Use Checkboxes","query-filter"),help:(0,l.__)("Use checkboxes to allow multiple choices","query-filter"),checked:b,onChange:e=>n({useCheckboxes:e})})]})}),(0,s.jsx)("div",{...(0,o.useBlockProps)({className:"wp-block-query-filter"}),children:b?(0,s.jsxs)("fieldset",{className:"wp-block-query-filter__checkboxes",children:[u&&(0,s.jsx)("legend",{className:"wp-block-query-filter__legend",children:c}),p.map((e=>(0,s.jsxs)("span",{className:"wp-block-query-filter__checkboxes-wrapper",children:[(0,s.jsx)("input",{type:"checkbox",value:e.slug,id:`query-filter-${e.slug}`,name:"taxonomy-term"}),(0,s.jsx)("label",{for:`query-filter-${e.slug}`,children:e.name})]},e.slug)))]}):(0,s.jsxs)(s.Fragment,{children:[u&&(0,s.jsx)("label",{className:"wp-block-query-filter-taxonomy__label wp-block-query-filter__label",children:c}),(0,s.jsxs)("select",{className:"wp-block-query-filter-taxonomy__select wp-block-query-filter__select",inert:!0,children:[(0,s.jsx)("option",{children:i||(0,l.__)("All","query-filter")}),p.map((e=>(0,s.jsx)("option",{children:e.name},e.slug)))]})]})})]})}})})(); \ No newline at end of file diff --git a/build/taxonomy/index.js.map b/build/taxonomy/index.js.map index 4898e71..1a2686c 100644 --- a/build/taxonomy/index.js.map +++ b/build/taxonomy/index.js.map @@ -1 +1 @@ -{"version":3,"file":"taxonomy/index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAqC;AACsC;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,CAAC;MAAAX,QAAA,GAC9Df,SAAS,iBACVX,sDAAA;QAAOqC,SAAS,EAAC,oEAAoE;QAAAX,QAAA,EAClFhB;MAAK,CACD,CACP,eACDR,uDAAA;QACCmC,SAAS,EAAC,sEAAsE;QAChFC,KAAK;QAAAZ,QAAA,gBAEL1B,sDAAA;UAAA0B,QAAA,EACGjB,UAAU,IAAIlB,mDAAE,CAAE,KAAK,EAAE,cAAe;QAAC,CACpC,CAAC,EACPgC,KAAK,CAACO,GAAG,CAAIS,IAAI,iBAClBvC,sDAAA;UAAA0B,QAAA,EAA4Ba,IAAI,CAACjB;QAAI,GAAvBiB,IAAI,CAAClB,IAA4B,CAC9C,CAAC;MAAA,CACI,CAAC;IAAA,CACL,CAAC;EAAA,CACL,CAAC;AAEL;;;;;;;;;;;AC5GA;;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;ACNsD;AAC5B;AACU;AACT;AAE3BmB,oEAAiB,CAAEC,6CAAa,EAAE;EACjC;AACD;AACA;EACCC,IAAI,EAAErC,6CAAIA;AACX,CAAE,CAAC,C","sources":["webpack://query-loop-filter/./src/taxonomy/edit.js","webpack://query-loop-filter/./src/taxonomy/style-index.css?27a5","webpack://query-loop-filter/external window \"ReactJSXRuntime\"","webpack://query-loop-filter/external window [\"wp\",\"blockEditor\"]","webpack://query-loop-filter/external window [\"wp\",\"blocks\"]","webpack://query-loop-filter/external window [\"wp\",\"components\"]","webpack://query-loop-filter/external window [\"wp\",\"data\"]","webpack://query-loop-filter/external window [\"wp\",\"i18n\"]","webpack://query-loop-filter/webpack/bootstrap","webpack://query-loop-filter/webpack/runtime/compat get default export","webpack://query-loop-filter/webpack/runtime/define property getters","webpack://query-loop-filter/webpack/runtime/hasOwnProperty shorthand","webpack://query-loop-filter/webpack/runtime/make namespace object","webpack://query-loop-filter/./src/taxonomy/index.js"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport {\n\tPanelBody,\n\tSelectControl,\n\tTextControl,\n\tToggleControl,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\nexport default function Edit( { attributes, setAttributes } ) {\n\tconst { taxonomy, emptyLabel, label, showLabel } = attributes;\n\n\tconst taxonomies = useSelect(\n\t\t( select ) => {\n\t\t\tconst results = (\n\t\t\t\tselect( 'core' ).getTaxonomies( { per_page: 100 } ) || []\n\t\t\t).filter( ( taxonomy ) => taxonomy.visibility.public );\n\n\t\t\tif ( results && results.length > 0 && ! taxonomy ) {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\ttaxonomy: results[ 0 ].slug,\n\t\t\t\t\tlabel: results[ 0 ].name,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn results;\n\t\t},\n\t\t[ taxonomy ]\n\t);\n\n\tconst terms = useSelect(\n\t\t( select ) => {\n\t\t\treturn (\n\t\t\t\tselect( 'core' ).getEntityRecords( 'taxonomy', taxonomy, {\n\t\t\t\t\tnumber: 50,\n\t\t\t\t} ) || []\n\t\t\t);\n\t\t},\n\t\t[ taxonomy ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t ( {\n\t\t\t\t\t\t\tlabel: taxonomy.name,\n\t\t\t\t\t\t\tvalue: taxonomy.slug,\n\t\t\t\t\t\t} ) ) }\n\t\t\t\t\t\tonChange={ ( taxonomy ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\ttaxonomy,\n\t\t\t\t\t\t\t\tlabel: taxonomies.find(\n\t\t\t\t\t\t\t\t\t( tax ) => tax.slug === taxonomy\n\t\t\t\t\t\t\t\t).name,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t setAttributes( { label } ) }\n\t\t\t\t\t/>\n\t\t\t\t\t\n\t\t\t\t\t\t\tsetAttributes( { showLabel } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t\n\t\t\t\t\t\t\tsetAttributes( { emptyLabel } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\n\t\t\t\n\t\t\t
\n\t\t\t\t{ showLabel && (\n\t\t\t\t\t\n\t\t\t\t) }\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t{ terms.map( ( term ) => (\n\t\t\t\t\t\t\n\t\t\t\t\t) ) }\n\t\t\t\t\n\t\t\t
\n\t\t\n\t);\n}\n","// extracted by mini-css-extract-plugin\nexport {};","module.exports = window[\"ReactJSXRuntime\"];","module.exports = window[\"wp\"][\"blockEditor\"];","module.exports = window[\"wp\"][\"blocks\"];","module.exports = window[\"wp\"][\"components\"];","module.exports = window[\"wp\"][\"data\"];","module.exports = window[\"wp\"][\"i18n\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { registerBlockType } from '@wordpress/blocks';\nimport Edit from './edit';\nimport metadata from './block.json';\nimport './style-index.css';\n\nregisterBlockType( metadata.name, {\n\t/**\n\t * @see ./edit.js\n\t */\n\tedit: Edit,\n} );\n"],"names":["__","useBlockProps","InspectorControls","PanelBody","SelectControl","TextControl","ToggleControl","useSelect","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","Edit","attributes","setAttributes","taxonomy","emptyLabel","label","showLabel","taxonomies","select","results","getTaxonomies","per_page","filter","visibility","public","length","slug","name","terms","getEntityRecords","number","children","title","value","options","map","onChange","find","tax","help","checked","placeholder","className","inert","term","registerBlockType","metadata","edit"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"taxonomy/index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAqC;AACsC;AAM5C;AACa;AAAA;AAE7B,SAASc,IAAIA,CAAE;EAAEC,UAAU;EAAEC;AAAc,CAAC,EAAG;EAC7D,MAAM;IAAEC,QAAQ;IAAEC,UAAU;IAAEC,KAAK;IAAEC,SAAS;IAAEC;EAAc,CAAC,GAAGN,UAAU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,CAAC;EAAA,CACL,CAAC;AAEL;;;;;;;;;;;ACzIA;;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;ACNsD;AAC5B;AACU;AACT;AAE3BsB,oEAAiB,CAAEC,6CAAa,EAAE;EACjC;AACD;AACA;EACCC,IAAI,EAAEzC,6CAAIA;AACX,CAAE,CAAC,C","sources":["webpack://query-loop-filter/./src/taxonomy/edit.js","webpack://query-loop-filter/./src/taxonomy/style-index.css","webpack://query-loop-filter/external window \"ReactJSXRuntime\"","webpack://query-loop-filter/external window [\"wp\",\"blockEditor\"]","webpack://query-loop-filter/external window [\"wp\",\"blocks\"]","webpack://query-loop-filter/external window [\"wp\",\"components\"]","webpack://query-loop-filter/external window [\"wp\",\"data\"]","webpack://query-loop-filter/external window [\"wp\",\"i18n\"]","webpack://query-loop-filter/webpack/bootstrap","webpack://query-loop-filter/webpack/runtime/compat get default export","webpack://query-loop-filter/webpack/runtime/define property getters","webpack://query-loop-filter/webpack/runtime/hasOwnProperty shorthand","webpack://query-loop-filter/webpack/runtime/make namespace object","webpack://query-loop-filter/./src/taxonomy/index.js"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport {\n\tPanelBody,\n\tSelectControl,\n\tTextControl,\n\tToggleControl,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\nexport default function Edit( { attributes, setAttributes } ) {\n\tconst { taxonomy, emptyLabel, label, showLabel, useCheckboxes } = attributes;\n\n\tconst taxonomies = useSelect(\n\t\t( select ) => {\n\t\t\tconst results = (\n\t\t\t\tselect( 'core' ).getTaxonomies( { per_page: 100 } ) || []\n\t\t\t).filter( ( taxonomy ) => taxonomy.visibility.publicly_queryable );\n\n\t\t\tif ( results && results.length > 0 && ! taxonomy ) {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\ttaxonomy: results[ 0 ].slug,\n\t\t\t\t\tlabel: results[ 0 ].name,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn results;\n\t\t},\n\t\t[ taxonomy ]\n\t);\n\n\tconst terms = useSelect(\n\t\t( select ) => {\n\t\t\treturn (\n\t\t\t\tselect( 'core' ).getEntityRecords( 'taxonomy', taxonomy, {\n\t\t\t\t\tnumber: 50,\n\t\t\t\t} ) || []\n\t\t\t);\n\t\t},\n\t\t[ taxonomy ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t ( {\n\t\t\t\t\t\t\tlabel: taxonomy.name,\n\t\t\t\t\t\t\tvalue: taxonomy.slug,\n\t\t\t\t\t\t} ) ) }\n\t\t\t\t\t\tonChange={ ( taxonomy ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\ttaxonomy,\n\t\t\t\t\t\t\t\tlabel: taxonomies.find(\n\t\t\t\t\t\t\t\t\t( tax ) => tax.slug === taxonomy\n\t\t\t\t\t\t\t\t).name,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t setAttributes( { label } ) }\n\t\t\t\t\t/>\n\t\t\t\t\t\n\t\t\t\t\t\t\tsetAttributes( { showLabel } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t\n\t\t\t\t\t\t\tsetAttributes( { emptyLabel } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t\n\t\t\t\t\t\t\tsetAttributes( { useCheckboxes } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\n\t\t\t\n\t\t\t
\n\t\t\t\t{ useCheckboxes ? (\n\t\t\t\t\t
\n\t\t\t\t\t\t{ showLabel && (\n\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ terms.map( ( term ) => (\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t
\n\t\t\t\t) : (\n\t\t\t\t<>\n\t\t\t\t\t{ showLabel && (\n\t\t\t\t\t\t\n\t\t\t\t\t) }\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t{ terms.map( ( term ) => (\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t\n\t\t\t\t \n\t\t\t\t) }\n\t\t\t
\n\t\t\n\t);\n}\n","// extracted by mini-css-extract-plugin\nexport {};","module.exports = window[\"ReactJSXRuntime\"];","module.exports = window[\"wp\"][\"blockEditor\"];","module.exports = window[\"wp\"][\"blocks\"];","module.exports = window[\"wp\"][\"components\"];","module.exports = window[\"wp\"][\"data\"];","module.exports = window[\"wp\"][\"i18n\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { registerBlockType } from '@wordpress/blocks';\nimport Edit from './edit';\nimport metadata from './block.json';\nimport './style-index.css';\n\nregisterBlockType( metadata.name, {\n\t/**\n\t * @see ./edit.js\n\t */\n\tedit: Edit,\n} );\n"],"names":["__","useBlockProps","InspectorControls","PanelBody","SelectControl","TextControl","ToggleControl","useSelect","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","Edit","attributes","setAttributes","taxonomy","emptyLabel","label","showLabel","useCheckboxes","taxonomies","select","results","getTaxonomies","per_page","filter","visibility","publicly_queryable","length","slug","name","terms","getEntityRecords","number","children","title","value","options","map","onChange","find","tax","help","checked","placeholder","className","term","type","id","for","inert","registerBlockType","metadata","edit"],"sourceRoot":""} \ No newline at end of file diff --git a/build/taxonomy/render.php b/build/taxonomy/render.php index 01d9800..bb03c56 100644 --- a/build/taxonomy/render.php +++ b/build/taxonomy/render.php @@ -7,15 +7,15 @@ $taxonomy = get_taxonomy( $attributes['taxonomy'] ); -if ( $block->context['query']['inherit'] ) { - $query_var = sprintf( 'query-%s', $attributes['taxonomy'] ); - $page_var = 'page'; - $base_url = str_replace( '/page/' . get_query_var( 'paged' ), '', remove_query_arg( [ $query_var, $page_var ] ) ); -} else { +if ( empty( $block->context['query']['inherit'] ) ) { $query_id = $block->context['queryId'] ?? 0; $query_var = sprintf( 'query-%d-%s', $query_id, $attributes['taxonomy'] ); $page_var = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page'; $base_url = remove_query_arg( [ $query_var, $page_var ] ); +} else { + $query_var = sprintf( 'query-%s', $attributes['taxonomy'] ); + $page_var = 'page'; + $base_url = str_replace( '/page/' . get_query_var( 'paged' ), '', remove_query_arg( [ $query_var, $page_var ] ) ); } $terms = get_terms( [ @@ -30,13 +30,36 @@ ?>
'wp-block-query-filter' ] ); ?> data-wp-interactive="query-filter" data-wp-context="{}"> - - + +
+ + label ); ?> + + slug, explode( ',', wp_unslash( $_GET[ $query_var ] ?? '' ) ), true ); + ?> + + + data-wp-on--change="actions.navigate" + /> + + + +
+ + + +
diff --git a/build/taxonomy/view.asset.php b/build/taxonomy/view.asset.php index b7d71e1..c4c1e50 100644 --- a/build/taxonomy/view.asset.php +++ b/build/taxonomy/view.asset.php @@ -1 +1 @@ - array('@wordpress/interactivity', array('id' => '@wordpress/interactivity-router', 'import' => 'dynamic')), 'version' => 'e7ba522c0e73d74a56f1', 'type' => 'module'); + array('@wordpress/interactivity', array('id' => '@wordpress/interactivity-router', 'import' => 'dynamic')), 'version' => '5af6e4304a514d63d5ed', 'type' => 'module'); diff --git a/build/taxonomy/view.js b/build/taxonomy/view.js index bf1481b..cbb82cf 100644 --- a/build/taxonomy/view.js +++ b/build/taxonomy/view.js @@ -1 +1 @@ -import*as e from"@wordpress/interactivity";var t={438:e=>{e.exports=import("@wordpress/interactivity-router")}},r={};function a(e){var o=r[e];if(void 0!==o)return o.exports;var s=r[e]={exports:{}};return t[e](s,s.exports,a),s.exports}a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const o=(n={getElement:()=>e.getElement,store:()=>e.store},i={},a.d(i,n),i),{state:s}=(0,o.store)("query-filter",{actions:{*navigate(e){e.preventDefault();const{actions:t}=yield Promise.resolve().then(a.bind(a,438));yield t.navigate(e.target.value)},*search(e){e.preventDefault();const{ref:t}=(0,o.getElement)();let r,n,i;if("FORM"===t.tagName){const e=t.querySelector('input[type="search"]');r=t.action,n=e.name,i=e.value}else r=t.closest("form").action,n=t.name,i=t.value;i!==s.searchValue&&(s.searchValue=i,yield(async(e,t,r)=>{const o=new URL(e);t||"s"===r?o.searchParams.set(r,t):o.searchParams.delete(r);const{actions:s}=await Promise.resolve().then(a.bind(a,438));await s.navigate(o.toString())})(r,i,n))}}});var n,i; \ No newline at end of file +import*as e from"@wordpress/interactivity";var t={438:e=>{e.exports=import("@wordpress/interactivity-router")}},r={};function a(e){var s=r[e];if(void 0!==s)return s.exports;var o=r[e]={exports:{}};return t[e](o,o.exports,a),o.exports}a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const s=(n={getElement:()=>e.getElement,store:()=>e.store},c={},a.d(c,n),c),{state:o}=(0,s.store)("query-filter",{actions:{*navigate(e){e.preventDefault();const{ref:t}=(0,s.getElement)();let r,o=[];const n=new URL(window.location.href);if("INPUT"===t.tagName&&"checkbox"===t.type){r=t.name,t.closest(".wp-block-query-filter__checkboxes").querySelectorAll(`input[name="${r}"]:checked`).forEach((e=>{o.push(e.value)}));const e=o.join(",");e?n.searchParams.set(r,e):n.searchParams.delete(r)}else r=t.name,o=[t.value],""===o[0]?n.searchParams.delete(r):n.searchParams.set(r,o[0]);const{actions:c}=yield Promise.resolve().then(a.bind(a,438));yield c.navigate(n.toString())},*search(e){e.preventDefault();const{ref:t}=(0,s.getElement)();let r,n,c;if("FORM"===t.tagName){const e=t.querySelector('input[type="search"]');r=t.action,n=e.name,c=e.value}else r=t.closest("form").action,n=t.name,c=t.value;c!==o.searchValue&&(o.searchValue=c,yield(async(e,t,r)=>{const s=new URL(e);t||"s"===r?s.searchParams.set(r,t):s.searchParams.delete(r);const{actions:o}=await Promise.resolve().then(a.bind(a,438));await o.navigate(s.toString())})(r,c,n))}}});var n,c; \ No newline at end of file diff --git a/build/taxonomy/view.js.map b/build/taxonomy/view.js.map index 3396a07..cd43384 100644 --- a/build/taxonomy/view.js.map +++ b/build/taxonomy/view.js.map @@ -1 +1 @@ -{"version":3,"file":"taxonomy/view.js","mappings":";;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;SCAA;SACA;;SAEA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;;SAEA;SACA;;SAEA;SACA;SACA;;;;;UCtBA;UACA;UACA;UACA,uDAAuD,iBAAiB;UACxE;UACA,gDAAgD,aAAa;UAC7D;;;;;;;;;;ACN6D;AAE7D,MAAME,SAAS,GAAG,MAAAA,CAAQC,MAAM,EAAEC,KAAK,EAAEC,IAAI,KAAM;EAClD,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAAEJ,MAAO,CAAC;EAC7B,IAAKC,KAAK,IAAIC,IAAI,KAAK,GAAG,EAAG;IAC5BC,GAAG,CAACE,YAAY,CAACC,GAAG,CAAEJ,IAAI,EAAED,KAAM,CAAC;EACpC,CAAC,MAAM;IACNE,GAAG,CAACE,YAAY,CAACE,MAAM,CAAEL,IAAK,CAAC;EAChC;EACA,MAAM;IAAEM;EAAQ,CAAC,GAAG,MAAM,8JAA2C;EACrE,MAAMA,OAAO,CAACC,QAAQ,CAAEN,GAAG,CAACO,QAAQ,CAAC,CAAE,CAAC;AACzC,CAAC;AAED,MAAM;EAAEC;AAAM,CAAC,GAAGd,+DAAK,CAAE,cAAc,EAAE;EACxCW,OAAO,EAAE;IACR,CAACC,QAAQA,CAAEG,CAAC,EAAG;MACdA,CAAC,CAACC,cAAc,CAAC,CAAC;MAClB,MAAM;QAAEL;MAAQ,CAAC,GAAG,MAAM,8JAEzB;MACD,MAAMA,OAAO,CAACC,QAAQ,CAAEG,CAAC,CAACE,MAAM,CAACb,KAAM,CAAC;IACzC,CAAC;IACD,CAACc,MAAMA,CAAEH,CAAC,EAAG;MACZA,CAAC,CAACC,cAAc,CAAC,CAAC;MAClB,MAAM;QAAEG;MAAI,CAAC,GAAGlB,oEAAU,CAAC,CAAC;MAC5B,IAAIE,MAAM,EAAEE,IAAI,EAAED,KAAK;MACvB,IAAKe,GAAG,CAACC,OAAO,KAAK,MAAM,EAAG;QAC7B,MAAMC,KAAK,GAAGF,GAAG,CAACG,aAAa,CAAE,sBAAuB,CAAC;QACzDnB,MAAM,GAAGgB,GAAG,CAAChB,MAAM;QACnBE,IAAI,GAAGgB,KAAK,CAAChB,IAAI;QACjBD,KAAK,GAAGiB,KAAK,CAACjB,KAAK;MACpB,CAAC,MAAM;QACND,MAAM,GAAGgB,GAAG,CAACI,OAAO,CAAE,MAAO,CAAC,CAACpB,MAAM;QACrCE,IAAI,GAAGc,GAAG,CAACd,IAAI;QACfD,KAAK,GAAGe,GAAG,CAACf,KAAK;MAClB;;MAEA;MACA,IAAKA,KAAK,KAAKU,KAAK,CAACU,WAAW,EAAG;MAEnCV,KAAK,CAACU,WAAW,GAAGpB,KAAK;MAEzB,MAAMF,SAAS,CAAEC,MAAM,EAAEC,KAAK,EAAEC,IAAK,CAAC;IACvC;EACD;AACD,CAAE,CAAC,C","sources":["webpack://query-loop-filter/external import \"@wordpress/interactivity-router\"","webpack://query-loop-filter/external module \"@wordpress/interactivity\"","webpack://query-loop-filter/webpack/bootstrap","webpack://query-loop-filter/webpack/runtime/make namespace object","webpack://query-loop-filter/./src/taxonomy/view.js"],"sourcesContent":["module.exports = import(\"@wordpress/interactivity-router\");;","module.exports = __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { store, getElement } from '@wordpress/interactivity';\n\nconst updateURL = async ( action, value, name ) => {\n\tconst url = new URL( action );\n\tif ( value || name === 's' ) {\n\t\turl.searchParams.set( name, value );\n\t} else {\n\t\turl.searchParams.delete( name );\n\t}\n\tconst { actions } = await import( '@wordpress/interactivity-router' );\n\tawait actions.navigate( url.toString() );\n};\n\nconst { state } = store( 'query-filter', {\n\tactions: {\n\t\t*navigate( e ) {\n\t\t\te.preventDefault();\n\t\t\tconst { actions } = yield import(\n\t\t\t\t'@wordpress/interactivity-router'\n\t\t\t);\n\t\t\tyield actions.navigate( e.target.value );\n\t\t},\n\t\t*search( e ) {\n\t\t\te.preventDefault();\n\t\t\tconst { ref } = getElement();\n\t\t\tlet action, name, value;\n\t\t\tif ( ref.tagName === 'FORM' ) {\n\t\t\t\tconst input = ref.querySelector( 'input[type=\"search\"]' );\n\t\t\t\taction = ref.action;\n\t\t\t\tname = input.name;\n\t\t\t\tvalue = input.value;\n\t\t\t} else {\n\t\t\t\taction = ref.closest( 'form' ).action;\n\t\t\t\tname = ref.name;\n\t\t\t\tvalue = ref.value;\n\t\t\t}\n\n\t\t\t// Don't navigate if the search didn't really change.\n\t\t\tif ( value === state.searchValue ) return;\n\n\t\t\tstate.searchValue = value;\n\n\t\t\tyield updateURL( action, value, name );\n\t\t},\n\t},\n} );\n"],"names":["store","getElement","updateURL","action","value","name","url","URL","searchParams","set","delete","actions","navigate","toString","state","e","preventDefault","target","search","ref","tagName","input","querySelector","closest","searchValue"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"taxonomy/view.js","mappings":";;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;SCAA;SACA;;SAEA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;SACA;;SAEA;SACA;;SAEA;SACA;SACA;;;;;UCtBA;UACA;UACA;UACA,uDAAuD,iBAAiB;UACxE;UACA,gDAAgD,aAAa;UAC7D;;;;;;;;;;ACN6D;AAE7D,MAAME,SAAS,GAAG,MAAAA,CAAQC,MAAM,EAAEC,KAAK,EAAEC,IAAI,KAAM;EAClD,MAAMC,GAAG,GAAG,IAAIC,GAAG,CAAEJ,MAAO,CAAC;EAC7B,IAAKC,KAAK,IAAIC,IAAI,KAAK,GAAG,EAAG;IAC5BC,GAAG,CAACE,YAAY,CAACC,GAAG,CAAEJ,IAAI,EAAED,KAAM,CAAC;EACpC,CAAC,MAAM;IACNE,GAAG,CAACE,YAAY,CAACE,MAAM,CAAEL,IAAK,CAAC;EAChC;EACA,MAAM;IAAEM;EAAQ,CAAC,GAAG,MAAM,8JAA2C;EACrE,MAAMA,OAAO,CAACC,QAAQ,CAAEN,GAAG,CAACO,QAAQ,CAAC,CAAE,CAAC;AACzC,CAAC;AAED,MAAM;EAAEC;AAAM,CAAC,GAAGd,+DAAK,CAAE,cAAc,EAAE;EACxCW,OAAO,EAAE;IACR,CAACC,QAAQA,CAAEG,CAAC,EAAG;MACdA,CAAC,CAACC,cAAc,CAAC,CAAC;MAClB,MAAM;QAAEC;MAAI,CAAC,GAAGhB,oEAAU,CAAC,CAAC;MAC5B,IAAII,IAAI;QAAEa,MAAM,GAAG,EAAE;;MAErB;MACA,MAAMC,UAAU,GAA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AACoB,MAAMA,CAAElB,CAAC,EAAG;MACZA,CAAC,CAACC,cAAc,CAAC,CAAC;MAClB,MAAM;QAAEC;MAAI,CAAC,GAAGhB,oEAAU,CAAC,CAAC;MAC5B,IAAIE,MAAM,EAAEE,IAAI,EAAED,KAAK;MACvB,IAAKa,GAAG,CAACM,OAAO,KAAK,MAAM,EAAG;QAC7B,MAAMW,KAAK,GAAGjB,GAAG,CAACkB,aAAa,CAAE,sBAAuB,CAAC;QACzDhC,MAAM,GAAGc,GAAG,CAACd,MAAM;QACnBE,IAAI,GAAG6B,KAAK,CAAC7B,IAAI;QACjBD,KAAK,GAAG8B,KAAK,CAAC9B,KAAK;MACpB,CAAC,MAAM;QACND,MAAM,GAAGc,GAAG,CAACS,OAAO,CAAE,MAAO,CAAC,CAACvB,MAAM;QACrCE,IAAI,GAAGY,GAAG,CAACZ,IAAI;QACfD,KAAK,GAAGa,GAAG,CAACb,KAAK;MAClB;;MAEA;MACA,IAAKA,KAAK,KAAKU,KAAK,CAACsB,WAAW,EAAG;MAEnCtB,KAAK,CAACsB,WAAW,GAAGhC,KAAK;MAEzB,MAAMF,SAAS,CAAEC,MAAM,EAAEC,KAAK,EAAEC,IAAK,CAAC;IACvC;EACD;AACD,CAAE,CAAC,C","sources":["webpack://query-loop-filter/external import \"@wordpress/interactivity-router\"","webpack://query-loop-filter/external module \"@wordpress/interactivity\"","webpack://query-loop-filter/webpack/bootstrap","webpack://query-loop-filter/webpack/runtime/make namespace object","webpack://query-loop-filter/./src/taxonomy/view.js"],"sourcesContent":["module.exports = import(\"@wordpress/interactivity-router\");;","module.exports = __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { store, getElement } from '@wordpress/interactivity';\n\nconst updateURL = async ( action, value, name ) => {\n\tconst url = new URL( action );\n\tif ( value || name === 's' ) {\n\t\turl.searchParams.set( name, value );\n\t} else {\n\t\turl.searchParams.delete( name );\n\t}\n\tconst { actions } = await import( '@wordpress/interactivity-router' );\n\tawait actions.navigate( url.toString() );\n};\n\nconst { state } = store( 'query-filter', {\n\tactions: {\n\t\t*navigate( e ) {\n\t\t\te.preventDefault();\n\t\t\tconst { ref } = getElement();\n\t\t\tlet name, values = [];\n\n\t\t\t// Get the current URL and preserve existing query parameters\n\t\t\tconst currentURL = new URL( window.location.href );\n\n\t\t\tif (ref.tagName === 'INPUT' && ref.type === 'checkbox') {\n\t\t\t\tname = ref.name;\n\n\t\t\t\t// Handle checkboxes directly\n\t\t\t\tconst container = ref.closest('.wp-block-query-filter__checkboxes');\n\t\t\t\tconst checkboxes = container.querySelectorAll(\n\t\t\t\t\t`input[name=\"${name}\"]:checked`\n\t\t\t\t);\n\n\t\t\t\t// Collect all selected values\n\t\t\t\tcheckboxes.forEach((checkbox) => {\n\t\t\t\t\tvalues.push(checkbox.value);\n\t\t\t\t});\n\n\t\t\t\t// Create a comma-separated string of values\n\t\t\t\tconst value = values.join(',');\n\n\t\t\t\t// Update the URL with the new value for checkboxes\n\t\t\t\tif (value) {\n\t\t\t\t\tcurrentURL.searchParams.set( name, value );\n\t\t\t\t} else {\n\t\t\t\t\tcurrentURL.searchParams.delete( name );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Handle other input types (e.g., \n\t\t\t\t\tcurrentURL.searchParams.set( name, values[0] );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Navigate to the updated URL\n\t\t\tconst { actions } = yield import( '@wordpress/interactivity-router' );\n\t\t\tyield actions.navigate( currentURL.toString() );\n\t\t},\n\t\t*search( e ) {\n\t\t\te.preventDefault();\n\t\t\tconst { ref } = getElement();\n\t\t\tlet action, name, value;\n\t\t\tif ( ref.tagName === 'FORM' ) {\n\t\t\t\tconst input = ref.querySelector( 'input[type=\"search\"]' );\n\t\t\t\taction = ref.action;\n\t\t\t\tname = input.name;\n\t\t\t\tvalue = input.value;\n\t\t\t} else {\n\t\t\t\taction = ref.closest( 'form' ).action;\n\t\t\t\tname = ref.name;\n\t\t\t\tvalue = ref.value;\n\t\t\t}\n\n\t\t\t// Don't navigate if the search didn't really change.\n\t\t\tif ( value === state.searchValue ) return;\n\n\t\t\tstate.searchValue = value;\n\n\t\t\tyield updateURL( action, value, name );\n\t\t},\n\t},\n} );\n"],"names":["store","getElement","updateURL","action","value","name","url","URL","searchParams","set","delete","actions","navigate","toString","state","e","preventDefault","ref","values","currentURL","window","location","href","tagName","type","container","closest","checkboxes","querySelectorAll","forEach","checkbox","push","join","search","input","querySelector","searchValue"],"sourceRoot":""} \ No newline at end of file diff --git a/inc/namespace.php b/inc/namespace.php index 0bd4afa..041bb17 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -105,10 +105,19 @@ function pre_get_posts_transpose_query_vars( WP_Query $query ) : void { // Handle taxonomies specifically. if ( get_taxonomy( $key ) ) { + // Allow multiple values by using array format for taxonomies. + $value = array_map( + 'sanitize_text_field', + array_map( + 'urldecode', + explode( ',', wp_unslash( $value ) ) // Split by commas + ) + ); + $tax_query['relation'] = 'AND'; $tax_query[] = [ 'taxonomy' => $key, - 'terms' => [ $value ], + 'terms' => $value, 'field' => 'slug', ]; } else { diff --git a/src/taxonomy/block.json b/src/taxonomy/block.json index 1f1a331..9345fc2 100644 --- a/src/taxonomy/block.json +++ b/src/taxonomy/block.json @@ -54,6 +54,10 @@ "showLabel": { "type": "boolean", "default": true + }, + "useCheckboxes": { + "type": "boolean", + "default": false } }, "textdomain": "query-filter", diff --git a/src/taxonomy/edit.js b/src/taxonomy/edit.js index 5562901..bf47246 100644 --- a/src/taxonomy/edit.js +++ b/src/taxonomy/edit.js @@ -9,7 +9,7 @@ import { import { useSelect } from '@wordpress/data'; export default function Edit( { attributes, setAttributes } ) { - const { taxonomy, emptyLabel, label, showLabel } = attributes; + const { taxonomy, emptyLabel, label, showLabel, useCheckboxes } = attributes; const taxonomies = useSelect( ( select ) => { @@ -84,25 +84,54 @@ export default function Edit( { attributes, setAttributes } ) { setAttributes( { emptyLabel } ) } /> + + setAttributes( { useCheckboxes } ) + } + />
- { showLabel && ( - + { useCheckboxes ? ( +
+ { showLabel && ( + { label } + ) } + { terms.map( ( term ) => ( + + + + + ) ) } +
+ ) : ( + <> + { showLabel && ( + + ) } + + ) } -
); diff --git a/src/taxonomy/render.php b/src/taxonomy/render.php index 97258b4..bb03c56 100644 --- a/src/taxonomy/render.php +++ b/src/taxonomy/render.php @@ -30,13 +30,36 @@ ?>
'wp-block-query-filter' ] ); ?> data-wp-interactive="query-filter" data-wp-context="{}"> - - + +
+ + label ); ?> + + slug, explode( ',', wp_unslash( $_GET[ $query_var ] ?? '' ) ), true ); + ?> + + + data-wp-on--change="actions.navigate" + /> + + + +
+ + + +
diff --git a/src/taxonomy/view.js b/src/taxonomy/view.js index 2438d11..f0e619f 100644 --- a/src/taxonomy/view.js +++ b/src/taxonomy/view.js @@ -15,10 +15,53 @@ const { state } = store( 'query-filter', { actions: { *navigate( e ) { e.preventDefault(); - const { actions } = yield import( - '@wordpress/interactivity-router' - ); - yield actions.navigate( e.target.value ); + const { ref } = getElement(); + let name, values = []; + + // Get the current URL and preserve existing query parameters + const currentURL = new URL( window.location.href ); + + if (ref.tagName === 'INPUT' && ref.type === 'checkbox') { + name = ref.name; + + // Handle checkboxes directly + const container = ref.closest('.wp-block-query-filter__checkboxes'); + const checkboxes = container.querySelectorAll( + `input[name="${name}"]:checked` + ); + + // Collect all selected values + checkboxes.forEach((checkbox) => { + values.push(checkbox.value); + }); + + // Create a comma-separated string of values + const value = values.join(','); + + // Update the URL with the new value for checkboxes + if (value) { + currentURL.searchParams.set( name, value ); + } else { + currentURL.searchParams.delete( name ); + } + } else { + // Handle other input types (e.g., + currentURL.searchParams.set( name, values[0] ); + } + } + + // Navigate to the updated URL + const { actions } = yield import( '@wordpress/interactivity-router' ); + yield actions.navigate( currentURL.toString() ); }, *search( e ) { e.preventDefault();