Files
2026-04-28 15:13:50 +02:00

2 lines
4.9 KiB
JavaScript

import{aq as m,f,i as w,j as p,U as l,a0 as c,R as d,ae as P,M as v,an as E}from"./js/vendor-vue-ui.de3ab35f.js";import{l as $}from"./js/index.faac30d2.js";import{l as b}from"./js/index.fae6edc8.js";import{l as B}from"./js/index.0d80c2c2.js";import{aO as k,u as A,i as C,L as N,M as L,l as T,ai as q,o as I}from"./js/app-core.ae890a3f.js";import{g as M,a as U,b as V,t as O,c as j}from"./js/helpers.f1b27f79.js";import{C as F}from"./js/Tooltip.ae7a1028.js";import{S as H}from"./js/Trash.d35f8063.js";import{_ as x}from"./js/_plugin-vue_export-helper.eefbdd86.js";import{x as Q}from"./js/vendor-lodash.8e35bd59.js";import{a as u,_ as y}from"./js/vendor-other.7b559694.js";import"./js/Button.a549093d.js";import"./js/Input.8918dec2.js";import"./js/Index.52399193.js";import"./js/Close.098d4b76.js";import"./js/Pencil.405b16d2.js";import"./js/Select.32af2da8.js";import"./js/Caret.a017b70a.js";import"./js/Toggle.26ac9b1a.js";const h="aioseo-pro",R={setup(){return{postEditorStore:A()}},components:{CoreTooltip:F,SvgCircleQuestionMark:H},props:{taxonomy:String},data(){return{term:null,terms:[],selectedTerms:[]}},watch:{terms(e){if(!this.term&&e&&this.postEditorStore.currentPost.primary_term[this.taxonomy]){const t=e.find(o=>o.value===this.postEditorStore.currentPost.primary_term[this.taxonomy]);this.setPrimaryTerm(t)}},selectedTerms(e,t){if(t.length<e.length){const o=e.filter(r=>!t.includes(r))[0];this.terms.some(r=>r.value===o)||this.updateTerms()}this.term&&this.term.value&&!e.includes(this.term.value)&&this.setPrimaryTerm(null)}},computed:{taxonomyName(){return V(this.taxonomy).singular},toolTipText(){return u(y("%1$s allows you to choose a primary %2$s for your posts. This feature works hand in hand with our powerful Breadcrumbs template to give you full navigational control to help improve your search rankings.",h),"AIOSEO Pro",this.taxonomyName)},labelString(){return u(y("Select Primary %1$s",h),this.taxonomyName)},options(){return this.terms.filter(e=>this.selectedTerms.includes(e.value))}},methods:{setPrimaryTerm(e){this.term=e,window.aioseoBus.$emit("standalone-update-post",{primary_term:Q({...this.postEditorStore.currentPost.primary_term,[this.taxonomy]:e&&e.value?e.value:null})})},updateTerms(){U(this.taxonomy).then(e=>{this.terms=[],e.forEach(t=>{this.terms.push({value:t.id,label:k(t.name)})})})},updateSelectedTerms(){this.selectedTerms=M(this.taxonomy)}},mounted(){this.updateTerms(),this.updateSelectedTerms(),window.aioseoBus.$on("updateSelectedTerms",this.updateSelectedTerms)},beforeUnmount(){window.aioseoBus.$off("updateSelectedTerms",this.updateSelectedTerms)}},z={key:0,class:"aioseo-primary-term-select"},D={class:"aioseo-primary-term-select__title"},G={class:"aioseo-primary-term-select__title-text"};function J(e,t,o,r,a,s){const i=m("svg-circle-question-mark"),n=m("core-tooltip"),g=m("base-select");return 1<a.selectedTerms.length?(f(),w("div",z,[p("div",D,[p("span",G,l(s.labelString),1),c(n,{offset:"-200px,0"},{tooltip:d(()=>[P(l(s.toolTipText),1)]),default:d(()=>[c(i)]),_:1})]),c(g,{size:"medium",options:s.options,modelValue:a.term,"onUpdate:modelValue":t[0]||(t[0]=S=>s.setPrimaryTerm(S))},null,8,["options","modelValue"])])):v("",!0)}const K=x(R,[["render",J]]),W={components:{PrimaryTerm:K},props:{taxonomy:String}},X={class:"aioseo-app aioseo-primary-term"};function Y(e,t,o,r,a,s){const i=m("primary-term");return f(),w("div",X,[c(i,{taxonomy:o.taxonomy},null,8,["taxonomy"])])}const Z=x(W,[["render",Y]]);if(C()&&window.wp){const{createElement:e,Fragment:t}=window.wp.element,{addFilter:o}=window.wp.hooks,{createHigherOrderComponent:r}=window.wp.compose,{subscribe:a}=window.wp.data;o("editor.PostTaxonomyType","aioseo/primary-term",r(s=>i=>{const{slug:n}=i;return O(n)?e(t,{},e(s,i),e("div",{id:`aioseo-primary-term-${n}`},e("div",{className:"aioseo-primary-term-app",taxonomy:n}))):e(s,i)},"withInspectorControls")),a(()=>{window.aioseoBus.$emit("updateSelectedTerms")})}(N()||L())&&(T(),j().forEach(e=>{const t=document.getElementById(`${e.name}div`)?.querySelector(".inside");if(!t)return;const o=document.createElement("div");o.setAttribute("id",`aioseo-primary-term-${e.name}`),o.setAttribute("class","aioseo-primary-term-app"),o.setAttribute("taxonomy",e.name),t.append(o),(function(r){r(`#${e.name}checklist`).on("change",'input[type="checkbox"]',()=>{window.aioseoBus.$emit("updateSelectedTerms")}),r(`#${e.name}checklist`).on("wpListAddEnd",()=>{window.aioseoBus.$emit("updateSelectedTerms")})})(window.jQuery)}));const _=e=>{if(!e)return;const t=e.getAttribute("taxonomy");let o=E({...Z,name:"Standalone/PrimaryTerm"},{taxonomy:t});o=$(o),o=b(o),o=B(o),T(o),o.mount(e)};if(q()&&window.aioseo&&window.aioseo.currentPost&&window.aioseo.currentPost.context==="post"){const e=document.getElementsByClassName("aioseo-primary-term-app");Array.prototype.forEach.call(e,t=>_(t)),I(".aioseo-primary-term-app","aioseoPrimaryTerm"),document.addEventListener("animationstart",function(t){t.animationName==="aioseoPrimaryTerm"&&_(t.target)},{passive:!0})}