nextcloud/dist/SystemTagPicker-L1La5tAP.chunk.mjs
Ferdinand Thiessen b4b5986be9 chore: compile assets
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2026-01-27 23:52:40 +01:00

2 lines
15 KiB
JavaScript

import{e as E,d as q,a as J}from"./index-6_gsQFyp.chunk.mjs";import{a as _}from"./index-JpgrUA2Z-D4yQFKNw.chunk.mjs";import{a as A,l as K}from"./index-xFugdZPW.chunk.mjs";import{t as y,g as S,e as Q,p as W,b as k}from"./translation-DoG5ZELJ-2ffMJaM4.chunk.mjs";import{c as X}from"./logger-D3RVzcfQ-iUjwSNGe.chunk.mjs";import{N as Y}from"./NcCheckboxRadioSwitch-BCSKF7Tk-BDM2s1GW.chunk.mjs";import{N as tt}from"./NcChip-D8tGFzRl-BmzaEo05.chunk.mjs";import{N as et}from"./NcColorPicker-Kc0JqRtp-DZI9oazy.chunk.mjs";import{N as st}from"./index-Dzo4H_NA.chunk.mjs";import{P as at,N as it}from"./Plus-BVjFGi0H.chunk.mjs";import{N as ot}from"./mdi-kAZc0JKn.chunk.mjs";import{N as lt}from"./NcNoteCard-CVhtNL04-CdF6Qoal.chunk.mjs";import{_ as nt}from"./TrashCanOutline-DKx7CxBb.chunk.mjs";import{j as d,o as a,k as g,l as C,t as p,z as w,b as rt,f as c,c as h,w as m,E as ct,F as R,e as u,C as dt,N as mt,g as N,G as gt,n as ht}from"./runtime-dom.esm-bundler-DSTOTAEf.chunk.mjs";import{P as pt}from"./PencilOutline-BPy7Lagu.chunk.mjs";import{l as L,g as O,s as z,e as I,h as x,c as ut,i as ft,f as yt,u as Ct}from"./api-CjYbYSSm.chunk.mjs";import{e as bt,i as kt,a as Nt}from"./systemtags-init.mjs";import"./createElementId-DhjFt1I9-Bjk2333q.chunk.mjs";import"./colors-Go3zmZRD-Bml2X1sg.chunk.mjs";import"./NcInputField-Bwsh2aHY-Bf_22pmD.chunk.mjs";import"./index-D9L8KHF3.chunk.mjs";import"./string_decoder-BO00msnV.chunk.mjs";import"./index-Buqk-yLP.chunk.mjs";import"./NcPasswordField-djttkA5Q-DvTgf1Bu.chunk.mjs";import"./dav-B62B0Btx.chunk.mjs";import"./index-BlJ76-SL.chunk.mjs";import"./folder-CeyZUHai-CVGj8rKf.chunk.mjs";import"./index-CE6ly_uD.chunk.mjs";const At={name:"CheckCircleIcon",emits:["click"],props:{title:{type:String},fillColor:{type:String,default:"currentColor"},size:{type:Number,default:24}}},vt=["aria-hidden","aria-label"],wt=["fill","width","height"],Tt={d:"M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M10 17L5 12L6.41 10.59L10 14.17L17.59 6.58L19 8L10 17Z"},_t={key:0};function St(t,s,e,o,l,n){return a(),d("span",w(t.$attrs,{"aria-hidden":e.title?null:"true","aria-label":e.title,class:"material-design-icon check-circle-icon",role:"img",onClick:s[0]||(s[0]=i=>t.$emit("click",i))}),[(a(),d("svg",{fill:e.fillColor,class:"material-design-icon__svg",width:e.size,height:e.size,viewBox:"0 0 24 24"},[g("path",Tt,[e.title?(a(),d("title",_t,p(e.title),1)):C("",!0)])],8,wt))],16,vt)}const Lt=A(At,[["render",St]]),It={name:"CircleIcon",emits:["click"],props:{title:{type:String},fillColor:{type:String,default:"currentColor"},size:{type:Number,default:24}}},$t=["aria-hidden","aria-label"],Et=["fill","width","height"],Rt={d:"M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"},Ot={key:0};function zt(t,s,e,o,l,n){return a(),d("span",w(t.$attrs,{"aria-hidden":e.title?null:"true","aria-label":e.title,class:"material-design-icon circle-icon",role:"img",onClick:s[0]||(s[0]=i=>t.$emit("click",i))}),[(a(),d("svg",{fill:e.fillColor,class:"material-design-icon__svg",width:e.size,height:e.size,viewBox:"0 0 24 24"},[g("path",Rt,[e.title?(a(),d("title",Ot,p(e.title),1)):C("",!0)])],8,Et))],16,$t)}const xt=A(It,[["render",zt]]),Pt={name:"CircleOutlineIcon",emits:["click"],props:{title:{type:String},fillColor:{type:String,default:"currentColor"},size:{type:Number,default:24}}},Mt=["aria-hidden","aria-label"],Vt=["fill","width","height"],Bt={d:"M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"},Ut={key:0};function Gt(t,s,e,o,l,n){return a(),d("span",w(t.$attrs,{"aria-hidden":e.title?null:"true","aria-label":e.title,class:"material-design-icon circle-outline-icon",role:"img",onClick:s[0]||(s[0]=i=>t.$emit("click",i))}),[(a(),d("svg",{fill:e.fillColor,class:"material-design-icon__svg",width:e.size,height:e.size,viewBox:"0 0 24 24"},[g("path",Bt,[e.title?(a(),d("title",Ut,p(e.title),1)):C("",!0)])],8,Vt))],16,Mt)}const Dt=A(Pt,[["render",Gt]]),jt={name:"TagOutlineIcon",emits:["click"],props:{title:{type:String},fillColor:{type:String,default:"currentColor"},size:{type:Number,default:24}}},Ft=["aria-hidden","aria-label"],Ht=["fill","width","height"],Zt={d:"M21.41 11.58L12.41 2.58A2 2 0 0 0 11 2H4A2 2 0 0 0 2 4V11A2 2 0 0 0 2.59 12.42L11.59 21.42A2 2 0 0 0 13 22A2 2 0 0 0 14.41 21.41L21.41 14.41A2 2 0 0 0 22 13A2 2 0 0 0 21.41 11.58M13 20L4 11V4H11L20 13M6.5 5A1.5 1.5 0 1 1 5 6.5A1.5 1.5 0 0 1 6.5 5Z"},qt={key:0};function Jt(t,s,e,o,l,n){return a(),d("span",w(t.$attrs,{"aria-hidden":e.title?null:"true","aria-label":e.title,class:"material-design-icon tag-outline-icon",role:"img",onClick:s[0]||(s[0]=i=>t.$emit("click",i))}),[(a(),d("svg",{fill:e.fillColor,class:"material-design-icon__svg",width:e.size,height:e.size,viewBox:"0 0 24 24"},[g("path",Zt,[e.title?(a(),d("title",qt,p(e.title),1)):C("",!0)])],8,Ht))],16,Ft)}const Kt=A(jt,[["render",Jt]]),Qt=q(Ct,500),Wt=getComputedStyle(document.body).getPropertyValue("--color-main-background").replace("#","")||(Nt()?"000000":"ffffff");var P=(t=>(t.BASE="base",t.LOADING="loading",t.CREATING_TAG="creating-tag",t.DONE="done",t))(P||{});const Xt=K("systemtags","restrictSystemTagsCreationToAdmin",!1),Yt=rt({name:"SystemTagPicker",components:{CheckIcon:Lt,CircleIcon:xt,CircleOutlineIcon:Dt,NcButton:X,NcCheckboxRadioSwitch:Y,NcChip:tt,NcColorPicker:et,NcDialog:st,NcEmptyContent:it,NcLoadingIcon:ot,NcNoteCard:lt,NcTextField:nt,PencilIcon:pt,PlusIcon:at,TagIcon:Kt},props:{nodes:{type:Array,required:!0}},emits:{close(t){return t===null||typeof t=="boolean"}},setup(){return{emit:E,Status:P,t:y,canEditOrCreateTag:!Xt||J()?.isAdmin}},data(){return{status:"base",opened:!0,openedPicker:!1,input:"",tags:[],tagList:{},toAdd:[],toRemove:[]}},computed:{sortedTags(){return[...this.tags].sort((t,s)=>t.displayName.localeCompare(s.displayName,S(),{ignorePunctuation:!0}))},filteredTags(){return this.input.trim()===""?this.sortedTags:this.sortedTags.filter(t=>t.displayName.normalize().toLowerCase().includes(this.input.normalize().toLowerCase()))},hasChanges(){return this.toAdd.length>0||this.toRemove.length>0},canCreateTag(){return this.input.trim()!==""&&!this.tags.some(t=>t.displayName.trim().toLocaleLowerCase()===this.input.trim().toLocaleLowerCase())},statusMessage(){if(this.toAdd.length===0&&this.toRemove.length===0)return"";if(this.toAdd.length===1&&this.toRemove.length===1)return k("systemtags","{tag1} will be set and {tag2} will be removed from 1 file.","{tag1} will be set and {tag2} will be removed from {count} files.",this.nodes.length,{tag1:this.formatTagChip(this.toAdd[0]),tag2:this.formatTagChip(this.toRemove[0]),count:this.nodes.length},{escape:!1});const t=this.toAdd.map(this.formatTagChip),s=t.pop(),e=this.toRemove.map(this.formatTagChip),o=e.pop(),l=k("systemtags","{tag} will be set to 1 file.","{tag} will be set to {count} files.",this.nodes.length,{tag:s,count:this.nodes.length},{escape:!1}),n=k("systemtags","{tag} will be removed from 1 file.","{tag} will be removed from {count} files.",this.nodes.length,{tag:o,count:this.nodes.length},{escape:!1}),i=k("systemtags","{tags} and {lastTag} will be set to 1 file.","{tags} and {lastTag} will be set to {count} files.",this.nodes.length,{tags:t.join(", "),lastTag:s,count:this.nodes.length},{escape:!1}),f=k("systemtags","{tags} and {lastTag} will be removed from 1 file.","{tags} and {lastTag} will be removed from {count} files.",this.nodes.length,{tags:e.join(", "),lastTag:o,count:this.nodes.length},{escape:!1});return this.toAdd.length===1&&this.toRemove.length===0?l:this.toAdd.length===0&&this.toRemove.length===1?n:this.toAdd.length>1&&this.toRemove.length===0?i:this.toAdd.length===0&&this.toRemove.length>1?f:this.toAdd.length>1&&this.toRemove.length===1?`${i} ${n}`:this.toAdd.length===1&&this.toRemove.length>1?`${l} ${f}`:`${i} ${f}`}},beforeMount(){yt().then(t=>{this.tags=t}),this.tagList=this.nodes.reduce((t,s)=>((I(s)||[]).forEach(e=>{t[e]=(t[e]||0)+1}),t),{}),this.canEditOrCreateTag||L.debug("System tag creation is restricted to admins and the current user is not an admin")},methods:{formatTagChip(t){const s=this.$refs.chip.$el.cloneNode(!0);if(t.color){const e=this.tagListStyle(t);Object.entries(e).forEach(([o,l])=>{s.style.setProperty(o,l)})}return s.outerHTML.replace("%s",Q(W.sanitize(t.displayName)))},formatTagName(t){return t.userVisible?t.userAssignable?t.displayName:y("systemtags","{displayName} (restricted)",{displayName:t.displayName}):y("systemtags","{displayName} (hidden)",{displayName:t.displayName})},onColorChange(t,s){t.color=s.replace("#",""),Qt(t)},isChecked(t){return t.displayName in this.tagList&&this.tagList[t.displayName]===this.nodes.length},isIndeterminate(t){return t.displayName in this.tagList&&this.tagList[t.displayName]!==0&&this.tagList[t.displayName]!==this.nodes.length},onCheckUpdate(t,s){s?(this.toAdd.push(t),this.toRemove=this.toRemove.filter(e=>e.id!==t.id),this.tagList[t.displayName]=this.nodes.length):(this.toRemove.push(t),this.toAdd=this.toAdd.filter(e=>e.id!==t.id),this.tagList[t.displayName]=0)},async onNewTag(){if(!this.canEditOrCreateTag){_(y("systemtags","Only admins can create new tags"));return}this.status="creating-tag";try{const t={displayName:this.input.trim(),userAssignable:!0,userVisible:!0,canAssign:!0},s=await ut(t),e=await ft(s);this.tags.push(e),this.input="",this.onCheckUpdate(e,!0),await this.$nextTick(),Array.isArray(this.$refs.tags)&&this.$refs.tags.find(o=>o.dataset.cySystemtagsPickerTag===s.toString())?.scrollIntoView({behavior:"instant",block:"center",inline:"center"})}catch(t){_(t?.message||y("systemtags","Failed to create tag"))}finally{this.status="base"}},async onSubmit(){this.status="loading",L.debug("Applying tags",{toAdd:this.toAdd,toRemove:this.toRemove});try{for(const s of this.toAdd){const{etag:e,objects:o}=await O(s,"files"),l=[...new Set([...o.map(n=>n.id).filter(Boolean),...this.nodes.map(n=>n.fileid).filter(Boolean)])];await z(s,"files",l.map(n=>({id:n,type:"files"})),e)}for(const s of this.toRemove){const{etag:e,objects:o}=await O(s,"files"),l=new Set(this.nodes.map(i=>i.fileid)),n=o.map(i=>i.id).filter((i,f,T)=>!l.has(i)&&T.indexOf(i)===f);await z(s,"files",n.map(i=>({id:i,type:"files"})),e)}}catch(s){L.error("Failed to apply tags",{error:s}),_(y("systemtags","Failed to apply tags changes")),this.status="base";return}const t=[];this.toAdd.forEach(s=>{this.nodes.forEach(e=>{const o=[...I(e)||[],s.displayName].sort((l,n)=>l.localeCompare(n,S(),{ignorePunctuation:!0}));x(e,o),t.push(e)})}),this.toRemove.forEach(s=>{this.nodes.forEach(e=>{const o=[...I(e)||[]].filter(l=>l!==s.displayName).sort((l,n)=>l.localeCompare(n,S(),{ignorePunctuation:!0}));x(e,o),t.push(e)})}),t.forEach(s=>E("systemtags:node:updated",s)),this.status="done",setTimeout(()=>{this.opened=!1,this.$emit("close",!0)},2e3)},onCancel(){this.opened=!1,this.$emit("close",null)},tagListStyle(t){if(!t.color)return{"--color-circle-icon":"var(--color-text-maxcontrast)"};const s=bt(`#${t.color}`,`#${Wt}`),e=kt(s)?"#000000":"#ffffff";return{"--color-circle-icon":"var(--color-primary-element)","--color-primary":s,"--color-primary-text":e,"--color-primary-element":s,"--color-primary-element-text":e}}}}),te={class:"systemtags-picker__input"},ee={class:"systemtags-picker__tags","data-cy-systemtags-picker-tags":""},se=["data-cy-systemtags-picker-tag"],ae={class:"systemtags-picker__tag-create-subline"},ie={class:"systemtags-picker__note"},oe=["innerHTML"];function le(t,s,e,o,l,n){const i=c("NcLoadingIcon"),f=c("CheckIcon"),T=c("NcEmptyContent"),M=c("TagIcon"),V=c("NcTextField"),B=c("NcCheckboxRadioSwitch"),U=c("CircleIcon"),G=c("CircleOutlineIcon"),D=c("PencilIcon"),v=c("NcButton"),j=c("NcColorPicker"),F=c("PlusIcon"),$=c("NcNoteCard"),H=c("NcChip"),Z=c("NcDialog");return a(),h(Z,{"data-cy-systemtags-picker":"",noClose:t.status===t.Status.LOADING,name:t.t("systemtags","Manage tags"),open:t.opened,class:ht(["systemtags-picker--"+t.status,"systemtags-picker"]),closeOnClickOutside:"",outTransition:"","onUpdate:open":t.onCancel},{actions:m(()=>[u(v,{disabled:t.status!==t.Status.BASE,variant:"tertiary","data-cy-systemtags-picker-button-cancel":"",onClick:t.onCancel},{default:m(()=>[N(p(t.t("systemtags","Cancel")),1)]),_:1},8,["disabled","onClick"]),u(v,{disabled:!t.hasChanges||t.status!==t.Status.BASE,"data-cy-systemtags-picker-button-submit":"",onClick:t.onSubmit},{default:m(()=>[N(p(t.t("systemtags","Apply")),1)]),_:1},8,["disabled","onClick"])]),default:m(()=>[t.status===t.Status.LOADING||t.status===t.Status.DONE?(a(),h(T,{key:0,name:t.t("systemtags","Applying tags changes…")},{icon:m(()=>[t.status===t.Status.LOADING?(a(),h(i,{key:0})):(a(),h(f,{key:1,fillColor:"var(--color-border-success)"}))]),_:1},8,["name"])):(a(),d(R,{key:1},[g("div",te,[u(V,{modelValue:t.input,"onUpdate:modelValue":s[0]||(s[0]=r=>t.input=r),label:t.canEditOrCreateTag?t.t("systemtags","Search or create tag"):t.t("systemtags","Search tag"),"data-cy-systemtags-picker-input":""},{default:m(()=>[u(M,{size:20})]),_:1},8,["modelValue","label"])]),g("ul",ee,[(a(!0),d(R,null,dt(t.filteredTags,r=>(a(),d("li",{key:r.id,ref_for:!0,ref:"tags","data-cy-systemtags-picker-tag":r.id,style:mt(t.tagListStyle(r)),class:"systemtags-picker__tag"},[u(B,{modelValue:t.isChecked(r),disabled:!r.canAssign,indeterminate:t.isIndeterminate(r),label:r.displayName,class:"systemtags-picker__tag-checkbox","onUpdate:modelValue":b=>t.onCheckUpdate(r,b)},{default:m(()=>[N(p(t.formatTagName(r)),1)]),_:2},1032,["modelValue","disabled","indeterminate","label","onUpdate:modelValue"]),t.canEditOrCreateTag?(a(),h(j,{key:0,"data-cy-systemtags-picker-tag-color":r.id,modelValue:`#${r.color||"000000"}`,shown:t.openedPicker===r.id,class:"systemtags-picker__tag-color","onUpdate:shown":b=>t.openedPicker=b?r.id:!1,onSubmit:b=>t.onColorChange(r,b)},{default:m(()=>[u(v,{"aria-label":t.t("systemtags","Change tag color"),variant:"tertiary"},{icon:m(()=>[r.color?(a(),h(U,{key:0,size:24,fillColor:"var(--color-circle-icon)",class:"button-color-circle"})):(a(),h(G,{key:1,size:24,fillColor:"var(--color-circle-icon)",class:"button-color-empty"})),u(D,{class:"button-color-pencil"})]),_:2},1032,["aria-label"])]),_:2},1032,["data-cy-systemtags-picker-tag-color","modelValue","shown","onUpdate:shown","onSubmit"])):C("",!0)],12,se))),128)),g("li",null,[t.canEditOrCreateTag&&t.canCreateTag?(a(),h(v,{key:0,disabled:t.status===t.Status.CREATING_TAG,alignment:"start",class:"systemtags-picker__tag-create",type:"submit",variant:"tertiary","data-cy-systemtags-picker-button-create":"",onClick:t.onNewTag},{icon:m(()=>[u(F)]),default:m(()=>[N(p(t.input.trim()),1),s[1]||(s[1]=g("br",null,null,-1)),g("span",ae,p(t.t("systemtags","Create new tag")),1)]),_:1},8,["disabled","onClick"])):C("",!0)])]),g("div",ie,[t.hasChanges?(a(),h($,{key:1,type:"info"},{default:m(()=>[g("span",{innerHTML:t.statusMessage},null,8,oe)]),_:1})):(a(),h($,{key:0,type:"info"},{default:m(()=>[N(p(t.t("systemtags","Choose tags for the selected files")),1)]),_:1}))])],64)),ct(g("div",null,[u(H,{ref:"chip",text:"%s",noClose:"",variant:"primary"},null,512)],512),[[gt,!1]])]),_:1},8,["noClose","name","open","class","onUpdate:open"])}const xe=A(Yt,[["render",le],["__scopeId","data-v-fbaf4147"]]);export{xe as default};
//# sourceMappingURL=SystemTagPicker-L1La5tAP.chunk.mjs.map