From 630d13fa384a9bbc6e723c877b79f89867bc6b9a Mon Sep 17 00:00:00 2001 From: randhirexpresstech Date: Tue, 26 Mar 2024 13:32:28 +0530 Subject: [PATCH] answer block highlight dotted and publish quiz on publish page --- blocks/block.php | 20 ++++++++++++++++++++ blocks/build/block.json | 4 ++++ blocks/build/index.asset.php | 2 +- blocks/build/index.css | 2 +- blocks/build/index.js | 2 +- blocks/build/question/index.asset.php | 2 +- blocks/build/question/index.js | 2 +- blocks/src/block.json | 1 + blocks/src/component/icon.js | 2 +- blocks/src/edit.js | 19 ++++++++++++++++++- blocks/src/editor.scss | 8 ++++++++ blocks/src/index.js | 25 +------------------------ 12 files changed, 58 insertions(+), 31 deletions(-) diff --git a/blocks/block.php b/blocks/block.php index 3bb4c0154..d04d0cf86 100644 --- a/blocks/block.php +++ b/blocks/block.php @@ -616,6 +616,26 @@ public function save_quiz( WP_REST_Request $request ) { $mlwQuizMasterNext->quizCreator->edit_quiz_name( $quiz_id, $quiz_name, $post_id ); } } + + //Update status + if ( ! empty( $quiz_id ) && ! empty( $post_id ) ) { + + //Default post status + $post_status = 'publish'; + + //page status which conatin quiz + if ( ! empty( $_POST['post_status'] )) { + $post_status = sanitize_key( wp_unslash( $_POST['post_status'] ) ); + } + + //Update quiz status + if ( 'publish' === $post_status ) { + wp_update_post( array( + 'ID' => $post_id, + 'post_status' => 'publish', + ) ); + } + } //Save Pages if ( ! empty( $_POST['quizData']['pages'] ) ) { diff --git a/blocks/build/block.json b/blocks/build/block.json index 45873767b..372e2ac66 100644 --- a/blocks/build/block.json +++ b/blocks/build/block.json @@ -30,6 +30,10 @@ "quiz-master-next/quizID": "quizID", "quiz-master-next/quizAttr": "quizAttr" }, + "usesContext": [ + "postId", + "postStatus" + ], "example": {}, "supports": { "html": false diff --git a/blocks/build/index.asset.php b/blocks/build/index.asset.php index dd8690bdd..03fa1bfc3 100644 --- a/blocks/build/index.asset.php +++ b/blocks/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-notices'), 'version' => '3bec0faae5335384534d'); + array('wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-notices'), 'version' => '9ae62c1e6dbc6a16c846'); diff --git a/blocks/build/index.css b/blocks/build/index.css index 569c1b2ea..4db4b6899 100644 --- a/blocks/build/index.css +++ b/blocks/build/index.css @@ -1 +1 @@ -.block-editor-block-inspector .qsm-inspector-label{display:inline-block;font-size:11px;font-weight:500;line-height:1.4;margin-bottom:.5rem;padding:0;text-transform:uppercase}.block-editor-block-inspector .qsm-inspector-label .qsm-inspector-label-value{padding-left:.5rem}.block-editor-block-inspector .qsm-inspector-label-value{font-weight:400;text-transform:capitalize}.block-editor-block-inspector .qsm-no-mb{margin-bottom:0}.qsm-placeholder-select-create-quiz{align-items:center;display:flex;gap:1rem;margin-bottom:1rem}.qsm-placeholder-select-create-quiz .components-base-control{max-width:50%}.qsm-ptb-1{padding:1rem 0}.qsm-error-text{color:#fd3e3e}.editor-styles-wrapper .qsm-placeholder-wrapper .components-placeholder__fieldset{flex-direction:column}.editor-styles-wrapper .qsm-advance-settings{display:flex;flex-direction:column;gap:2rem}.qsm-placeholder-quiz-create-form{width:75%}.qsm-placeholder-quiz-create-form .components-button{width:-moz-fit-content;width:fit-content}.wp-block-qsm-quiz-question.is-highlighted{padding:0 1rem}.wp-block-qsm-quiz-question .block-editor-block-list__insertion-point-inserter.qsm-add-new-ques-wrapper{bottom:25px;height:20px;left:auto;position:relative;z-index:9}.wp-block-qsm-quiz-question .qsm-question-title{color:#1f8cbe;font-size:1.38rem;padding-top:.8rem}.wp-block-qsm-quiz-question .qsm-question-correct-answer-info,.wp-block-qsm-quiz-question .qsm-question-description,.wp-block-qsm-quiz-question .qsm-question-hint{color:#666;font-size:1rem}.wp-block-qsm-quiz-question .wp-block-qsm-quiz-answer-option input:disabled{border-color:inherit}.wp-block-qsm-quiz-question .wp-block-qsm-quiz-answer-option input[type=checkbox]:disabled,.wp-block-qsm-quiz-question .wp-block-qsm-quiz-answer-option input[type=radio]:disabled{opacity:1}.wp-block-qsm-quiz-question .qsm-question-answer-option{color:#666;font-size:.9rem;margin-left:1rem}.wp-block-qsm-quiz-question.in-editing-mode .qsm-question-title{color:#666}.wp-block-qsm-quiz-question .add-new-question-btn{margin-top:2rem}.qsm-advance-q-modal{justify-content:center;max-width:580px;text-align:center}.qsm-advance-q-modal .qsm-title{margin-top:0}.qsm-advance-q-modal .qsm-modal-btn-wrapper{display:flex;gap:1rem;justify-content:center}.qsm-advance-q-modal .qsm-modal-btn-wrapper .components-external-link{color:#fff;text-decoration:none} +.block-editor-block-inspector .qsm-inspector-label{display:inline-block;font-size:11px;font-weight:500;line-height:1.4;margin-bottom:.5rem;padding:0;text-transform:uppercase}.block-editor-block-inspector .qsm-inspector-label .qsm-inspector-label-value{padding-left:.5rem}.block-editor-block-inspector .qsm-inspector-label-value{font-weight:400;text-transform:capitalize}.block-editor-block-inspector .qsm-no-mb{margin-bottom:0}.qsm-placeholder-select-create-quiz{align-items:center;display:flex;gap:1rem;margin-bottom:1rem}.qsm-placeholder-select-create-quiz .components-base-control{max-width:50%}.qsm-ptb-1{padding:1rem 0}.qsm-error-text{color:#fd3e3e}.editor-styles-wrapper .qsm-placeholder-wrapper .components-placeholder__fieldset{flex-direction:column}.editor-styles-wrapper .qsm-advance-settings{display:flex;flex-direction:column;gap:2rem}.qsm-placeholder-quiz-create-form{width:75%}.qsm-placeholder-quiz-create-form .components-button{width:-moz-fit-content;width:fit-content}.wp-block-qsm-quiz-question.is-highlighted{padding:0 1rem}.wp-block-qsm-quiz-question .block-editor-block-list__insertion-point-inserter.qsm-add-new-ques-wrapper{bottom:25px;height:20px;left:auto;position:relative;z-index:9}.wp-block-qsm-quiz-question .qsm-question-title{color:#1f8cbe;font-size:1.38rem;padding-top:.8rem}.wp-block-qsm-quiz-question .qsm-question-correct-answer-info,.wp-block-qsm-quiz-question .qsm-question-description,.wp-block-qsm-quiz-question .qsm-question-hint{color:#666;font-size:1rem}.wp-block-qsm-quiz-question .wp-block-qsm-quiz-answer-option{padding-left:.8rem}.wp-block-qsm-quiz-question .wp-block-qsm-quiz-answer-option.block-editor-block-list__block.is-highlighted:after{border:2px dotted #c3c5cc;box-shadow:none}.wp-block-qsm-quiz-question .wp-block-qsm-quiz-answer-option input:disabled{border-color:inherit}.wp-block-qsm-quiz-question .wp-block-qsm-quiz-answer-option input[type=checkbox]:disabled,.wp-block-qsm-quiz-question .wp-block-qsm-quiz-answer-option input[type=radio]:disabled{opacity:1}.wp-block-qsm-quiz-question .wp-block-qsm-quiz-answer-option .qsm-question-answer-option.rich-text{margin-left:5px}.wp-block-qsm-quiz-question .qsm-question-answer-option{color:#666;font-size:.9rem;margin-left:1rem}.wp-block-qsm-quiz-question.in-editing-mode .qsm-question-title{color:#666}.wp-block-qsm-quiz-question .add-new-question-btn{margin-top:2rem}.qsm-advance-q-modal{justify-content:center;max-width:580px;text-align:center}.qsm-advance-q-modal .qsm-title{margin-top:0}.qsm-advance-q-modal .qsm-modal-btn-wrapper{display:flex;gap:1rem;justify-content:center}.qsm-advance-q-modal .qsm-modal-btn-wrapper .components-external-link{color:#fff;text-decoration:none} diff --git a/blocks/build/index.js b/blocks/build/index.js index e3a320357..ad8727a25 100644 --- a/blocks/build/index.js +++ b/blocks/build/index.js @@ -1 +1 @@ -(()=>{"use strict";var e,t={818:(e,t,n)=>{const a=window.wp.element,s=window.wp.blocks,i=window.wp.i18n,r=window.wp.apiFetch;var o=n.n(r);const l=window.wp.htmlEntities,u=window.wp.blockEditor,c=window.wp.notices,m=window.wp.data,p=window.wp.editor,d=window.wp.components,q=e=>null==e||""===e,g=e=>{var t=document.createElement("textarea");return t.innerHTML=e,t.value},_=e=>{let t=document.createElement("div");return t.innerHTML=g(e),t.innerText},h=(e=!1)=>{let t=new FormData;if(t.append("qsm_block_api_call","1"),!1!==e)for(let n in e)e.hasOwnProperty(n)&&t.append(n,e[n]);return t},z=e=>{let t="";const n=new Uint8Array(e);window.crypto.getRandomValues(n);for(let a=0;a`${e}${z(8)}${t?`.${z(7)}`:""}`,w=(e,t="")=>q(e)?t:e,f=()=>{};function v({className:e="",quizAttr:t,setAttributes:n,data:s,onChangeFunc:i=f}){var r,o,l,u,c;const m=(()=>{if(s.defaultvalue=s.default,!q(s?.options))switch(s.type){case"checkbox":1===s.options.length&&(s.type="toggle"),s.label=s.options[0].label;break;case"radio":1==s.options.length?(s.label=s.options[0].label,s.type="toggle"):s.type="select"}return s.label=q(s.label)?"":_(s.label),s.help=q(s.help)?"":_(s.help),s})(),{id:p,label:g="",type:h,help:z="",options:b=[],defaultvalue:w}=m;return(0,a.createElement)(a.Fragment,null,"toggle"===h&&(0,a.createElement)(d.ToggleControl,{label:g,help:z,checked:!q(t[p])&&"1"==t[p],onChange:()=>i(q(t[p])||"1"!=t[p]?1:0,p)}),"select"===h&&(0,a.createElement)(d.SelectControl,{label:g,value:null!==(r=t[p])&&void 0!==r?r:w,options:b,onChange:e=>i(e,p),help:z,__nextHasNoMarginBottom:!0}),"number"===h&&(0,a.createElement)(d.TextControl,{type:"number",label:g,value:null!==(o=t[p])&&void 0!==o?o:w,onChange:e=>i(e,p),help:z,__nextHasNoMarginBottom:!0}),"text"===h&&(0,a.createElement)(d.TextControl,{type:"text",label:g,value:null!==(l=t[p])&&void 0!==l?l:w,onChange:e=>i(e,p),help:z,__nextHasNoMarginBottom:!0}),"textarea"===h&&(0,a.createElement)(d.TextareaControl,{label:g,value:null!==(u=t[p])&&void 0!==u?u:w,onChange:e=>i(e,p),help:z,__nextHasNoMarginBottom:!0}),"checkbox"===h&&(0,a.createElement)(d.CheckboxControl,{label:g,help:z,checked:!q(t[p])&&"1"==t[p],onChange:()=>i(q(t[p])||"1"!=t[p]?1:0,p)}),"radio"===h&&(0,a.createElement)(d.RadioControl,{label:g,help:z,selected:null!==(c=t[p])&&void 0!==c?c:w,options:b,onChange:e=>i(e,p)}))}const y=()=>(0,a.createElement)(d.Icon,{icon:()=>(0,a.createElement)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,a.createElement)("rect",{width:"24",height:"24",rx:"3",fill:"black"}),(0,a.createElement)("path",{d:"M17.8146 17.8349C19.3188 16.3426 20.25 14.2793 20.25 12C20.2485 7.44425 16.5267 3.75 11.9348 3.75C7.34282 3.75 3.62109 7.44425 3.62109 12C3.62109 16.5558 7.34282 20.25 11.9348 20.25H18.9988C19.4682 20.25 19.7074 19.7112 19.3813 19.3885L17.8146 17.8334V17.8349ZM11.8753 17.5195C8.72666 17.5195 6.17388 15.0737 6.17388 12.0569C6.17388 9.04022 8.72666 6.59442 11.8753 6.59442C15.024 6.59442 17.5768 9.04022 17.5768 12.0569C17.5768 15.0737 15.024 17.5195 11.8753 17.5195Z",fill:"white"}))}),E=window.wp.compose;(0,s.registerBlockType)("qsm/quiz",{icon:y,edit:function(e){if("undefined"==typeof qsmBlockData)return null;const{className:t,attributes:n,setAttributes:s,isSelected:r,clientId:_}=e,{createNotice:z}=(0,m.useDispatch)(c.store),f=qsmBlockData.globalQuizsetting,{quizID:E,postID:k,quizAttr:x=f}=n,[D,I]=(0,a.useState)(qsmBlockData.QSMQuizList),[C,B]=(0,a.useState)({error:!1,msg:""}),[S,N]=(0,a.useState)(!1),[O,A]=(0,a.useState)(!1),[P,T]=(0,a.useState)(!1),[M,Q]=(0,a.useState)([]),H=qsmBlockData.quizOptions,F=(0,m.useSelect)((e=>{const{isAutosavingPost:t,isSavingPost:n}=e(p.store);return n()&&!t()}),[]),{getBlock:j}=(0,m.useSelect)(u.store);(0,a.useEffect)((()=>{let e=!0;if(e&&("0"==qsmBlockData.is_pro_activated&&setTimeout((()=>{L()}),100),!q(E)&&0{if(E==t.value)return e=!0,!0})),e?K(E):(s({quizID:void 0}),B({error:!0,msg:(0,i.__)("Quiz not found. Please select an existing quiz or create a new one.","quiz-master-next")}))}return()=>{e=!1}}),[]);const L=()=>{let e=document.getElementById("modal-advanced-question-type");q(e)&&o()({path:"/quiz-survey-master/v1/quiz/advance-ques-type-upgrade-popup",method:"POST"}).then((e=>{let t=document.getElementById("wpbody-content");q(t)||"success"!=e.status||t.insertAdjacentHTML("afterbegin",e.result)})).catch((e=>{console.log("error",e)}))},K=e=>{!q(e)&&0{if("success"==t.status){B({error:!1,msg:""});let n=t.result;if(s({quizID:parseInt(e),postID:n.post_id,quizAttr:{...x,...n}}),!q(n.qpages)){let e=[];n.qpages.forEach((t=>{let n=[];q(t.question_arr)||t.question_arr.forEach((e=>{if(!q(e)){let t=[];!q(e.answers)&&0{t.push(["qsm/quiz-answer-option",{optionID:n,content:e[0],points:e[1],isCorrect:e[2],caption:w(e[3])}])})),n.push(["qsm/quiz-question",{questionID:e.question_id,type:e.question_type_new,answerEditor:e.settings.answerEditor,title:e.settings.question_title,description:e.question_name,required:e.settings.required,hint:e.hints,answers:e.answers,correctAnswerInfo:e.question_answer_info,category:e.category,multicategories:e.multicategories,commentBox:e.comments,matchAnswer:e.settings.matchAnswer,featureImageID:e.settings.featureImageID,featureImageSrc:e.settings.featureImageSrc,settings:e.settings},t])}})),e.push(["qsm/quiz-page",{pageID:t.id,pageKey:t.pagekey,hidePrevBtn:t.hide_prevbtn,quizID:t.quizID},n])})),Q(e)}}else console.log("error "+t.msg)})).catch((e=>{console.log("error",e)}))},R=(e,t)=>{let n=x;n[t]=e,s({quizAttr:{...n}})};(0,a.useEffect)((()=>{if(F){let e=(()=>{let e=j(_);if(q(e))return!1;e=e.innerBlocks;let t={quiz_id:x.quiz_id,post_id:x.post_id,quiz:{},pages:[],qpages:[],questions:[]},n=0;return e.forEach((e=>{if("qsm/quiz-page"===e.name){let a=e.attributes.pageID,s=[];!q(e.innerBlocks)&&0{if("qsm/quiz-question"!==e.name)return!0;let a=e.attributes,i=w(a?.answerEditor,"text"),r=[];!q(e.innerBlocks)&&0{if("qsm/quiz-answer-option"!==e.name)return!0;let t=e.attributes,n=w(t?.content);q(a?.answerEditor)||"rich"!==a.answerEditor||(n=g((0,l.decodeEntities)(n)));let s=[n,w(t?.points),w(t?.isCorrect)];"image"!==i||q(t?.caption)||s.push(t?.caption),r.push(s)})),s.push(a.questionID),a.isChanged&&t.questions.push({id:a.questionID,quizID:x.quiz_id,postID:x.post_id,answerEditor:i,type:w(a?.type,"0"),name:g(w(a?.description)),question_title:w(a?.title),answerInfo:g(w(a?.correctAnswerInfo)),comments:w(a?.commentBox,"1"),hint:w(a?.hint),category:w(a?.category),multicategories:w(a?.multicategories,[]),required:w(a?.required,0),answers:r,featureImageID:w(a?.featureImageID),featureImageSrc:w(a?.featureImageSrc),page:n,other_settings:{...w(a?.settings,{}),required:w(a?.required,0)}})})),t.pages.push(s),t.qpages.push({id:a,quizID:x.quiz_id,pagekey:q(e.attributes.pageKey)?b():e.attributes.pageKey,hide_prevbtn:e.attributes.hidePrevBtn,questions:s}),n++}})),t.quiz={quiz_name:x.quiz_name,quiz_id:x.quiz_id,post_id:x.post_id},P&&["form_type","system","timer_limit","pagination","enable_contact_form","enable_pagination_quiz","show_question_featured_image_in_result","progress_bar","require_log_in","disable_first_page","comment_section"].forEach((e=>{void 0!==x[e]&&null!==x[e]&&(t.quiz[e]=x[e])})),t})();A(!0),e=h({save_entire_quiz:"1",quizData:JSON.stringify(e),qsm_block_quiz_nonce:qsmBlockData.nonce,nonce:qsmBlockData.saveNonce}),o()({path:"/quiz-survey-master/v1/quiz/save_quiz",method:"POST",body:e}).then((e=>{z(e.status,e.msg,{isDismissible:!0,type:"snackbar"})})).catch((e=>{console.log("error",e),z("error",e.message,{isDismissible:!0,type:"snackbar"})}))}}),[F]);const V=(0,u.useBlockProps)(),$=(0,u.useInnerBlocksProps)(V,{template:M,allowedBlocks:["qsm/quiz-page"]});return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(u.InspectorControls,null,(0,a.createElement)(d.PanelBody,{title:(0,i.__)("Quiz settings","quiz-master-next"),initialOpen:!0},(0,a.createElement)("label",{className:"qsm-inspector-label"},(0,i.__)("Status","quiz-master-next")+":",(0,a.createElement)("span",{className:"qsm-inspector-label-value"},x.post_status)),(0,a.createElement)(d.TextControl,{label:(0,i.__)("Quiz Name *","quiz-master-next"),help:(0,i.__)("Enter a name for this Quiz","quiz-master-next"),value:x?.quiz_name||"",onChange:e=>R(e,"quiz_name"),className:"qsm-no-mb"}),(!q(E)||"0"!=E)&&(0,a.createElement)("p",null,(0,a.createElement)(d.ExternalLink,{href:qsmBlockData.quiz_settings_url+"&quiz_id="+E+"&tab=options"},(0,i.__)("Advance Quiz Settings","quiz-master-next"))))),q(E)||"0"==E?(0,a.createElement)("div",{...V}," ",(0,a.createElement)(d.Placeholder,{className:"qsm-placeholder-wrapper",icon:y,label:(0,i.__)("Quiz And Survey Master","quiz-master-next"),instructions:(0,i.__)("Easily and quickly add quizzes and surveys inside the block editor.","quiz-master-next")},(0,a.createElement)(a.Fragment,null,!q(D)&&0K(e),disabled:S,__nextHasNoMarginBottom:!0}),(0,a.createElement)("span",null,(0,i.__)("OR","quiz-master-next")),(0,a.createElement)(d.Button,{variant:"link",onClick:()=>N(!S)},(0,i.__)("Add New","quiz-master-next"))),(q(D)||S)&&(0,a.createElement)(d.__experimentalVStack,{spacing:"3",className:"qsm-placeholder-quiz-create-form"},(0,a.createElement)(d.TextControl,{label:(0,i.__)("Quiz Name *","quiz-master-next"),help:(0,i.__)("Enter a name for this Quiz","quiz-master-next"),value:x?.quiz_name||"",onChange:e=>R(e,"quiz_name")}),(0,a.createElement)(d.Button,{variant:"link",onClick:()=>T(!P)},(0,i.__)("Advance options","quiz-master-next")),(0,a.createElement)("div",{className:"qsm-advance-settings"},P&&H.map((e=>(0,a.createElement)(v,{key:"qsm-settings"+e.id,data:e,quizAttr:x,setAttributes:s,onChangeFunc:R})))),(0,a.createElement)(d.Button,{variant:"primary",disabled:O||q(x.quiz_name),onClick:()=>(()=>{if(q(x.quiz_name))return void console.log("empty quiz_name");A(!0);let e=h({quiz_name:x.quiz_name,qsm_new_quiz_nonce:qsmBlockData.qsm_new_quiz_nonce});["form_type","system","timer_limit","pagination","enable_contact_form","enable_pagination_quiz","show_question_featured_image_in_result","progress_bar","require_log_in","disable_first_page","comment_section"].forEach((t=>void 0===x[t]||null===x[t]?"":e.append(t,x[t]))),o()({path:"/quiz-survey-master/v1/quiz/create_quiz",method:"POST",body:e}).then((e=>{if(A(!1),"success"==e.status){let t=h({id:null,quizID:e.quizID,answerEditor:"text",type:"0",name:"",question_title:"",answerInfo:"",comments:"1",hint:"",category:"",required:0,answers:[],page:0});o()({path:"/quiz-survey-master/v1/questions",method:"POST",body:t}).then((t=>{if("success"==t.status){let n=t.id,a=h({action:qsmBlockData.save_pages_action,quiz_id:e.quizID,nonce:qsmBlockData.saveNonce,post_id:e.quizPostID});a.append("pages[0][]",n),a.append("qpages[0][id]",1),a.append("qpages[0][quizID]",e.quizID),a.append("qpages[0][pagekey]",b()),a.append("qpages[0][hide_prevbtn]",0),a.append("qpages[0][questions][]",n),o()({url:qsmBlockData.ajax_url,method:"POST",body:a}).then((t=>{"success"==t.status&&K(e.quizID)}))}})).catch((e=>{console.log("error",e),z("error",e.message,{isDismissible:!0,type:"snackbar"})}))}z(e.status,e.msg,{isDismissible:!0,type:"snackbar"})})).catch((e=>{console.log("error",e),z("error",e.message,{isDismissible:!0,type:"snackbar"})}))})()},(0,i.__)("Create Quiz","quiz-master-next"))),C.error&&(0,a.createElement)("p",{className:"qsm-error-text"},C.msg)))," "):(0,a.createElement)("div",{...$}))},save:e=>null});const k=(0,E.createHigherOrderComponent)((e=>t=>{const{name:n,className:s,attributes:i,setAttributes:r,isSelected:o,clientId:l,context:u}=t;return"core/group"!==n?(0,a.createElement)(e,{key:"edit",...t}):(console.log("props",t),(0,a.createElement)(a.Fragment,null,(0,a.createElement)(e,{key:"edit",...t})))}),"withMyPluginControls");wp.hooks.addFilter("editor.BlockEdit","my-plugin/with-inspector-controls",k)}},n={};function a(e){var s=n[e];if(void 0!==s)return s.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,a),i.exports}a.m=t,e=[],a.O=(t,n,s,i)=>{if(!n){var r=1/0;for(c=0;c=i)&&Object.keys(a.O).every((e=>a.O[e](n[l])))?n.splice(l--,1):(o=!1,i0&&e[c-1][2]>i;c--)e[c]=e[c-1];e[c]=[n,s,i]},a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var n in t)a.o(t,n)&&!a.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={826:0,431:0};a.O.j=t=>0===e[t];var t=(t,n)=>{var s,i,[r,o,l]=n,u=0;if(r.some((t=>0!==e[t]))){for(s in o)a.o(o,s)&&(a.m[s]=o[s]);if(l)var c=l(a)}for(t&&t(n);ua(818)));s=a.O(s)})(); \ No newline at end of file +(()=>{"use strict";var e,t={818:(e,t,n)=>{const a=window.wp.blocks,s=window.wp.element,i=window.wp.i18n,r=window.wp.apiFetch;var o=n.n(r);const l=window.wp.htmlEntities,u=window.wp.blockEditor,c=window.wp.notices,m=window.wp.data,p=window.wp.editor,d=window.wp.components,q=e=>null==e||""===e,g=e=>{var t=document.createElement("textarea");return t.innerHTML=e,t.value},_=e=>{let t=document.createElement("div");return t.innerHTML=g(e),t.innerText},h=(e=!1)=>{let t=new FormData;if(t.append("qsm_block_api_call","1"),!1!==e)for(let n in e)e.hasOwnProperty(n)&&t.append(n,e[n]);return t},z=e=>{let t="";const n=new Uint8Array(e);window.crypto.getRandomValues(n);for(let a=0;a`${e}${z(8)}${t?`.${z(7)}`:""}`,f=(e,t="")=>q(e)?t:e,v=()=>{};function w({className:e="",quizAttr:t,setAttributes:n,data:a,onChangeFunc:i=v}){var r,o,l,u,c;const m=(()=>{if(a.defaultvalue=a.default,!q(a?.options))switch(a.type){case"checkbox":1===a.options.length&&(a.type="toggle"),a.label=a.options[0].label;break;case"radio":1==a.options.length?(a.label=a.options[0].label,a.type="toggle"):a.type="select"}return a.label=q(a.label)?"":_(a.label),a.help=q(a.help)?"":_(a.help),a})(),{id:p,label:g="",type:h,help:z="",options:b=[],defaultvalue:f}=m;return(0,s.createElement)(s.Fragment,null,"toggle"===h&&(0,s.createElement)(d.ToggleControl,{label:g,help:z,checked:!q(t[p])&&"1"==t[p],onChange:()=>i(q(t[p])||"1"!=t[p]?1:0,p)}),"select"===h&&(0,s.createElement)(d.SelectControl,{label:g,value:null!==(r=t[p])&&void 0!==r?r:f,options:b,onChange:e=>i(e,p),help:z,__nextHasNoMarginBottom:!0}),"number"===h&&(0,s.createElement)(d.TextControl,{type:"number",label:g,value:null!==(o=t[p])&&void 0!==o?o:f,onChange:e=>i(e,p),help:z,__nextHasNoMarginBottom:!0}),"text"===h&&(0,s.createElement)(d.TextControl,{type:"text",label:g,value:null!==(l=t[p])&&void 0!==l?l:f,onChange:e=>i(e,p),help:z,__nextHasNoMarginBottom:!0}),"textarea"===h&&(0,s.createElement)(d.TextareaControl,{label:g,value:null!==(u=t[p])&&void 0!==u?u:f,onChange:e=>i(e,p),help:z,__nextHasNoMarginBottom:!0}),"checkbox"===h&&(0,s.createElement)(d.CheckboxControl,{label:g,help:z,checked:!q(t[p])&&"1"==t[p],onChange:()=>i(q(t[p])||"1"!=t[p]?1:0,p)}),"radio"===h&&(0,s.createElement)(d.RadioControl,{label:g,help:z,selected:null!==(c=t[p])&&void 0!==c?c:f,options:b,onChange:e=>i(e,p)}))}const E=()=>(0,s.createElement)(d.Icon,{icon:()=>(0,s.createElement)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,s.createElement)("rect",{width:"24",height:"24",rx:"3",fill:"black"}),(0,s.createElement)("path",{d:"M17.8146 17.8349C19.3188 16.3426 20.25 14.2793 20.25 12C20.2485 7.44425 16.5267 3.75 11.9348 3.75C7.34282 3.75 3.62109 7.44425 3.62109 12C3.62109 16.5558 7.34282 20.25 11.9348 20.25H18.9988C19.4682 20.25 19.7074 19.7112 19.3813 19.3885L17.8146 17.8334V17.8349ZM11.8753 17.5195C8.72666 17.5195 6.17388 15.0737 6.17388 12.0569C6.17388 9.04022 8.72666 6.59442 11.8753 6.59442C15.024 6.59442 17.5768 9.04022 17.5768 12.0569C17.5768 15.0737 15.024 17.5195 11.8753 17.5195Z",fill:"white"}))});window.wp.compose,(0,a.registerBlockType)("qsm/quiz",{icon:E,edit:function(e){if("undefined"==typeof qsmBlockData)return null;const{className:t,attributes:n,setAttributes:a,isSelected:r,clientId:_,context:z}=e,v=z.postId,{createNotice:y}=(0,m.useDispatch)(c.store),k=qsmBlockData.globalQuizsetting,{quizID:x,postID:D,quizAttr:I=k}=n,[C,B]=(0,s.useState)(qsmBlockData.QSMQuizList),[S,N]=(0,s.useState)({error:!1,msg:""}),[O,A]=(0,s.useState)(!1),[P,T]=(0,s.useState)(!1),[M,Q]=(0,s.useState)(!1),[H,F]=(0,s.useState)([]),j=qsmBlockData.quizOptions,L=(0,m.useSelect)((e=>{const{isAutosavingPost:t,isSavingPost:n}=e(p.store);return n()&&!t()}),[]),K=(0,m.useSelect)((e=>e("core/editor")),[]),{getBlock:R}=(0,m.useSelect)(u.store);(0,s.useEffect)((()=>{let e=!0;if(e&&("0"==qsmBlockData.is_pro_activated&&setTimeout((()=>{V()}),100),!q(x)&&0{if(x==t.value)return e=!0,!0})),e?$(x):(a({quizID:void 0}),N({error:!0,msg:(0,i.__)("Quiz not found. Please select an existing quiz or create a new one.","quiz-master-next")}))}return()=>{e=!1}}),[]);const V=()=>{let e=document.getElementById("modal-advanced-question-type");q(e)&&o()({path:"/quiz-survey-master/v1/quiz/advance-ques-type-upgrade-popup",method:"POST"}).then((e=>{let t=document.getElementById("wpbody-content");q(t)||"success"!=e.status||t.insertAdjacentHTML("afterbegin",e.result)})).catch((e=>{console.log("error",e)}))},$=e=>{!q(e)&&0{if("success"==t.status){N({error:!1,msg:""});let n=t.result;if(a({quizID:parseInt(e),postID:n.post_id,quizAttr:{...I,...n}}),!q(n.qpages)){let e=[];n.qpages.forEach((t=>{let n=[];q(t.question_arr)||t.question_arr.forEach((e=>{if(!q(e)){let t=[];!q(e.answers)&&0{t.push(["qsm/quiz-answer-option",{optionID:n,content:e[0],points:e[1],isCorrect:e[2],caption:f(e[3])}])})),n.push(["qsm/quiz-question",{questionID:e.question_id,type:e.question_type_new,answerEditor:e.settings.answerEditor,title:e.settings.question_title,description:e.question_name,required:e.settings.required,hint:e.hints,answers:e.answers,correctAnswerInfo:e.question_answer_info,category:e.category,multicategories:e.multicategories,commentBox:e.comments,matchAnswer:e.settings.matchAnswer,featureImageID:e.settings.featureImageID,featureImageSrc:e.settings.featureImageSrc,settings:e.settings},t])}})),e.push(["qsm/quiz-page",{pageID:t.id,pageKey:t.pagekey,hidePrevBtn:t.hide_prevbtn,quizID:t.quizID},n])})),F(e)}}else console.log("error "+t.msg)})).catch((e=>{console.log("error",e)}))},Z=(e,t)=>{let n=I;n[t]=e,a({quizAttr:{...n}})};(0,s.useEffect)((()=>{if(L){let e=(()=>{let e=R(_);if(q(e))return!1;e=e.innerBlocks;let t={quiz_id:I.quiz_id,post_id:I.post_id,quiz:{},pages:[],qpages:[],questions:[]},n=0;return e.forEach((e=>{if("qsm/quiz-page"===e.name){let a=e.attributes.pageID,s=[];!q(e.innerBlocks)&&0{if("qsm/quiz-question"!==e.name)return!0;let a=e.attributes,i=f(a?.answerEditor,"text"),r=[];!q(e.innerBlocks)&&0{if("qsm/quiz-answer-option"!==e.name)return!0;let t=e.attributes,n=f(t?.content);q(a?.answerEditor)||"rich"!==a.answerEditor||(n=g((0,l.decodeEntities)(n)));let s=[n,f(t?.points),f(t?.isCorrect)];"image"!==i||q(t?.caption)||s.push(t?.caption),r.push(s)})),s.push(a.questionID),a.isChanged&&t.questions.push({id:a.questionID,quizID:I.quiz_id,postID:I.post_id,answerEditor:i,type:f(a?.type,"0"),name:g(f(a?.description)),question_title:f(a?.title),answerInfo:g(f(a?.correctAnswerInfo)),comments:f(a?.commentBox,"1"),hint:f(a?.hint),category:f(a?.category),multicategories:f(a?.multicategories,[]),required:f(a?.required,0),answers:r,featureImageID:f(a?.featureImageID),featureImageSrc:f(a?.featureImageSrc),page:n,other_settings:{...f(a?.settings,{}),required:f(a?.required,0)}})})),t.pages.push(s),t.qpages.push({id:a,quizID:I.quiz_id,pagekey:q(e.attributes.pageKey)?b():e.attributes.pageKey,hide_prevbtn:e.attributes.hidePrevBtn,questions:s}),n++}})),t.quiz={quiz_name:I.quiz_name,quiz_id:I.quiz_id,post_id:I.post_id},M&&["form_type","system","timer_limit","pagination","enable_contact_form","enable_pagination_quiz","show_question_featured_image_in_result","progress_bar","require_log_in","disable_first_page","comment_section"].forEach((e=>{void 0!==I[e]&&null!==I[e]&&(t.quiz[e]=I[e])})),t})();T(!0);let t="publish";q(K)||(t=K.getEditedPostAttribute("status")),q(t)&&(t="publish"),e=h({save_entire_quiz:"1",quizData:JSON.stringify(e),qsm_block_quiz_nonce:qsmBlockData.nonce,page_post_id:q(v)?0:v,post_status:t,nonce:qsmBlockData.saveNonce}),o()({path:"/quiz-survey-master/v1/quiz/save_quiz",method:"POST",body:e}).then((e=>{y(e.status,e.msg,{isDismissible:!0,type:"snackbar"})})).catch((e=>{console.log("error",e),y("error",e.message,{isDismissible:!0,type:"snackbar"})}))}}),[L]);const J=(0,u.useBlockProps)(),U=(0,u.useInnerBlocksProps)(J,{template:H,allowedBlocks:["qsm/quiz-page"]});return(0,s.createElement)(s.Fragment,null,(0,s.createElement)(u.InspectorControls,null,(0,s.createElement)(d.PanelBody,{title:(0,i.__)("Quiz settings","quiz-master-next"),initialOpen:!0},(0,s.createElement)("label",{className:"qsm-inspector-label"},(0,i.__)("Status","quiz-master-next")+":",(0,s.createElement)("span",{className:"qsm-inspector-label-value"},I.post_status)),(0,s.createElement)(d.TextControl,{label:(0,i.__)("Quiz Name *","quiz-master-next"),help:(0,i.__)("Enter a name for this Quiz","quiz-master-next"),value:I?.quiz_name||"",onChange:e=>Z(e,"quiz_name"),className:"qsm-no-mb"}),(!q(x)||"0"!=x)&&(0,s.createElement)("p",null,(0,s.createElement)(d.ExternalLink,{href:qsmBlockData.quiz_settings_url+"&quiz_id="+x+"&tab=options"},(0,i.__)("Advance Quiz Settings","quiz-master-next"))))),q(x)||"0"==x?(0,s.createElement)("div",{...J}," ",(0,s.createElement)(d.Placeholder,{className:"qsm-placeholder-wrapper",icon:E,label:(0,i.__)("Quiz And Survey Master","quiz-master-next"),instructions:(0,i.__)("Easily and quickly add quizzes and surveys inside the block editor.","quiz-master-next")},(0,s.createElement)(s.Fragment,null,!q(C)&&0$(e),disabled:O,__nextHasNoMarginBottom:!0}),(0,s.createElement)("span",null,(0,i.__)("OR","quiz-master-next")),(0,s.createElement)(d.Button,{variant:"link",onClick:()=>A(!O)},(0,i.__)("Add New","quiz-master-next"))),(q(C)||O)&&(0,s.createElement)(d.__experimentalVStack,{spacing:"3",className:"qsm-placeholder-quiz-create-form"},(0,s.createElement)(d.TextControl,{label:(0,i.__)("Quiz Name *","quiz-master-next"),help:(0,i.__)("Enter a name for this Quiz","quiz-master-next"),value:I?.quiz_name||"",onChange:e=>Z(e,"quiz_name")}),(0,s.createElement)(d.Button,{variant:"link",onClick:()=>Q(!M)},(0,i.__)("Advance options","quiz-master-next")),(0,s.createElement)("div",{className:"qsm-advance-settings"},M&&j.map((e=>(0,s.createElement)(w,{key:"qsm-settings"+e.id,data:e,quizAttr:I,setAttributes:a,onChangeFunc:Z})))),(0,s.createElement)(d.Button,{variant:"primary",disabled:P||q(I.quiz_name),onClick:()=>(()=>{if(q(I.quiz_name))return void console.log("empty quiz_name");T(!0);let e=h({quiz_name:I.quiz_name,qsm_new_quiz_nonce:qsmBlockData.qsm_new_quiz_nonce});["form_type","system","timer_limit","pagination","enable_contact_form","enable_pagination_quiz","show_question_featured_image_in_result","progress_bar","require_log_in","disable_first_page","comment_section"].forEach((t=>void 0===I[t]||null===I[t]?"":e.append(t,I[t]))),o()({path:"/quiz-survey-master/v1/quiz/create_quiz",method:"POST",body:e}).then((e=>{if(T(!1),"success"==e.status){let t=h({id:null,quizID:e.quizID,answerEditor:"text",type:"0",name:"",question_title:"",answerInfo:"",comments:"1",hint:"",category:"",required:0,answers:[],page:0});o()({path:"/quiz-survey-master/v1/questions",method:"POST",body:t}).then((t=>{if("success"==t.status){let n=t.id,a=h({action:qsmBlockData.save_pages_action,quiz_id:e.quizID,nonce:qsmBlockData.saveNonce,post_id:e.quizPostID});a.append("pages[0][]",n),a.append("qpages[0][id]",1),a.append("qpages[0][quizID]",e.quizID),a.append("qpages[0][pagekey]",b()),a.append("qpages[0][hide_prevbtn]",0),a.append("qpages[0][questions][]",n),o()({url:qsmBlockData.ajax_url,method:"POST",body:a}).then((t=>{"success"==t.status&&$(e.quizID)}))}})).catch((e=>{console.log("error",e),y("error",e.message,{isDismissible:!0,type:"snackbar"})}))}y(e.status,e.msg,{isDismissible:!0,type:"snackbar"})})).catch((e=>{console.log("error",e),y("error",e.message,{isDismissible:!0,type:"snackbar"})}))})()},(0,i.__)("Create Quiz","quiz-master-next"))),S.error&&(0,s.createElement)("p",{className:"qsm-error-text"},S.msg)))," "):(0,s.createElement)("div",{...U}))},save:e=>null})}},n={};function a(e){var s=n[e];if(void 0!==s)return s.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,a),i.exports}a.m=t,e=[],a.O=(t,n,s,i)=>{if(!n){var r=1/0;for(c=0;c=i)&&Object.keys(a.O).every((e=>a.O[e](n[l])))?n.splice(l--,1):(o=!1,i0&&e[c-1][2]>i;c--)e[c]=e[c-1];e[c]=[n,s,i]},a.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return a.d(t,{a:t}),t},a.d=(e,t)=>{for(var n in t)a.o(t,n)&&!a.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={826:0,431:0};a.O.j=t=>0===e[t];var t=(t,n)=>{var s,i,[r,o,l]=n,u=0;if(r.some((t=>0!==e[t]))){for(s in o)a.o(o,s)&&(a.m[s]=o[s]);if(l)var c=l(a)}for(t&&t(n);ua(818)));s=a.O(s)})(); \ No newline at end of file diff --git a/blocks/build/question/index.asset.php b/blocks/build/question/index.asset.php index 981f19975..3697cd262 100644 --- a/blocks/build/question/index.asset.php +++ b/blocks/build/question/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-notices'), 'version' => '8c84bc3be26cb4988adf'); + array('wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-notices'), 'version' => '45906d9cb21e070d8451'); diff --git a/blocks/build/question/index.js b/blocks/build/question/index.js index 56d1d90ec..7503ac0b7 100644 --- a/blocks/build/question/index.js +++ b/blocks/build/question/index.js @@ -2,4 +2,4 @@ // Translators: %s: The selected image alt text. (0,n.__)("Current image: %s"),h.alt_text),!h.alt_text&&(0,n.sprintf)( // Translators: %s: The selected image filename. -(0,n.__)("The current image has no alternative text. The file name is: %s"),h.slug)),(0,a.createElement)(i.MediaUploadCheck,{fallback:x},(0,a.createElement)(i.MediaUpload,{title:f,onSelect:e=>{q(e),t(e)},unstableFeaturedImageFlow:!0,allowedTypes:E,modalClass:"editor-post-featured-image__media-modal",render:({open:t})=>(0,a.createElement)("div",{className:"editor-post-featured-image__container"},(0,a.createElement)(c.Button,{ref:_,className:e?"editor-post-featured-image__preview":"editor-post-featured-image__toggle",onClick:t,"aria-label":e?(0,n.__)("Edit or replace the image"):null,"aria-describedby":e?`editor-post-featured-image-${e}-describedby`:null},!!e&&h&&(0,a.createElement)(c.ResponsiveWrapper,{naturalWidth:h.width,naturalHeight:h.height,isInline:!0},(0,a.createElement)("img",{src:h.url,alt:h.alt_text})),p&&(0,a.createElement)(c.Spinner,null),!e&&!p&&w),!!e&&(0,a.createElement)(c.__experimentalHStack,{className:"editor-post-featured-image__actions"},(0,a.createElement)(c.Button,{className:"editor-post-featured-image__action",onClick:t,"aria-hidden":"true"},(0,n.__)("Replace")),(0,a.createElement)(c.Button,{className:"editor-post-featured-image__action",onClick:()=>{r(),_.current.focus()}},(0,n.__)("Remove"))),(0,a.createElement)(c.DropZone,{onFilesDrop:y})),value:e})))},b=({isCategorySelected:e,setUnsetCatgory:t})=>{const[r,i]=(0,a.useState)(!1),[o,s]=(0,a.useState)(""),[m,u]=(0,a.useState)(0),[_,p]=(0,a.useState)(!1),[g,q]=(0,a.useState)(!1),[E,f]=(0,a.useState)(qsmBlockData?.hierarchicalCategoryList),w=e=>{let t={};return e.forEach((e=>{if(t[e.id]=e,0{let t=[];return e.forEach((e=>{if(t.push(e.name),0n.map((n=>(0,a.createElement)("div",{key:n.id,className:"editor-post-taxonomies__hierarchical-terms-choice"},(0,a.createElement)(c.CheckboxControl,{label:n.name,checked:e(n.id),onChange:()=>t(n.id,x)}),!!n.children.length&&(0,a.createElement)("div",{className:"editor-post-taxonomies__hierarchical-terms-subchoices"},v(n.children)))));return(0,a.createElement)(c.PanelBody,{title:(0,n.__)("Categories","quiz-master-next"),initialOpen:!0},(0,a.createElement)("div",{className:"editor-post-taxonomies__hierarchical-terms-list",tabIndex:"0",role:"group","aria-label":(0,n.__)("Categories","quiz-master-next")},v(E)),(0,a.createElement)("div",{className:"qsm-ptb-1"},(0,a.createElement)(c.Button,{variant:"link",onClick:()=>i(!r)},b)),r&&(0,a.createElement)("form",{onSubmit:async e=>{e.preventDefault(),g||d(o)||_||(p(!0),l()({url:qsmBlockData.ajax_url,method:"POST",body:h({action:"save_new_category",name:o,parent:m})}).then((e=>{if(!d(e.term_id)){let a=e.term_id;l()({path:"/quiz-survey-master/v1/quiz/hierarchical-category-list",method:"POST"}).then((e=>{"success"==e.status&&(f(e.result),C(e.result),s(""),u(0),t(a,w(term.id)),p(!1))}))}})))}},(0,a.createElement)(c.Flex,{direction:"column",gap:"1"},(0,a.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,className:"editor-post-taxonomies__hierarchical-terms-input",label:(0,n.__)("Category Name","quiz-master-next"),value:o,onChange:e=>((e,t)=>{t=k(t),console.log("categories",t),t.includes(e)?q(e):(q(!1),s(e))})(e,E),required:!0}),0u(e),selectedId:m,tree:E}),(0,a.createElement)(c.FlexItem,null,(0,a.createElement)(c.Button,{variant:"secondary",type:"submit",className:"editor-post-taxonomies__hierarchical-terms-submit",disabled:g||_},b)),(0,a.createElement)(c.FlexItem,null,(0,a.createElement)("p",{className:"qsm-error-text"},!1!==g&&(0,n.__)("Category ","quiz-master-next")+g+(0,n.__)(" already exists.","quiz-master-next"))))))},y=()=>(0,a.createElement)(c.Icon,{icon:()=>(0,a.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",ariaHidden:"true",focusable:"false"},(0,a.createElement)("path",{d:"M18 11.2h-5.2V6h-1.6v5.2H6v1.6h5.2V18h1.6v-5.2H18z"}))}),k=JSON.parse('{"u2":"qsm/quiz-question"}');(0,t.registerBlockType)(k.u2,{icon:()=>(0,a.createElement)(c.Icon,{icon:()=>(0,a.createElement)("svg",{width:"25",height:"25",viewBox:"0 0 25 25",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,a.createElement)("rect",{x:"0.102539",y:"0.101562",width:"24",height:"24",rx:"4.68852",fill:"#ADADAD"}),(0,a.createElement)("path",{d:"M17.0475 17.191C17.2367 17.3683 17.3313 17.5752 17.3313 17.8117C17.3313 18.06 17.2426 18.2787 17.0653 18.4679C16.8879 18.6453 16.6751 18.734 16.4268 18.734C16.1667 18.734 15.9538 18.6512 15.7883 18.4857L14.937 17.6521C13.8492 18.4088 12.5959 18.7872 11.177 18.7872C10.0301 18.7872 9.01325 18.533 8.12646 18.0245C7.2515 17.5161 6.57163 16.8126 6.08685 15.914C5.6139 15.0035 5.37742 13.9631 5.37742 12.7925C5.37742 11.5273 5.64937 10.41 6.19327 9.44044C6.74898 8.45907 7.48206 7.70234 8.3925 7.17027C9.31475 6.6382 10.308 6.37216 11.3721 6.37216C12.4481 6.37216 13.459 6.64411 14.4049 7.18801C15.3508 7.72008 16.1075 8.46498 16.6751 9.42271C17.2426 10.3804 17.5264 11.4505 17.5264 12.6329C17.5264 14.0636 17.1007 15.3287 16.2494 16.4283L17.0475 17.191ZM11.177 17.1732C12.0874 17.1732 12.9269 16.9249 13.6955 16.4283L12.5604 15.311C12.3949 15.1454 12.3121 14.9799 12.3121 14.8144C12.3121 14.6015 12.4244 14.3887 12.6491 14.1759C12.8855 13.9631 13.122 13.8566 13.3585 13.8566C13.5122 13.8566 13.6364 13.9039 13.7309 13.9985L14.9724 15.1868C15.4927 14.4183 15.7528 13.5492 15.7528 12.5797C15.7528 11.7284 15.5518 10.9539 15.1498 10.2563C14.7596 9.54686 14.2335 8.99114 13.5713 8.58913C12.9092 8.18712 12.1998 7.98611 11.443 7.98611C10.6981 7.98611 9.99462 8.18121 9.33249 8.57139C8.67036 8.94975 8.13828 9.49956 7.73627 10.2208C7.34609 10.9421 7.15099 11.7756 7.15099 12.7216C7.15099 13.6083 7.32244 14.3887 7.66533 15.0627C8.02005 15.7366 8.49891 16.2569 9.10192 16.6234C9.71676 16.99 10.4085 17.1732 11.177 17.1732Z",fill:"white"}))}),edit:function(e){var r;if("undefined"==typeof qsmBlockData)return null;const{className:m,attributes:u,setAttributes:E,isSelected:f,clientId:w,context:x}=e,k=(0,s.useSelect)((e=>f||e("core/block-editor").hasSelectedInnerBlock(w,!0))),v=x["quiz-master-next/quizID"],{quiz_name:B,post_id:z,rest_nonce:D}=x["quiz-master-next/quizAttr"],{createNotice:I}=(x["quiz-master-next/pageID"],(0,s.useDispatch)(o.store)),{getBlockRootClientId:N,getBlockIndex:S}=(0,s.useSelect)(i.store),{insertBlock:T}=(0,s.useDispatch)(i.store),{isChanged:A=!1,questionID:M,type:L,description:P,title:F,correctAnswerInfo:O,commentBox:H,category:Q,multicategories:R=[],hint:U,featureImageID:j,featureImageSrc:V,answers:W,answerEditor:Z,matchAnswer:$,required:G,settings:J={}}=u,[K,X]=(0,a.useState)(!d(O)),[Y,ee]=(0,a.useState)(!1),te="1"==qsmBlockData.is_pro_activated,ae=e=>14{let e=J?.file_upload_type||qsmBlockData.file_upload_type.default;return d(e)?[]:e.split(",")};(0,a.useEffect)((()=>{let e=!0;if(e&&(d(M)||"0"==M||!d(M)&&((e,t)=>{const a=(0,s.select)("core/block-editor").getClientIdsWithDescendants();return!d(a)&&a.some((a=>{const{questionID:n}=(0,s.select)("core/block-editor").getBlockAttributes(a);return t!==a&&n===e}))})(M,w))){let e=h({id:null,rest_nonce:D,quizID:v,quiz_name:B,postID:z,answerEditor:q(Z,"text"),type:q(L,"0"),name:p(q(P)),question_title:q(F),answerInfo:p(q(O)),comments:q(H,"1"),hint:q(U),category:q(Q),multicategories:[],required:q(G,0),answers:W,page:0,featureImageID:j,featureImageSrc:V,matchAnswer:null});l()({path:"/quiz-survey-master/v1/questions",method:"POST",body:e}).then((e=>{if("success"==e.status){let t=e.id;E({questionID:t})}})).catch((e=>{console.log("error",e),I("error",e.message,{isDismissible:!0,type:"snackbar"})}))}return()=>{e=!1}}),[]),(0,a.useEffect)((()=>{let e=!0;return e&&f&&!1===A&&E({isChanged:!0}),()=>{e=!1}}),[M,L,P,F,O,H,Q,R,U,j,V,W,Z,$,G,J]);const le=(0,i.useBlockProps)({className:k?" in-editing-mode is-highlighted ":""}),ie=(e,t)=>{let a=[];if(!d(t[e])&&"0"!=t[e].parent&&(e=t[e].parent,a.push(e),!d(t[e])&&"0"!=t[e].parent)){let n=ie(e,t);a=[...a,...n]}return _(a)},oe=["12","7","3","5","14"].includes(L)?(0,n.__)("Note: Add only correct answer options with their respective points score.","quiz-master-next"):"",se=()=>{if(d(e?.name))return console.log("block name not found"),!0;const a=(0,t.createBlock)(e.name);T(a,S(w)+1,N(w),!0)};return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(i.BlockControls,null,(0,a.createElement)(c.ToolbarGroup,null,(0,a.createElement)(c.ToolbarButton,{icon:"plus-alt2",label:(0,n.__)("Add New Question","quiz-master-next"),onClick:()=>se()}),(0,a.createElement)(c.ToolbarButton,{icon:"welcome-add-page",label:(0,n.__)("Add New Page","quiz-master-next"),onClick:()=>(()=>{const e=(0,t.createBlock)("qsm/quiz-page"),a=N(w),n=S(a)+1,r=N(a);T(e,n,r,!0)})()}))),Y&&(0,a.createElement)(c.Modal,{contentLabel:(0,n.__)("Use QSM Editor for Advanced Question","quiz-master-next"),className:"qsm-advance-q-modal",isDismissible:!1,size:"small",__experimentalHideHeader:!0},(0,a.createElement)("div",{className:"qsm-modal-body"},(0,a.createElement)("h3",{className:"qsm-title"},(0,a.createElement)(c.Icon,{icon:()=>(0,a.createElement)("svg",{width:"54",height:"54",viewBox:"0 0 54 54",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,a.createElement)("path",{d:"M27.1855 23.223V28.0626M15.1794 32.4196C14.0618 34.3554 15.4595 36.7739 17.6934 36.7739H36.6776C38.9102 36.7739 40.3079 34.3554 39.1916 32.4196L29.7008 15.9675C28.5832 14.0317 25.7878 14.0317 24.6702 15.9675L15.1794 32.4196ZM27.1855 31.9343H27.1945V31.9446H27.1855V31.9343Z",stroke:"#B45309",strokeWidth:"1.65929",strokeLinecap:"round",strokeLinejoin:"round"}))}),(0,a.createElement)("br",null),(0,n.__)("Use QSM editor for Advanced Question","quiz-master-next")),(0,a.createElement)("p",{className:"qsm-description"},(0,n.__)("Currently, the block editor doesn't support advanced question type. We are working on it. Alternatively, you can add advanced questions from your QSM's quiz editor.","quiz-master-next")),(0,a.createElement)("div",{className:"qsm-modal-btn-wrapper"},(0,a.createElement)(c.Button,{variant:"secondary",onClick:()=>ee(!1)},(0,n.__)("Cancel","quiz-master-next")),(0,a.createElement)(c.Button,{variant:"primary",onClick:()=>{}},(0,a.createElement)(c.ExternalLink,{href:qsmBlockData.quiz_settings_url+"&quiz_id="+v},(0,n.__)("Add Question from quiz editor","quiz-master-next")))))),ae(L)?(0,a.createElement)(a.Fragment,null,(0,a.createElement)(i.InspectorControls,null,(0,a.createElement)(c.PanelBody,{title:(0,n.__)("Question settings","quiz-master-next"),initialOpen:!0},(0,a.createElement)("h2",{className:"block-editor-block-card__title"},(0,n.__)("ID","quiz-master-next")+": "+M),(0,a.createElement)("h3",null,(0,n.__)("Advanced Question Type","quiz-master-next")))),(0,a.createElement)("div",{...le},(0,a.createElement)("h4",{className:"qsm-question-title qsm-error-text"},(0,n.__)("Advanced Question Type : ","quiz-master-next")+F),(0,a.createElement)("p",null,(0,n.__)("Edit question in QSM ","quiz-master-next"),(0,a.createElement)(c.ExternalLink,{href:qsmBlockData.quiz_settings_url+"&quiz_id="+v},(0,n.__)("editor","quiz-master-next"))))):(0,a.createElement)(a.Fragment,null,(0,a.createElement)(i.InspectorControls,null,(0,a.createElement)(c.PanelBody,{title:(0,n.__)("Question settings","quiz-master-next"),initialOpen:!0},(0,a.createElement)("h2",{className:"block-editor-block-card__title"},(0,n.__)("ID","quiz-master-next")+": "+M),(0,a.createElement)(c.SelectControl,{label:qsmBlockData.question_type.label,value:L||qsmBlockData.question_type.default,onChange:e=>(e=>{if(d(MicroModal)||te||!["15","16","17"].includes(e))te&&ae(e)?ee(!0):E({type:e});else{let e=document.getElementById("modal-advanced-question-type");d(e)||MicroModal.show("modal-advanced-question-type")}})(e),help:d(qsmBlockData.question_type_description[L])?"":qsmBlockData.question_type_description[L]+" "+oe,__nextHasNoMarginBottom:!0},!d(qsmBlockData.question_type.options)&&qsmBlockData.question_type.options.map((e=>(0,a.createElement)("optgroup",{label:e.category,key:"qtypes"+e.category},e.types.map((e=>(0,a.createElement)("option",{value:e.slug,key:"qtype"+e.slug},e.name))))))),["0","4","1","10","13"].includes(L)&&(0,a.createElement)(c.SelectControl,{label:qsmBlockData.answerEditor.label,value:Z||qsmBlockData.answerEditor.default,options:qsmBlockData.answerEditor.options,onChange:e=>E({answerEditor:e}),__nextHasNoMarginBottom:!0}),(0,a.createElement)(c.ToggleControl,{label:(0,n.__)("Required","quiz-master-next"),checked:!d(G)&&"1"==G,onChange:()=>E({required:d(G)||"1"!=G?1:0})}),(0,a.createElement)(c.ToggleControl,{label:(0,n.__)("Show Correct Answer Info","quiz-master-next"),checked:K,onChange:()=>X(!K)})),"11"==L&&(0,a.createElement)(c.PanelBody,{title:(0,n.__)("File Settings","quiz-master-next"),initialOpen:!1},(0,a.createElement)(c.TextControl,{type:"number",label:qsmBlockData.file_upload_limit.heading,value:null!==(r=J?.file_upload_limit)&&void 0!==r?r:qsmBlockData.file_upload_limit.default,onChange:e=>E({settings:{...J,file_upload_limit:e}})}),(0,a.createElement)("label",{className:"qsm-inspector-label"},qsmBlockData.file_upload_type.heading),Object.keys(qsmBlockData.file_upload_type.options).map((e=>{return(0,a.createElement)(c.CheckboxControl,{key:"filetype-"+e,label:ne[e],checked:(t=e,re().includes(t)),onChange:()=>(e=>{let t=re();t.includes(e)?t=t.filter((t=>t!=e)):t.push(e),t=t.join(","),E({settings:{...J,file_upload_type:t}})})(e)});var t}))),(0,a.createElement)(b,{isCategorySelected:e=>R.includes(e),setUnsetCatgory:(e,t)=>{let a=d(R)||0===R.length?d(Q)?[]:[Q]:R;if(a.includes(e))a=a.filter((t=>t!=e)),a.forEach((n=>{ie(n,t).includes(e)&&(a=a.filter((e=>e!=n)))}));else{a.push(e);let n=ie(e,t);a=[...a,...n]}a=_(a),E({category:"",multicategories:[...a]})}}),(0,a.createElement)(c.PanelBody,{title:(0,n.__)("Hint","quiz-master-next"),initialOpen:!1},(0,a.createElement)(c.TextControl,{label:"",value:U,onChange:e=>E({hint:g(e)})})),(0,a.createElement)(c.PanelBody,{title:qsmBlockData.commentBox.heading,initialOpen:!1},(0,a.createElement)(c.SelectControl,{label:qsmBlockData.commentBox.label,value:H||qsmBlockData.commentBox.default,options:qsmBlockData.commentBox.options,onChange:e=>E({commentBox:e}),__nextHasNoMarginBottom:!0})),(0,a.createElement)(c.PanelBody,{title:(0,n.__)("Featured image","quiz-master-next"),initialOpen:!0},(0,a.createElement)(C,{featureImageID:j,onUpdateImage:e=>{E({featureImageID:e.id,featureImageSrc:e.url})},onRemoveImage:e=>{E({featureImageID:void 0,featureImageSrc:void 0})}}))),(0,a.createElement)("div",{...le},(0,a.createElement)(i.RichText,{tagName:"h4",title:(0,n.__)("Question title","quiz-master-next"),"aria-label":(0,n.__)("Question title","quiz-master-next"),placeholder:(0,n.__)("Type your question here","quiz-master-next"),value:F,onChange:e=>E({title:g(e)}),allowedFormats:[],withoutInteractiveFormatting:!0,className:"qsm-question-title"}),k&&(0,a.createElement)(a.Fragment,null,(0,a.createElement)(i.RichText,{tagName:"p",title:(0,n.__)("Question description","quiz-master-next"),"aria-label":(0,n.__)("Question description","quiz-master-next"),placeholder:(0,n.__)("Description goes here... (optional)","quiz-master-next"),value:p(P),onChange:e=>E({description:e}),className:"qsm-question-description",__unstableEmbedURLOnPaste:!0,__unstableAllowPrefixTransformations:!0}),!["8","11","6","9"].includes(L)&&(0,a.createElement)(i.InnerBlocks,{allowedBlocks:["qsm/quiz-answer-option"],template:[["qsm/quiz-answer-option",{optionID:"0"}],["qsm/quiz-answer-option",{optionID:"1"}]]}),K&&(0,a.createElement)(i.RichText,{tagName:"p",title:(0,n.__)("Correct Answer Info","quiz-master-next"),"aria-label":(0,n.__)("Correct Answer Info","quiz-master-next"),placeholder:(0,n.__)("Correct answer info goes here","quiz-master-next"),value:p(O),onChange:e=>E({correctAnswerInfo:e}),className:"qsm-question-correct-answer-info",__unstableEmbedURLOnPaste:!0,__unstableAllowPrefixTransformations:!0}),k&&(0,a.createElement)("div",{className:"block-editor-block-list__insertion-point-inserter qsm-add-new-ques-wrapper"},(0,a.createElement)(c.Button,{icon:y,label:(0,n.__)("Add New Question","quiz-master-next"),tooltipPosition:"bottom",onClick:()=>se(),variant:"secondary",className:"add-new-question-btn block-editor-inserter__toggle"}))))))},__experimentalLabel(e,{context:t}){const{title:a}=e,n=e?.metadata?.name;if("list-view"===t&&(n||a?.length>0))return n||a}})})(); \ No newline at end of file +(0,n.__)("The current image has no alternative text. The file name is: %s"),h.slug)),(0,a.createElement)(i.MediaUploadCheck,{fallback:x},(0,a.createElement)(i.MediaUpload,{title:f,onSelect:e=>{q(e),t(e)},unstableFeaturedImageFlow:!0,allowedTypes:E,modalClass:"editor-post-featured-image__media-modal",render:({open:t})=>(0,a.createElement)("div",{className:"editor-post-featured-image__container"},(0,a.createElement)(c.Button,{ref:_,className:e?"editor-post-featured-image__preview":"editor-post-featured-image__toggle",onClick:t,"aria-label":e?(0,n.__)("Edit or replace the image"):null,"aria-describedby":e?`editor-post-featured-image-${e}-describedby`:null},!!e&&h&&(0,a.createElement)(c.ResponsiveWrapper,{naturalWidth:h.width,naturalHeight:h.height,isInline:!0},(0,a.createElement)("img",{src:h.url,alt:h.alt_text})),p&&(0,a.createElement)(c.Spinner,null),!e&&!p&&w),!!e&&(0,a.createElement)(c.__experimentalHStack,{className:"editor-post-featured-image__actions"},(0,a.createElement)(c.Button,{className:"editor-post-featured-image__action",onClick:t,"aria-hidden":"true"},(0,n.__)("Replace")),(0,a.createElement)(c.Button,{className:"editor-post-featured-image__action",onClick:()=>{r(),_.current.focus()}},(0,n.__)("Remove"))),(0,a.createElement)(c.DropZone,{onFilesDrop:y})),value:e})))},b=({isCategorySelected:e,setUnsetCatgory:t})=>{const[r,i]=(0,a.useState)(!1),[o,s]=(0,a.useState)(""),[m,u]=(0,a.useState)(0),[_,p]=(0,a.useState)(!1),[g,q]=(0,a.useState)(!1),[E,f]=(0,a.useState)(qsmBlockData?.hierarchicalCategoryList),w=e=>{let t={};return e.forEach((e=>{if(t[e.id]=e,0{let t=[];return e.forEach((e=>{if(t.push(e.name),0n.map((n=>(0,a.createElement)("div",{key:n.id,className:"editor-post-taxonomies__hierarchical-terms-choice"},(0,a.createElement)(c.CheckboxControl,{label:n.name,checked:e(n.id),onChange:()=>t(n.id,x)}),!!n.children.length&&(0,a.createElement)("div",{className:"editor-post-taxonomies__hierarchical-terms-subchoices"},v(n.children)))));return(0,a.createElement)(c.PanelBody,{title:(0,n.__)("Categories","quiz-master-next"),initialOpen:!0},(0,a.createElement)("div",{className:"editor-post-taxonomies__hierarchical-terms-list",tabIndex:"0",role:"group","aria-label":(0,n.__)("Categories","quiz-master-next")},v(E)),(0,a.createElement)("div",{className:"qsm-ptb-1"},(0,a.createElement)(c.Button,{variant:"link",onClick:()=>i(!r)},b)),r&&(0,a.createElement)("form",{onSubmit:async e=>{e.preventDefault(),g||d(o)||_||(p(!0),l()({url:qsmBlockData.ajax_url,method:"POST",body:h({action:"save_new_category",name:o,parent:m})}).then((e=>{if(!d(e.term_id)){let a=e.term_id;l()({path:"/quiz-survey-master/v1/quiz/hierarchical-category-list",method:"POST"}).then((e=>{"success"==e.status&&(f(e.result),C(e.result),s(""),u(0),t(a,w(term.id)),p(!1))}))}})))}},(0,a.createElement)(c.Flex,{direction:"column",gap:"1"},(0,a.createElement)(c.TextControl,{__nextHasNoMarginBottom:!0,className:"editor-post-taxonomies__hierarchical-terms-input",label:(0,n.__)("Category Name","quiz-master-next"),value:o,onChange:e=>((e,t)=>{t=k(t),console.log("categories",t),t.includes(e)?q(e):(q(!1),s(e))})(e,E),required:!0}),0u(e),selectedId:m,tree:E}),(0,a.createElement)(c.FlexItem,null,(0,a.createElement)(c.Button,{variant:"secondary",type:"submit",className:"editor-post-taxonomies__hierarchical-terms-submit",disabled:g||_},b)),(0,a.createElement)(c.FlexItem,null,(0,a.createElement)("p",{className:"qsm-error-text"},!1!==g&&(0,n.__)("Category ","quiz-master-next")+g+(0,n.__)(" already exists.","quiz-master-next"))))))},y=()=>(0,a.createElement)(c.Icon,{icon:()=>(0,a.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24","aria-hidden":"true",focusable:"false"},(0,a.createElement)("path",{d:"M18 11.2h-5.2V6h-1.6v5.2H6v1.6h5.2V18h1.6v-5.2H18z"}))}),k=JSON.parse('{"u2":"qsm/quiz-question"}');(0,t.registerBlockType)(k.u2,{icon:()=>(0,a.createElement)(c.Icon,{icon:()=>(0,a.createElement)("svg",{width:"25",height:"25",viewBox:"0 0 25 25",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,a.createElement)("rect",{x:"0.102539",y:"0.101562",width:"24",height:"24",rx:"4.68852",fill:"#ADADAD"}),(0,a.createElement)("path",{d:"M17.0475 17.191C17.2367 17.3683 17.3313 17.5752 17.3313 17.8117C17.3313 18.06 17.2426 18.2787 17.0653 18.4679C16.8879 18.6453 16.6751 18.734 16.4268 18.734C16.1667 18.734 15.9538 18.6512 15.7883 18.4857L14.937 17.6521C13.8492 18.4088 12.5959 18.7872 11.177 18.7872C10.0301 18.7872 9.01325 18.533 8.12646 18.0245C7.2515 17.5161 6.57163 16.8126 6.08685 15.914C5.6139 15.0035 5.37742 13.9631 5.37742 12.7925C5.37742 11.5273 5.64937 10.41 6.19327 9.44044C6.74898 8.45907 7.48206 7.70234 8.3925 7.17027C9.31475 6.6382 10.308 6.37216 11.3721 6.37216C12.4481 6.37216 13.459 6.64411 14.4049 7.18801C15.3508 7.72008 16.1075 8.46498 16.6751 9.42271C17.2426 10.3804 17.5264 11.4505 17.5264 12.6329C17.5264 14.0636 17.1007 15.3287 16.2494 16.4283L17.0475 17.191ZM11.177 17.1732C12.0874 17.1732 12.9269 16.9249 13.6955 16.4283L12.5604 15.311C12.3949 15.1454 12.3121 14.9799 12.3121 14.8144C12.3121 14.6015 12.4244 14.3887 12.6491 14.1759C12.8855 13.9631 13.122 13.8566 13.3585 13.8566C13.5122 13.8566 13.6364 13.9039 13.7309 13.9985L14.9724 15.1868C15.4927 14.4183 15.7528 13.5492 15.7528 12.5797C15.7528 11.7284 15.5518 10.9539 15.1498 10.2563C14.7596 9.54686 14.2335 8.99114 13.5713 8.58913C12.9092 8.18712 12.1998 7.98611 11.443 7.98611C10.6981 7.98611 9.99462 8.18121 9.33249 8.57139C8.67036 8.94975 8.13828 9.49956 7.73627 10.2208C7.34609 10.9421 7.15099 11.7756 7.15099 12.7216C7.15099 13.6083 7.32244 14.3887 7.66533 15.0627C8.02005 15.7366 8.49891 16.2569 9.10192 16.6234C9.71676 16.99 10.4085 17.1732 11.177 17.1732Z",fill:"white"}))}),edit:function(e){var r;if("undefined"==typeof qsmBlockData)return null;const{className:m,attributes:u,setAttributes:E,isSelected:f,clientId:w,context:x}=e,k=(0,s.useSelect)((e=>f||e("core/block-editor").hasSelectedInnerBlock(w,!0))),v=x["quiz-master-next/quizID"],{quiz_name:B,post_id:z,rest_nonce:D}=x["quiz-master-next/quizAttr"],{createNotice:I}=(x["quiz-master-next/pageID"],(0,s.useDispatch)(o.store)),{getBlockRootClientId:N,getBlockIndex:S}=(0,s.useSelect)(i.store),{insertBlock:T}=(0,s.useDispatch)(i.store),{isChanged:A=!1,questionID:M,type:L,description:P,title:F,correctAnswerInfo:O,commentBox:H,category:Q,multicategories:R=[],hint:U,featureImageID:j,featureImageSrc:V,answers:W,answerEditor:Z,matchAnswer:$,required:G,settings:J={}}=u,[K,X]=(0,a.useState)(!d(O)),[Y,ee]=(0,a.useState)(!1),te="1"==qsmBlockData.is_pro_activated,ae=e=>14{let e=J?.file_upload_type||qsmBlockData.file_upload_type.default;return d(e)?[]:e.split(",")};(0,a.useEffect)((()=>{let e=!0;if(e&&(d(M)||"0"==M||!d(M)&&((e,t)=>{const a=(0,s.select)("core/block-editor").getClientIdsWithDescendants();return!d(a)&&a.some((a=>{const{questionID:n}=(0,s.select)("core/block-editor").getBlockAttributes(a);return t!==a&&n===e}))})(M,w))){let e=h({id:null,rest_nonce:D,quizID:v,quiz_name:B,postID:z,answerEditor:q(Z,"text"),type:q(L,"0"),name:p(q(P)),question_title:q(F),answerInfo:p(q(O)),comments:q(H,"1"),hint:q(U),category:q(Q),multicategories:[],required:q(G,0),answers:W,page:0,featureImageID:j,featureImageSrc:V,matchAnswer:null});l()({path:"/quiz-survey-master/v1/questions",method:"POST",body:e}).then((e=>{if("success"==e.status){let t=e.id;E({questionID:t})}})).catch((e=>{console.log("error",e),I("error",e.message,{isDismissible:!0,type:"snackbar"})}))}return()=>{e=!1}}),[]),(0,a.useEffect)((()=>{let e=!0;return e&&f&&!1===A&&E({isChanged:!0}),()=>{e=!1}}),[M,L,P,F,O,H,Q,R,U,j,V,W,Z,$,G,J]);const le=(0,i.useBlockProps)({className:k?" in-editing-mode is-highlighted ":""}),ie=(e,t)=>{let a=[];if(!d(t[e])&&"0"!=t[e].parent&&(e=t[e].parent,a.push(e),!d(t[e])&&"0"!=t[e].parent)){let n=ie(e,t);a=[...a,...n]}return _(a)},oe=["12","7","3","5","14"].includes(L)?(0,n.__)("Note: Add only correct answer options with their respective points score.","quiz-master-next"):"",se=()=>{if(d(e?.name))return console.log("block name not found"),!0;const a=(0,t.createBlock)(e.name);T(a,S(w)+1,N(w),!0)};return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(i.BlockControls,null,(0,a.createElement)(c.ToolbarGroup,null,(0,a.createElement)(c.ToolbarButton,{icon:"plus-alt2",label:(0,n.__)("Add New Question","quiz-master-next"),onClick:()=>se()}),(0,a.createElement)(c.ToolbarButton,{icon:"welcome-add-page",label:(0,n.__)("Add New Page","quiz-master-next"),onClick:()=>(()=>{const e=(0,t.createBlock)("qsm/quiz-page"),a=N(w),n=S(a)+1,r=N(a);T(e,n,r,!0)})()}))),Y&&(0,a.createElement)(c.Modal,{contentLabel:(0,n.__)("Use QSM Editor for Advanced Question","quiz-master-next"),className:"qsm-advance-q-modal",isDismissible:!1,size:"small",__experimentalHideHeader:!0},(0,a.createElement)("div",{className:"qsm-modal-body"},(0,a.createElement)("h3",{className:"qsm-title"},(0,a.createElement)(c.Icon,{icon:()=>(0,a.createElement)("svg",{width:"54",height:"54",viewBox:"0 0 54 54",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,a.createElement)("path",{d:"M27.1855 23.223V28.0626M15.1794 32.4196C14.0618 34.3554 15.4595 36.7739 17.6934 36.7739H36.6776C38.9102 36.7739 40.3079 34.3554 39.1916 32.4196L29.7008 15.9675C28.5832 14.0317 25.7878 14.0317 24.6702 15.9675L15.1794 32.4196ZM27.1855 31.9343H27.1945V31.9446H27.1855V31.9343Z",stroke:"#B45309",strokeWidth:"1.65929",strokeLinecap:"round",strokeLinejoin:"round"}))}),(0,a.createElement)("br",null),(0,n.__)("Use QSM editor for Advanced Question","quiz-master-next")),(0,a.createElement)("p",{className:"qsm-description"},(0,n.__)("Currently, the block editor doesn't support advanced question type. We are working on it. Alternatively, you can add advanced questions from your QSM's quiz editor.","quiz-master-next")),(0,a.createElement)("div",{className:"qsm-modal-btn-wrapper"},(0,a.createElement)(c.Button,{variant:"secondary",onClick:()=>ee(!1)},(0,n.__)("Cancel","quiz-master-next")),(0,a.createElement)(c.Button,{variant:"primary",onClick:()=>{}},(0,a.createElement)(c.ExternalLink,{href:qsmBlockData.quiz_settings_url+"&quiz_id="+v},(0,n.__)("Add Question from quiz editor","quiz-master-next")))))),ae(L)?(0,a.createElement)(a.Fragment,null,(0,a.createElement)(i.InspectorControls,null,(0,a.createElement)(c.PanelBody,{title:(0,n.__)("Question settings","quiz-master-next"),initialOpen:!0},(0,a.createElement)("h2",{className:"block-editor-block-card__title"},(0,n.__)("ID","quiz-master-next")+": "+M),(0,a.createElement)("h3",null,(0,n.__)("Advanced Question Type","quiz-master-next")))),(0,a.createElement)("div",{...le},(0,a.createElement)("h4",{className:"qsm-question-title qsm-error-text"},(0,n.__)("Advanced Question Type : ","quiz-master-next")+F),(0,a.createElement)("p",null,(0,n.__)("Edit question in QSM ","quiz-master-next"),(0,a.createElement)(c.ExternalLink,{href:qsmBlockData.quiz_settings_url+"&quiz_id="+v},(0,n.__)("editor","quiz-master-next"))))):(0,a.createElement)(a.Fragment,null,(0,a.createElement)(i.InspectorControls,null,(0,a.createElement)(c.PanelBody,{title:(0,n.__)("Question settings","quiz-master-next"),initialOpen:!0},(0,a.createElement)("h2",{className:"block-editor-block-card__title"},(0,n.__)("ID","quiz-master-next")+": "+M),(0,a.createElement)(c.SelectControl,{label:qsmBlockData.question_type.label,value:L||qsmBlockData.question_type.default,onChange:e=>(e=>{if(d(MicroModal)||te||!["15","16","17"].includes(e))te&&ae(e)?ee(!0):E({type:e});else{let e=document.getElementById("modal-advanced-question-type");d(e)||MicroModal.show("modal-advanced-question-type")}})(e),help:d(qsmBlockData.question_type_description[L])?"":qsmBlockData.question_type_description[L]+" "+oe,__nextHasNoMarginBottom:!0},!d(qsmBlockData.question_type.options)&&qsmBlockData.question_type.options.map((e=>(0,a.createElement)("optgroup",{label:e.category,key:"qtypes"+e.category},e.types.map((e=>(0,a.createElement)("option",{value:e.slug,key:"qtype"+e.slug},e.name))))))),["0","4","1","10","13"].includes(L)&&(0,a.createElement)(c.SelectControl,{label:qsmBlockData.answerEditor.label,value:Z||qsmBlockData.answerEditor.default,options:qsmBlockData.answerEditor.options,onChange:e=>E({answerEditor:e}),__nextHasNoMarginBottom:!0}),(0,a.createElement)(c.ToggleControl,{label:(0,n.__)("Required","quiz-master-next"),checked:!d(G)&&"1"==G,onChange:()=>E({required:d(G)||"1"!=G?1:0})}),(0,a.createElement)(c.ToggleControl,{label:(0,n.__)("Show Correct Answer Info","quiz-master-next"),checked:K,onChange:()=>X(!K)})),"11"==L&&(0,a.createElement)(c.PanelBody,{title:(0,n.__)("File Settings","quiz-master-next"),initialOpen:!1},(0,a.createElement)(c.TextControl,{type:"number",label:qsmBlockData.file_upload_limit.heading,value:null!==(r=J?.file_upload_limit)&&void 0!==r?r:qsmBlockData.file_upload_limit.default,onChange:e=>E({settings:{...J,file_upload_limit:e}})}),(0,a.createElement)("label",{className:"qsm-inspector-label"},qsmBlockData.file_upload_type.heading),Object.keys(qsmBlockData.file_upload_type.options).map((e=>{return(0,a.createElement)(c.CheckboxControl,{key:"filetype-"+e,label:ne[e],checked:(t=e,re().includes(t)),onChange:()=>(e=>{let t=re();t.includes(e)?t=t.filter((t=>t!=e)):t.push(e),t=t.join(","),E({settings:{...J,file_upload_type:t}})})(e)});var t}))),(0,a.createElement)(b,{isCategorySelected:e=>R.includes(e),setUnsetCatgory:(e,t)=>{let a=d(R)||0===R.length?d(Q)?[]:[Q]:R;if(a.includes(e))a=a.filter((t=>t!=e)),a.forEach((n=>{ie(n,t).includes(e)&&(a=a.filter((e=>e!=n)))}));else{a.push(e);let n=ie(e,t);a=[...a,...n]}a=_(a),E({category:"",multicategories:[...a]})}}),(0,a.createElement)(c.PanelBody,{title:(0,n.__)("Hint","quiz-master-next"),initialOpen:!1},(0,a.createElement)(c.TextControl,{label:"",value:U,onChange:e=>E({hint:g(e)})})),(0,a.createElement)(c.PanelBody,{title:qsmBlockData.commentBox.heading,initialOpen:!1},(0,a.createElement)(c.SelectControl,{label:qsmBlockData.commentBox.label,value:H||qsmBlockData.commentBox.default,options:qsmBlockData.commentBox.options,onChange:e=>E({commentBox:e}),__nextHasNoMarginBottom:!0})),(0,a.createElement)(c.PanelBody,{title:(0,n.__)("Featured image","quiz-master-next"),initialOpen:!0},(0,a.createElement)(C,{featureImageID:j,onUpdateImage:e=>{E({featureImageID:e.id,featureImageSrc:e.url})},onRemoveImage:e=>{E({featureImageID:void 0,featureImageSrc:void 0})}}))),(0,a.createElement)("div",{...le},(0,a.createElement)(i.RichText,{tagName:"h4",title:(0,n.__)("Question title","quiz-master-next"),"aria-label":(0,n.__)("Question title","quiz-master-next"),placeholder:(0,n.__)("Type your question here","quiz-master-next"),value:F,onChange:e=>E({title:g(e)}),allowedFormats:[],withoutInteractiveFormatting:!0,className:"qsm-question-title"}),k&&(0,a.createElement)(a.Fragment,null,(0,a.createElement)(i.RichText,{tagName:"p",title:(0,n.__)("Question description","quiz-master-next"),"aria-label":(0,n.__)("Question description","quiz-master-next"),placeholder:(0,n.__)("Description goes here... (optional)","quiz-master-next"),value:p(P),onChange:e=>E({description:e}),className:"qsm-question-description",__unstableEmbedURLOnPaste:!0,__unstableAllowPrefixTransformations:!0}),!["8","11","6","9"].includes(L)&&(0,a.createElement)(i.InnerBlocks,{allowedBlocks:["qsm/quiz-answer-option"],template:[["qsm/quiz-answer-option",{optionID:"0"}],["qsm/quiz-answer-option",{optionID:"1"}]]}),K&&(0,a.createElement)(i.RichText,{tagName:"p",title:(0,n.__)("Correct Answer Info","quiz-master-next"),"aria-label":(0,n.__)("Correct Answer Info","quiz-master-next"),placeholder:(0,n.__)("Correct answer info goes here","quiz-master-next"),value:p(O),onChange:e=>E({correctAnswerInfo:e}),className:"qsm-question-correct-answer-info",__unstableEmbedURLOnPaste:!0,__unstableAllowPrefixTransformations:!0}),k&&(0,a.createElement)("div",{className:"block-editor-block-list__insertion-point-inserter qsm-add-new-ques-wrapper"},(0,a.createElement)(c.Button,{icon:y,label:(0,n.__)("Add New Question","quiz-master-next"),tooltipPosition:"bottom",onClick:()=>se(),variant:"secondary",className:"add-new-question-btn block-editor-inserter__toggle"}))))))},__experimentalLabel(e,{context:t}){const{title:a}=e,n=e?.metadata?.name;if("list-view"===t&&(n||a?.length>0))return n||a}})})(); \ No newline at end of file diff --git a/blocks/src/block.json b/blocks/src/block.json index 448069156..763d22a52 100644 --- a/blocks/src/block.json +++ b/blocks/src/block.json @@ -24,6 +24,7 @@ "quiz-master-next/quizID": "quizID", "quiz-master-next/quizAttr": "quizAttr" }, + "usesContext": [ "postId", "postStatus" ], "example": {}, "supports": { "html": false diff --git a/blocks/src/component/icon.js b/blocks/src/component/icon.js index 6f2b2a344..d588a6d9c 100644 --- a/blocks/src/component/icon.js +++ b/blocks/src/component/icon.js @@ -50,7 +50,7 @@ export const warningIcon = () => ( export const plusIcon = () => ( ( - + ) } /> ); \ No newline at end of file diff --git a/blocks/src/edit.js b/blocks/src/edit.js index cfa74765a..f782a0564 100644 --- a/blocks/src/edit.js +++ b/blocks/src/edit.js @@ -32,7 +32,9 @@ export default function Edit( props ) { return null; } - const { className, attributes, setAttributes, isSelected, clientId } = props; + const { className, attributes, setAttributes, isSelected, clientId, context } = props; + + const page_post_id = context['postId']; const { createNotice } = useDispatch( noticesStore ); //quiz attribute const globalQuizsetting = qsmBlockData.globalQuizsetting; @@ -67,6 +69,10 @@ export default function Edit( props ) { return isSavingPost() && ! isAutosavingPost(); }, [] ); + const editorSelectors = useSelect( ( select ) => { + return select( 'core/editor' ); + }, [] ); + const { getBlock } = useSelect( blockEditorStore ); /**Initialize block from server */ @@ -478,11 +484,22 @@ export default function Edit( props ) { let quizData = getQuizDataToSave(); //save quiz status setSaveQuiz( true ); + + //post status + let post_status = 'publish'; + if ( ! qsmIsEmpty( editorSelectors ) ) { + post_status = editorSelectors.getEditedPostAttribute( 'status' ); + } + if ( qsmIsEmpty( post_status ) ) { + post_status = 'publish'; + } quizData = qsmFormData({ 'save_entire_quiz': '1', 'quizData': JSON.stringify( quizData ), 'qsm_block_quiz_nonce' : qsmBlockData.nonce, + 'page_post_id' : qsmIsEmpty( page_post_id ) ? 0: page_post_id , + 'post_status' : post_status, "nonce": qsmBlockData.saveNonce,//save pages nonce }); diff --git a/blocks/src/editor.scss b/blocks/src/editor.scss index 4f460ebf8..cd3844700 100644 --- a/blocks/src/editor.scss +++ b/blocks/src/editor.scss @@ -98,12 +98,20 @@ /*Question options*/ .wp-block-qsm-quiz-answer-option{ + padding-left: 0.8rem; + &.block-editor-block-list__block.is-highlighted:after{ + box-shadow: none; + border: 2px dotted #c3c5cc; + } input:disabled{ border-color: inherit; } input[type="radio"]:disabled, input[type="checkbox"]:disabled{ opacity: 1; } + .qsm-question-answer-option.rich-text{ + margin-left: 5px; + } } .qsm-question-answer-option{ color: $qsm_primary_color; diff --git a/blocks/src/index.js b/blocks/src/index.js index dd01cde3b..b3ee36cf2 100644 --- a/blocks/src/index.js +++ b/blocks/src/index.js @@ -13,27 +13,4 @@ registerBlockType( metadata.name, { */ edit: Edit, save: save, -} ); - - -const withMyPluginControls = createHigherOrderComponent( ( BlockEdit ) => { - return ( props ) => { - const { name, className, attributes, setAttributes, isSelected, clientId, context } = props; - if ( 'core/group' !== name ) { - return ; - } - - console.log("props",props); - return ( - <> - - - ); - }; -}, 'withMyPluginControls' ); - -wp.hooks.addFilter( - 'editor.BlockEdit', - 'my-plugin/with-inspector-controls', - withMyPluginControls -); \ No newline at end of file +} ); \ No newline at end of file