From 5fbb9fe9a79e2f58fdac929a7be779ee57a5fdf7 Mon Sep 17 00:00:00 2001 From: flarum-bot Date: Fri, 29 Nov 2024 09:57:59 +0000 Subject: [PATCH] Bundled output for commit 33a72f5c14c00671eedcee5d64a0edf5d6db3441 Includes transpiled JS/TS, and Typescript declaration files (typings). [skip ci] --- .../js/dist-typings/common/components/TagSelectionModal.d.ts | 1 + extensions/tags/js/dist/common/components/TagSelectionModal.js | 2 +- .../tags/js/dist/common/components/TagSelectionModal.js.map | 2 +- extensions/tags/js/dist/forum/components/TagDiscussionModal.js | 2 +- .../tags/js/dist/forum/components/TagDiscussionModal.js.map | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/extensions/tags/js/dist-typings/common/components/TagSelectionModal.d.ts b/extensions/tags/js/dist-typings/common/components/TagSelectionModal.d.ts index 7da528458a..a75bdc942b 100644 --- a/extensions/tags/js/dist-typings/common/components/TagSelectionModal.d.ts +++ b/extensions/tags/js/dist-typings/common/components/TagSelectionModal.d.ts @@ -58,6 +58,7 @@ export default class TagSelectionModal): void; className(): string; title(): string | undefined; + lengthWithCJK(text: string): number; content(): JSX.Element | JSX.Element[]; /** * Filters the available tags on every state change. diff --git a/extensions/tags/js/dist/common/components/TagSelectionModal.js b/extensions/tags/js/dist/common/components/TagSelectionModal.js index 06cf54ee4d..38126ce072 100644 --- a/extensions/tags/js/dist/common/components/TagSelectionModal.js +++ b/extensions/tags/js/dist/common/components/TagSelectionModal.js @@ -1,2 +1,2 @@ -"use strict";(self.webpackChunkmodule_exports=self.webpackChunkmodule_exports||[]).push([[955],{671:(t,e,s)=>{s.r(e),s.d(e,{default:()=>C});var i=s(805),a=s(954),n=s.n(a),r=s(336),l=s.n(r),o=s(443),c=s.n(o),h=s(233),d=s.n(h),g=s(607),u=s.n(g),p=s(280),f=s.n(p),y=s(661),T=s.n(y),b=s(15),x=s.n(b),w=s(821),I=s.n(w),v=s(618),N=s(339),_=s(968),S=s(506);class C extends(x()){constructor(){super(...arguments),(0,i.A)(this,"loading",!0),(0,i.A)(this,"tags",void 0),(0,i.A)(this,"selected",[]),(0,i.A)(this,"bypassReqs",!1),(0,i.A)(this,"filter",I()("")),(0,i.A)(this,"focused",!1),(0,i.A)(this,"navigator",new(f())),(0,i.A)(this,"indexTag",void 0)}static initAttrs(t){super.initAttrs(t),t.title||=d()(n().translator.trans("flarum-tags.lib.tag_selection_modal.title")),t.canSelect||=()=>!0,t.allowResetting??=!0,t.limits={min:{total:t.limits?.min?.total??-1/0,primary:t.limits?.min?.primary??-1/0,secondary:t.limits?.min?.secondary??-1/0},max:{total:t.limits?.max?.total??1/0,primary:t.limits?.max?.primary??1/0,secondary:t.limits?.max?.secondary??1/0}},function(t){if(t.min.primary>t.max.primary)throw new Error("The minimum number of primary tags allowed cannot be more than the maximum number of primary tags allowed.");if(t.min.secondary>t.max.secondary)throw new Error("The minimum number of secondary tags allowed cannot be more than the maximum number of secondary tags allowed.");if(t.min.total>t.max.primary+t.max.secondary)throw new Error("The minimum number of tags allowed cannot be more than the maximum number of primary and secondary tags allowed together.");if(t.max.totalt.max.total)throw new Error("The minimum number of tags allowed cannot be more than the maximum number of tags allowed.")}(t.limits)}oninit(t){super.oninit(t),this.navigator.onUp((()=>this.setIndex(this.getCurrentNumericIndex()-1,!0))).onDown((()=>this.setIndex(this.getCurrentNumericIndex()+1,!0))).onSelect(this.select.bind(this)).onRemove((()=>this.selected.splice(this.selected.length-1,1))),n().tagList.load(["parent"]).then((t=>{this.loading=!1,this.attrs.selectableTags&&(t=this.attrs.selectableTags(t)),this.tags=(0,v.A)(t),this.attrs.selectedTags&&this.attrs.selectedTags.map(this.addTag.bind(this)),this.indexTag=t[0],m.redraw()}))}className(){return c()("TagSelectionModal Modal--simple",this.attrs.className)}title(){return this.attrs.title}content(){if(this.loading||!this.tags)return m(T(),null);const t=this.filter().toLowerCase(),e=this.primaryCount(),s=this.secondaryCount(),i=this.getFilteredTags(),a=Math.max(d()(this.getInstruction(e,s)).length,this.filter().length);return[m("div",{className:"Modal-body"},m("div",{className:"TagSelectionModal-form"},m("div",{className:"TagSelectionModal-form-input"},m("div",{className:"TagsInput FormControl "+(this.focused?"focus":""),onclick:()=>this.$(".TagsInput input").focus()},m("span",{className:"TagsInput-selected"},this.selected.map((t=>m("span",{className:"TagsInput-tag",onclick:()=>{this.removeTag(t),this.onready()}},(0,N.A)(t))))),m("input",{className:"FormControl",placeholder:d()(this.getInstruction(e,s)),bidi:this.filter,style:{width:a+"ch"},onkeydown:this.navigator.navigate.bind(this.navigator),onfocus:()=>this.focused=!0,onblur:()=>this.focused=!1}))),m("div",{className:"TagSelectionModal-form-submit App-primaryControl"},m(l(),{type:"submit",className:"Button Button--primary",disabled:!this.meetsRequirements(e,s),icon:"fas fa-check"},n().translator.trans("flarum-tags.lib.tag_selection_modal.submit_button"))))),m("div",{className:"Modal-footer"},m("ul",{className:"TagSelectionModal-list SelectTagList"},i.map((e=>m("li",{"data-index":e.id(),className:c()("SelectTagListItem",{pinned:null!==e.position(),child:!!e.parent(),colored:!!e.color(),selected:this.selected.includes(e),active:this.indexTag===e}),style:{color:e.color()},onmouseover:()=>this.indexTag=e,onclick:this.toggleTag.bind(this,e)},m("i",{className:"SelectTagListItem-icon"},(0,_.A)(e,{className:"SelectTagListItem-tagIcon"}),m("i",{className:"icon TagIcon fas fa-check SelectTagListItem-checkIcon"})),m("span",{className:"SelectTagListItem-name"},u()(e.name(),t)),e.description()?m("span",{className:"SelectTagListItem-description"},e.description()):"")))),this.attrs.limits.allowBypassing&&m("div",{className:"TagSelectionModal-controls"},m(S.A,{className:"Button",onclick:()=>this.bypassReqs=!this.bypassReqs,isToggled:this.bypassReqs},n().translator.trans("flarum-tags.lib.tag_selection_modal.bypass_requirements"))))]}getFilteredTags(){const t=this.filter().toLowerCase(),e=this.primaryCount(),s=this.secondaryCount();let i=this.tags;return this.attrs.requireParentTag&&(i=i.filter((t=>{const e=t.parent();return null!==e&&(!1===e||this.selected.includes(e))}))),this.bypassReqs||(this.selected.length>=this.attrs.limits.max.total?i=i.filter((t=>this.selected.includes(t))):(e>=this.attrs.limits.max.primary&&(i=i.filter((t=>!t.isPrimaryParent()||this.selected.includes(t)))),s>=this.attrs.limits.max.secondary&&(i=i.filter((t=>t.isPrimaryParent()||this.selected.includes(t)))))),t&&(i=i.filter((e=>e.name().toLowerCase().includes(t)))),this.indexTag&&i.includes(this.indexTag)||(this.indexTag=i[0]),i}primaryCount(){return this.selected.filter((t=>t.isPrimaryParent())).length}secondaryCount(){return this.selected.filter((t=>!t.isPrimaryParent())).length}meetsRequirements(t,e){return!!(this.bypassReqs||this.attrs.allowResetting&&0===this.selected.length)||!(this.selected.length=this.attrs.limits.min.primary&&e>=this.attrs.limits.min.secondary}addTag(t){if(t&&this.attrs.canSelect(t)){if(this.attrs.onSelect&&this.attrs.onSelect(t,this.selected),this.attrs.requireParentTag){const e=t.parent();e&&!this.selected.includes(e)&&this.selected.push(e)}this.selected.includes(t)||this.selected.push(t)}}removeTag(t){const e=this.selected.indexOf(t);-1!==e&&(this.selected.splice(e,1),this.attrs.requireParentTag&&this.selected.filter((e=>e.parent()===t)).forEach(this.removeTag.bind(this)),this.attrs.onDeselect&&this.attrs.onDeselect(t,this.selected))}toggleTag(t){this.tags&&(this.selected.includes(t)?this.removeTag(t):this.addTag(t),this.filter()&&(this.filter(""),this.indexTag=this.tags[0]),this.onready())}getInstruction(t,e){if(this.bypassReqs)return"";if(t li")}getCurrentNumericIndex(){return this.indexTag?this.selectableItems().index(this.getItem(this.indexTag)):-1}getItem(t){return this.selectableItems().filter(`[data-index="${t.id()}"]`)}setIndex(t,e){const s=this.selectableItems(),i=s.parent();t<0?t=s.length-1:t>=s.length&&(t=0);const a=s.eq(t);if(this.indexTag=n().store.getById("tags",a.attr("data-index")),m.redraw(),e&&this.indexTag){const t=i.scrollTop(),e=i.offset().top,s=e+i.outerHeight(),n=a.offset().top,r=n+a.outerHeight();let l;ns&&(l=t-s+r+parseInt(i.css("padding-bottom"),10)),void 0!==l&&i.stop(!0).animate({scrollTop:l},100)}}}flarum.reg.add("flarum-tags","common/components/TagSelectionModal",C)},506:(t,e,s)=>{s.d(e,{A:()=>c});var i=s(950),a=s.n(i),n=s(336),r=s.n(n),l=s(443),o=s.n(l);class c extends(a()){view(t){const{className:e,isToggled:s,...i}=this.attrs,a=s?"far fa-check-circle":"far fa-circle";return m(r(),Object.assign({},i,{icon:a,className:o()([e,s&&"Button--toggled"])}),t.children)}}flarum.reg.add("flarum-tags","forum/components/ToggleButton",c)}}]); +"use strict";(self.webpackChunkmodule_exports=self.webpackChunkmodule_exports||[]).push([[955],{671:(t,e,s)=>{s.r(e),s.d(e,{default:()=>S});var i=s(805),a=s(954),n=s.n(a),r=s(336),l=s.n(r),o=s(443),c=s.n(o),h=s(233),d=s.n(h),g=s(607),u=s.n(g),p=s(280),f=s.n(p),y=s(661),T=s.n(y),b=s(15),x=s.n(b),w=s(821),I=s.n(w),v=s(618),N=s(339),_=s(968),C=s(506);class S extends(x()){constructor(){super(...arguments),(0,i.A)(this,"loading",!0),(0,i.A)(this,"tags",void 0),(0,i.A)(this,"selected",[]),(0,i.A)(this,"bypassReqs",!1),(0,i.A)(this,"filter",I()("")),(0,i.A)(this,"focused",!1),(0,i.A)(this,"navigator",new(f())),(0,i.A)(this,"indexTag",void 0)}static initAttrs(t){super.initAttrs(t),t.title||=d()(n().translator.trans("flarum-tags.lib.tag_selection_modal.title")),t.canSelect||=()=>!0,t.allowResetting??=!0,t.limits={min:{total:t.limits?.min?.total??-1/0,primary:t.limits?.min?.primary??-1/0,secondary:t.limits?.min?.secondary??-1/0},max:{total:t.limits?.max?.total??1/0,primary:t.limits?.max?.primary??1/0,secondary:t.limits?.max?.secondary??1/0}},function(t){if(t.min.primary>t.max.primary)throw new Error("The minimum number of primary tags allowed cannot be more than the maximum number of primary tags allowed.");if(t.min.secondary>t.max.secondary)throw new Error("The minimum number of secondary tags allowed cannot be more than the maximum number of secondary tags allowed.");if(t.min.total>t.max.primary+t.max.secondary)throw new Error("The minimum number of tags allowed cannot be more than the maximum number of primary and secondary tags allowed together.");if(t.max.totalt.max.total)throw new Error("The minimum number of tags allowed cannot be more than the maximum number of tags allowed.")}(t.limits)}oninit(t){super.oninit(t),this.navigator.onUp((()=>this.setIndex(this.getCurrentNumericIndex()-1,!0))).onDown((()=>this.setIndex(this.getCurrentNumericIndex()+1,!0))).onSelect(this.select.bind(this)).onRemove((()=>this.selected.splice(this.selected.length-1,1))),n().tagList.load(["parent"]).then((t=>{this.loading=!1,this.attrs.selectableTags&&(t=this.attrs.selectableTags(t)),this.tags=(0,v.A)(t),this.attrs.selectedTags&&this.attrs.selectedTags.map(this.addTag.bind(this)),this.indexTag=t[0],m.redraw()}))}className(){return c()("TagSelectionModal Modal--simple",this.attrs.className)}title(){return this.attrs.title}lengthWithCJK(t){let e=0;for(const s of t)e+=/[\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF]/.test(s)?2:1;return e}content(){if(this.loading||!this.tags)return m(T(),null);const t=this.filter().toLowerCase(),e=this.primaryCount(),s=this.secondaryCount(),i=this.getFilteredTags(),a=Math.max(this.lengthWithCJK(d()(this.getInstruction(e,s))),this.lengthWithCJK(this.filter()));return[m("div",{className:"Modal-body"},m("div",{className:"TagSelectionModal-form"},m("div",{className:"TagSelectionModal-form-input"},m("div",{className:"TagsInput FormControl "+(this.focused?"focus":""),onclick:()=>this.$(".TagsInput input").focus()},m("span",{className:"TagsInput-selected"},this.selected.map((t=>m("span",{className:"TagsInput-tag",onclick:()=>{this.removeTag(t),this.onready()}},(0,N.A)(t))))),m("input",{className:"FormControl",placeholder:d()(this.getInstruction(e,s)),bidi:this.filter,style:{width:a+"ch"},onkeydown:this.navigator.navigate.bind(this.navigator),onfocus:()=>this.focused=!0,onblur:()=>this.focused=!1}))),m("div",{className:"TagSelectionModal-form-submit App-primaryControl"},m(l(),{type:"submit",className:"Button Button--primary",disabled:!this.meetsRequirements(e,s),icon:"fas fa-check"},n().translator.trans("flarum-tags.lib.tag_selection_modal.submit_button"))))),m("div",{className:"Modal-footer"},m("ul",{className:"TagSelectionModal-list SelectTagList"},i.map((e=>m("li",{"data-index":e.id(),className:c()("SelectTagListItem",{pinned:null!==e.position(),child:!!e.parent(),colored:!!e.color(),selected:this.selected.includes(e),active:this.indexTag===e}),style:{color:e.color()},onmouseover:()=>this.indexTag=e,onclick:this.toggleTag.bind(this,e)},m("i",{className:"SelectTagListItem-icon"},(0,_.A)(e,{className:"SelectTagListItem-tagIcon"}),m("i",{className:"icon TagIcon fas fa-check SelectTagListItem-checkIcon"})),m("span",{className:"SelectTagListItem-name"},u()(e.name(),t)),e.description()?m("span",{className:"SelectTagListItem-description"},e.description()):"")))),this.attrs.limits.allowBypassing&&m("div",{className:"TagSelectionModal-controls"},m(C.A,{className:"Button",onclick:()=>this.bypassReqs=!this.bypassReqs,isToggled:this.bypassReqs},n().translator.trans("flarum-tags.lib.tag_selection_modal.bypass_requirements"))))]}getFilteredTags(){const t=this.filter().toLowerCase(),e=this.primaryCount(),s=this.secondaryCount();let i=this.tags;return this.attrs.requireParentTag&&(i=i.filter((t=>{const e=t.parent();return null!==e&&(!1===e||this.selected.includes(e))}))),this.bypassReqs||(this.selected.length>=this.attrs.limits.max.total?i=i.filter((t=>this.selected.includes(t))):(e>=this.attrs.limits.max.primary&&(i=i.filter((t=>!t.isPrimaryParent()||this.selected.includes(t)))),s>=this.attrs.limits.max.secondary&&(i=i.filter((t=>t.isPrimaryParent()||this.selected.includes(t)))))),t&&(i=i.filter((e=>e.name().toLowerCase().includes(t)))),this.indexTag&&i.includes(this.indexTag)||(this.indexTag=i[0]),i}primaryCount(){return this.selected.filter((t=>t.isPrimaryParent())).length}secondaryCount(){return this.selected.filter((t=>!t.isPrimaryParent())).length}meetsRequirements(t,e){return!!(this.bypassReqs||this.attrs.allowResetting&&0===this.selected.length)||!(this.selected.length=this.attrs.limits.min.primary&&e>=this.attrs.limits.min.secondary}addTag(t){if(t&&this.attrs.canSelect(t)){if(this.attrs.onSelect&&this.attrs.onSelect(t,this.selected),this.attrs.requireParentTag){const e=t.parent();e&&!this.selected.includes(e)&&this.selected.push(e)}this.selected.includes(t)||this.selected.push(t)}}removeTag(t){const e=this.selected.indexOf(t);-1!==e&&(this.selected.splice(e,1),this.attrs.requireParentTag&&this.selected.filter((e=>e.parent()===t)).forEach(this.removeTag.bind(this)),this.attrs.onDeselect&&this.attrs.onDeselect(t,this.selected))}toggleTag(t){this.tags&&(this.selected.includes(t)?this.removeTag(t):this.addTag(t),this.filter()&&(this.filter(""),this.indexTag=this.tags[0]),this.onready())}getInstruction(t,e){if(this.bypassReqs)return"";if(t li")}getCurrentNumericIndex(){return this.indexTag?this.selectableItems().index(this.getItem(this.indexTag)):-1}getItem(t){return this.selectableItems().filter(`[data-index="${t.id()}"]`)}setIndex(t,e){const s=this.selectableItems(),i=s.parent();t<0?t=s.length-1:t>=s.length&&(t=0);const a=s.eq(t);if(this.indexTag=n().store.getById("tags",a.attr("data-index")),m.redraw(),e&&this.indexTag){const t=i.scrollTop(),e=i.offset().top,s=e+i.outerHeight(),n=a.offset().top,r=n+a.outerHeight();let l;ns&&(l=t-s+r+parseInt(i.css("padding-bottom"),10)),void 0!==l&&i.stop(!0).animate({scrollTop:l},100)}}}flarum.reg.add("flarum-tags","common/components/TagSelectionModal",S)},506:(t,e,s)=>{s.d(e,{A:()=>c});var i=s(950),a=s.n(i),n=s(336),r=s.n(n),l=s(443),o=s.n(l);class c extends(a()){view(t){const{className:e,isToggled:s,...i}=this.attrs,a=s?"far fa-check-circle":"far fa-circle";return m(r(),Object.assign({},i,{icon:a,className:o()([e,s&&"Button--toggled"])}),t.children)}}flarum.reg.add("flarum-tags","forum/components/ToggleButton",c)}}]); //# sourceMappingURL=TagSelectionModal.js.map \ No newline at end of file diff --git a/extensions/tags/js/dist/common/components/TagSelectionModal.js.map b/extensions/tags/js/dist/common/components/TagSelectionModal.js.map index f2111590df..e5c37941b7 100644 --- a/extensions/tags/js/dist/common/components/TagSelectionModal.js.map +++ b/extensions/tags/js/dist/common/components/TagSelectionModal.js.map @@ -1 +1 @@ -{"version":3,"file":"common/components/TagSelectionModal.js","mappings":"8VAce,MAAMA,UAA0B,KAC7C,WAAAC,GACEC,SAASC,YACT,OAAgBC,KAAM,WAAW,IACjC,OAAgBA,KAAM,YAAQ,IAC9B,OAAgBA,KAAM,WAAY,KAClC,OAAgBA,KAAM,cAAc,IACpC,OAAgBA,KAAM,SAAU,IAAO,MACvC,OAAgBA,KAAM,WAAW,IACjC,OAAgBA,KAAM,YAAa,IAAI,OACvC,OAAgBA,KAAM,gBAAY,EACpC,CACA,gBAAOC,CAAUC,GACfJ,MAAMG,UAAUC,GAGhBA,EAAMC,QAAU,IAAY,eAAeC,MAAM,8CACjDF,EAAMG,YAAc,KAAM,EAC1BH,EAAMI,kBAAmB,EACzBJ,EAAMK,OAAS,CACbC,IAAK,CACHC,MAAOP,EAAMK,QAAQC,KAAKC,QAAS,IACnCC,QAASR,EAAMK,QAAQC,KAAKE,UAAW,IACvCC,UAAWT,EAAMK,QAAQC,KAAKG,YAAa,KAE7CC,IAAK,CACHH,MAAOP,EAAMK,QAAQK,KAAKH,OAASI,IACnCH,QAASR,EAAMK,QAAQK,KAAKF,SAAWG,IACvCF,UAAWT,EAAMK,QAAQK,KAAKD,WAAaE,MAoUnD,SAA4BN,GAC1B,GAAIA,EAAOC,IAAIE,QAAUH,EAAOK,IAAIF,QAClC,MAAM,IAAII,MAAM,8GAElB,GAAIP,EAAOC,IAAIG,UAAYJ,EAAOK,IAAID,UACpC,MAAM,IAAIG,MAAM,kHAElB,GAAIP,EAAOC,IAAIC,MAAQF,EAAOK,IAAIF,QAAUH,EAAOK,IAAID,UACrD,MAAM,IAAIG,MAAM,6HAElB,GAAIP,EAAOK,IAAIH,MAAQF,EAAOC,IAAIE,QAAUH,EAAOC,IAAIG,UACrD,MAAM,IAAIG,MAAM,6HAElB,GAAIP,EAAOC,IAAIC,MAAQF,EAAOK,IAAIH,MAChC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gBgE,EAAYrC,SACnE,CACA,QAAAlD,CAASqE,EAAOmB,GACd,MAAMC,EAAS7G,KAAK0G,kBACdI,EAAYD,EAAOnC,SACrBe,EAAQ,EACVA,EAAQoB,EAAOhF,OAAS,EACf4D,GAASoB,EAAOhF,SACzB4D,EAAQ,GAEV,MAAMsB,EAAQF,EAAOG,GAAGvB,GAGxB,GAFAzF,KAAKsC,SAAW,UAAU2E,QAAQ,OAAQF,EAAMG,KAAK,eACrD3E,EAAEC,SACEoE,GAAgB5G,KAAKsC,SAAU,CACjC,MAAM6E,EAAiBL,EAAUM,YAC3BC,EAAcP,EAAUQ,SAASC,IACjCC,EAAiBH,EAAcP,EAAUW,cACzCC,EAAUX,EAAMO,SAASC,IACzBI,EAAaD,EAAUX,EAAMU,cACnC,IAAIL,EACAM,EAAUL,EACZD,EAAYD,EAAiBE,EAAcK,EAAUE,SAASd,EAAUe,IAAI,eAAgB,IACnFF,EAAaH,IACtBJ,EAAYD,EAAiBK,EAAiBG,EAAaC,SAASd,EAAUe,IAAI,kBAAmB,UAE9E,IAAdT,GACTN,EAAUgB,MAAK,GAAMC,QAAQ,CAC3BX,aACC,IAEP,CACF,EAuBFY,OAAOC,IAAIC,IAAI,cAAe,sCAAuCtI,E,2FCxXtD,MAAMuI,UAAqB,KACxC,IAAAC,CAAKnH,GACH,MAAM,UACJwB,EAAS,UACT4C,KACGnF,GACDF,KAAKE,MACHmE,EAAOgB,EAAY,sBAAwB,gBACjD,OAAO9C,EAAE,IAAQ8F,OAAOC,OAAO,CAAC,EAAGpI,EAAO,CACxCmE,KAAMA,EACN5B,UAAW,IAAU,CAACA,EAAW4C,GAAa,sBAC5CpE,EAAMsH,SACZ,EAEFP,OAAOC,IAAIC,IAAI,cAAe,gCAAiCC,E","sources":["webpack://@flarum/tags/./src/common/components/TagSelectionModal.tsx","webpack://@flarum/tags/./src/forum/components/ToggleButton.js"],"sourcesContent":["import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport app from 'flarum/common/app';\nimport Button from 'flarum/common/components/Button';\nimport classList from 'flarum/common/utils/classList';\nimport extractText from 'flarum/common/utils/extractText';\nimport highlight from 'flarum/common/helpers/highlight';\nimport KeyboardNavigatable from 'flarum/common/utils/KeyboardNavigatable';\nimport LoadingIndicator from 'flarum/common/components/LoadingIndicator';\nimport FormModal from 'flarum/common/components/FormModal';\nimport Stream from 'flarum/common/utils/Stream';\nimport sortTags from '../utils/sortTags';\nimport tagLabel from '../helpers/tagLabel';\nimport tagIcon from '../helpers/tagIcon';\nimport ToggleButton from '../../forum/components/ToggleButton';\nexport default class TagSelectionModal extends FormModal {\n constructor() {\n super(...arguments);\n _defineProperty(this, \"loading\", true);\n _defineProperty(this, \"tags\", void 0);\n _defineProperty(this, \"selected\", []);\n _defineProperty(this, \"bypassReqs\", false);\n _defineProperty(this, \"filter\", Stream(''));\n _defineProperty(this, \"focused\", false);\n _defineProperty(this, \"navigator\", new KeyboardNavigatable());\n _defineProperty(this, \"indexTag\", void 0);\n }\n static initAttrs(attrs) {\n super.initAttrs(attrs);\n\n // Default values for optional attributes.\n attrs.title ||= extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.title'));\n attrs.canSelect ||= () => true;\n attrs.allowResetting ??= true;\n attrs.limits = {\n min: {\n total: attrs.limits?.min?.total ?? -Infinity,\n primary: attrs.limits?.min?.primary ?? -Infinity,\n secondary: attrs.limits?.min?.secondary ?? -Infinity\n },\n max: {\n total: attrs.limits?.max?.total ?? Infinity,\n primary: attrs.limits?.max?.primary ?? Infinity,\n secondary: attrs.limits?.max?.secondary ?? Infinity\n }\n };\n\n // Prevent illogical limits from being provided.\n catchInvalidLimits(attrs.limits);\n }\n oninit(vnode) {\n super.oninit(vnode);\n this.navigator.onUp(() => this.setIndex(this.getCurrentNumericIndex() - 1, true)).onDown(() => this.setIndex(this.getCurrentNumericIndex() + 1, true)).onSelect(this.select.bind(this)).onRemove(() => this.selected.splice(this.selected.length - 1, 1));\n app.tagList.load(['parent']).then(tags => {\n this.loading = false;\n if (this.attrs.selectableTags) {\n tags = this.attrs.selectableTags(tags);\n }\n this.tags = sortTags(tags);\n if (this.attrs.selectedTags) {\n this.attrs.selectedTags.map(this.addTag.bind(this));\n }\n this.indexTag = tags[0];\n m.redraw();\n });\n }\n className() {\n return classList('TagSelectionModal Modal--simple', this.attrs.className);\n }\n title() {\n return this.attrs.title;\n }\n content() {\n if (this.loading || !this.tags) {\n return m(LoadingIndicator, null);\n }\n const filter = this.filter().toLowerCase();\n const primaryCount = this.primaryCount();\n const secondaryCount = this.secondaryCount();\n const tags = this.getFilteredTags();\n const inputWidth = Math.max(extractText(this.getInstruction(primaryCount, secondaryCount)).length, this.filter().length);\n return [m(\"div\", {\n className: \"Modal-body\"\n }, m(\"div\", {\n className: \"TagSelectionModal-form\"\n }, m(\"div\", {\n className: \"TagSelectionModal-form-input\"\n }, m(\"div\", {\n className: 'TagsInput FormControl ' + (this.focused ? 'focus' : ''),\n onclick: () => this.$('.TagsInput input').focus()\n }, m(\"span\", {\n className: \"TagsInput-selected\"\n }, this.selected.map(tag => m(\"span\", {\n className: \"TagsInput-tag\",\n onclick: () => {\n this.removeTag(tag);\n this.onready();\n }\n }, tagLabel(tag)))), m(\"input\", {\n className: \"FormControl\",\n placeholder: extractText(this.getInstruction(primaryCount, secondaryCount)),\n bidi: this.filter,\n style: {\n width: inputWidth + 'ch'\n },\n onkeydown: this.navigator.navigate.bind(this.navigator),\n onfocus: () => this.focused = true,\n onblur: () => this.focused = false\n }))), m(\"div\", {\n className: \"TagSelectionModal-form-submit App-primaryControl\"\n }, m(Button, {\n type: \"submit\",\n className: \"Button Button--primary\",\n disabled: !this.meetsRequirements(primaryCount, secondaryCount),\n icon: \"fas fa-check\"\n }, app.translator.trans('flarum-tags.lib.tag_selection_modal.submit_button'))))), m(\"div\", {\n className: \"Modal-footer\"\n }, m(\"ul\", {\n className: \"TagSelectionModal-list SelectTagList\"\n }, tags.map(tag => m(\"li\", {\n \"data-index\": tag.id(),\n className: classList('SelectTagListItem', {\n pinned: tag.position() !== null,\n child: !!tag.parent(),\n colored: !!tag.color(),\n selected: this.selected.includes(tag),\n active: this.indexTag === tag\n }),\n style: {\n color: tag.color()\n },\n onmouseover: () => this.indexTag = tag,\n onclick: this.toggleTag.bind(this, tag)\n }, m(\"i\", {\n className: \"SelectTagListItem-icon\"\n }, tagIcon(tag, {\n className: 'SelectTagListItem-tagIcon'\n }), m(\"i\", {\n className: \"icon TagIcon fas fa-check SelectTagListItem-checkIcon\"\n })), m(\"span\", {\n className: \"SelectTagListItem-name\"\n }, highlight(tag.name(), filter)), tag.description() ? m(\"span\", {\n className: \"SelectTagListItem-description\"\n }, tag.description()) : ''))), this.attrs.limits.allowBypassing && m(\"div\", {\n className: \"TagSelectionModal-controls\"\n }, m(ToggleButton, {\n className: \"Button\",\n onclick: () => this.bypassReqs = !this.bypassReqs,\n isToggled: this.bypassReqs\n }, app.translator.trans('flarum-tags.lib.tag_selection_modal.bypass_requirements'))))];\n }\n\n /**\n * Filters the available tags on every state change.\n */\n getFilteredTags() {\n const filter = this.filter().toLowerCase();\n const primaryCount = this.primaryCount();\n const secondaryCount = this.secondaryCount();\n let tags = this.tags;\n if (this.attrs.requireParentTag) {\n // Filter out all child tags whose parents have not been selected. This\n // makes it impossible to select a child if its parent hasn't been selected.\n tags = tags.filter(tag => {\n const parent = tag.parent();\n return parent !== null && (parent === false || this.selected.includes(parent));\n });\n }\n if (!this.bypassReqs) {\n // If we reached the total maximum number of tags, we can't select anymore.\n if (this.selected.length >= this.attrs.limits.max.total) {\n tags = tags.filter(tag => this.selected.includes(tag));\n }\n // If the number of selected primary/secondary tags is at the maximum, then\n // we'll filter out all other tags of that type.\n else {\n if (primaryCount >= this.attrs.limits.max.primary) {\n tags = tags.filter(tag => !tag.isPrimaryParent() || this.selected.includes(tag));\n }\n if (secondaryCount >= this.attrs.limits.max.secondary) {\n tags = tags.filter(tag => tag.isPrimaryParent() || this.selected.includes(tag));\n }\n }\n }\n\n // If the user has entered text in the filter input, then filter by tags\n // whose name matches what they've entered.\n if (filter) {\n tags = tags.filter(tag => tag.name().toLowerCase().includes(filter));\n }\n if (!this.indexTag || !tags.includes(this.indexTag)) this.indexTag = tags[0];\n return tags;\n }\n\n /**\n * Counts the number of selected primary tags.\n */\n primaryCount() {\n return this.selected.filter(tag => tag.isPrimaryParent()).length;\n }\n\n /**\n * Counts the number of selected secondary tags.\n */\n secondaryCount() {\n return this.selected.filter(tag => !tag.isPrimaryParent()).length;\n }\n\n /**\n * Validates the number of selected primary/secondary tags against the set min max limits.\n */\n meetsRequirements(primaryCount, secondaryCount) {\n if (this.bypassReqs || this.attrs.allowResetting && this.selected.length === 0) {\n return true;\n }\n if (this.selected.length < this.attrs.limits.min.total) {\n return false;\n }\n return primaryCount >= this.attrs.limits.min.primary && secondaryCount >= this.attrs.limits.min.secondary;\n }\n\n /**\n * Add the given tag to the list of selected tags.\n */\n addTag(tag) {\n if (!tag || !this.attrs.canSelect(tag)) return;\n if (this.attrs.onSelect) {\n this.attrs.onSelect(tag, this.selected);\n }\n\n // If this tag has a parent, we'll also need to add the parent tag to the\n // selected list if it's not already in there.\n if (this.attrs.requireParentTag) {\n const parent = tag.parent();\n if (parent && !this.selected.includes(parent)) {\n this.selected.push(parent);\n }\n }\n if (!this.selected.includes(tag)) {\n this.selected.push(tag);\n }\n }\n\n /**\n * Remove the given tag from the list of selected tags.\n */\n removeTag(tag) {\n const index = this.selected.indexOf(tag);\n if (index !== -1) {\n this.selected.splice(index, 1);\n\n // Look through the list of selected tags for any tags which have the tag\n // we just removed as their parent. We'll need to remove them too.\n if (this.attrs.requireParentTag) {\n this.selected.filter(t => t.parent() === tag).forEach(this.removeTag.bind(this));\n }\n if (this.attrs.onDeselect) {\n this.attrs.onDeselect(tag, this.selected);\n }\n }\n }\n toggleTag(tag) {\n // Won't happen, needed for type safety.\n if (!this.tags) return;\n if (this.selected.includes(tag)) {\n this.removeTag(tag);\n } else {\n this.addTag(tag);\n }\n if (this.filter()) {\n this.filter('');\n this.indexTag = this.tags[0];\n }\n this.onready();\n }\n\n /**\n * Gives human text instructions based on the current number of selected tags and set limits.\n */\n getInstruction(primaryCount, secondaryCount) {\n if (this.bypassReqs) {\n return '';\n }\n if (primaryCount < this.attrs.limits.min.primary) {\n const remaining = this.attrs.limits.min.primary - primaryCount;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_primary_placeholder', {\n count: remaining\n }));\n } else if (secondaryCount < this.attrs.limits.min.secondary) {\n const remaining = this.attrs.limits.min.secondary - secondaryCount;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_secondary_placeholder', {\n count: remaining\n }));\n } else if (this.selected.length < this.attrs.limits.min.total) {\n const remaining = this.attrs.limits.min.total - this.selected.length;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_tags_placeholder', {\n count: remaining\n }));\n }\n return '';\n }\n\n /**\n * Submit tag selection.\n */\n onsubmit(e) {\n e.preventDefault();\n if (this.attrs.onsubmit) this.attrs.onsubmit(this.selected);\n this.hide();\n }\n select(e) {\n // Ctrl + Enter submits the selection, just Enter completes the current entry\n if (e.metaKey || e.ctrlKey || this.indexTag && this.selected.includes(this.indexTag)) {\n if (this.selected.length) {\n // The DOM submit method doesn't emit a `submit event, so we\n // simulate a manual submission so our `onsubmit` logic is run.\n this.$('button[type=\"submit\"]').click();\n }\n } else if (this.indexTag) {\n this.getItem(this.indexTag)[0].dispatchEvent(new Event('click'));\n }\n }\n selectableItems() {\n return this.$('.TagSelectionModal-list > li');\n }\n getCurrentNumericIndex() {\n if (!this.indexTag) return -1;\n return this.selectableItems().index(this.getItem(this.indexTag));\n }\n getItem(selectedTag) {\n return this.selectableItems().filter(`[data-index=\"${selectedTag.id()}\"]`);\n }\n setIndex(index, scrollToItem) {\n const $items = this.selectableItems();\n const $dropdown = $items.parent();\n if (index < 0) {\n index = $items.length - 1;\n } else if (index >= $items.length) {\n index = 0;\n }\n const $item = $items.eq(index);\n this.indexTag = app.store.getById('tags', $item.attr('data-index'));\n m.redraw();\n if (scrollToItem && this.indexTag) {\n const dropdownScroll = $dropdown.scrollTop();\n const dropdownTop = $dropdown.offset().top;\n const dropdownBottom = dropdownTop + $dropdown.outerHeight();\n const itemTop = $item.offset().top;\n const itemBottom = itemTop + $item.outerHeight();\n let scrollTop;\n if (itemTop < dropdownTop) {\n scrollTop = dropdownScroll - dropdownTop + itemTop - parseInt($dropdown.css('padding-top'), 10);\n } else if (itemBottom > dropdownBottom) {\n scrollTop = dropdownScroll - dropdownBottom + itemBottom + parseInt($dropdown.css('padding-bottom'), 10);\n }\n if (typeof scrollTop !== 'undefined') {\n $dropdown.stop(true).animate({\n scrollTop\n }, 100);\n }\n }\n }\n}\n\n/**\n * Catch invalid limits provided to the tag selection modal.\n */\nfunction catchInvalidLimits(limits) {\n if (limits.min.primary > limits.max.primary) {\n throw new Error('The minimum number of primary tags allowed cannot be more than the maximum number of primary tags allowed.');\n }\n if (limits.min.secondary > limits.max.secondary) {\n throw new Error('The minimum number of secondary tags allowed cannot be more than the maximum number of secondary tags allowed.');\n }\n if (limits.min.total > limits.max.primary + limits.max.secondary) {\n throw new Error('The minimum number of tags allowed cannot be more than the maximum number of primary and secondary tags allowed together.');\n }\n if (limits.max.total < limits.min.primary + limits.min.secondary) {\n throw new Error('The maximum number of tags allowed cannot be less than the minimum number of primary and secondary tags allowed together.');\n }\n if (limits.min.total > limits.max.total) {\n throw new Error('The minimum number of tags allowed cannot be more than the maximum number of tags allowed.');\n }\n}\nflarum.reg.add('flarum-tags', 'common/components/TagSelectionModal', TagSelectionModal);","import Component from 'flarum/common/Component';\nimport Button from 'flarum/common/components/Button';\nimport classList from 'flarum/common/utils/classList';\n\n/**\n * @TODO move to core\n */\nexport default class ToggleButton extends Component {\n view(vnode) {\n const {\n className,\n isToggled,\n ...attrs\n } = this.attrs;\n const icon = isToggled ? 'far fa-check-circle' : 'far fa-circle';\n return m(Button, Object.assign({}, attrs, {\n icon: icon,\n className: classList([className, isToggled && 'Button--toggled'])\n }), vnode.children);\n }\n}\nflarum.reg.add('flarum-tags', 'forum/components/ToggleButton', ToggleButton);"],"names":["TagSelectionModal","constructor","super","arguments","this","initAttrs","attrs","title","trans","canSelect","allowResetting","limits","min","total","primary","secondary","max","Infinity","Error","catchInvalidLimits","oninit","vnode","navigator","onUp","setIndex","getCurrentNumericIndex","onDown","onSelect","select","bind","onRemove","selected","splice","length","load","then","tags","loading","selectableTags","selectedTags","map","addTag","indexTag","m","redraw","className","content","filter","toLowerCase","primaryCount","secondaryCount","getFilteredTags","inputWidth","Math","getInstruction","focused","onclick","$","focus","tag","removeTag","onready","placeholder","bidi","style","width","onkeydown","navigate","onfocus","onblur","type","disabled","meetsRequirements","icon","id","pinned","position","child","parent","colored","color","includes","active","onmouseover","toggleTag","name","description","allowBypassing","bypassReqs","isToggled","requireParentTag","isPrimaryParent","push","index","indexOf","t","forEach","onDeselect","remaining","count","onsubmit","e","preventDefault","hide","metaKey","ctrlKey","click","getItem","dispatchEvent","Event","selectableItems","selectedTag","scrollToItem","$items","$dropdown","$item","eq","getById","attr","dropdownScroll","scrollTop","dropdownTop","offset","top","dropdownBottom","outerHeight","itemTop","itemBottom","parseInt","css","stop","animate","flarum","reg","add","ToggleButton","view","Object","assign","children"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"common/components/TagSelectionModal.js","mappings":"8VAce,MAAMA,UAA0B,KAC7C,WAAAC,GACEC,SAASC,YACT,OAAgBC,KAAM,WAAW,IACjC,OAAgBA,KAAM,YAAQ,IAC9B,OAAgBA,KAAM,WAAY,KAClC,OAAgBA,KAAM,cAAc,IACpC,OAAgBA,KAAM,SAAU,IAAO,MACvC,OAAgBA,KAAM,WAAW,IACjC,OAAgBA,KAAM,YAAa,IAAI,OACvC,OAAgBA,KAAM,gBAAY,EACpC,CACA,gBAAOC,CAAUC,GACfJ,MAAMG,UAAUC,GAGhBA,EAAMC,QAAU,IAAY,eAAeC,MAAM,8CACjDF,E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KAAKsC,SAAU,CACjC,MAAMiF,EAAiBL,EAAUM,YAC3BC,EAAcP,EAAUQ,SAASC,IACjCC,EAAiBH,EAAcP,EAAUW,cACzCC,EAAUX,EAAMO,SAASC,IACzBI,EAAaD,EAAUX,EAAMU,cACnC,IAAIL,EACAM,EAAUL,EACZD,EAAYD,EAAiBE,EAAcK,EAAUE,SAASd,EAAUe,IAAI,eAAgB,IACnFF,EAAaH,IACtBJ,EAAYD,EAAiBK,EAAiBG,EAAaC,SAASd,EAAUe,IAAI,kBAAmB,UAE9E,IAAdT,GACTN,EAAUgB,MAAK,GAAMC,QAAQ,CAC3BX,aACC,IAEP,CACF,EAuBFY,OAAOC,IAAIC,IAAI,cAAe,sCAAuC1I,E,2FClYtD,MAAM2I,UAAqB,KACxC,IAAAC,CAAKvH,GACH,MAAM,UACJwB,EAAS,UACTgD,KACGvF,GACDF,KAAKE,MACHuE,EAAOgB,EAAY,sBAAwB,gBACjD,OAAOlD,EAAE,IAAQkG,OAAOC,OAAO,CAAC,EAAGxI,EAAO,CACxCuE,KAAMA,EACNhC,UAAW,IAAU,CAACA,EAAWgD,GAAa,sBAC5CxE,EAAM0H,SACZ,EAEFP,OAAOC,IAAIC,IAAI,cAAe,gCAAiCC,E","sources":["webpack://@flarum/tags/./src/common/components/TagSelectionModal.tsx","webpack://@flarum/tags/./src/forum/components/ToggleButton.js"],"sourcesContent":["import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport app from 'flarum/common/app';\nimport Button from 'flarum/common/components/Button';\nimport classList from 'flarum/common/utils/classList';\nimport extractText from 'flarum/common/utils/extractText';\nimport highlight from 'flarum/common/helpers/highlight';\nimport KeyboardNavigatable from 'flarum/common/utils/KeyboardNavigatable';\nimport LoadingIndicator from 'flarum/common/components/LoadingIndicator';\nimport FormModal from 'flarum/common/components/FormModal';\nimport Stream from 'flarum/common/utils/Stream';\nimport sortTags from '../utils/sortTags';\nimport tagLabel from '../helpers/tagLabel';\nimport tagIcon from '../helpers/tagIcon';\nimport ToggleButton from '../../forum/components/ToggleButton';\nexport default class TagSelectionModal extends FormModal {\n constructor() {\n super(...arguments);\n _defineProperty(this, \"loading\", true);\n _defineProperty(this, \"tags\", void 0);\n _defineProperty(this, \"selected\", []);\n _defineProperty(this, \"bypassReqs\", false);\n _defineProperty(this, \"filter\", Stream(''));\n _defineProperty(this, \"focused\", false);\n _defineProperty(this, \"navigator\", new KeyboardNavigatable());\n _defineProperty(this, \"indexTag\", void 0);\n }\n static initAttrs(attrs) {\n super.initAttrs(attrs);\n\n // Default values for optional attributes.\n attrs.title ||= extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.title'));\n attrs.canSelect ||= () => true;\n attrs.allowResetting ??= true;\n attrs.limits = {\n min: {\n total: attrs.limits?.min?.total ?? -Infinity,\n primary: attrs.limits?.min?.primary ?? -Infinity,\n secondary: attrs.limits?.min?.secondary ?? -Infinity\n },\n max: {\n total: attrs.limits?.max?.total ?? Infinity,\n primary: attrs.limits?.max?.primary ?? Infinity,\n secondary: attrs.limits?.max?.secondary ?? Infinity\n }\n };\n\n // Prevent illogical limits from being provided.\n catchInvalidLimits(attrs.limits);\n }\n oninit(vnode) {\n super.oninit(vnode);\n this.navigator.onUp(() => this.setIndex(this.getCurrentNumericIndex() - 1, true)).onDown(() => this.setIndex(this.getCurrentNumericIndex() + 1, true)).onSelect(this.select.bind(this)).onRemove(() => this.selected.splice(this.selected.length - 1, 1));\n app.tagList.load(['parent']).then(tags => {\n this.loading = false;\n if (this.attrs.selectableTags) {\n tags = this.attrs.selectableTags(tags);\n }\n this.tags = sortTags(tags);\n if (this.attrs.selectedTags) {\n this.attrs.selectedTags.map(this.addTag.bind(this));\n }\n this.indexTag = tags[0];\n m.redraw();\n });\n }\n className() {\n return classList('TagSelectionModal Modal--simple', this.attrs.className);\n }\n title() {\n return this.attrs.title;\n }\n lengthWithCJK(text) {\n let length = 0;\n for (const char of text) {\n length += /[\\u4E00-\\u9FFF\\u3400-\\u4DBF\\uF900-\\uFAFF]/.test(char) ? 2 : 1;\n }\n return length;\n }\n content() {\n if (this.loading || !this.tags) {\n return m(LoadingIndicator, null);\n }\n const filter = this.filter().toLowerCase();\n const primaryCount = this.primaryCount();\n const secondaryCount = this.secondaryCount();\n const tags = this.getFilteredTags();\n\n // 1 CJK character's width equals to 2ch,\n // so we count 1 CJK character as 2 characters.\n const inputWidth = Math.max(this.lengthWithCJK(extractText(this.getInstruction(primaryCount, secondaryCount))), this.lengthWithCJK(this.filter()));\n return [m(\"div\", {\n className: \"Modal-body\"\n }, m(\"div\", {\n className: \"TagSelectionModal-form\"\n }, m(\"div\", {\n className: \"TagSelectionModal-form-input\"\n }, m(\"div\", {\n className: 'TagsInput FormControl ' + (this.focused ? 'focus' : ''),\n onclick: () => this.$('.TagsInput input').focus()\n }, m(\"span\", {\n className: \"TagsInput-selected\"\n }, this.selected.map(tag => m(\"span\", {\n className: \"TagsInput-tag\",\n onclick: () => {\n this.removeTag(tag);\n this.onready();\n }\n }, tagLabel(tag)))), m(\"input\", {\n className: \"FormControl\",\n placeholder: extractText(this.getInstruction(primaryCount, secondaryCount)),\n bidi: this.filter,\n style: {\n width: inputWidth + 'ch'\n },\n onkeydown: this.navigator.navigate.bind(this.navigator),\n onfocus: () => this.focused = true,\n onblur: () => this.focused = false\n }))), m(\"div\", {\n className: \"TagSelectionModal-form-submit App-primaryControl\"\n }, m(Button, {\n type: \"submit\",\n className: \"Button Button--primary\",\n disabled: !this.meetsRequirements(primaryCount, secondaryCount),\n icon: \"fas fa-check\"\n }, app.translator.trans('flarum-tags.lib.tag_selection_modal.submit_button'))))), m(\"div\", {\n className: \"Modal-footer\"\n }, m(\"ul\", {\n className: \"TagSelectionModal-list SelectTagList\"\n }, tags.map(tag => m(\"li\", {\n \"data-index\": tag.id(),\n className: classList('SelectTagListItem', {\n pinned: tag.position() !== null,\n child: !!tag.parent(),\n colored: !!tag.color(),\n selected: this.selected.includes(tag),\n active: this.indexTag === tag\n }),\n style: {\n color: tag.color()\n },\n onmouseover: () => this.indexTag = tag,\n onclick: this.toggleTag.bind(this, tag)\n }, m(\"i\", {\n className: \"SelectTagListItem-icon\"\n }, tagIcon(tag, {\n className: 'SelectTagListItem-tagIcon'\n }), m(\"i\", {\n className: \"icon TagIcon fas fa-check SelectTagListItem-checkIcon\"\n })), m(\"span\", {\n className: \"SelectTagListItem-name\"\n }, highlight(tag.name(), filter)), tag.description() ? m(\"span\", {\n className: \"SelectTagListItem-description\"\n }, tag.description()) : ''))), this.attrs.limits.allowBypassing && m(\"div\", {\n className: \"TagSelectionModal-controls\"\n }, m(ToggleButton, {\n className: \"Button\",\n onclick: () => this.bypassReqs = !this.bypassReqs,\n isToggled: this.bypassReqs\n }, app.translator.trans('flarum-tags.lib.tag_selection_modal.bypass_requirements'))))];\n }\n\n /**\n * Filters the available tags on every state change.\n */\n getFilteredTags() {\n const filter = this.filter().toLowerCase();\n const primaryCount = this.primaryCount();\n const secondaryCount = this.secondaryCount();\n let tags = this.tags;\n if (this.attrs.requireParentTag) {\n // Filter out all child tags whose parents have not been selected. This\n // makes it impossible to select a child if its parent hasn't been selected.\n tags = tags.filter(tag => {\n const parent = tag.parent();\n return parent !== null && (parent === false || this.selected.includes(parent));\n });\n }\n if (!this.bypassReqs) {\n // If we reached the total maximum number of tags, we can't select anymore.\n if (this.selected.length >= this.attrs.limits.max.total) {\n tags = tags.filter(tag => this.selected.includes(tag));\n }\n // If the number of selected primary/secondary tags is at the maximum, then\n // we'll filter out all other tags of that type.\n else {\n if (primaryCount >= this.attrs.limits.max.primary) {\n tags = tags.filter(tag => !tag.isPrimaryParent() || this.selected.includes(tag));\n }\n if (secondaryCount >= this.attrs.limits.max.secondary) {\n tags = tags.filter(tag => tag.isPrimaryParent() || this.selected.includes(tag));\n }\n }\n }\n\n // If the user has entered text in the filter input, then filter by tags\n // whose name matches what they've entered.\n if (filter) {\n tags = tags.filter(tag => tag.name().toLowerCase().includes(filter));\n }\n if (!this.indexTag || !tags.includes(this.indexTag)) this.indexTag = tags[0];\n return tags;\n }\n\n /**\n * Counts the number of selected primary tags.\n */\n primaryCount() {\n return this.selected.filter(tag => tag.isPrimaryParent()).length;\n }\n\n /**\n * Counts the number of selected secondary tags.\n */\n secondaryCount() {\n return this.selected.filter(tag => !tag.isPrimaryParent()).length;\n }\n\n /**\n * Validates the number of selected primary/secondary tags against the set min max limits.\n */\n meetsRequirements(primaryCount, secondaryCount) {\n if (this.bypassReqs || this.attrs.allowResetting && this.selected.length === 0) {\n return true;\n }\n if (this.selected.length < this.attrs.limits.min.total) {\n return false;\n }\n return primaryCount >= this.attrs.limits.min.primary && secondaryCount >= this.attrs.limits.min.secondary;\n }\n\n /**\n * Add the given tag to the list of selected tags.\n */\n addTag(tag) {\n if (!tag || !this.attrs.canSelect(tag)) return;\n if (this.attrs.onSelect) {\n this.attrs.onSelect(tag, this.selected);\n }\n\n // If this tag has a parent, we'll also need to add the parent tag to the\n // selected list if it's not already in there.\n if (this.attrs.requireParentTag) {\n const parent = tag.parent();\n if (parent && !this.selected.includes(parent)) {\n this.selected.push(parent);\n }\n }\n if (!this.selected.includes(tag)) {\n this.selected.push(tag);\n }\n }\n\n /**\n * Remove the given tag from the list of selected tags.\n */\n removeTag(tag) {\n const index = this.selected.indexOf(tag);\n if (index !== -1) {\n this.selected.splice(index, 1);\n\n // Look through the list of selected tags for any tags which have the tag\n // we just removed as their parent. We'll need to remove them too.\n if (this.attrs.requireParentTag) {\n this.selected.filter(t => t.parent() === tag).forEach(this.removeTag.bind(this));\n }\n if (this.attrs.onDeselect) {\n this.attrs.onDeselect(tag, this.selected);\n }\n }\n }\n toggleTag(tag) {\n // Won't happen, needed for type safety.\n if (!this.tags) return;\n if (this.selected.includes(tag)) {\n this.removeTag(tag);\n } else {\n this.addTag(tag);\n }\n if (this.filter()) {\n this.filter('');\n this.indexTag = this.tags[0];\n }\n this.onready();\n }\n\n /**\n * Gives human text instructions based on the current number of selected tags and set limits.\n */\n getInstruction(primaryCount, secondaryCount) {\n if (this.bypassReqs) {\n return '';\n }\n if (primaryCount < this.attrs.limits.min.primary) {\n const remaining = this.attrs.limits.min.primary - primaryCount;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_primary_placeholder', {\n count: remaining\n }));\n } else if (secondaryCount < this.attrs.limits.min.secondary) {\n const remaining = this.attrs.limits.min.secondary - secondaryCount;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_secondary_placeholder', {\n count: remaining\n }));\n } else if (this.selected.length < this.attrs.limits.min.total) {\n const remaining = this.attrs.limits.min.total - this.selected.length;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_tags_placeholder', {\n count: remaining\n }));\n }\n return '';\n }\n\n /**\n * Submit tag selection.\n */\n onsubmit(e) {\n e.preventDefault();\n if (this.attrs.onsubmit) this.attrs.onsubmit(this.selected);\n this.hide();\n }\n select(e) {\n // Ctrl + Enter submits the selection, just Enter completes the current entry\n if (e.metaKey || e.ctrlKey || this.indexTag && this.selected.includes(this.indexTag)) {\n if (this.selected.length) {\n // The DOM submit method doesn't emit a `submit event, so we\n // simulate a manual submission so our `onsubmit` logic is run.\n this.$('button[type=\"submit\"]').click();\n }\n } else if (this.indexTag) {\n this.getItem(this.indexTag)[0].dispatchEvent(new Event('click'));\n }\n }\n selectableItems() {\n return this.$('.TagSelectionModal-list > li');\n }\n getCurrentNumericIndex() {\n if (!this.indexTag) return -1;\n return this.selectableItems().index(this.getItem(this.indexTag));\n }\n getItem(selectedTag) {\n return this.selectableItems().filter(`[data-index=\"${selectedTag.id()}\"]`);\n }\n setIndex(index, scrollToItem) {\n const $items = this.selectableItems();\n const $dropdown = $items.parent();\n if (index < 0) {\n index = $items.length - 1;\n } else if (index >= $items.length) {\n index = 0;\n }\n const $item = $items.eq(index);\n this.indexTag = app.store.getById('tags', $item.attr('data-index'));\n m.redraw();\n if (scrollToItem && this.indexTag) {\n const dropdownScroll = $dropdown.scrollTop();\n const dropdownTop = $dropdown.offset().top;\n const dropdownBottom = dropdownTop + $dropdown.outerHeight();\n const itemTop = $item.offset().top;\n const itemBottom = itemTop + $item.outerHeight();\n let scrollTop;\n if (itemTop < dropdownTop) {\n scrollTop = dropdownScroll - dropdownTop + itemTop - parseInt($dropdown.css('padding-top'), 10);\n } else if (itemBottom > dropdownBottom) {\n scrollTop = dropdownScroll - dropdownBottom + itemBottom + parseInt($dropdown.css('padding-bottom'), 10);\n }\n if (typeof scrollTop !== 'undefined') {\n $dropdown.stop(true).animate({\n scrollTop\n }, 100);\n }\n }\n }\n}\n\n/**\n * Catch invalid limits provided to the tag selection modal.\n */\nfunction catchInvalidLimits(limits) {\n if (limits.min.primary > limits.max.primary) {\n throw new Error('The minimum number of primary tags allowed cannot be more than the maximum number of primary tags allowed.');\n }\n if (limits.min.secondary > limits.max.secondary) {\n throw new Error('The minimum number of secondary tags allowed cannot be more than the maximum number of secondary tags allowed.');\n }\n if (limits.min.total > limits.max.primary + limits.max.secondary) {\n throw new Error('The minimum number of tags allowed cannot be more than the maximum number of primary and secondary tags allowed together.');\n }\n if (limits.max.total < limits.min.primary + limits.min.secondary) {\n throw new Error('The maximum number of tags allowed cannot be less than the minimum number of primary and secondary tags allowed together.');\n }\n if (limits.min.total > limits.max.total) {\n throw new Error('The minimum number of tags allowed cannot be more than the maximum number of tags allowed.');\n }\n}\nflarum.reg.add('flarum-tags', 'common/components/TagSelectionModal', TagSelectionModal);","import Component from 'flarum/common/Component';\nimport Button from 'flarum/common/components/Button';\nimport classList from 'flarum/common/utils/classList';\n\n/**\n * @TODO move to core\n */\nexport default class ToggleButton extends Component {\n view(vnode) {\n const {\n className,\n isToggled,\n ...attrs\n } = this.attrs;\n const icon = isToggled ? 'far fa-check-circle' : 'far fa-circle';\n return m(Button, Object.assign({}, attrs, {\n icon: icon,\n className: classList([className, isToggled && 'Button--toggled'])\n }), vnode.children);\n }\n}\nflarum.reg.add('flarum-tags', 'forum/components/ToggleButton', ToggleButton);"],"names":["TagSelectionModal","constructor","super","arguments","this","initAttrs","attrs","title","trans","canSelect","allowResetting","limits","min","total","primary","secondary","max","Infinity","Error","catchInvalidLimits","oninit","vnode","navigator","onUp","setIndex","getCurrentNumericIndex","onDown","onSelect","select","bind","onRemove","selected","splice","length","load","then","tags","loading","selectableTags","selectedTags","map","addTag","indexTag","m","redraw","className","lengthWithCJK","text","char","test","content","filter","toLowerCase","primaryCount","secondaryCount","getFilteredTags","inputWidth","Math","getInstruction","focused","onclick","$","focus","tag","removeTag","onready","placeholder","bidi","style","width","onkeydown","navigate","onfocus","onblur","type","disabled","meetsRequirements","icon","id","pinned","position","child","parent","colored","color","includes","active","onmouseover","toggleTag","name","description","allowBypassing","bypassReqs","isToggled","requireParentTag","isPrimaryParent","push","index","indexOf","t","forEach","onDeselect","remaining","count","onsubmit","e","preventDefault","hide","metaKey","ctrlKey","click","getItem","dispatchEvent","Event","selectableItems","selectedTag","scrollToItem","$items","$dropdown","$item","eq","getById","attr","dropdownScroll","scrollTop","dropdownTop","offset","top","dropdownBottom","outerHeight","itemTop","itemBottom","parseInt","css","stop","animate","flarum","reg","add","ToggleButton","view","Object","assign","children"],"sourceRoot":""} \ No newline at end of file diff --git a/extensions/tags/js/dist/forum/components/TagDiscussionModal.js b/extensions/tags/js/dist/forum/components/TagDiscussionModal.js index 1b4ad51d60..b72f829869 100644 --- a/extensions/tags/js/dist/forum/components/TagDiscussionModal.js +++ b/extensions/tags/js/dist/forum/components/TagDiscussionModal.js @@ -1,2 +1,2 @@ -"use strict";(self.webpackChunkmodule_exports=self.webpackChunkmodule_exports||[]).push([[371],{440:(t,e,s)=>{s.r(e),s.d(e,{default:()=>B});var i=s(488),a=s.n(i),n=s(137),r=s.n(n),l=s(443),o=s.n(l),c=s(233),d=s.n(c),h=s(838),u=s(805),g=s(954),p=s.n(g),f=s(336),y=s.n(f),T=s(607),b=s.n(T),x=s(280),w=s.n(x),I=s(661),v=s.n(I),N=s(15),_=s.n(N),S=s(821),C=s.n(S),A=s(618),k=s(339),q=s(968),M=s(950),P=s.n(M);class R extends(P()){view(t){const{className:e,isToggled:s,...i}=this.attrs,a=s?"far fa-check-circle":"far fa-circle";return m(y(),Object.assign({},i,{icon:a,className:o()([e,s&&"Button--toggled"])}),t.children)}}flarum.reg.add("flarum-tags","forum/components/ToggleButton",R);class L extends(_()){constructor(){super(...arguments),(0,u.A)(this,"loading",!0),(0,u.A)(this,"tags",void 0),(0,u.A)(this,"selected",[]),(0,u.A)(this,"bypassReqs",!1),(0,u.A)(this,"filter",C()("")),(0,u.A)(this,"focused",!1),(0,u.A)(this,"navigator",new(w())),(0,u.A)(this,"indexTag",void 0)}static initAttrs(t){super.initAttrs(t),t.title||=d()(p().translator.trans("flarum-tags.lib.tag_selection_modal.title")),t.canSelect||=()=>!0,t.allowResetting??=!0,t.limits={min:{total:t.limits?.min?.total??-1/0,primary:t.limits?.min?.primary??-1/0,secondary:t.limits?.min?.secondary??-1/0},max:{total:t.limits?.max?.total??1/0,primary:t.limits?.max?.primary??1/0,secondary:t.limits?.max?.secondary??1/0}},function(t){if(t.min.primary>t.max.primary)throw new Error("The minimum number of primary tags allowed cannot be more than the maximum number of primary tags allowed.");if(t.min.secondary>t.max.secondary)throw new Error("The minimum number of secondary tags allowed cannot be more than the maximum number of secondary tags allowed.");if(t.min.total>t.max.primary+t.max.secondary)throw new Error("The minimum number of tags allowed cannot be more than the maximum number of primary and secondary tags allowed together.");if(t.max.totalt.max.total)throw new Error("The minimum number of tags allowed cannot be more than the maximum number of tags allowed.")}(t.limits)}oninit(t){super.oninit(t),this.navigator.onUp((()=>this.setIndex(this.getCurrentNumericIndex()-1,!0))).onDown((()=>this.setIndex(this.getCurrentNumericIndex()+1,!0))).onSelect(this.select.bind(this)).onRemove((()=>this.selected.splice(this.selected.length-1,1))),p().tagList.load(["parent"]).then((t=>{this.loading=!1,this.attrs.selectableTags&&(t=this.attrs.selectableTags(t)),this.tags=(0,A.A)(t),this.attrs.selectedTags&&this.attrs.selectedTags.map(this.addTag.bind(this)),this.indexTag=t[0],m.redraw()}))}className(){return o()("TagSelectionModal Modal--simple",this.attrs.className)}title(){return this.attrs.title}content(){if(this.loading||!this.tags)return m(v(),null);const t=this.filter().toLowerCase(),e=this.primaryCount(),s=this.secondaryCount(),i=this.getFilteredTags(),a=Math.max(d()(this.getInstruction(e,s)).length,this.filter().length);return[m("div",{className:"Modal-body"},m("div",{className:"TagSelectionModal-form"},m("div",{className:"TagSelectionModal-form-input"},m("div",{className:"TagsInput FormControl "+(this.focused?"focus":""),onclick:()=>this.$(".TagsInput input").focus()},m("span",{className:"TagsInput-selected"},this.selected.map((t=>m("span",{className:"TagsInput-tag",onclick:()=>{this.removeTag(t),this.onready()}},(0,k.A)(t))))),m("input",{className:"FormControl",placeholder:d()(this.getInstruction(e,s)),bidi:this.filter,style:{width:a+"ch"},onkeydown:this.navigator.navigate.bind(this.navigator),onfocus:()=>this.focused=!0,onblur:()=>this.focused=!1}))),m("div",{className:"TagSelectionModal-form-submit App-primaryControl"},m(y(),{type:"submit",className:"Button Button--primary",disabled:!this.meetsRequirements(e,s),icon:"fas fa-check"},p().translator.trans("flarum-tags.lib.tag_selection_modal.submit_button"))))),m("div",{className:"Modal-footer"},m("ul",{className:"TagSelectionModal-list SelectTagList"},i.map((e=>m("li",{"data-index":e.id(),className:o()("SelectTagListItem",{pinned:null!==e.position(),child:!!e.parent(),colored:!!e.color(),selected:this.selected.includes(e),active:this.indexTag===e}),style:{color:e.color()},onmouseover:()=>this.indexTag=e,onclick:this.toggleTag.bind(this,e)},m("i",{className:"SelectTagListItem-icon"},(0,q.A)(e,{className:"SelectTagListItem-tagIcon"}),m("i",{className:"icon TagIcon fas fa-check SelectTagListItem-checkIcon"})),m("span",{className:"SelectTagListItem-name"},b()(e.name(),t)),e.description()?m("span",{className:"SelectTagListItem-description"},e.description()):"")))),this.attrs.limits.allowBypassing&&m("div",{className:"TagSelectionModal-controls"},m(R,{className:"Button",onclick:()=>this.bypassReqs=!this.bypassReqs,isToggled:this.bypassReqs},p().translator.trans("flarum-tags.lib.tag_selection_modal.bypass_requirements"))))]}getFilteredTags(){const t=this.filter().toLowerCase(),e=this.primaryCount(),s=this.secondaryCount();let i=this.tags;return this.attrs.requireParentTag&&(i=i.filter((t=>{const e=t.parent();return null!==e&&(!1===e||this.selected.includes(e))}))),this.bypassReqs||(this.selected.length>=this.attrs.limits.max.total?i=i.filter((t=>this.selected.includes(t))):(e>=this.attrs.limits.max.primary&&(i=i.filter((t=>!t.isPrimaryParent()||this.selected.includes(t)))),s>=this.attrs.limits.max.secondary&&(i=i.filter((t=>t.isPrimaryParent()||this.selected.includes(t)))))),t&&(i=i.filter((e=>e.name().toLowerCase().includes(t)))),this.indexTag&&i.includes(this.indexTag)||(this.indexTag=i[0]),i}primaryCount(){return this.selected.filter((t=>t.isPrimaryParent())).length}secondaryCount(){return this.selected.filter((t=>!t.isPrimaryParent())).length}meetsRequirements(t,e){return!!(this.bypassReqs||this.attrs.allowResetting&&0===this.selected.length)||!(this.selected.length=this.attrs.limits.min.primary&&e>=this.attrs.limits.min.secondary}addTag(t){if(t&&this.attrs.canSelect(t)){if(this.attrs.onSelect&&this.attrs.onSelect(t,this.selected),this.attrs.requireParentTag){const e=t.parent();e&&!this.selected.includes(e)&&this.selected.push(e)}this.selected.includes(t)||this.selected.push(t)}}removeTag(t){const e=this.selected.indexOf(t);-1!==e&&(this.selected.splice(e,1),this.attrs.requireParentTag&&this.selected.filter((e=>e.parent()===t)).forEach(this.removeTag.bind(this)),this.attrs.onDeselect&&this.attrs.onDeselect(t,this.selected))}toggleTag(t){this.tags&&(this.selected.includes(t)?this.removeTag(t):this.addTag(t),this.filter()&&(this.filter(""),this.indexTag=this.tags[0]),this.onready())}getInstruction(t,e){if(this.bypassReqs)return"";if(t li")}getCurrentNumericIndex(){return this.indexTag?this.selectableItems().index(this.getItem(this.indexTag)):-1}getItem(t){return this.selectableItems().filter(`[data-index="${t.id()}"]`)}setIndex(t,e){const s=this.selectableItems(),i=s.parent();t<0?t=s.length-1:t>=s.length&&(t=0);const a=s.eq(t);if(this.indexTag=p().store.getById("tags",a.attr("data-index")),m.redraw(),e&&this.indexTag){const t=i.scrollTop(),e=i.offset().top,s=e+i.outerHeight(),n=a.offset().top,r=n+a.outerHeight();let l;ns&&(l=t-s+r+parseInt(i.css("padding-bottom"),10)),void 0!==l&&i.stop(!0).animate({scrollTop:l},100)}}}flarum.reg.add("flarum-tags","common/components/TagSelectionModal",L);class B extends L{static initAttrs(t){super.initAttrs(t);const e=t.discussion?a().translator.trans("flarum-tags.forum.choose_tags.edit_title",{title:m("em",null,t.discussion.title())}):a().translator.trans("flarum-tags.forum.choose_tags.title");t.className=o()(t.className,"TagDiscussionModal"),t.title=d()(e),t.allowResetting=!!a().forum.attribute("canBypassTagCounts"),t.limits={allowBypassing:t.allowResetting,max:{primary:a().forum.attribute("maxPrimaryTags"),secondary:a().forum.attribute("maxSecondaryTags")},min:{primary:a().forum.attribute("minPrimaryTags"),secondary:a().forum.attribute("minSecondaryTags")}},t.requireParentTag=!0,t.selectableTags=()=>(0,h.A)(t.discussion),t.selectedTags??=t.discussion?.tags()||[],t.canSelect=t=>t.canStartDiscussion();const s=t.onsubmit||null;t.onsubmit=function(e){const i=t.discussion;i&&i.save({relationships:{tags:e}}).then((()=>{a().current.matches(r())&&a().current.get("stream").update(),m.redraw()})),s&&s(e)}}}flarum.reg.add("flarum-tags","forum/components/TagDiscussionModal",B)}}]); +"use strict";(self.webpackChunkmodule_exports=self.webpackChunkmodule_exports||[]).push([[371],{440:(t,e,s)=>{s.r(e),s.d(e,{default:()=>L});var i=s(488),a=s.n(i),n=s(137),r=s.n(n),l=s(443),o=s.n(l),c=s(233),d=s.n(c),h=s(838),u=s(805),g=s(954),p=s.n(g),f=s(336),y=s.n(f),T=s(607),b=s.n(T),x=s(280),w=s.n(x),I=s(661),v=s.n(I),N=s(15),_=s.n(N),S=s(821),C=s.n(S),A=s(618),k=s(339),q=s(968),M=s(950),P=s.n(M);class R extends(P()){view(t){const{className:e,isToggled:s,...i}=this.attrs,a=s?"far fa-check-circle":"far fa-circle";return m(y(),Object.assign({},i,{icon:a,className:o()([e,s&&"Button--toggled"])}),t.children)}}flarum.reg.add("flarum-tags","forum/components/ToggleButton",R);class F extends(_()){constructor(){super(...arguments),(0,u.A)(this,"loading",!0),(0,u.A)(this,"tags",void 0),(0,u.A)(this,"selected",[]),(0,u.A)(this,"bypassReqs",!1),(0,u.A)(this,"filter",C()("")),(0,u.A)(this,"focused",!1),(0,u.A)(this,"navigator",new(w())),(0,u.A)(this,"indexTag",void 0)}static initAttrs(t){super.initAttrs(t),t.title||=d()(p().translator.trans("flarum-tags.lib.tag_selection_modal.title")),t.canSelect||=()=>!0,t.allowResetting??=!0,t.limits={min:{total:t.limits?.min?.total??-1/0,primary:t.limits?.min?.primary??-1/0,secondary:t.limits?.min?.secondary??-1/0},max:{total:t.limits?.max?.total??1/0,primary:t.limits?.max?.primary??1/0,secondary:t.limits?.max?.secondary??1/0}},function(t){if(t.min.primary>t.max.primary)throw new Error("The minimum number of primary tags allowed cannot be more than the maximum number of primary tags allowed.");if(t.min.secondary>t.max.secondary)throw new Error("The minimum number of secondary tags allowed cannot be more than the maximum number of secondary tags allowed.");if(t.min.total>t.max.primary+t.max.secondary)throw new Error("The minimum number of tags allowed cannot be more than the maximum number of primary and secondary tags allowed together.");if(t.max.totalt.max.total)throw new Error("The minimum number of tags allowed cannot be more than the maximum number of tags allowed.")}(t.limits)}oninit(t){super.oninit(t),this.navigator.onUp((()=>this.setIndex(this.getCurrentNumericIndex()-1,!0))).onDown((()=>this.setIndex(this.getCurrentNumericIndex()+1,!0))).onSelect(this.select.bind(this)).onRemove((()=>this.selected.splice(this.selected.length-1,1))),p().tagList.load(["parent"]).then((t=>{this.loading=!1,this.attrs.selectableTags&&(t=this.attrs.selectableTags(t)),this.tags=(0,A.A)(t),this.attrs.selectedTags&&this.attrs.selectedTags.map(this.addTag.bind(this)),this.indexTag=t[0],m.redraw()}))}className(){return o()("TagSelectionModal Modal--simple",this.attrs.className)}title(){return this.attrs.title}lengthWithCJK(t){let e=0;for(const s of t)e+=/[\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF]/.test(s)?2:1;return e}content(){if(this.loading||!this.tags)return m(v(),null);const t=this.filter().toLowerCase(),e=this.primaryCount(),s=this.secondaryCount(),i=this.getFilteredTags(),a=Math.max(this.lengthWithCJK(d()(this.getInstruction(e,s))),this.lengthWithCJK(this.filter()));return[m("div",{className:"Modal-body"},m("div",{className:"TagSelectionModal-form"},m("div",{className:"TagSelectionModal-form-input"},m("div",{className:"TagsInput FormControl "+(this.focused?"focus":""),onclick:()=>this.$(".TagsInput input").focus()},m("span",{className:"TagsInput-selected"},this.selected.map((t=>m("span",{className:"TagsInput-tag",onclick:()=>{this.removeTag(t),this.onready()}},(0,k.A)(t))))),m("input",{className:"FormControl",placeholder:d()(this.getInstruction(e,s)),bidi:this.filter,style:{width:a+"ch"},onkeydown:this.navigator.navigate.bind(this.navigator),onfocus:()=>this.focused=!0,onblur:()=>this.focused=!1}))),m("div",{className:"TagSelectionModal-form-submit App-primaryControl"},m(y(),{type:"submit",className:"Button Button--primary",disabled:!this.meetsRequirements(e,s),icon:"fas fa-check"},p().translator.trans("flarum-tags.lib.tag_selection_modal.submit_button"))))),m("div",{className:"Modal-footer"},m("ul",{className:"TagSelectionModal-list SelectTagList"},i.map((e=>m("li",{"data-index":e.id(),className:o()("SelectTagListItem",{pinned:null!==e.position(),child:!!e.parent(),colored:!!e.color(),selected:this.selected.includes(e),active:this.indexTag===e}),style:{color:e.color()},onmouseover:()=>this.indexTag=e,onclick:this.toggleTag.bind(this,e)},m("i",{className:"SelectTagListItem-icon"},(0,q.A)(e,{className:"SelectTagListItem-tagIcon"}),m("i",{className:"icon TagIcon fas fa-check SelectTagListItem-checkIcon"})),m("span",{className:"SelectTagListItem-name"},b()(e.name(),t)),e.description()?m("span",{className:"SelectTagListItem-description"},e.description()):"")))),this.attrs.limits.allowBypassing&&m("div",{className:"TagSelectionModal-controls"},m(R,{className:"Button",onclick:()=>this.bypassReqs=!this.bypassReqs,isToggled:this.bypassReqs},p().translator.trans("flarum-tags.lib.tag_selection_modal.bypass_requirements"))))]}getFilteredTags(){const t=this.filter().toLowerCase(),e=this.primaryCount(),s=this.secondaryCount();let i=this.tags;return this.attrs.requireParentTag&&(i=i.filter((t=>{const e=t.parent();return null!==e&&(!1===e||this.selected.includes(e))}))),this.bypassReqs||(this.selected.length>=this.attrs.limits.max.total?i=i.filter((t=>this.selected.includes(t))):(e>=this.attrs.limits.max.primary&&(i=i.filter((t=>!t.isPrimaryParent()||this.selected.includes(t)))),s>=this.attrs.limits.max.secondary&&(i=i.filter((t=>t.isPrimaryParent()||this.selected.includes(t)))))),t&&(i=i.filter((e=>e.name().toLowerCase().includes(t)))),this.indexTag&&i.includes(this.indexTag)||(this.indexTag=i[0]),i}primaryCount(){return this.selected.filter((t=>t.isPrimaryParent())).length}secondaryCount(){return this.selected.filter((t=>!t.isPrimaryParent())).length}meetsRequirements(t,e){return!!(this.bypassReqs||this.attrs.allowResetting&&0===this.selected.length)||!(this.selected.length=this.attrs.limits.min.primary&&e>=this.attrs.limits.min.secondary}addTag(t){if(t&&this.attrs.canSelect(t)){if(this.attrs.onSelect&&this.attrs.onSelect(t,this.selected),this.attrs.requireParentTag){const e=t.parent();e&&!this.selected.includes(e)&&this.selected.push(e)}this.selected.includes(t)||this.selected.push(t)}}removeTag(t){const e=this.selected.indexOf(t);-1!==e&&(this.selected.splice(e,1),this.attrs.requireParentTag&&this.selected.filter((e=>e.parent()===t)).forEach(this.removeTag.bind(this)),this.attrs.onDeselect&&this.attrs.onDeselect(t,this.selected))}toggleTag(t){this.tags&&(this.selected.includes(t)?this.removeTag(t):this.addTag(t),this.filter()&&(this.filter(""),this.indexTag=this.tags[0]),this.onready())}getInstruction(t,e){if(this.bypassReqs)return"";if(t li")}getCurrentNumericIndex(){return this.indexTag?this.selectableItems().index(this.getItem(this.indexTag)):-1}getItem(t){return this.selectableItems().filter(`[data-index="${t.id()}"]`)}setIndex(t,e){const s=this.selectableItems(),i=s.parent();t<0?t=s.length-1:t>=s.length&&(t=0);const a=s.eq(t);if(this.indexTag=p().store.getById("tags",a.attr("data-index")),m.redraw(),e&&this.indexTag){const t=i.scrollTop(),e=i.offset().top,s=e+i.outerHeight(),n=a.offset().top,r=n+a.outerHeight();let l;ns&&(l=t-s+r+parseInt(i.css("padding-bottom"),10)),void 0!==l&&i.stop(!0).animate({scrollTop:l},100)}}}flarum.reg.add("flarum-tags","common/components/TagSelectionModal",F);class L extends F{static initAttrs(t){super.initAttrs(t);const e=t.discussion?a().translator.trans("flarum-tags.forum.choose_tags.edit_title",{title:m("em",null,t.discussion.title())}):a().translator.trans("flarum-tags.forum.choose_tags.title");t.className=o()(t.className,"TagDiscussionModal"),t.title=d()(e),t.allowResetting=!!a().forum.attribute("canBypassTagCounts"),t.limits={allowBypassing:t.allowResetting,max:{primary:a().forum.attribute("maxPrimaryTags"),secondary:a().forum.attribute("maxSecondaryTags")},min:{primary:a().forum.attribute("minPrimaryTags"),secondary:a().forum.attribute("minSecondaryTags")}},t.requireParentTag=!0,t.selectableTags=()=>(0,h.A)(t.discussion),t.selectedTags??=t.discussion?.tags()||[],t.canSelect=t=>t.canStartDiscussion();const s=t.onsubmit||null;t.onsubmit=function(e){const i=t.discussion;i&&i.save({relationships:{tags:e}}).then((()=>{a().current.matches(r())&&a().current.get("stream").update(),m.redraw()})),s&&s(e)}}}flarum.reg.add("flarum-tags","forum/components/TagDiscussionModal",L)}}]); //# sourceMappingURL=TagDiscussionModal.js.map \ No newline at end of file diff --git a/extensions/tags/js/dist/forum/components/TagDiscussionModal.js.map b/extensions/tags/js/dist/forum/components/TagDiscussionModal.js.map index 2a08d801d5..06392535fc 100644 --- a/extensions/tags/js/dist/forum/components/TagDiscussionModal.js.map +++ b/extensions/tags/js/dist/forum/components/TagDiscussionModal.js.map @@ -1 +1 @@ -{"version":3,"file":"forum/components/TagDiscussionMod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H,WACnC,eAAeC,MAAM,uCAC1BhB,EAAMF,UAAY,IAAUE,EAAMF,UAAW,sBAC7CE,EAAMe,MAAQ,IAAYA,GAC1Bf,EAAMkB,iBAAmB,UAAU0H,UAAU,sBAC7C5I,EAAMmB,OAAS,CACb2E,eAAgB9F,EAAMkB,eACtBM,IAAK,CACHF,QAAS,UAAUsH,UAAU,kBAC7BrH,UAAW,UAAUqH,UAAU,qBAEjCxH,IAAK,CACHE,QAAS,UAAUsH,UAAU,kBAC7BrH,UAAW,UAAUqH,UAAU,sBAGnC5I,EAAMgG,kBAAmB,EACzBhG,EAAM6C,eAAiB,KAAM,EAAAgG,EAAA,GAAkB7I,EAAM2I,YACrD3I,EAAM+C,eAAiB/C,EAAM2I,YAAYhG,QAAU,GACnD3C,EAAMiB,UAAYgD,GAAOA,EAAI6E,qBAC7B,MAAMC,EAAmB/I,EAAM0G,UAAY,KAG3C1G,EAAM0G,SAAW,SAAU/D,GACzB,MAAMgG,EAAa3I,EAAM2I,WACrBA,GACFA,EAAWK,KAAK,CACdC,cAAe,CACbtG,UAEDD,MAAK,KACF,YAAYwG,QAAQ,MACtB,YAAYC,IAAI,UAAUC,SAE5BjJ,EAAEgD,QAAQ,IAGV4F,GAAkBA,EAAiBpG,EACzC,CACF,EAEFpC,OAAOC,IAAIC,IAAI,cAAe,sCAAuCiI,E","sources":["webpack://@flarum/tags/./src/forum/components/ToggleButton.js","webpack://@flarum/tags/./src/common/components/TagSelectionModal.tsx","webpack://@flarum/tags/./src/forum/components/TagDiscussionModal.tsx"],"sourcesContent":["import Component from 'flarum/common/Component';\nimport Button from 'flarum/common/components/Button';\nimport classList from 'flarum/common/utils/classList';\n\n/**\n * @TODO move to core\n */\nexport default class ToggleButton extends Component {\n view(vnode) {\n const {\n className,\n isToggled,\n ...attrs\n } = this.attrs;\n const icon = isToggled ? 'far fa-check-circle' : 'far fa-circle';\n return m(Button, Object.assign({}, attrs, {\n icon: icon,\n className: classList([className, isToggled && 'Button--toggled'])\n }), vnode.children);\n }\n}\nflarum.reg.add('flarum-tags', 'forum/components/ToggleButton', ToggleButton);","import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport app from 'flarum/common/app';\nimport Button from 'flarum/common/components/Button';\nimport classList from 'flarum/common/utils/classList';\nimport extractText from 'flarum/common/utils/extractText';\nimport highlight from 'flarum/common/helpers/highlight';\nimport KeyboardNavigatable from 'flarum/common/utils/KeyboardNavigatable';\nimport LoadingIndicator from 'flarum/common/components/LoadingIndicator';\nimport FormModal from 'flarum/common/components/FormModal';\nimport Stream from 'flarum/common/utils/Stream';\nimport sortTags from '../utils/sortTags';\nimport tagLabel from '../helpers/tagLabel';\nimport tagIcon from '../helpers/tagIcon';\nimport ToggleButton from '../../forum/components/ToggleButton';\nexport default class TagSelectionModal extends FormModal {\n constructor() {\n super(...arguments);\n _defineProperty(this, \"loading\", true);\n _defineProperty(this, \"tags\", void 0);\n _defineProperty(this, \"selected\", []);\n _defineProperty(this, \"bypassReqs\", false);\n _defineProperty(this, \"filter\", Stream(''));\n _defineProperty(this, \"focused\", false);\n _defineProperty(this, \"navigator\", new KeyboardNavigatable());\n _defineProperty(this, \"indexTag\", void 0);\n }\n static initAttrs(attrs) {\n super.initAttrs(attrs);\n\n // Default values for optional attributes.\n attrs.title ||= extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.title'));\n attrs.canSelect ||= () => true;\n attrs.allowResetting ??= true;\n attrs.limits = {\n min: {\n total: attrs.limits?.min?.total ?? -Infinity,\n primary: attrs.limits?.min?.primary ?? -Infinity,\n secondary: attrs.limits?.min?.secondary ?? -Infinity\n },\n max: {\n total: attrs.limits?.max?.total ?? Infinity,\n primary: attrs.limits?.max?.primary ?? Infinity,\n secondary: attrs.limits?.max?.secondary ?? Infinity\n }\n };\n\n // Prevent illogical limits from being provided.\n catchInvalidLimits(attrs.limits);\n }\n oninit(vnode) {\n super.oninit(vnode);\n this.navigator.onUp(() => this.setIndex(this.getCurrentNumericIndex() - 1, true)).onDown(() => this.setIndex(this.getCurrentNumericIndex() + 1, true)).onSelect(this.select.bind(this)).onRemove(() => this.selected.splice(this.selected.length - 1, 1));\n app.tagList.load(['parent']).then(tags => {\n this.loading = false;\n if (this.attrs.selectableTags) {\n tags = this.attrs.selectableTags(tags);\n }\n this.tags = sortTags(tags);\n if (this.attrs.selectedTags) {\n this.attrs.selectedTags.map(this.addTag.bind(this));\n }\n this.indexTag = tags[0];\n m.redraw();\n });\n }\n className() {\n return classList('TagSelectionModal Modal--simple', this.attrs.className);\n }\n title() {\n return this.attrs.title;\n }\n content() {\n if (this.loading || !this.tags) {\n return m(LoadingIndicator, null);\n }\n const filter = this.filter().toLowerCase();\n const primaryCount = this.primaryCount();\n const secondaryCount = this.secondaryCount();\n const tags = this.getFilteredTags();\n const inputWidth = Math.max(extractText(this.getInstruction(primaryCount, secondaryCount)).length, this.filter().length);\n return [m(\"div\", {\n className: \"Modal-body\"\n }, m(\"div\", {\n className: \"TagSelectionModal-form\"\n }, m(\"div\", {\n className: \"TagSelectionModal-form-input\"\n }, m(\"div\", {\n className: 'TagsInput FormControl ' + (this.focused ? 'focus' : ''),\n onclick: () => this.$('.TagsInput input').focus()\n }, m(\"span\", {\n className: \"TagsInput-selected\"\n }, this.selected.map(tag => m(\"span\", {\n className: \"TagsInput-tag\",\n onclick: () => {\n this.removeTag(tag);\n this.onready();\n }\n }, tagLabel(tag)))), m(\"input\", {\n className: \"FormControl\",\n placeholder: extractText(this.getInstruction(primaryCount, secondaryCount)),\n bidi: this.filter,\n style: {\n width: inputWidth + 'ch'\n },\n onkeydown: this.navigator.navigate.bind(this.navigator),\n onfocus: () => this.focused = true,\n onblur: () => this.focused = false\n }))), m(\"div\", {\n className: \"TagSelectionModal-form-submit App-primaryControl\"\n }, m(Button, {\n type: \"submit\",\n className: \"Button Button--primary\",\n disabled: !this.meetsRequirements(primaryCount, secondaryCount),\n icon: \"fas fa-check\"\n }, app.translator.trans('flarum-tags.lib.tag_selection_modal.submit_button'))))), m(\"div\", {\n className: \"Modal-footer\"\n }, m(\"ul\", {\n className: \"TagSelectionModal-list SelectTagList\"\n }, tags.map(tag => m(\"li\", {\n \"data-index\": tag.id(),\n className: classList('SelectTagListItem', {\n pinned: tag.position() !== null,\n child: !!tag.parent(),\n colored: !!tag.color(),\n selected: this.selected.includes(tag),\n active: this.indexTag === tag\n }),\n style: {\n color: tag.color()\n },\n onmouseover: () => this.indexTag = tag,\n onclick: this.toggleTag.bind(this, tag)\n }, m(\"i\", {\n className: \"SelectTagListItem-icon\"\n }, tagIcon(tag, {\n className: 'SelectTagListItem-tagIcon'\n }), m(\"i\", {\n className: \"icon TagIcon fas fa-check SelectTagListItem-checkIcon\"\n })), m(\"span\", {\n className: \"SelectTagListItem-name\"\n }, highlight(tag.name(), filter)), tag.description() ? m(\"span\", {\n className: \"SelectTagListItem-description\"\n }, tag.description()) : ''))), this.attrs.limits.allowBypassing && m(\"div\", {\n className: \"TagSelectionModal-controls\"\n }, m(ToggleButton, {\n className: \"Button\",\n onclick: () => this.bypassReqs = !this.bypassReqs,\n isToggled: this.bypassReqs\n }, app.translator.trans('flarum-tags.lib.tag_selection_modal.bypass_requirements'))))];\n }\n\n /**\n * Filters the available tags on every state change.\n */\n getFilteredTags() {\n const filter = this.filter().toLowerCase();\n const primaryCount = this.primaryCount();\n const secondaryCount = this.secondaryCount();\n let tags = this.tags;\n if (this.attrs.requireParentTag) {\n // Filter out all child tags whose parents have not been selected. This\n // makes it impossible to select a child if its parent hasn't been selected.\n tags = tags.filter(tag => {\n const parent = tag.parent();\n return parent !== null && (parent === false || this.selected.includes(parent));\n });\n }\n if (!this.bypassReqs) {\n // If we reached the total maximum number of tags, we can't select anymore.\n if (this.selected.length >= this.attrs.limits.max.total) {\n tags = tags.filter(tag => this.selected.includes(tag));\n }\n // If the number of selected primary/secondary tags is at the maximum, then\n // we'll filter out all other tags of that type.\n else {\n if (primaryCount >= this.attrs.limits.max.primary) {\n tags = tags.filter(tag => !tag.isPrimaryParent() || this.selected.includes(tag));\n }\n if (secondaryCount >= this.attrs.limits.max.secondary) {\n tags = tags.filter(tag => tag.isPrimaryParent() || this.selected.includes(tag));\n }\n }\n }\n\n // If the user has entered text in the filter input, then filter by tags\n // whose name matches what they've entered.\n if (filter) {\n tags = tags.filter(tag => tag.name().toLowerCase().includes(filter));\n }\n if (!this.indexTag || !tags.includes(this.indexTag)) this.indexTag = tags[0];\n return tags;\n }\n\n /**\n * Counts the number of selected primary tags.\n */\n primaryCount() {\n return this.selected.filter(tag => tag.isPrimaryParent()).length;\n }\n\n /**\n * Counts the number of selected secondary tags.\n */\n secondaryCount() {\n return this.selected.filter(tag => !tag.isPrimaryParent()).length;\n }\n\n /**\n * Validates the number of selected primary/secondary tags against the set min max limits.\n */\n meetsRequirements(primaryCount, secondaryCount) {\n if (this.bypassReqs || this.attrs.allowResetting && this.selected.length === 0) {\n return true;\n }\n if (this.selected.length < this.attrs.limits.min.total) {\n return false;\n }\n return primaryCount >= this.attrs.limits.min.primary && secondaryCount >= this.attrs.limits.min.secondary;\n }\n\n /**\n * Add the given tag to the list of selected tags.\n */\n addTag(tag) {\n if (!tag || !this.attrs.canSelect(tag)) return;\n if (this.attrs.onSelect) {\n this.attrs.onSelect(tag, this.selected);\n }\n\n // If this tag has a parent, we'll also need to add the parent tag to the\n // selected list if it's not already in there.\n if (this.attrs.requireParentTag) {\n const parent = tag.parent();\n if (parent && !this.selected.includes(parent)) {\n this.selected.push(parent);\n }\n }\n if (!this.selected.includes(tag)) {\n this.selected.push(tag);\n }\n }\n\n /**\n * Remove the given tag from the list of selected tags.\n */\n removeTag(tag) {\n const index = this.selected.indexOf(tag);\n if (index !== -1) {\n this.selected.splice(index, 1);\n\n // Look through the list of selected tags for any tags which have the tag\n // we just removed as their parent. We'll need to remove them too.\n if (this.attrs.requireParentTag) {\n this.selected.filter(t => t.parent() === tag).forEach(this.removeTag.bind(this));\n }\n if (this.attrs.onDeselect) {\n this.attrs.onDeselect(tag, this.selected);\n }\n }\n }\n toggleTag(tag) {\n // Won't happen, needed for type safety.\n if (!this.tags) return;\n if (this.selected.includes(tag)) {\n this.removeTag(tag);\n } else {\n this.addTag(tag);\n }\n if (this.filter()) {\n this.filter('');\n this.indexTag = this.tags[0];\n }\n this.onready();\n }\n\n /**\n * Gives human text instructions based on the current number of selected tags and set limits.\n */\n getInstruction(primaryCount, secondaryCount) {\n if (this.bypassReqs) {\n return '';\n }\n if (primaryCount < this.attrs.limits.min.primary) {\n const remaining = this.attrs.limits.min.primary - primaryCount;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_primary_placeholder', {\n count: remaining\n }));\n } else if (secondaryCount < this.attrs.limits.min.secondary) {\n const remaining = this.attrs.limits.min.secondary - secondaryCount;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_secondary_placeholder', {\n count: remaining\n }));\n } else if (this.selected.length < this.attrs.limits.min.total) {\n const remaining = this.attrs.limits.min.total - this.selected.length;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_tags_placeholder', {\n count: remaining\n }));\n }\n return '';\n }\n\n /**\n * Submit tag selection.\n */\n onsubmit(e) {\n e.preventDefault();\n if (this.attrs.onsubmit) this.attrs.onsubmit(this.selected);\n this.hide();\n }\n select(e) {\n // Ctrl + Enter submits the selection, just Enter completes the current entry\n if (e.metaKey || e.ctrlKey || this.indexTag && this.selected.includes(this.indexTag)) {\n if (this.selected.length) {\n // The DOM submit method doesn't emit a `submit event, so we\n // simulate a manual submission so our `onsubmit` logic is run.\n this.$('button[type=\"submit\"]').click();\n }\n } else if (this.indexTag) {\n this.getItem(this.indexTag)[0].dispatchEvent(new Event('click'));\n }\n }\n selectableItems() {\n return this.$('.TagSelectionModal-list > li');\n }\n getCurrentNumericIndex() {\n if (!this.indexTag) return -1;\n return this.selectableItems().index(this.getItem(this.indexTag));\n }\n getItem(selectedTag) {\n return this.selectableItems().filter(`[data-index=\"${selectedTag.id()}\"]`);\n }\n setIndex(index, scrollToItem) {\n const $items = this.selectableItems();\n const $dropdown = $items.parent();\n if (index < 0) {\n index = $items.length - 1;\n } else if (index >= $items.length) {\n index = 0;\n }\n const $item = $items.eq(index);\n this.indexTag = app.store.getById('tags', $item.attr('data-index'));\n m.redraw();\n if (scrollToItem && this.indexTag) {\n const dropdownScroll = $dropdown.scrollTop();\n const dropdownTop = $dropdown.offset().top;\n const dropdownBottom = dropdownTop + $dropdown.outerHeight();\n const itemTop = $item.offset().top;\n const itemBottom = itemTop + $item.outerHeight();\n let scrollTop;\n if (itemTop < dropdownTop) {\n scrollTop = dropdownScroll - dropdownTop + itemTop - parseInt($dropdown.css('padding-top'), 10);\n } else if (itemBottom > dropdownBottom) {\n scrollTop = dropdownScroll - dropdownBottom + itemBottom + parseInt($dropdown.css('padding-bottom'), 10);\n }\n if (typeof scrollTop !== 'undefined') {\n $dropdown.stop(true).animate({\n scrollTop\n }, 100);\n }\n }\n }\n}\n\n/**\n * Catch invalid limits provided to the tag selection modal.\n */\nfunction catchInvalidLimits(limits) {\n if (limits.min.primary > limits.max.primary) {\n throw new Error('The minimum number of primary tags allowed cannot be more than the maximum number of primary tags allowed.');\n }\n if (limits.min.secondary > limits.max.secondary) {\n throw new Error('The minimum number of secondary tags allowed cannot be more than the maximum number of secondary tags allowed.');\n }\n if (limits.min.total > limits.max.primary + limits.max.secondary) {\n throw new Error('The minimum number of tags allowed cannot be more than the maximum number of primary and secondary tags allowed together.');\n }\n if (limits.max.total < limits.min.primary + limits.min.secondary) {\n throw new Error('The maximum number of tags allowed cannot be less than the minimum number of primary and secondary tags allowed together.');\n }\n if (limits.min.total > limits.max.total) {\n throw new Error('The minimum number of tags allowed cannot be more than the maximum number of tags allowed.');\n }\n}\nflarum.reg.add('flarum-tags', 'common/components/TagSelectionModal', TagSelectionModal);","import app from 'flarum/forum/app';\nimport DiscussionPage from 'flarum/forum/components/DiscussionPage';\nimport classList from 'flarum/common/utils/classList';\nimport extractText from 'flarum/common/utils/extractText';\nimport getSelectableTags from '../utils/getSelectableTags';\nimport TagSelectionModal from '../../common/components/TagSelectionModal';\nexport default class TagDiscussionModal extends TagSelectionModal {\n static initAttrs(attrs) {\n super.initAttrs(attrs);\n const title = attrs.discussion ? app.translator.trans('flarum-tags.forum.choose_tags.edit_title', {\n title: m(\"em\", null, attrs.discussion.title())\n }) : app.translator.trans('flarum-tags.forum.choose_tags.title');\n attrs.className = classList(attrs.className, 'TagDiscussionModal');\n attrs.title = extractText(title);\n attrs.allowResetting = !!app.forum.attribute('canBypassTagCounts');\n attrs.limits = {\n allowBypassing: attrs.allowResetting,\n max: {\n primary: app.forum.attribute('maxPrimaryTags'),\n secondary: app.forum.attribute('maxSecondaryTags')\n },\n min: {\n primary: app.forum.attribute('minPrimaryTags'),\n secondary: app.forum.attribute('minSecondaryTags')\n }\n };\n attrs.requireParentTag = true;\n attrs.selectableTags = () => getSelectableTags(attrs.discussion);\n attrs.selectedTags ??= attrs.discussion?.tags() || [];\n attrs.canSelect = tag => tag.canStartDiscussion();\n const suppliedOnsubmit = attrs.onsubmit || null;\n\n // Save changes.\n attrs.onsubmit = function (tags) {\n const discussion = attrs.discussion;\n if (discussion) {\n discussion.save({\n relationships: {\n tags\n }\n }).then(() => {\n if (app.current.matches(DiscussionPage)) {\n app.current.get('stream').update();\n }\n m.redraw();\n });\n }\n if (suppliedOnsubmit) suppliedOnsubmit(tags);\n };\n }\n}\nflarum.reg.add('flarum-tags', 'forum/components/TagDiscussionModal', TagDiscussionModal);"],"names":["ToggleButton","view","vnode","className","isToggled","attrs","this","icon","m","Object","assign","children","flarum","reg","add","TagSelectionModal","constructor","super","arguments","initAttrs","title","trans","canSelect","allowResetting","limits","min","total","primary","secondary","max","Infinity","Error","catchInvalidLimits","oninit","navigator","onUp","setIndex","getCurrentNumericIndex","onDown","onSelect","select","bind","onRemove","selected","splice","length","load","then","tags","loading","selectableTags","sortTags","selectedTags","map","addTag","indexTag","redraw","content","filter","toLowerCase","primaryCount","secondaryCount","getFilteredTags","inputWidth","Math","getInstruction","focused","onclick","$","focus","tag","removeTag","onready","tagLabel","placeholder","bidi","style","width","onkeydown","navigate","onfocus","onblur","type","disabled","meetsRequirements","id","pinned","position","child","parent","colored","color","includes","active","onmouseover","toggleTag","tagIcon","name","description","allowBypassing","bypassReqs","requireParentTag","isPrimaryParent","push","index","indexOf","t","forEach","onDeselect","remaining","count","onsubmit","e","preventDefault","hide","metaKey","ctrlKey","click","getItem","dispatchEvent","Event","selectableItems","selectedTag","scrollToItem","$items","$dropdown","$item","eq","getById","attr","dropdownScroll","scrollTop","dropdownTop","offset","top","dropdownBottom","outerHeight","itemTop","itemBottom","parseInt","css","stop","animate","TagDiscussionModal","discussion","attribute","getSelectableTags","canStartDiscussion","suppliedOnsubmit","save","relationships","matches","get","update"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"forum/components/TagDiscussionModal.js","mappings":"oZAOe,MAAMA,UAAqB,KACxC,IAAAC,CAAKC,GACH,MAAM,UACJC,EAAS,UACTC,KACGC,GACDC,KAAKD,MACHE,EAAOH,EAAY,sBAAwB,gBACjD,OAAOI,EAAE,IAAQC,OAAOC,OAAO,CAAC,EAAGL,EAAO,CACxCE,KAAMA,EACNJ,UAAW,IAAU,CAACA,EAAWC,GAAa,sBAC5CF,EAAMS,SACZ,EAEFC,OAAOC,IAAIC,IAAI,cAAe,gCAAiCd,GCPhD,MAAMe,UAA0B,KAC7C,WAAAC,GACEC,SAASC,YACT,OAAgBZ,KAAM,WAAW,IACjC,OAAgBA,KAAM,YAAQ,IAC9B,OAAgBA,KAAM,WAAY,KAClC,OAAgBA,KAAM,cAAc,IACpC,OAAgBA,KAAM,SAAU,IAAO,MACvC,OAAgBA,KAAM,WAAW,IACjC,OAAgBA,KAAM,YAAa,IAAI,OACvC,OAAgBA,KAAM,gBAAY,EACpC,CACA,gBAAOa,CAAUd,GACfY,MAAME,UAAUd,GAGhBA,EAAMe,QAAU,IAAY,eAAeC,MAAM,8CACjDhB,EAAMiB,YAAc,KAAM,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,EAAM8G,UAAY,KAG3C9G,EAAM8G,SAAW,SAAUnE,GACzB,MAAMoG,EAAa/I,EAAM+I,WACrBA,GACFA,EAAWK,KAAK,CACdC,cAAe,CACb1G,UAEDD,MAAK,KACF,YAAY4G,QAAQ,MACtB,YAAYC,IAAI,UAAUC,SAE5BrJ,EAAEgD,QAAQ,IAGVgG,GAAkBA,EAAiBxG,EACzC,CACF,EAEFpC,OAAOC,IAAIC,IAAI,cAAe,sCAAuCqI,E","sources":["webpack://@flarum/tags/./src/forum/components/ToggleButton.js","webpack://@flarum/tags/./src/common/components/TagSelectionModal.tsx","webpack://@flarum/tags/./src/forum/components/TagDiscussionModal.tsx"],"sourcesContent":["import Component from 'flarum/common/Component';\nimport Button from 'flarum/common/components/Button';\nimport classList from 'flarum/common/utils/classList';\n\n/**\n * @TODO move to core\n */\nexport default class ToggleButton extends Component {\n view(vnode) {\n const {\n className,\n isToggled,\n ...attrs\n } = this.attrs;\n const icon = isToggled ? 'far fa-check-circle' : 'far fa-circle';\n return m(Button, Object.assign({}, attrs, {\n icon: icon,\n className: classList([className, isToggled && 'Button--toggled'])\n }), vnode.children);\n }\n}\nflarum.reg.add('flarum-tags', 'forum/components/ToggleButton', ToggleButton);","import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport app from 'flarum/common/app';\nimport Button from 'flarum/common/components/Button';\nimport classList from 'flarum/common/utils/classList';\nimport extractText from 'flarum/common/utils/extractText';\nimport highlight from 'flarum/common/helpers/highlight';\nimport KeyboardNavigatable from 'flarum/common/utils/KeyboardNavigatable';\nimport LoadingIndicator from 'flarum/common/components/LoadingIndicator';\nimport FormModal from 'flarum/common/components/FormModal';\nimport Stream from 'flarum/common/utils/Stream';\nimport sortTags from '../utils/sortTags';\nimport tagLabel from '../helpers/tagLabel';\nimport tagIcon from '../helpers/tagIcon';\nimport ToggleButton from '../../forum/components/ToggleButton';\nexport default class TagSelectionModal extends FormModal {\n constructor() {\n super(...arguments);\n _defineProperty(this, \"loading\", true);\n _defineProperty(this, \"tags\", void 0);\n _defineProperty(this, \"selected\", []);\n _defineProperty(this, \"bypassReqs\", false);\n _defineProperty(this, \"filter\", Stream(''));\n _defineProperty(this, \"focused\", false);\n _defineProperty(this, \"navigator\", new KeyboardNavigatable());\n _defineProperty(this, \"indexTag\", void 0);\n }\n static initAttrs(attrs) {\n super.initAttrs(attrs);\n\n // Default values for optional attributes.\n attrs.title ||= extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.title'));\n attrs.canSelect ||= () => true;\n attrs.allowResetting ??= true;\n attrs.limits = {\n min: {\n total: attrs.limits?.min?.total ?? -Infinity,\n primary: attrs.limits?.min?.primary ?? -Infinity,\n secondary: attrs.limits?.min?.secondary ?? -Infinity\n },\n max: {\n total: attrs.limits?.max?.total ?? Infinity,\n primary: attrs.limits?.max?.primary ?? Infinity,\n secondary: attrs.limits?.max?.secondary ?? Infinity\n }\n };\n\n // Prevent illogical limits from being provided.\n catchInvalidLimits(attrs.limits);\n }\n oninit(vnode) {\n super.oninit(vnode);\n this.navigator.onUp(() => this.setIndex(this.getCurrentNumericIndex() - 1, true)).onDown(() => this.setIndex(this.getCurrentNumericIndex() + 1, true)).onSelect(this.select.bind(this)).onRemove(() => this.selected.splice(this.selected.length - 1, 1));\n app.tagList.load(['parent']).then(tags => {\n this.loading = false;\n if (this.attrs.selectableTags) {\n tags = this.attrs.selectableTags(tags);\n }\n this.tags = sortTags(tags);\n if (this.attrs.selectedTags) {\n this.attrs.selectedTags.map(this.addTag.bind(this));\n }\n this.indexTag = tags[0];\n m.redraw();\n });\n }\n className() {\n return classList('TagSelectionModal Modal--simple', this.attrs.className);\n }\n title() {\n return this.attrs.title;\n }\n lengthWithCJK(text) {\n let length = 0;\n for (const char of text) {\n length += /[\\u4E00-\\u9FFF\\u3400-\\u4DBF\\uF900-\\uFAFF]/.test(char) ? 2 : 1;\n }\n return length;\n }\n content() {\n if (this.loading || !this.tags) {\n return m(LoadingIndicator, null);\n }\n const filter = this.filter().toLowerCase();\n const primaryCount = this.primaryCount();\n const secondaryCount = this.secondaryCount();\n const tags = this.getFilteredTags();\n\n // 1 CJK character's width equals to 2ch,\n // so we count 1 CJK character as 2 characters.\n const inputWidth = Math.max(this.lengthWithCJK(extractText(this.getInstruction(primaryCount, secondaryCount))), this.lengthWithCJK(this.filter()));\n return [m(\"div\", {\n className: \"Modal-body\"\n }, m(\"div\", {\n className: \"TagSelectionModal-form\"\n }, m(\"div\", {\n className: \"TagSelectionModal-form-input\"\n }, m(\"div\", {\n className: 'TagsInput FormControl ' + (this.focused ? 'focus' : ''),\n onclick: () => this.$('.TagsInput input').focus()\n }, m(\"span\", {\n className: \"TagsInput-selected\"\n }, this.selected.map(tag => m(\"span\", {\n className: \"TagsInput-tag\",\n onclick: () => {\n this.removeTag(tag);\n this.onready();\n }\n }, tagLabel(tag)))), m(\"input\", {\n className: \"FormControl\",\n placeholder: extractText(this.getInstruction(primaryCount, secondaryCount)),\n bidi: this.filter,\n style: {\n width: inputWidth + 'ch'\n },\n onkeydown: this.navigator.navigate.bind(this.navigator),\n onfocus: () => this.focused = true,\n onblur: () => this.focused = false\n }))), m(\"div\", {\n className: \"TagSelectionModal-form-submit App-primaryControl\"\n }, m(Button, {\n type: \"submit\",\n className: \"Button Button--primary\",\n disabled: !this.meetsRequirements(primaryCount, secondaryCount),\n icon: \"fas fa-check\"\n }, app.translator.trans('flarum-tags.lib.tag_selection_modal.submit_button'))))), m(\"div\", {\n className: \"Modal-footer\"\n }, m(\"ul\", {\n className: \"TagSelectionModal-list SelectTagList\"\n }, tags.map(tag => m(\"li\", {\n \"data-index\": tag.id(),\n className: classList('SelectTagListItem', {\n pinned: tag.position() !== null,\n child: !!tag.parent(),\n colored: !!tag.color(),\n selected: this.selected.includes(tag),\n active: this.indexTag === tag\n }),\n style: {\n color: tag.color()\n },\n onmouseover: () => this.indexTag = tag,\n onclick: this.toggleTag.bind(this, tag)\n }, m(\"i\", {\n className: \"SelectTagListItem-icon\"\n }, tagIcon(tag, {\n className: 'SelectTagListItem-tagIcon'\n }), m(\"i\", {\n className: \"icon TagIcon fas fa-check SelectTagListItem-checkIcon\"\n })), m(\"span\", {\n className: \"SelectTagListItem-name\"\n }, highlight(tag.name(), filter)), tag.description() ? m(\"span\", {\n className: \"SelectTagListItem-description\"\n }, tag.description()) : ''))), this.attrs.limits.allowBypassing && m(\"div\", {\n className: \"TagSelectionModal-controls\"\n }, m(ToggleButton, {\n className: \"Button\",\n onclick: () => this.bypassReqs = !this.bypassReqs,\n isToggled: this.bypassReqs\n }, app.translator.trans('flarum-tags.lib.tag_selection_modal.bypass_requirements'))))];\n }\n\n /**\n * Filters the available tags on every state change.\n */\n getFilteredTags() {\n const filter = this.filter().toLowerCase();\n const primaryCount = this.primaryCount();\n const secondaryCount = this.secondaryCount();\n let tags = this.tags;\n if (this.attrs.requireParentTag) {\n // Filter out all child tags whose parents have not been selected. This\n // makes it impossible to select a child if its parent hasn't been selected.\n tags = tags.filter(tag => {\n const parent = tag.parent();\n return parent !== null && (parent === false || this.selected.includes(parent));\n });\n }\n if (!this.bypassReqs) {\n // If we reached the total maximum number of tags, we can't select anymore.\n if (this.selected.length >= this.attrs.limits.max.total) {\n tags = tags.filter(tag => this.selected.includes(tag));\n }\n // If the number of selected primary/secondary tags is at the maximum, then\n // we'll filter out all other tags of that type.\n else {\n if (primaryCount >= this.attrs.limits.max.primary) {\n tags = tags.filter(tag => !tag.isPrimaryParent() || this.selected.includes(tag));\n }\n if (secondaryCount >= this.attrs.limits.max.secondary) {\n tags = tags.filter(tag => tag.isPrimaryParent() || this.selected.includes(tag));\n }\n }\n }\n\n // If the user has entered text in the filter input, then filter by tags\n // whose name matches what they've entered.\n if (filter) {\n tags = tags.filter(tag => tag.name().toLowerCase().includes(filter));\n }\n if (!this.indexTag || !tags.includes(this.indexTag)) this.indexTag = tags[0];\n return tags;\n }\n\n /**\n * Counts the number of selected primary tags.\n */\n primaryCount() {\n return this.selected.filter(tag => tag.isPrimaryParent()).length;\n }\n\n /**\n * Counts the number of selected secondary tags.\n */\n secondaryCount() {\n return this.selected.filter(tag => !tag.isPrimaryParent()).length;\n }\n\n /**\n * Validates the number of selected primary/secondary tags against the set min max limits.\n */\n meetsRequirements(primaryCount, secondaryCount) {\n if (this.bypassReqs || this.attrs.allowResetting && this.selected.length === 0) {\n return true;\n }\n if (this.selected.length < this.attrs.limits.min.total) {\n return false;\n }\n return primaryCount >= this.attrs.limits.min.primary && secondaryCount >= this.attrs.limits.min.secondary;\n }\n\n /**\n * Add the given tag to the list of selected tags.\n */\n addTag(tag) {\n if (!tag || !this.attrs.canSelect(tag)) return;\n if (this.attrs.onSelect) {\n this.attrs.onSelect(tag, this.selected);\n }\n\n // If this tag has a parent, we'll also need to add the parent tag to the\n // selected list if it's not already in there.\n if (this.attrs.requireParentTag) {\n const parent = tag.parent();\n if (parent && !this.selected.includes(parent)) {\n this.selected.push(parent);\n }\n }\n if (!this.selected.includes(tag)) {\n this.selected.push(tag);\n }\n }\n\n /**\n * Remove the given tag from the list of selected tags.\n */\n removeTag(tag) {\n const index = this.selected.indexOf(tag);\n if (index !== -1) {\n this.selected.splice(index, 1);\n\n // Look through the list of selected tags for any tags which have the tag\n // we just removed as their parent. We'll need to remove them too.\n if (this.attrs.requireParentTag) {\n this.selected.filter(t => t.parent() === tag).forEach(this.removeTag.bind(this));\n }\n if (this.attrs.onDeselect) {\n this.attrs.onDeselect(tag, this.selected);\n }\n }\n }\n toggleTag(tag) {\n // Won't happen, needed for type safety.\n if (!this.tags) return;\n if (this.selected.includes(tag)) {\n this.removeTag(tag);\n } else {\n this.addTag(tag);\n }\n if (this.filter()) {\n this.filter('');\n this.indexTag = this.tags[0];\n }\n this.onready();\n }\n\n /**\n * Gives human text instructions based on the current number of selected tags and set limits.\n */\n getInstruction(primaryCount, secondaryCount) {\n if (this.bypassReqs) {\n return '';\n }\n if (primaryCount < this.attrs.limits.min.primary) {\n const remaining = this.attrs.limits.min.primary - primaryCount;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_primary_placeholder', {\n count: remaining\n }));\n } else if (secondaryCount < this.attrs.limits.min.secondary) {\n const remaining = this.attrs.limits.min.secondary - secondaryCount;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_secondary_placeholder', {\n count: remaining\n }));\n } else if (this.selected.length < this.attrs.limits.min.total) {\n const remaining = this.attrs.limits.min.total - this.selected.length;\n return extractText(app.translator.trans('flarum-tags.lib.tag_selection_modal.choose_tags_placeholder', {\n count: remaining\n }));\n }\n return '';\n }\n\n /**\n * Submit tag selection.\n */\n onsubmit(e) {\n e.preventDefault();\n if (this.attrs.onsubmit) this.attrs.onsubmit(this.selected);\n this.hide();\n }\n select(e) {\n // Ctrl + Enter submits the selection, just Enter completes the current entry\n if (e.metaKey || e.ctrlKey || this.indexTag && this.selected.includes(this.indexTag)) {\n if (this.selected.length) {\n // The DOM submit method doesn't emit a `submit event, so we\n // simulate a manual submission so our `onsubmit` logic is run.\n this.$('button[type=\"submit\"]').click();\n }\n } else if (this.indexTag) {\n this.getItem(this.indexTag)[0].dispatchEvent(new Event('click'));\n }\n }\n selectableItems() {\n return this.$('.TagSelectionModal-list > li');\n }\n getCurrentNumericIndex() {\n if (!this.indexTag) return -1;\n return this.selectableItems().index(this.getItem(this.indexTag));\n }\n getItem(selectedTag) {\n return this.selectableItems().filter(`[data-index=\"${selectedTag.id()}\"]`);\n }\n setIndex(index, scrollToItem) {\n const $items = this.selectableItems();\n const $dropdown = $items.parent();\n if (index < 0) {\n index = $items.length - 1;\n } else if (index >= $items.length) {\n index = 0;\n }\n const $item = $items.eq(index);\n this.indexTag = app.store.getById('tags', $item.attr('data-index'));\n m.redraw();\n if (scrollToItem && this.indexTag) {\n const dropdownScroll = $dropdown.scrollTop();\n const dropdownTop = $dropdown.offset().top;\n const dropdownBottom = dropdownTop + $dropdown.outerHeight();\n const itemTop = $item.offset().top;\n const itemBottom = itemTop + $item.outerHeight();\n let scrollTop;\n if (itemTop < dropdownTop) {\n scrollTop = dropdownScroll - dropdownTop + itemTop - parseInt($dropdown.css('padding-top'), 10);\n } else if (itemBottom > dropdownBottom) {\n scrollTop = dropdownScroll - dropdownBottom + itemBottom + parseInt($dropdown.css('padding-bottom'), 10);\n }\n if (typeof scrollTop !== 'undefined') {\n $dropdown.stop(true).animate({\n scrollTop\n }, 100);\n }\n }\n }\n}\n\n/**\n * Catch invalid limits provided to the tag selection modal.\n */\nfunction catchInvalidLimits(limits) {\n if (limits.min.primary > limits.max.primary) {\n throw new Error('The minimum number of primary tags allowed cannot be more than the maximum number of primary tags allowed.');\n }\n if (limits.min.secondary > limits.max.secondary) {\n throw new Error('The minimum number of secondary tags allowed cannot be more than the maximum number of secondary tags allowed.');\n }\n if (limits.min.total > limits.max.primary + limits.max.secondary) {\n throw new Error('The minimum number of tags allowed cannot be more than the maximum number of primary and secondary tags allowed together.');\n }\n if (limits.max.total < limits.min.primary + limits.min.secondary) {\n throw new Error('The maximum number of tags allowed cannot be less than the minimum number of primary and secondary tags allowed together.');\n }\n if (limits.min.total > limits.max.total) {\n throw new Error('The minimum number of tags allowed cannot be more than the maximum number of tags allowed.');\n }\n}\nflarum.reg.add('flarum-tags', 'common/components/TagSelectionModal', TagSelectionModal);","import app from 'flarum/forum/app';\nimport DiscussionPage from 'flarum/forum/components/DiscussionPage';\nimport classList from 'flarum/common/utils/classList';\nimport extractText from 'flarum/common/utils/extractText';\nimport getSelectableTags from '../utils/getSelectableTags';\nimport TagSelectionModal from '../../common/components/TagSelectionModal';\nexport default class TagDiscussionModal extends TagSelectionModal {\n static initAttrs(attrs) {\n super.initAttrs(attrs);\n const title = attrs.discussion ? app.translator.trans('flarum-tags.forum.choose_tags.edit_title', {\n title: m(\"em\", null, attrs.discussion.title())\n }) : app.translator.trans('flarum-tags.forum.choose_tags.title');\n attrs.className = classList(attrs.className, 'TagDiscussionModal');\n attrs.title = extractText(title);\n attrs.allowResetting = !!app.forum.attribute('canBypassTagCounts');\n attrs.limits = {\n allowBypassing: attrs.allowResetting,\n max: {\n primary: app.forum.attribute('maxPrimaryTags'),\n secondary: app.forum.attribute('maxSecondaryTags')\n },\n min: {\n primary: app.forum.attribute('minPrimaryTags'),\n secondary: app.forum.attribute('minSecondaryTags')\n }\n };\n attrs.requireParentTag = true;\n attrs.selectableTags = () => getSelectableTags(attrs.discussion);\n attrs.selectedTags ??= attrs.discussion?.tags() || [];\n attrs.canSelect = tag => tag.canStartDiscussion();\n const suppliedOnsubmit = attrs.onsubmit || null;\n\n // Save changes.\n attrs.onsubmit = function (tags) {\n const discussion = attrs.discussion;\n if (discussion) {\n discussion.save({\n relationships: {\n tags\n }\n }).then(() => {\n if (app.current.matches(DiscussionPage)) {\n app.current.get('stream').update();\n }\n m.redraw();\n });\n }\n if (suppliedOnsubmit) suppliedOnsubmit(tags);\n };\n }\n}\nflarum.reg.add('flarum-tags', 'forum/components/TagDiscussionModal', TagDiscussionModal);"],"names":["ToggleButton","view","vnode","className","isToggled","attrs","this","icon","m","Object","assign","children","flarum","reg","add","TagSelectionModal","constructor","super","arguments","initAttrs","title","trans","canSelect","allowResetting","limits","min","total","primary","secondary","max","Infinity","Error","catchInvalidLimits","oninit","navigator","onUp","setIndex","getCurrentNumericIndex","onDown","onSelect","select","bind","onRemove","selected","splice","length","load","then","tags","loading","selectableTags","sortTags","selectedTags","map","addTag","indexTag","redraw","lengthWithCJK","text","char","test","content","filter","toLowerCase","primaryCount","secondaryCount","getFilteredTags","inputWidth","Math","getInstruction","focused","onclick","$","focus","tag","removeTag","onready","tagLabel","placeholder","bidi","style","width","onkeydown","navigate","onfocus","onblur","type","disabled","meetsRequirements","id","pinned","position","child","parent","colored","color","includes","active","onmouseover","toggleTag","tagIcon","name","description","allowBypassing","bypassReqs","requireParentTag","isPrimaryParent","push","index","indexOf","t","forEach","onDeselect","remaining","count","onsubmit","e","preventDefault","hide","metaKey","ctrlKey","click","getItem","dispatchEvent","Event","selectableItems","selectedTag","scrollToItem","$items","$dropdown","$item","eq","getById","attr","dropdownScroll","scrollTop","dropdownTop","offset","top","dropdownBottom","outerHeight","itemTop","itemBottom","parseInt","css","stop","animate","TagDiscussionModal","discussion","attribute","getSelectableTags","canStartDiscussion","suppliedOnsubmit","save","relationships","matches","get","update"],"sourceRoot":""} \ No newline at end of file