@nationalarchives/frontend 1.6.2 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("TNAFrontend",[],t):"object"==typeof exports?exports.TNAFrontend=t():e.TNAFrontend=t()}(self,()=>(()=>{"use strict";const e={d:(t,r)=>{for(var a in r)e.o(r,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:r[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}};let t={};e.r(t),e.d(t,{default:()=>r});class r{constructor(e,t={}){this.$module=e,this.$formFieldInput=this.$module&&this.$module.querySelector(".tna-textarea"),this.$formFieldCharacterCount=this.$module&&this.$module.querySelector(".tna-textarea-count"),this.$formFieldCharacterCountScreenReader=this.$module&&this.$module.querySelector(".tna-textarea-count__screen-reader-status"),this.max=parseInt(this.$formFieldInput?.dataset?.maxLength,10),this.countType=this.$formFieldInput?.dataset?.countType||"characters",this.$module&&this.$formFieldInput&&this.$formFieldCharacterCount&&this.$formFieldCharacterCountScreenReader&&this.max&&this.init(t)}init(e){this.threshold=e.threshold||parseInt(this.$formFieldInput?.dataset?.countThreshold,10)||0,this.debounceDuration=e.debounceDuration||parseInt(this.$formFieldInput?.dataset?.debounceDuration,10)||1e3,this.intervalChecker=e.intervalChecker||1e3,this.debounceTimeout=null,this.lastInputValue="",this.$formFieldInput.addEventListener("input",()=>{this.handleInput(),this.lastInputTimestamp=Date.now()}),this.$formFieldInput.addEventListener("focus",()=>{this.handleFocus()}),this.$formFieldInput.addEventListener("blur",()=>{this.handleBlur()}),this.updateVisualCharacterCount(),this.updateScreenReaderCharacterCount()}handleFocus(){this.valueChecker=window.setInterval(()=>{(!this.lastInputTimestamp||Date.now()-this.intervalChecker/2>=this.lastInputTimestamp)&&this.updateIfValueChanged()},this.intervalChecker)}handleBlur(){this.valueChecker&&window.clearInterval(this.valueChecker),this.updateScreenReaderCharacterCount()}updateIfValueChanged(){this.$formFieldInput.value!==this.lastInputValue&&(this.lastInputValue=this.$formFieldInput.value,this.updateVisualCharacterCount(),this.updateScreenReaderCharacterCount())}handleInput(){this.updateVisualCharacterCount(),clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{this.updateScreenReaderCharacterCount()},this.debounceDuration)}getCurrentLength(){const e=this.$formFieldInput.value;if("words"===this.countType){const t=e.trim();return""===t?0:t.split(/\s+/).length}return Array.from(e).length}getCurrentLengthMessage(){const e=this.getCurrentLength();let t=this.countType;return 1===Math.abs(this.max-e)&&(t=t.replace(/s$/,"")),e>this.max?`You have ${(new Intl.NumberFormat).format(e-this.max)} ${t} too many`:`You have ${(new Intl.NumberFormat).format(this.max-e)} ${t} remaining`}isOverThreshold(){return this.getCurrentLength()>this.max}updateVisualCharacterCount(){this.threshold&&(this.getCurrentLength()>this.max*(this.threshold/100)?this.showCharacterCount():this.hideCharacterCount()),this.$formFieldCharacterCount.innerText=this.getCurrentLengthMessage(),this.isOverThreshold()?(this.$formFieldInput.classList.add("tna-textarea--error"),this.$formFieldCharacterCount.classList.add("tna-textarea-count--error")):(this.$formFieldInput.classList.remove("tna-textarea--error"),this.$formFieldCharacterCount.classList.remove("tna-textarea-count--error"))}updateScreenReaderCharacterCount(){const e=this.getCurrentLengthMessage();this.$formFieldCharacterCountScreenReader.innerText=e}showCharacterCount(){this.$formFieldCharacterCount.removeAttribute("hidden"),this.$formFieldCharacterCountScreenReader.removeAttribute("aria-hidden")}hideCharacterCount(){this.$formFieldCharacterCount.setAttribute("hidden",""),this.$formFieldCharacterCountScreenReader.setAttribute("aria-hidden","true")}}return t})());
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("TNAFrontend",[],t):"object"==typeof exports?exports.TNAFrontend=t():e.TNAFrontend=t()}(self,()=>(()=>{"use strict";const e={d:(t,r)=>{for(var a in r)e.o(r,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:r[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}};let t={};e.r(t),e.d(t,{default:()=>r});class r{constructor(e,t={}){if(this.$module=e,this.$formFieldInput=this.$module&&this.$module.querySelector(".tna-textarea"),this.$formFieldCharacterCount=this.$module&&this.$module.querySelector(".tna-textarea-count"),this.$formFieldCharacterCountScreenReader=this.$module&&this.$module.querySelector(".tna-textarea-count__screen-reader-status"),this.max=parseInt(this.$formFieldInput?.dataset?.maxLength,10),!(this.$module&&this.$formFieldInput&&this.$formFieldCharacterCount&&this.$formFieldCharacterCountScreenReader&&this.max))return;const r={length:{labels:["character","characters"]},characters:{labels:["character","characters"],segmenterGranularity:"grapheme"},words:{labels:["word","words"],segmenterGranularity:"word"}};if(this.countType=this.$formFieldInput?.dataset?.countType||"length",!r[this.countType])throw new Error(`Unsupported count type: ${this.countType}`);this.config=r[this.countType],this.init(t)}init(e){if(this.segmenter=null,"undefined"!=typeof Intl&&"function"==typeof Intl.Segmenter&&this.config.segmenterGranularity){const t=e.language||navigator.language||"en";this.segmenter=new Intl.Segmenter(t,{granularity:this.config.segmenterGranularity})}this.threshold=e.threshold||parseInt(this.$formFieldInput?.dataset?.countThreshold,10)||0,this.debounceDuration=e.debounceDuration||parseInt(this.$formFieldInput?.dataset?.debounceDuration,10)||1e3,this.intervalChecker=e.intervalChecker||1e3,this.debounceTimeout=null,this.lastInputValue="",this.$formFieldInput.addEventListener("input",()=>{this.handleInput(),this.lastInputTimestamp=Date.now()}),this.$formFieldInput.addEventListener("focus",()=>{this.handleFocus()}),this.$formFieldInput.addEventListener("blur",()=>{this.handleBlur()}),this.updateVisualCharacterCount(),this.updateScreenReaderCharacterCount()}handleFocus(){this.valueChecker=window.setInterval(()=>{(!this.lastInputTimestamp||Date.now()-this.intervalChecker/2>=this.lastInputTimestamp)&&this.updateIfValueChanged()},this.intervalChecker)}handleBlur(){this.valueChecker&&window.clearInterval(this.valueChecker),this.updateScreenReaderCharacterCount()}updateIfValueChanged(){this.$formFieldInput.value!==this.lastInputValue&&(this.lastInputValue=this.$formFieldInput.value,this.updateVisualCharacterCount(),this.updateScreenReaderCharacterCount())}handleInput(){this.updateVisualCharacterCount(),clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{this.updateScreenReaderCharacterCount()},this.debounceDuration)}getCurrentLength(){const e=this.$formFieldInput.value;return"length"===this.countType?e.length:"characters"===this.countType?this.segmenter?Array.from(this.segmenter.segment(e)).length:Array.from(e).length:"words"===this.countType?this.segmenter?Array.from(this.segmenter.segment(e)).filter(e=>e.isWordLike).length:e.trim().split(/\s+/).length:0}getCurrentLengthMessage(){const e=this.getCurrentLength(),[t,r]=this.config.labels;let a=r;return 1===Math.abs(this.max-e)&&(a=t),e>this.max?`You have ${(new Intl.NumberFormat).format(e-this.max)} ${a} too many`:`You have ${(new Intl.NumberFormat).format(this.max-e)} ${a} remaining`}isOverThreshold(){return this.getCurrentLength()>this.max}updateVisualCharacterCount(){this.threshold&&(this.getCurrentLength()>this.max*(this.threshold/100)?this.showCharacterCount():this.hideCharacterCount()),this.$formFieldCharacterCount.innerText=this.getCurrentLengthMessage(),this.isOverThreshold()?(this.$formFieldInput.classList.add("tna-textarea--error"),this.$formFieldCharacterCount.classList.add("tna-textarea-count--error")):(this.$formFieldInput.classList.remove("tna-textarea--error"),this.$formFieldCharacterCount.classList.remove("tna-textarea-count--error"))}updateScreenReaderCharacterCount(){const e=this.getCurrentLengthMessage();this.$formFieldCharacterCountScreenReader.innerText=e}showCharacterCount(){this.$formFieldCharacterCount.removeAttribute("hidden"),this.$formFieldCharacterCountScreenReader.removeAttribute("aria-hidden")}hideCharacterCount(){this.$formFieldCharacterCount.setAttribute("hidden",""),this.$formFieldCharacterCountScreenReader.setAttribute("aria-hidden","true")}}return t})());
2
2
  //# sourceMappingURL=TextAreaCharacterCount.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"components/TextAreaCharacterCount/TextAreaCharacterCount.js","mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAAG,QAAAA,OAAAC,IACAD,OAAA,iBAAAH,GACA,iBAAAC,QACAA,QAAA,YAAAD,IAEAD,EAAA,YAAAC,GACC,CATD,CASCK,KAAA,I,mBCRD,MAAAC,EAAA,CCAAA,EAAA,CAAAL,EAAAM,KACA,QAAAC,KAAAD,EACAD,EAAAG,EAAAF,EAAAC,KAAAF,EAAAG,EAAAR,EAAAO,IACAE,OAAAC,eAAAV,EAAAO,EAAA,CAAyCI,YAAA,EAAAC,IAAAN,EAAAC,MCJzCF,EAAA,CAAAQ,EAAAC,IAAAL,OAAAM,UAAAC,eAAAC,KAAAJ,EAAAC,GCCAT,EAAAL,IACAS,OAAAC,eAAAV,EAAAkB,OAAAC,YAAA,CAAsDC,MAAA,WACtDX,OAAAC,eAAAV,EAAA,cAAgDoB,OAAA,M,uCCHjC,MAAMC,EACnB,WAAAC,CAAYC,EAASC,EAAU,CAAC,GAC9BC,KAAKF,QAAUA,EACfE,KAAKC,gBACHD,KAAKF,SAAWE,KAAKF,QAAQI,cAAc,iBAC7CF,KAAKG,yBACHH,KAAKF,SAAWE,KAAKF,QAAQI,cAAc,uBAC7CF,KAAKI,qCACHJ,KAAKF,SACLE,KAAKF,QAAQI,cAAc,6CAC7BF,KAAKK,IAAMC,SAASN,KAAKC,iBAAiBM,SAASC,UAAW,IAC9DR,KAAKS,UAAYT,KAAKC,iBAAiBM,SAASE,WAAa,aAG1DT,KAAKF,SACLE,KAAKC,iBACLD,KAAKG,0BACLH,KAAKI,sCACLJ,KAAKK,KAKRL,KAAKU,KAAKX,EACZ,CAEA,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B,CAEA,uBAAAG,GACE,MAAMC,EAAgB1C,KAAKiC,mBAC3B,IAAIU,EAAY3C,KAAKS,UAKrB,OAH2C,IAAvCmC,KAAKC,IAAI7C,KAAKK,IAAMqC,KACtBC,EAAYA,EAAUG,QAAQ,KAAM,KAElCJ,EAAgB1C,KAAKK,IAChB,aAAY,IAAI0C,KAAKC,cAAeC,OAAOP,EAAgB1C,KAAKK,QAAQsC,aAE1E,aAAY,IAAII,KAAKC,cAAeC,OAAOjD,KAAKK,IAAMqC,MAAkBC,aACjF,CAEA,eAAAO,GACE,OAAOlD,KAAKiC,mBAAqBjC,KAAKK,GACxC,CAEA,0BAAAmB,GACMxB,KAAKW,YAEHX,KAAKiC,mBAAqBjC,KAAKK,KAAOL,KAAKW,UAAY,KACzDX,KAAKmD,qBAELnD,KAAKoD,sBAITpD,KAAKG,yBAAyBkD,UAAYrD,KAAKyC,0BAC3CzC,KAAKkD,mBACPlD,KAAKC,gBAAgBqD,UAAUC,IAAI,uBACnCvD,KAAKG,yBAAyBmD,UAAUC,IAAI,+BAE5CvD,KAAKC,gBAAgBqD,UAAUE,OAAO,uBACtCxD,KAAKG,yBAAyBmD,UAAUE,OACtC,6BAGN,CAEA,gCAAA/B,GACE,MAAMgC,EAAuBzD,KAAKyC,0BAClCzC,KAAKI,qCAAqCiD,UAAYI,CACxD,CAEA,kBAAAN,GACEnD,KAAKG,yBAAyBuD,gBAAgB,UAC9C1D,KAAKI,qCAAqCsD,gBAAgB,cAC5D,CAEA,kBAAAN,GACEpD,KAAKG,yBAAyBwD,aAAa,SAAU,IACrD3D,KAAKI,qCAAqCuD,aACxC,cACA,OAEJ,E","sources":["webpack://TNAFrontend/webpack/universalModuleDefinition","webpack://TNAFrontend/webpack/bootstrap","webpack://TNAFrontend/webpack/runtime/define property getters","webpack://TNAFrontend/webpack/runtime/hasOwnProperty shorthand","webpack://TNAFrontend/webpack/runtime/make namespace object","webpack://TNAFrontend/./src/nationalarchives/components/textarea/TextAreaCharacterCount.mjs"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"TNAFrontend\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"TNAFrontend\"] = factory();\n\telse\n\t\troot[\"TNAFrontend\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nconst __webpack_require__ = {};\n\n","// define getter/value functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop));","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export default class TextAreaCharacterCount {\n constructor($module, options = {}) {\n this.$module = $module;\n this.$formFieldInput =\n this.$module && this.$module.querySelector(\".tna-textarea\");\n this.$formFieldCharacterCount =\n this.$module && this.$module.querySelector(\".tna-textarea-count\");\n this.$formFieldCharacterCountScreenReader =\n this.$module &&\n this.$module.querySelector(\".tna-textarea-count__screen-reader-status\");\n this.max = parseInt(this.$formFieldInput?.dataset?.maxLength, 10);\n this.countType = this.$formFieldInput?.dataset?.countType || \"characters\";\n\n if (\n !this.$module ||\n !this.$formFieldInput ||\n !this.$formFieldCharacterCount ||\n !this.$formFieldCharacterCountScreenReader ||\n !this.max\n ) {\n return;\n }\n\n this.init(options);\n }\n\n init(options) {\n this.threshold =\n options.threshold ||\n parseInt(this.$formFieldInput?.dataset?.countThreshold, 10) ||\n /* eslint-disable-next-line no-magic-numbers */\n 0;\n this.debounceDuration =\n options.debounceDuration ||\n parseInt(this.$formFieldInput?.dataset?.debounceDuration, 10) ||\n /* eslint-disable-next-line no-magic-numbers */\n 1000;\n /* eslint-disable-next-line no-magic-numbers */\n this.intervalChecker = options.intervalChecker || 1000;\n this.debounceTimeout = null;\n this.lastInputValue = \"\";\n\n this.$formFieldInput.addEventListener(\"input\", () => {\n this.handleInput();\n this.lastInputTimestamp = Date.now();\n });\n this.$formFieldInput.addEventListener(\"focus\", () => {\n this.handleFocus();\n });\n this.$formFieldInput.addEventListener(\"blur\", () => {\n this.handleBlur();\n });\n this.updateVisualCharacterCount();\n this.updateScreenReaderCharacterCount();\n }\n\n handleFocus() {\n this.valueChecker = window.setInterval(() => {\n if (\n !this.lastInputTimestamp ||\n /* eslint-disable-next-line no-magic-numbers */\n Date.now() - this.intervalChecker / 2 >= this.lastInputTimestamp\n ) {\n this.updateIfValueChanged();\n }\n }, this.intervalChecker);\n }\n\n handleBlur() {\n if (this.valueChecker) {\n window.clearInterval(this.valueChecker);\n }\n this.updateScreenReaderCharacterCount();\n }\n\n updateIfValueChanged() {\n if (this.$formFieldInput.value !== this.lastInputValue) {\n this.lastInputValue = this.$formFieldInput.value;\n this.updateVisualCharacterCount();\n this.updateScreenReaderCharacterCount();\n }\n }\n\n handleInput() {\n this.updateVisualCharacterCount();\n clearTimeout(this.debounceTimeout);\n this.debounceTimeout = setTimeout(() => {\n this.updateScreenReaderCharacterCount();\n }, this.debounceDuration);\n }\n\n getCurrentLength() {\n const rawValue = this.$formFieldInput.value;\n if (this.countType === \"words\") {\n const trimmedValue = rawValue.trim();\n if (trimmedValue === \"\") {\n /* eslint-disable-next-line no-magic-numbers */\n return 0;\n }\n return trimmedValue.split(/\\s+/).length;\n }\n return Array.from(rawValue).length;\n }\n\n getCurrentLengthMessage() {\n const currentLength = this.getCurrentLength();\n let typeLabel = this.countType;\n /* eslint-disable-next-line no-magic-numbers */\n if (Math.abs(this.max - currentLength) === 1) {\n typeLabel = typeLabel.replace(/s$/, \"\");\n }\n if (currentLength > this.max) {\n return `You have ${new Intl.NumberFormat().format(currentLength - this.max)} ${typeLabel} too many`;\n }\n return `You have ${new Intl.NumberFormat().format(this.max - currentLength)} ${typeLabel} remaining`;\n }\n\n isOverThreshold() {\n return this.getCurrentLength() > this.max;\n }\n\n updateVisualCharacterCount() {\n if (this.threshold) {\n /* eslint-disable-next-line no-magic-numbers */\n if (this.getCurrentLength() > this.max * (this.threshold / 100)) {\n this.showCharacterCount();\n } else {\n this.hideCharacterCount();\n }\n }\n\n this.$formFieldCharacterCount.innerText = this.getCurrentLengthMessage();\n if (this.isOverThreshold()) {\n this.$formFieldInput.classList.add(\"tna-textarea--error\");\n this.$formFieldCharacterCount.classList.add(\"tna-textarea-count--error\");\n } else {\n this.$formFieldInput.classList.remove(\"tna-textarea--error\");\n this.$formFieldCharacterCount.classList.remove(\n \"tna-textarea-count--error\",\n );\n }\n }\n\n updateScreenReaderCharacterCount() {\n const currentLengthMessage = this.getCurrentLengthMessage();\n this.$formFieldCharacterCountScreenReader.innerText = currentLengthMessage;\n }\n\n showCharacterCount() {\n this.$formFieldCharacterCount.removeAttribute(\"hidden\");\n this.$formFieldCharacterCountScreenReader.removeAttribute(\"aria-hidden\");\n }\n\n hideCharacterCount() {\n this.$formFieldCharacterCount.setAttribute(\"hidden\", \"\");\n this.$formFieldCharacterCountScreenReader.setAttribute(\n \"aria-hidden\",\n \"true\",\n );\n }\n}\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","TextAreaCharacterCount","constructor","$module","options","this","$formFieldInput","querySelector","$formFieldCharacterCount","$formFieldCharacterCountScreenReader","max","parseInt","dataset","maxLength","countType","init","threshold","countThreshold","debounceDuration","intervalChecker","debounceTimeout","lastInputValue","addEventListener","handleInput","lastInputTimestamp","Date","now","handleFocus","handleBlur","updateVisualCharacterCount","updateScreenReaderCharacterCount","valueChecker","window","setInterval","updateIfValueChanged","clearInterval","clearTimeout","setTimeout","getCurrentLength","rawValue","trimmedValue","trim","split","length","Array","from","getCurrentLengthMessage","currentLength","typeLabel","Math","abs","replace","Intl","NumberFormat","format","isOverThreshold","showCharacterCount","hideCharacterCount","innerText","classList","add","remove","currentLengthMessage","removeAttribute","setAttribute"],"sourceRoot":""}
1
+ {"version":3,"file":"components/TextAreaCharacterCount/TextAreaCharacterCount.js","mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAAG,QAAAA,OAAAC,IACAD,OAAA,iBAAAH,GACA,iBAAAC,QACAA,QAAA,YAAAD,IAEAD,EAAA,YAAAC,GACC,CATD,CASCK,KAAA,I,mBCRD,MAAAC,EAAA,CCAAA,EAAA,CAAAL,EAAAM,KACA,QAAAC,KAAAD,EACAD,EAAAG,EAAAF,EAAAC,KAAAF,EAAAG,EAAAR,EAAAO,IACAE,OAAAC,eAAAV,EAAAO,EAAA,CAAyCI,YAAA,EAAAC,IAAAN,EAAAC,MCJzCF,EAAA,CAAAQ,EAAAC,IAAAL,OAAAM,UAAAC,eAAAC,KAAAJ,EAAAC,GCCAT,EAAAL,IACAS,OAAAC,eAAAV,EAAAkB,OAAAC,YAAA,CAAsDC,MAAA,WACtDX,OAAAC,eAAAV,EAAA,cAAgDoB,OAAA,M,uCCHjC,MAAMC,EACnB,WAAAC,CAAYC,EAASC,EAAU,CAAC,GAW9B,GAVAC,KAAKF,QAAUA,EACfE,KAAKC,gBACHD,KAAKF,SAAWE,KAAKF,QAAQI,cAAc,iBAC7CF,KAAKG,yBACHH,KAAKF,SAAWE,KAAKF,QAAQI,cAAc,uBAC7CF,KAAKI,qCACHJ,KAAKF,SACLE,KAAKF,QAAQI,cAAc,6CAC7BF,KAAKK,IAAMC,SAASN,KAAKC,iBAAiBM,SAASC,UAAW,MAG3DR,KAAKF,SACLE,KAAKC,iBACLD,KAAKG,0BACLH,KAAKI,sCACLJ,KAAKK,KAEN,OAGF,MAAMI,EAAqB,CACzBC,OAAQ,CAAEC,OAAQ,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KK,KAAOL,KAAKyB,UAAY,KACzDzB,KAAKkE,qBAELlE,KAAKmE,sBAITnE,KAAKG,yBAAyBiE,UAAYpE,KAAKwD,0BAC3CxD,KAAKiE,mBACPjE,KAAKC,gBAAgBoE,UAAUC,IAAI,uBACnCtE,KAAKG,yBAAyBkE,UAAUC,IAAI,+BAE5CtE,KAAKC,gBAAgBoE,UAAUE,OAAO,uBACtCvE,KAAKG,yBAAyBkE,UAAUE,OACtC,6BAGN,CAEA,gCAAAhC,GACE,MAAMiC,EAAuBxE,KAAKwD,0BAClCxD,KAAKI,qCAAqCgE,UAAYI,CACxD,CAEA,kBAAAN,GACElE,KAAKG,yBAAyBsE,gBAAgB,UAC9CzE,KAAKI,qCAAqCqE,gBAAgB,cAC5D,CAEA,kBAAAN,GACEnE,KAAKG,yBAAyBuE,aAAa,SAAU,IACrD1E,KAAKI,qCAAqCsE,aACxC,cACA,OAEJ,E","sources":["webpack://TNAFrontend/webpack/universalModuleDefinition","webpack://TNAFrontend/webpack/bootstrap","webpack://TNAFrontend/webpack/runtime/define property getters","webpack://TNAFrontend/webpack/runtime/hasOwnProperty shorthand","webpack://TNAFrontend/webpack/runtime/make namespace object","webpack://TNAFrontend/./src/nationalarchives/components/textarea/TextAreaCharacterCount.mjs"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"TNAFrontend\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"TNAFrontend\"] = factory();\n\telse\n\t\troot[\"TNAFrontend\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nconst __webpack_require__ = {};\n\n","// define getter/value functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop));","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export default class TextAreaCharacterCount {\n constructor($module, options = {}) {\n this.$module = $module;\n this.$formFieldInput =\n this.$module && this.$module.querySelector(\".tna-textarea\");\n this.$formFieldCharacterCount =\n this.$module && this.$module.querySelector(\".tna-textarea-count\");\n this.$formFieldCharacterCountScreenReader =\n this.$module &&\n this.$module.querySelector(\".tna-textarea-count__screen-reader-status\");\n this.max = parseInt(this.$formFieldInput?.dataset?.maxLength, 10);\n\n if (\n !this.$module ||\n !this.$formFieldInput ||\n !this.$formFieldCharacterCount ||\n !this.$formFieldCharacterCountScreenReader ||\n !this.max\n ) {\n return;\n }\n\n const countConfigOptions = {\n length: { labels: [\"character\", \"characters\"] },\n characters: {\n labels: [\"character\", \"characters\"],\n segmenterGranularity: \"grapheme\",\n },\n words: { labels: [\"word\", \"words\"], segmenterGranularity: \"word\" },\n };\n\n this.countType = this.$formFieldInput?.dataset?.countType || \"length\";\n if (!countConfigOptions[this.countType]) {\n throw new Error(`Unsupported count type: ${this.countType}`);\n }\n this.config = countConfigOptions[this.countType];\n\n this.init(options);\n }\n\n init(options) {\n this.segmenter = null;\n if (\n typeof Intl !== \"undefined\" &&\n typeof Intl.Segmenter === \"function\" &&\n this.config.segmenterGranularity\n ) {\n const language = options.language || navigator.language || \"en\";\n this.segmenter = new Intl.Segmenter(language, {\n granularity: this.config.segmenterGranularity,\n });\n }\n this.threshold =\n options.threshold ||\n parseInt(this.$formFieldInput?.dataset?.countThreshold, 10) ||\n /* eslint-disable-next-line no-magic-numbers */\n 0;\n this.debounceDuration =\n options.debounceDuration ||\n parseInt(this.$formFieldInput?.dataset?.debounceDuration, 10) ||\n /* eslint-disable-next-line no-magic-numbers */\n 1000;\n /* eslint-disable-next-line no-magic-numbers */\n this.intervalChecker = options.intervalChecker || 1000;\n this.debounceTimeout = null;\n this.lastInputValue = \"\";\n\n this.$formFieldInput.addEventListener(\"input\", () => {\n this.handleInput();\n this.lastInputTimestamp = Date.now();\n });\n this.$formFieldInput.addEventListener(\"focus\", () => {\n this.handleFocus();\n });\n this.$formFieldInput.addEventListener(\"blur\", () => {\n this.handleBlur();\n });\n this.updateVisualCharacterCount();\n this.updateScreenReaderCharacterCount();\n }\n\n handleFocus() {\n this.valueChecker = window.setInterval(() => {\n if (\n !this.lastInputTimestamp ||\n /* eslint-disable-next-line no-magic-numbers */\n Date.now() - this.intervalChecker / 2 >= this.lastInputTimestamp\n ) {\n this.updateIfValueChanged();\n }\n }, this.intervalChecker);\n }\n\n handleBlur() {\n if (this.valueChecker) {\n window.clearInterval(this.valueChecker);\n }\n this.updateScreenReaderCharacterCount();\n }\n\n updateIfValueChanged() {\n if (this.$formFieldInput.value !== this.lastInputValue) {\n this.lastInputValue = this.$formFieldInput.value;\n this.updateVisualCharacterCount();\n this.updateScreenReaderCharacterCount();\n }\n }\n\n handleInput() {\n this.updateVisualCharacterCount();\n clearTimeout(this.debounceTimeout);\n this.debounceTimeout = setTimeout(() => {\n this.updateScreenReaderCharacterCount();\n }, this.debounceDuration);\n }\n\n getCurrentLength() {\n const rawValue = this.$formFieldInput.value;\n\n if (this.countType === \"length\") {\n return rawValue.length;\n }\n\n if (this.countType === \"characters\") {\n if (this.segmenter) {\n const segments = Array.from(this.segmenter.segment(rawValue));\n return segments.length;\n }\n return Array.from(rawValue).length;\n }\n\n if (this.countType === \"words\") {\n if (this.segmenter) {\n const segments = Array.from(this.segmenter.segment(rawValue));\n return segments.filter((segment) => segment.isWordLike).length;\n }\n return rawValue.trim().split(/\\s+/).length;\n }\n return 0;\n }\n\n getCurrentLengthMessage() {\n const currentLength = this.getCurrentLength();\n\n const [singularLabel, pluralLabel] = this.config.labels;\n let typeLabel = pluralLabel;\n /* eslint-disable-next-line no-magic-numbers */\n if (Math.abs(this.max - currentLength) === 1) {\n typeLabel = singularLabel;\n }\n if (currentLength > this.max) {\n return `You have ${new Intl.NumberFormat().format(currentLength - this.max)} ${typeLabel} too many`;\n }\n return `You have ${new Intl.NumberFormat().format(this.max - currentLength)} ${typeLabel} remaining`;\n }\n\n isOverThreshold() {\n return this.getCurrentLength() > this.max;\n }\n\n updateVisualCharacterCount() {\n if (this.threshold) {\n /* eslint-disable-next-line no-magic-numbers */\n if (this.getCurrentLength() > this.max * (this.threshold / 100)) {\n this.showCharacterCount();\n } else {\n this.hideCharacterCount();\n }\n }\n\n this.$formFieldCharacterCount.innerText = this.getCurrentLengthMessage();\n if (this.isOverThreshold()) {\n this.$formFieldInput.classList.add(\"tna-textarea--error\");\n this.$formFieldCharacterCount.classList.add(\"tna-textarea-count--error\");\n } else {\n this.$formFieldInput.classList.remove(\"tna-textarea--error\");\n this.$formFieldCharacterCount.classList.remove(\n \"tna-textarea-count--error\",\n );\n }\n }\n\n updateScreenReaderCharacterCount() {\n const currentLengthMessage = this.getCurrentLengthMessage();\n this.$formFieldCharacterCountScreenReader.innerText = currentLengthMessage;\n }\n\n showCharacterCount() {\n this.$formFieldCharacterCount.removeAttribute(\"hidden\");\n this.$formFieldCharacterCountScreenReader.removeAttribute(\"aria-hidden\");\n }\n\n hideCharacterCount() {\n this.$formFieldCharacterCount.setAttribute(\"hidden\", \"\");\n this.$formFieldCharacterCountScreenReader.setAttribute(\n \"aria-hidden\",\n \"true\",\n );\n }\n}\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","TextAreaCharacterCount","constructor","$module","options","this","$formFieldInput","querySelector","$formFieldCharacterCount","$formFieldCharacterCountScreenReader","max","parseInt","dataset","maxLength","countConfigOptions","length","labels","characters","segmenterGranularity","words","countType","Error","config","init","segmenter","Intl","Segmenter","language","navigator","granularity","threshold","countThreshold","debounceDuration","intervalChecker","debounceTimeout","lastInputValue","addEventListener","handleInput","lastInputTimestamp","Date","now","handleFocus","handleBlur","updateVisualCharacterCount","updateScreenReaderCharacterCount","valueChecker","window","setInterval","updateIfValueChanged","clearInterval","clearTimeout","setTimeout","getCurrentLength","rawValue","Array","from","segment","filter","isWordLike","trim","split","getCurrentLengthMessage","currentLength","singularLabel","pluralLabel","typeLabel","Math","abs","NumberFormat","format","isOverThreshold","showCharacterCount","hideCharacterCount","innerText","classList","add","remove","currentLengthMessage","removeAttribute","setAttribute"],"sourceRoot":""}
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("TNAFrontend",[],e):"object"==typeof exports?exports.TNAFrontend=e():t.TNAFrontend=e()}(self,()=>(()=>{"use strict";const t={d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}};let e={};t.r(e),t.d(e,{default:()=>i});class i{constructor(t,e={}){if(this.$module=t,this.$formFieldInput=this.$module&&this.$module.querySelector(".tna-textarea"),this.$formFieldInputHint=this.$module&&this.$module.querySelector(".tna-form-item__hint"),this.$formFieldBody=this.$module&&this.$module.querySelector(".tna-form-item__body"),!this.$module||!this.$formFieldInput||!this.$formFieldBody||null!==this.$formFieldInput.getAttribute("hidden"))return;if(!(this.$formFieldInput instanceof HTMLTextAreaElement))throw new Error("Expected a textarea element");const{enhancedHint:i}=e;this.enhancedHint=i||"Enter an item and press enter",this.values=this.$formFieldInput.value.split("\n").map(t=>t.trim()).filter(t=>t),this.id=this.$formFieldInput.id,this.init()}init(){this.$formFieldNewInput=document.createElement("input"),this.$formFieldNewInput.classList.add("tna-text-input"),["id","aria-describedby"].forEach(t=>{this.$formFieldNewInput.setAttribute(t,this.$formFieldInput.getAttribute(t)),this.$formFieldInput.removeAttribute(t)}),this.$formFieldBody.appendChild(this.$formFieldNewInput),this.$formFieldInput.setAttribute("hidden",""),this.$formFieldInput.addEventListener("keyup",()=>this.updateList()),this.$formFieldNewInput.addEventListener("keypress",t=>{"Enter"===t.key&&this.appendValue(t.target.value)}),this.$formFieldNewInputAddButton=document.createElement("button"),this.$formFieldNewInputAddButton.setAttribute("type","button"),this.$formFieldNewInputAddButton.classList.add("tna-button","tna-button--small"),this.$formFieldNewInputAddButtonInner=document.createElement("span"),this.$formFieldNewInputAddButtonInner.innerText="Add",this.$formFieldNewInputAddButtonInnerExtra=document.createElement("span"),this.$formFieldNewInputAddButtonInnerExtra.classList.add("tna-visually-hidden"),this.$formFieldNewInputAddButtonInnerExtra.innerText=" to list",this.$formFieldNewInputAddButtonInner.appendChild(this.$formFieldNewInputAddButtonInnerExtra),this.$formFieldNewInputAddButton.appendChild(this.$formFieldNewInputAddButtonInner),this.$formFieldBody.appendChild(this.$formFieldNewInputAddButton),this.$formFieldNewInputAddButton.addEventListener("click",()=>{this.appendValue(this.$formFieldNewInput.value)}),this.$formFieldLiveAria=document.createElement("div"),this.$formFieldLiveAria.setAttribute("aria-live","polite"),this.$formFieldLiveAria.classList.add("tna-visually-hidden"),this.$module.appendChild(this.$formFieldLiveAria),this.$formFieldCounter=document.createElement("p"),this.$formFieldCounter.id=`${this.id}-list-helper`,this.$formFieldCounter.classList.add("tna-!--margin-top-xs"),this.$module.appendChild(this.$formFieldCounter),this.$formFieldNewInput.setAttribute("aria-describedby",`${this.$formFieldNewInput.getAttribute("aria-describedby")} ${this.$formFieldCounter.id}`),this.$valuesList=document.createElement("ul"),this.$valuesList.classList.add("tna-compound-filters","tna-!--margin-top-xs"),this.$valuesList.addEventListener("blur",()=>{this.$valuesList.removeAttribute("tabindex"),this.updateAriaText("")}),this.$module.appendChild(this.$valuesList),this.$formFieldInputHint||(this.$formFieldInputHint=document.createElement("p"),this.$formFieldInputHint.classList.add("tna-form-item__hint"),this.$formFieldBody.parentNode.insertBefore(this.$formFieldInputHint,this.$formFieldBody)),this.$formFieldInputHint.innerText=this.enhancedHint,this.updateList()}updateAriaText(t){this.$formFieldLiveAria.innerText=t}normaliseValue(t){return t.replace(/\s{2,}/u," ").trim()}isValueInList(t){return this.values.map(t=>this.normaliseValue(t).toLowerCase()).includes(t.toLowerCase().trim())}appendValue(t){const e=this.normaliseValue(t);e?this.isValueInList(e)?this.updateAriaText(`'${e}' already added`):(this.values.push(e),this.$formFieldInput.value=this.values.join("\n"),this.updateList(),this.updateAriaText(`'${e}' added`)):this.updateAriaText("Enter an item to add"),this.$formFieldNewInput.value="",this.$formFieldNewInput.focus()}removeValue(t){const e=this.normaliseValue(t);e&&this.isValueInList(e)&&(this.values=this.values.filter(t=>t!==e),this.$formFieldInput.value=this.values.join("\n"),this.updateList(),this.updateAriaText(`'${e}' removed`)),this.values.length?(this.$valuesList.setAttribute("tabindex","0"),this.$valuesList.focus()):this.$formFieldNewInput.focus()}updateList(){this.$valuesList.innerHTML="",this.values.map(t=>{const e=document.createElement("li");e.classList.add("tna-compound-filters__item");const i=document.createElement("span");i.innerText=t,e.appendChild(i);const n=document.createElement("button");return n.innerText=`Remove '${t}'`,n.setAttribute("type","button"),n.classList.add("tna-compound-filters__link"),n.addEventListener("click",()=>{this.removeValue(t)}),e.appendChild(n),e}).forEach(t=>this.$valuesList.appendChild(t));let t="item";1!==this.values.length&&(t+="s");const e=`${(new Intl.NumberFormat).format(this.values.length)} ${t} added`;this.$formFieldCounter.innerText=e}}return e})());
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("TNAFrontend",[],e):"object"==typeof exports?exports.TNAFrontend=e():t.TNAFrontend=e()}(self,()=>(()=>{"use strict";const t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}};let e={};t.r(e),t.d(e,{default:()=>i});class i{constructor(t,e={}){if(this.$module=t,this.$formItemInput=this.$module&&this.$module.querySelector(".tna-textarea"),this.$formItemHeader=this.$module&&this.$module.querySelector(".tna-form-item__header"),this.$formItemInputHint=this.$module&&this.$module.querySelector(".tna-form-item__hint"),this.$formItemBody=this.$module&&this.$module.querySelector(".tna-form-item__body"),!(this.$module&&this.$formItemHeader&&this.$formItemInput&&this.$formItemBody&&null===this.$formItemInput.getAttribute("hidden")))return;if(!(this.$formItemInput instanceof HTMLTextAreaElement))throw new Error("Expected a textarea element");const{enhancedHint:i}=e;this.enhancedHint=i||"Enter an item and press enter",this.values=this.$formItemInput.value.split("\n").map(t=>t.trim()).filter(t=>t),this.id=this.$formItemInput.id,this.init()}init(){this.$formFieldNewInput=document.createElement("input"),this.$formFieldNewInput.classList.add("tna-text-input"),["id","aria-describedby"].forEach(t=>{this.$formFieldNewInput.setAttribute(t,this.$formItemInput.getAttribute(t)),this.$formItemInput.removeAttribute(t)}),this.$formItemBody.appendChild(this.$formFieldNewInput),this.$formItemInput.setAttribute("hidden",""),this.$formItemInput.addEventListener("keyup",()=>this.updateList()),this.$formFieldNewInput.addEventListener("keypress",t=>{"Enter"===t.key&&this.appendValue(t.target.value)}),this.$formFieldNewInputAddButton=document.createElement("button"),this.$formFieldNewInputAddButton.setAttribute("type","button"),this.$formFieldNewInputAddButton.classList.add("tna-button","tna-button--small"),this.$formFieldNewInputAddButton.innerText="Add",this.$formFieldNewInputAddButton.setAttribute("aria-label",`Add to list for '${this.$formItemHeader.innerText}'`),this.$formItemBody.appendChild(this.$formFieldNewInputAddButton),this.$formFieldNewInputAddButton.addEventListener("click",()=>{this.appendValue(this.$formFieldNewInput.value)}),this.$formFieldLiveAria=document.createElement("div"),this.$formFieldLiveAria.setAttribute("aria-live","polite"),this.$formFieldLiveAria.classList.add("tna-visually-hidden"),this.$module.appendChild(this.$formFieldLiveAria),this.$formFieldCounter=document.createElement("p"),this.$formFieldCounter.id=`${this.id}-list-helper`,this.$formFieldCounter.classList.add("tna-!--margin-top-xs"),this.$module.appendChild(this.$formFieldCounter),this.$formFieldNewInput.setAttribute("aria-describedby",`${this.$formFieldNewInput.getAttribute("aria-describedby")} ${this.$formFieldCounter.id}`),this.$valuesList=document.createElement("ul"),this.$valuesList.classList.add("tna-compound-filters","tna-!--margin-top-xs"),this.$valuesList.addEventListener("blur",()=>{this.$valuesList.removeAttribute("tabindex"),this.updateAriaText("")}),this.$module.appendChild(this.$valuesList),this.$formItemInputHint||(this.$formItemInputHint=document.createElement("p"),this.$formItemInputHint.classList.add("tna-form-item__hint"),this.$formItemBody.parentNode.insertBefore(this.$formItemInputHint,this.$formItemBody)),this.$formItemInputHint.innerText=this.enhancedHint,this.updateList()}updateAriaText(t){this.$formFieldLiveAria.innerText=t}normaliseValue(t){return t.replace(/\s{2,}/u," ").trim()}isValueInList(t){return this.values.map(t=>this.normaliseValue(t).toLowerCase()).includes(t.toLowerCase().trim())}appendValue(t){const e=this.normaliseValue(t);e?this.isValueInList(e)?this.updateAriaText(`'${e}' already added`):(this.values.push(e),this.$formItemInput.value=this.values.join("\n"),this.updateList(),this.updateAriaText(`'${e}' added`)):this.updateAriaText("Enter an item to add"),this.$formFieldNewInput.value="",this.$formFieldNewInput.focus()}removeValue(t){const e=this.normaliseValue(t);e&&this.isValueInList(e)&&(this.values=this.values.filter(t=>t!==e),this.$formItemInput.value=this.values.join("\n"),this.updateList(),this.updateAriaText(`'${e}' removed`)),this.values.length?(this.$valuesList.setAttribute("tabindex","0"),this.$valuesList.focus()):this.$formFieldNewInput.focus()}updateList(){this.$valuesList.innerHTML="",this.values.map(t=>{const e=document.createElement("li");e.classList.add("tna-compound-filters__item");const i=document.createElement("span");i.innerText=t,e.appendChild(i);const s=document.createElement("button");return s.innerText=`Remove '${t}'`,s.setAttribute("type","button"),s.classList.add("tna-compound-filters__link"),s.addEventListener("click",()=>{this.removeValue(t)}),e.appendChild(s),e}).forEach(t=>this.$valuesList.appendChild(t));let t="item";1!==this.values.length&&(t+="s");const e=`${(new Intl.NumberFormat).format(this.values.length)} ${t} added`;this.$formFieldCounter.innerText=e}}return e})());
2
2
  //# sourceMappingURL=TextAreaItemisedRows.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"components/TextAreaItemisedRows/TextAreaItemisedRows.js","mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAAG,QAAAA,OAAAC,IACAD,OAAA,iBAAAH,GACA,iBAAAC,QACAA,QAAA,YAAAD,IAEAD,EAAA,YAAAC,GACC,CATD,CASCK,KAAA,I,mBCRD,MAAAC,EAAA,CCAAA,EAAA,CAAAL,EAAAM,KACA,QAAAC,KAAAD,EACAD,EAAAG,EAAAF,EAAAC,KAAAF,EAAAG,EAAAR,EAAAO,IACAE,OAAAC,eAAAV,EAAAO,EAAA,CAAyCI,YAAA,EAAAC,IAAAN,EAAAC,MCJzCF,EAAA,CAAAQ,EAAAC,IAAAL,OAAAM,UAAAC,eAAAC,KAAAJ,EAAAC,GCCAT,EAAAL,IACAS,OAAAC,eAAAV,EAAAkB,OAAAC,YAAA,CAAsDC,MAAA,WACtDX,OAAAC,eAAAV,EAAA,cAAgDoB,OAAA,M,uCCHjC,MAAMC,EACnB,WAAAC,CAAYC,EAASC,EAAU,CAAC,GAS9B,GARAC,KAAKF,QAAUA,EACfE,KAAKC,gBACHD,KAAKF,SAAWE,KAAKF,QAAQI,cAAc,iBAC7CF,KAAKG,oBACHH,KAAKF,SAAWE,KAAKF,QAAQI,cAAc,wBAC7CF,KAAKI,eACHJ,KAAKF,SAAWE,KAAKF,QAAQI,cAAc,yBAG1CF,KAAKF,UACLE,KAAKC,kBACLD,KAAKI,gBAC0C,OAAhDJ,KAAKC,gBAAgBI,aAAa,UAElC,OAGF,KAAML,KAAKC,2BAA2BK,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B,MAAMC,EAAiB,IAAG,IAAIC,KAAKC,cAAeC,OAAO/D,KAAKS,OAAO6C,WAAWK,UAChF3D,KAAKoC,kBAAkBH,UAAY2B,CACrC,E","sources":["webpack://TNAFrontend/webpack/universalModuleDefinition","webpack://TNAFrontend/webpack/bootstrap","webpack://TNAFrontend/webpack/runtime/define property getters","webpack://TNAFrontend/webpack/runtime/hasOwnProperty shorthand","webpack://TNAFrontend/webpack/runtime/make namespace object","webpack://TNAFrontend/./src/nationalarchives/components/textarea/TextAreaItemisedRows.mjs"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"TNAFrontend\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"TNAFrontend\"] = factory();\n\telse\n\t\troot[\"TNAFrontend\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nconst __webpack_require__ = {};\n\n","// define getter/value functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop));","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export default class TextAreaItemisedRows {\n constructor($module, options = {}) {\n this.$module = $module;\n this.$formFieldInput =\n this.$module && this.$module.querySelector(\".tna-textarea\");\n this.$formFieldInputHint =\n this.$module && this.$module.querySelector(\".tna-form-item__hint\");\n this.$formFieldBody =\n this.$module && this.$module.querySelector(\".tna-form-item__body\");\n\n if (\n !this.$module ||\n !this.$formFieldInput ||\n !this.$formFieldBody ||\n this.$formFieldInput.getAttribute(\"hidden\") !== null\n ) {\n return;\n }\n\n if (!(this.$formFieldInput instanceof HTMLTextAreaElement)) {\n throw new Error(\"Expected a textarea element\");\n }\n\n const { enhancedHint } = options;\n this.enhancedHint = enhancedHint || \"Enter an item and press enter\";\n\n this.values = this.$formFieldInput.value\n .split(\"\\n\")\n .map((value) => value.trim())\n .filter((value) => value);\n\n this.id = this.$formFieldInput.id;\n\n this.init();\n }\n\n init() {\n this.$formFieldNewInput = document.createElement(\"input\");\n this.$formFieldNewInput.classList.add(\"tna-text-input\");\n [\"id\", \"aria-describedby\"].forEach((attribute) => {\n this.$formFieldNewInput.setAttribute(\n attribute,\n this.$formFieldInput.getAttribute(attribute),\n );\n this.$formFieldInput.removeAttribute(attribute);\n });\n this.$formFieldBody.appendChild(this.$formFieldNewInput);\n this.$formFieldInput.setAttribute(\"hidden\", \"\");\n this.$formFieldInput.addEventListener(\"keyup\", () => this.updateList());\n this.$formFieldNewInput.addEventListener(\"keypress\", (event) => {\n if (event.key === \"Enter\") {\n this.appendValue(event.target.value);\n }\n });\n\n this.$formFieldNewInputAddButton = document.createElement(\"button\");\n this.$formFieldNewInputAddButton.setAttribute(\"type\", \"button\");\n this.$formFieldNewInputAddButton.classList.add(\n \"tna-button\",\n \"tna-button--small\",\n );\n this.$formFieldNewInputAddButtonInner = document.createElement(\"span\");\n this.$formFieldNewInputAddButtonInner.innerText = \"Add\";\n this.$formFieldNewInputAddButtonInnerExtra = document.createElement(\"span\");\n this.$formFieldNewInputAddButtonInnerExtra.classList.add(\n \"tna-visually-hidden\",\n );\n this.$formFieldNewInputAddButtonInnerExtra.innerText = \" to list\";\n this.$formFieldNewInputAddButtonInner.appendChild(\n this.$formFieldNewInputAddButtonInnerExtra,\n );\n this.$formFieldNewInputAddButton.appendChild(\n this.$formFieldNewInputAddButtonInner,\n );\n this.$formFieldBody.appendChild(this.$formFieldNewInputAddButton);\n this.$formFieldNewInputAddButton.addEventListener(\"click\", () => {\n this.appendValue(this.$formFieldNewInput.value);\n });\n\n this.$formFieldLiveAria = document.createElement(\"div\");\n this.$formFieldLiveAria.setAttribute(\"aria-live\", \"polite\");\n this.$formFieldLiveAria.classList.add(\"tna-visually-hidden\");\n this.$module.appendChild(this.$formFieldLiveAria);\n\n this.$formFieldCounter = document.createElement(\"p\");\n this.$formFieldCounter.id = `${this.id}-list-helper`;\n this.$formFieldCounter.classList.add(\"tna-!--margin-top-xs\");\n this.$module.appendChild(this.$formFieldCounter);\n\n this.$formFieldNewInput.setAttribute(\n \"aria-describedby\",\n `${this.$formFieldNewInput.getAttribute(\"aria-describedby\")} ${\n this.$formFieldCounter.id\n }`,\n );\n\n this.$valuesList = document.createElement(\"ul\");\n this.$valuesList.classList.add(\n \"tna-compound-filters\",\n \"tna-!--margin-top-xs\",\n );\n this.$valuesList.addEventListener(\"blur\", () => {\n this.$valuesList.removeAttribute(\"tabindex\");\n this.updateAriaText(\"\");\n });\n this.$module.appendChild(this.$valuesList);\n\n if (!this.$formFieldInputHint) {\n this.$formFieldInputHint = document.createElement(\"p\");\n this.$formFieldInputHint.classList.add(\"tna-form-item__hint\");\n this.$formFieldBody.parentNode.insertBefore(\n this.$formFieldInputHint,\n this.$formFieldBody,\n );\n }\n this.$formFieldInputHint.innerText = this.enhancedHint;\n\n this.updateList();\n }\n\n updateAriaText(content) {\n this.$formFieldLiveAria.innerText = content;\n }\n\n /* eslint-disable-next-line class-methods-use-this */\n normaliseValue(value) {\n return value.replace(/\\s{2,}/u, \" \").trim();\n }\n\n isValueInList(value) {\n return this.values\n .map((eachValue) => this.normaliseValue(eachValue).toLowerCase())\n .includes(value.toLowerCase().trim());\n }\n\n appendValue(value) {\n const newValue = this.normaliseValue(value);\n if (newValue) {\n if (this.isValueInList(newValue)) {\n this.updateAriaText(`'${newValue}' already added`);\n } else {\n this.values.push(newValue);\n this.$formFieldInput.value = this.values.join(\"\\n\");\n this.updateList();\n this.updateAriaText(`'${newValue}' added`);\n }\n } else {\n this.updateAriaText(\"Enter an item to add\");\n }\n this.$formFieldNewInput.value = \"\";\n this.$formFieldNewInput.focus();\n }\n\n removeValue(value) {\n const removeValue = this.normaliseValue(value);\n if (removeValue && this.isValueInList(removeValue)) {\n this.values = this.values.filter(\n (existingValue) => existingValue !== removeValue,\n );\n this.$formFieldInput.value = this.values.join(\"\\n\");\n this.updateList();\n this.updateAriaText(`'${removeValue}' removed`);\n }\n if (this.values.length) {\n this.$valuesList.setAttribute(\"tabindex\", \"0\");\n this.$valuesList.focus();\n } else {\n this.$formFieldNewInput.focus();\n }\n }\n\n updateList() {\n this.$valuesList.innerHTML = \"\";\n this.values\n .map((value) => {\n const $item = document.createElement(\"li\");\n $item.classList.add(\"tna-compound-filters__item\");\n const $itemLabel = document.createElement(\"span\");\n $itemLabel.innerText = value;\n $item.appendChild($itemLabel);\n\n const $removeItemButton = document.createElement(\"button\");\n $removeItemButton.innerText = `Remove '${value}'`;\n $removeItemButton.setAttribute(\"type\", \"button\");\n $removeItemButton.classList.add(\"tna-compound-filters__link\");\n $removeItemButton.addEventListener(\"click\", () => {\n this.removeValue(value);\n });\n $item.appendChild($removeItemButton);\n return $item;\n })\n .forEach(($item) => this.$valuesList.appendChild($item));\n\n let innerTextItemValue = \"item\";\n /* eslint-disable-next-line no-magic-numbers */\n if (this.values.length !== 1) {\n innerTextItemValue += \"s\";\n }\n const innerTextValue = `${new Intl.NumberFormat().format(this.values.length)} ${innerTextItemValue} added`;\n this.$formFieldCounter.innerText = innerTextValue;\n }\n}\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","TextAreaItemisedRows","constructor","$module","options","this","$formFieldInput","querySelector","$formFieldInputHint","$formFieldBody","getAttribute","HTMLTextAreaElement","Error","enhancedHint","values","split","map","trim","filter","id","init","$formFieldNewInput","document","createElement","classList","add","forEach","attribute","setAttribute","removeAttribute","appendChild","addEventListener","updateList","event","appendValue","target","$formFieldNewInputAddButton","$formFieldNewInputAddButtonInner","innerText","$formFieldNewInputAddButtonInnerExtra","$formFieldLiveAria","$formFieldCounter","$valuesList","updateAriaText","parentNode","insertBefore","content","normaliseValue","replace","isValueInList","eachValue","toLowerCase","includes","newValue","push","join","focus","removeValue","existingValue","length","innerHTML","$item","$itemLabel","$removeItemButton","innerTextItemValue","innerTextValue","Intl","NumberFormat","format"],"sourceRoot":""}
1
+ {"version":3,"file":"components/TextAreaItemisedRows/TextAreaItemisedRows.js","mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAAG,QAAAA,OAAAC,IACAD,OAAA,iBAAAH,GACA,iBAAAC,QACAA,QAAA,YAAAD,IAEAD,EAAA,YAAAC,GACC,CATD,CASCK,KAAA,I,mBCRD,MAAAC,EAAA,CCAAA,EAAA,CAAAL,EAAAM,KACA,QAAAC,KAAAD,EACAD,EAAAG,EAAAF,EAAAC,KAAAF,EAAAG,EAAAR,EAAAO,IACAE,OAAAC,eAAAV,EAAAO,EAAA,CAAyCI,YAAA,EAAAC,IAAAN,EAAAC,MCJzCF,EAAA,CAAAQ,EAAAC,IAAAL,OAAAM,UAAAC,eAAAC,KAAAJ,EAAAC,GCCAT,EAAAL,IACAS,OAAAC,eAAAV,EAAAkB,OAAAC,YAAA,CAAsDC,MAAA,WACtDX,OAAAC,eAAAV,EAAA,cAAgDoB,OAAA,M,uCCHjC,MAAMC,EACnB,WAAAC,CAAYC,EAASC,EAAU,CAAC,GAW9B,GAVAC,KAAKF,QAAUA,EACfE,KAAKC,eACHD,KAAKF,SAAWE,KAAKF,QAAQI,cAAc,iBAC7CF,KAAKG,gBACHH,KAAKF,SAAWE,KAAKF,QAAQI,cAAc,0BAC7CF,KAAKI,mBACHJ,KAAKF,SAAWE,KAAKF,QAAQI,cAAc,wBAC7CF,KAAKK,cACHL,KAAKF,SAAWE,KAAKF,QAAQI,cAAc,0BAG1CF,KAAKF,SACLE,KAAKG,iBACLH,K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Y0B,CACrC,E","sources":["webpack://TNAFrontend/webpack/universalModuleDefinition","webpack://TNAFrontend/webpack/bootstrap","webpack://TNAFrontend/webpack/runtime/define property getters","webpack://TNAFrontend/webpack/runtime/hasOwnProperty shorthand","webpack://TNAFrontend/webpack/runtime/make namespace object","webpack://TNAFrontend/./src/nationalarchives/components/textarea/TextAreaItemisedRows.mjs"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"TNAFrontend\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"TNAFrontend\"] = factory();\n\telse\n\t\troot[\"TNAFrontend\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nconst __webpack_require__ = {};\n\n","// define getter/value functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop));","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export default class TextAreaItemisedRows {\n constructor($module, options = {}) {\n this.$module = $module;\n this.$formItemInput =\n this.$module && this.$module.querySelector(\".tna-textarea\");\n this.$formItemHeader =\n this.$module && this.$module.querySelector(\".tna-form-item__header\");\n this.$formItemInputHint =\n this.$module && this.$module.querySelector(\".tna-form-item__hint\");\n this.$formItemBody =\n this.$module && this.$module.querySelector(\".tna-form-item__body\");\n\n if (\n !this.$module ||\n !this.$formItemHeader ||\n !this.$formItemInput ||\n !this.$formItemBody ||\n this.$formItemInput.getAttribute(\"hidden\") !== null\n ) {\n return;\n }\n\n if (!(this.$formItemInput instanceof HTMLTextAreaElement)) {\n throw new Error(\"Expected a textarea element\");\n }\n\n const { enhancedHint } = options;\n this.enhancedHint = enhancedHint || \"Enter an item and press enter\";\n\n this.values = this.$formItemInput.value\n .split(\"\\n\")\n .map((value) => value.trim())\n .filter((value) => value);\n\n this.id = this.$formItemInput.id;\n\n this.init();\n }\n\n init() {\n this.$formFieldNewInput = document.createElement(\"input\");\n this.$formFieldNewInput.classList.add(\"tna-text-input\");\n [\"id\", \"aria-describedby\"].forEach((attribute) => {\n this.$formFieldNewInput.setAttribute(\n attribute,\n this.$formItemInput.getAttribute(attribute),\n );\n this.$formItemInput.removeAttribute(attribute);\n });\n this.$formItemBody.appendChild(this.$formFieldNewInput);\n this.$formItemInput.setAttribute(\"hidden\", \"\");\n this.$formItemInput.addEventListener(\"keyup\", () => this.updateList());\n this.$formFieldNewInput.addEventListener(\"keypress\", (event) => {\n if (event.key === \"Enter\") {\n this.appendValue(event.target.value);\n }\n });\n\n this.$formFieldNewInputAddButton = document.createElement(\"button\");\n this.$formFieldNewInputAddButton.setAttribute(\"type\", \"button\");\n this.$formFieldNewInputAddButton.classList.add(\n \"tna-button\",\n \"tna-button--small\",\n );\n this.$formFieldNewInputAddButton.innerText = \"Add\";\n this.$formFieldNewInputAddButton.setAttribute(\n \"aria-label\",\n `Add to list for '${this.$formItemHeader.innerText}'`,\n );\n this.$formItemBody.appendChild(this.$formFieldNewInputAddButton);\n this.$formFieldNewInputAddButton.addEventListener(\"click\", () => {\n this.appendValue(this.$formFieldNewInput.value);\n });\n\n this.$formFieldLiveAria = document.createElement(\"div\");\n this.$formFieldLiveAria.setAttribute(\"aria-live\", \"polite\");\n this.$formFieldLiveAria.classList.add(\"tna-visually-hidden\");\n this.$module.appendChild(this.$formFieldLiveAria);\n\n this.$formFieldCounter = document.createElement(\"p\");\n this.$formFieldCounter.id = `${this.id}-list-helper`;\n this.$formFieldCounter.classList.add(\"tna-!--margin-top-xs\");\n this.$module.appendChild(this.$formFieldCounter);\n\n this.$formFieldNewInput.setAttribute(\n \"aria-describedby\",\n `${this.$formFieldNewInput.getAttribute(\"aria-describedby\")} ${\n this.$formFieldCounter.id\n }`,\n );\n\n this.$valuesList = document.createElement(\"ul\");\n this.$valuesList.classList.add(\n \"tna-compound-filters\",\n \"tna-!--margin-top-xs\",\n );\n this.$valuesList.addEventListener(\"blur\", () => {\n this.$valuesList.removeAttribute(\"tabindex\");\n this.updateAriaText(\"\");\n });\n this.$module.appendChild(this.$valuesList);\n\n if (!this.$formItemInputHint) {\n this.$formItemInputHint = document.createElement(\"p\");\n this.$formItemInputHint.classList.add(\"tna-form-item__hint\");\n this.$formItemBody.parentNode.insertBefore(\n this.$formItemInputHint,\n this.$formItemBody,\n );\n }\n this.$formItemInputHint.innerText = this.enhancedHint;\n\n this.updateList();\n }\n\n updateAriaText(content) {\n this.$formFieldLiveAria.innerText = content;\n }\n\n /* eslint-disable-next-line class-methods-use-this */\n normaliseValue(value) {\n return value.replace(/\\s{2,}/u, \" \").trim();\n }\n\n isValueInList(value) {\n return this.values\n .map((eachValue) => this.normaliseValue(eachValue).toLowerCase())\n .includes(value.toLowerCase().trim());\n }\n\n appendValue(value) {\n const newValue = this.normaliseValue(value);\n if (newValue) {\n if (this.isValueInList(newValue)) {\n this.updateAriaText(`'${newValue}' already added`);\n } else {\n this.values.push(newValue);\n this.$formItemInput.value = this.values.join(\"\\n\");\n this.updateList();\n this.updateAriaText(`'${newValue}' added`);\n }\n } else {\n this.updateAriaText(\"Enter an item to add\");\n }\n this.$formFieldNewInput.value = \"\";\n this.$formFieldNewInput.focus();\n }\n\n removeValue(value) {\n const removeValue = this.normaliseValue(value);\n if (removeValue && this.isValueInList(removeValue)) {\n this.values = this.values.filter(\n (existingValue) => existingValue !== removeValue,\n );\n this.$formItemInput.value = this.values.join(\"\\n\");\n this.updateList();\n this.updateAriaText(`'${removeValue}' removed`);\n }\n if (this.values.length) {\n this.$valuesList.setAttribute(\"tabindex\", \"0\");\n this.$valuesList.focus();\n } else {\n this.$formFieldNewInput.focus();\n }\n }\n\n updateList() {\n this.$valuesList.innerHTML = \"\";\n this.values\n .map((value) => {\n const $item = document.createElement(\"li\");\n $item.classList.add(\"tna-compound-filters__item\");\n const $itemLabel = document.createElement(\"span\");\n $itemLabel.innerText = value;\n $item.appendChild($itemLabel);\n\n const $removeItemButton = document.createElement(\"button\");\n $removeItemButton.innerText = `Remove '${value}'`;\n $removeItemButton.setAttribute(\"type\", \"button\");\n $removeItemButton.classList.add(\"tna-compound-filters__link\");\n $removeItemButton.addEventListener(\"click\", () => {\n this.removeValue(value);\n });\n $item.appendChild($removeItemButton);\n return $item;\n })\n .forEach(($item) => this.$valuesList.appendChild($item));\n\n let innerTextItemValue = \"item\";\n /* eslint-disable-next-line no-magic-numbers */\n if (this.values.length !== 1) {\n innerTextItemValue += \"s\";\n }\n const innerTextValue = `${new Intl.NumberFormat().format(this.values.length)} ${innerTextItemValue} added`;\n this.$formFieldCounter.innerText = innerTextValue;\n }\n}\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","TextAreaItemisedRows","constructor","$module","options","this","$formItemInput","querySelector","$formItemHeader","$formItemInputHint","$formItemBody","getAttribute","HTMLTextAreaElement","Error","enhancedHint","values","split","map","trim","filter","id","init","$formFieldNewInput","document","createElement","classList","add","forEach","attribute","setAttribute","removeAttribute","appendChild","addEventListener","updateList","event","appendValue","target","$formFieldNewInputAddButton","innerText","$formFieldLiveAria","$formFieldCounter","$valuesList","updateAriaText","parentNode","insertBefore","content","normaliseValue","replace","isValueInList","eachValue","toLowerCase","includes","newValue","push","join","focus","removeValue","existingValue","length","innerHTML","$item","$itemLabel","$removeItemButton","innerTextItemValue","innerTextValue","Intl","NumberFormat","format"],"sourceRoot":""}
@@ -9,7 +9,6 @@ export default class TextAreaCharacterCount {
9
9
  this.$module &&
10
10
  this.$module.querySelector(".tna-textarea-count__screen-reader-status");
11
11
  this.max = parseInt(this.$formFieldInput?.dataset?.maxLength, 10);
12
- this.countType = this.$formFieldInput?.dataset?.countType || "characters";
13
12
 
14
13
  if (
15
14
  !this.$module ||
@@ -21,10 +20,36 @@ export default class TextAreaCharacterCount {
21
20
  return;
22
21
  }
23
22
 
23
+ const countConfigOptions = {
24
+ length: { labels: ["character", "characters"] },
25
+ characters: {
26
+ labels: ["character", "characters"],
27
+ segmenterGranularity: "grapheme",
28
+ },
29
+ words: { labels: ["word", "words"], segmenterGranularity: "word" },
30
+ };
31
+
32
+ this.countType = this.$formFieldInput?.dataset?.countType || "length";
33
+ if (!countConfigOptions[this.countType]) {
34
+ throw new Error(`Unsupported count type: ${this.countType}`);
35
+ }
36
+ this.config = countConfigOptions[this.countType];
37
+
24
38
  this.init(options);
25
39
  }
26
40
 
27
41
  init(options) {
42
+ this.segmenter = null;
43
+ if (
44
+ typeof Intl !== "undefined" &&
45
+ typeof Intl.Segmenter === "function" &&
46
+ this.config.segmenterGranularity
47
+ ) {
48
+ const language = options.language || navigator.language || "en";
49
+ this.segmenter = new Intl.Segmenter(language, {
50
+ granularity: this.config.segmenterGranularity,
51
+ });
52
+ }
28
53
  this.threshold =
29
54
  options.threshold ||
30
55
  parseInt(this.$formFieldInput?.dataset?.countThreshold, 10) ||
@@ -91,23 +116,37 @@ export default class TextAreaCharacterCount {
91
116
 
92
117
  getCurrentLength() {
93
118
  const rawValue = this.$formFieldInput.value;
119
+
120
+ if (this.countType === "length") {
121
+ return rawValue.length;
122
+ }
123
+
124
+ if (this.countType === "characters") {
125
+ if (this.segmenter) {
126
+ const segments = Array.from(this.segmenter.segment(rawValue));
127
+ return segments.length;
128
+ }
129
+ return Array.from(rawValue).length;
130
+ }
131
+
94
132
  if (this.countType === "words") {
95
- const trimmedValue = rawValue.trim();
96
- if (trimmedValue === "") {
97
- /* eslint-disable-next-line no-magic-numbers */
98
- return 0;
133
+ if (this.segmenter) {
134
+ const segments = Array.from(this.segmenter.segment(rawValue));
135
+ return segments.filter((segment) => segment.isWordLike).length;
99
136
  }
100
- return trimmedValue.split(/\s+/).length;
137
+ return rawValue.trim().split(/\s+/).length;
101
138
  }
102
- return Array.from(rawValue).length;
139
+ return 0;
103
140
  }
104
141
 
105
142
  getCurrentLengthMessage() {
106
143
  const currentLength = this.getCurrentLength();
107
- let typeLabel = this.countType;
144
+
145
+ const [singularLabel, pluralLabel] = this.config.labels;
146
+ let typeLabel = pluralLabel;
108
147
  /* eslint-disable-next-line no-magic-numbers */
109
148
  if (Math.abs(this.max - currentLength) === 1) {
110
- typeLabel = typeLabel.replace(/s$/, "");
149
+ typeLabel = singularLabel;
111
150
  }
112
151
  if (currentLength > this.max) {
113
152
  return `You have ${new Intl.NumberFormat().format(currentLength - this.max)} ${typeLabel} too many`;
@@ -1,35 +1,38 @@
1
1
  export default class TextAreaItemisedRows {
2
2
  constructor($module, options = {}) {
3
3
  this.$module = $module;
4
- this.$formFieldInput =
4
+ this.$formItemInput =
5
5
  this.$module && this.$module.querySelector(".tna-textarea");
6
- this.$formFieldInputHint =
6
+ this.$formItemHeader =
7
+ this.$module && this.$module.querySelector(".tna-form-item__header");
8
+ this.$formItemInputHint =
7
9
  this.$module && this.$module.querySelector(".tna-form-item__hint");
8
- this.$formFieldBody =
10
+ this.$formItemBody =
9
11
  this.$module && this.$module.querySelector(".tna-form-item__body");
10
12
 
11
13
  if (
12
14
  !this.$module ||
13
- !this.$formFieldInput ||
14
- !this.$formFieldBody ||
15
- this.$formFieldInput.getAttribute("hidden") !== null
15
+ !this.$formItemHeader ||
16
+ !this.$formItemInput ||
17
+ !this.$formItemBody ||
18
+ this.$formItemInput.getAttribute("hidden") !== null
16
19
  ) {
17
20
  return;
18
21
  }
19
22
 
20
- if (!(this.$formFieldInput instanceof HTMLTextAreaElement)) {
23
+ if (!(this.$formItemInput instanceof HTMLTextAreaElement)) {
21
24
  throw new Error("Expected a textarea element");
22
25
  }
23
26
 
24
27
  const { enhancedHint } = options;
25
28
  this.enhancedHint = enhancedHint || "Enter an item and press enter";
26
29
 
27
- this.values = this.$formFieldInput.value
30
+ this.values = this.$formItemInput.value
28
31
  .split("\n")
29
32
  .map((value) => value.trim())
30
33
  .filter((value) => value);
31
34
 
32
- this.id = this.$formFieldInput.id;
35
+ this.id = this.$formItemInput.id;
33
36
 
34
37
  this.init();
35
38
  }
@@ -40,13 +43,13 @@ export default class TextAreaItemisedRows {
40
43
  ["id", "aria-describedby"].forEach((attribute) => {
41
44
  this.$formFieldNewInput.setAttribute(
42
45
  attribute,
43
- this.$formFieldInput.getAttribute(attribute),
46
+ this.$formItemInput.getAttribute(attribute),
44
47
  );
45
- this.$formFieldInput.removeAttribute(attribute);
48
+ this.$formItemInput.removeAttribute(attribute);
46
49
  });
47
- this.$formFieldBody.appendChild(this.$formFieldNewInput);
48
- this.$formFieldInput.setAttribute("hidden", "");
49
- this.$formFieldInput.addEventListener("keyup", () => this.updateList());
50
+ this.$formItemBody.appendChild(this.$formFieldNewInput);
51
+ this.$formItemInput.setAttribute("hidden", "");
52
+ this.$formItemInput.addEventListener("keyup", () => this.updateList());
50
53
  this.$formFieldNewInput.addEventListener("keypress", (event) => {
51
54
  if (event.key === "Enter") {
52
55
  this.appendValue(event.target.value);
@@ -59,20 +62,12 @@ export default class TextAreaItemisedRows {
59
62
  "tna-button",
60
63
  "tna-button--small",
61
64
  );
62
- this.$formFieldNewInputAddButtonInner = document.createElement("span");
63
- this.$formFieldNewInputAddButtonInner.innerText = "Add";
64
- this.$formFieldNewInputAddButtonInnerExtra = document.createElement("span");
65
- this.$formFieldNewInputAddButtonInnerExtra.classList.add(
66
- "tna-visually-hidden",
65
+ this.$formFieldNewInputAddButton.innerText = "Add";
66
+ this.$formFieldNewInputAddButton.setAttribute(
67
+ "aria-label",
68
+ `Add to list for '${this.$formItemHeader.innerText}'`,
67
69
  );
68
- this.$formFieldNewInputAddButtonInnerExtra.innerText = " to list";
69
- this.$formFieldNewInputAddButtonInner.appendChild(
70
- this.$formFieldNewInputAddButtonInnerExtra,
71
- );
72
- this.$formFieldNewInputAddButton.appendChild(
73
- this.$formFieldNewInputAddButtonInner,
74
- );
75
- this.$formFieldBody.appendChild(this.$formFieldNewInputAddButton);
70
+ this.$formItemBody.appendChild(this.$formFieldNewInputAddButton);
76
71
  this.$formFieldNewInputAddButton.addEventListener("click", () => {
77
72
  this.appendValue(this.$formFieldNewInput.value);
78
73
  });
@@ -105,15 +100,15 @@ export default class TextAreaItemisedRows {
105
100
  });
106
101
  this.$module.appendChild(this.$valuesList);
107
102
 
108
- if (!this.$formFieldInputHint) {
109
- this.$formFieldInputHint = document.createElement("p");
110
- this.$formFieldInputHint.classList.add("tna-form-item__hint");
111
- this.$formFieldBody.parentNode.insertBefore(
112
- this.$formFieldInputHint,
113
- this.$formFieldBody,
103
+ if (!this.$formItemInputHint) {
104
+ this.$formItemInputHint = document.createElement("p");
105
+ this.$formItemInputHint.classList.add("tna-form-item__hint");
106
+ this.$formItemBody.parentNode.insertBefore(
107
+ this.$formItemInputHint,
108
+ this.$formItemBody,
114
109
  );
115
110
  }
116
- this.$formFieldInputHint.innerText = this.enhancedHint;
111
+ this.$formItemInputHint.innerText = this.enhancedHint;
117
112
 
118
113
  this.updateList();
119
114
  }
@@ -140,7 +135,7 @@ export default class TextAreaItemisedRows {
140
135
  this.updateAriaText(`'${newValue}' already added`);
141
136
  } else {
142
137
  this.values.push(newValue);
143
- this.$formFieldInput.value = this.values.join("\n");
138
+ this.$formItemInput.value = this.values.join("\n");
144
139
  this.updateList();
145
140
  this.updateAriaText(`'${newValue}' added`);
146
141
  }
@@ -157,7 +152,7 @@ export default class TextAreaItemisedRows {
157
152
  this.values = this.values.filter(
158
153
  (existingValue) => existingValue !== removeValue,
159
154
  );
160
- this.$formFieldInput.value = this.values.join("\n");
155
+ this.$formItemInput.value = this.values.join("\n");
161
156
  this.updateList();
162
157
  this.updateAriaText(`'${removeValue}' removed`);
163
158
  }
@@ -72,8 +72,8 @@
72
72
  "name": "countType",
73
73
  "type": "string",
74
74
  "required": false,
75
- "description": "The type of character count to display. Can be `characters` or `words`.",
76
- "default": "characters"
75
+ "description": "The type of character count to display. Can be `length`, `characters` or `words`. `length` counts the number of raw characters used, `characters` counts the number of visual characters, and `words` counts the number of words.",
76
+ "default": "length"
77
77
  },
78
78
  {
79
79
  "name": "threshold",
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("TNAFrontend",[],e):"object"==typeof exports?exports.TNAFrontend=e():t.TNAFrontend=e()}(self,()=>(()=>{"use strict";var t={740(t,e,i){i.d(e,{default:()=>r});class r{constructor(t,e={}){this.$module=t,this.$formFieldInput=this.$module&&this.$module.querySelector(".tna-textarea"),this.$formFieldCharacterCount=this.$module&&this.$module.querySelector(".tna-textarea-count"),this.$formFieldCharacterCountScreenReader=this.$module&&this.$module.querySelector(".tna-textarea-count__screen-reader-status"),this.max=parseInt(this.$formFieldInput?.dataset?.maxLength,10),this.countType=this.$formFieldInput?.dataset?.countType||"characters",this.$module&&this.$formFieldInput&&this.$formFieldCharacterCount&&this.$formFieldCharacterCountScreenReader&&this.max&&this.init(e)}init(t){this.threshold=t.threshold||parseInt(this.$formFieldInput?.dataset?.countThreshold,10)||0,this.debounceDuration=t.debounceDuration||parseInt(this.$formFieldInput?.dataset?.debounceDuration,10)||1e3,this.intervalChecker=t.intervalChecker||1e3,this.debounceTimeout=null,this.lastInputValue="",this.$formFieldInput.addEventListener("input",()=>{this.handleInput(),this.lastInputTimestamp=Date.now()}),this.$formFieldInput.addEventListener("focus",()=>{this.handleFocus()}),this.$formFieldInput.addEventListener("blur",()=>{this.handleBlur()}),this.updateVisualCharacterCount(),this.updateScreenReaderCharacterCount()}handleFocus(){this.valueChecker=window.setInterval(()=>{(!this.lastInputTimestamp||Date.now()-this.intervalChecker/2>=this.lastInputTimestamp)&&this.updateIfValueChanged()},this.intervalChecker)}handleBlur(){this.valueChecker&&window.clearInterval(this.valueChecker),this.updateScreenReaderCharacterCount()}updateIfValueChanged(){this.$formFieldInput.value!==this.lastInputValue&&(this.lastInputValue=this.$formFieldInput.value,this.updateVisualCharacterCount(),this.updateScreenReaderCharacterCount())}handleInput(){this.updateVisualCharacterCount(),clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{this.updateScreenReaderCharacterCount()},this.debounceDuration)}getCurrentLength(){const t=this.$formFieldInput.value;if("words"===this.countType){const e=t.trim();return""===e?0:e.split(/\s+/).length}return Array.from(t).length}getCurrentLengthMessage(){const t=this.getCurrentLength();let e=this.countType;return 1===Math.abs(this.max-t)&&(e=e.replace(/s$/,"")),t>this.max?`You have ${(new Intl.NumberFormat).format(t-this.max)} ${e} too many`:`You have ${(new Intl.NumberFormat).format(this.max-t)} ${e} remaining`}isOverThreshold(){return this.getCurrentLength()>this.max}updateVisualCharacterCount(){this.threshold&&(this.getCurrentLength()>this.max*(this.threshold/100)?this.showCharacterCount():this.hideCharacterCount()),this.$formFieldCharacterCount.innerText=this.getCurrentLengthMessage(),this.isOverThreshold()?(this.$formFieldInput.classList.add("tna-textarea--error"),this.$formFieldCharacterCount.classList.add("tna-textarea-count--error")):(this.$formFieldInput.classList.remove("tna-textarea--error"),this.$formFieldCharacterCount.classList.remove("tna-textarea-count--error"))}updateScreenReaderCharacterCount(){const t=this.getCurrentLengthMessage();this.$formFieldCharacterCountScreenReader.innerText=t}showCharacterCount(){this.$formFieldCharacterCount.removeAttribute("hidden"),this.$formFieldCharacterCountScreenReader.removeAttribute("aria-hidden")}hideCharacterCount(){this.$formFieldCharacterCount.setAttribute("hidden",""),this.$formFieldCharacterCountScreenReader.setAttribute("aria-hidden","true")}}},371(t,e,i){i.d(e,{default:()=>r});class r{constructor(t,e={}){if(this.$module=t,this.$formFieldInput=this.$module&&this.$module.querySelector(".tna-textarea"),this.$formFieldInputHint=this.$module&&this.$module.querySelector(".tna-form-item__hint"),this.$formFieldBody=this.$module&&this.$module.querySelector(".tna-form-item__body"),!this.$module||!this.$formFieldInput||!this.$formFieldBody||null!==this.$formFieldInput.getAttribute("hidden"))return;if(!(this.$formFieldInput instanceof HTMLTextAreaElement))throw new Error("Expected a textarea element");const{enhancedHint:i}=e;this.enhancedHint=i||"Enter an item and press enter",this.values=this.$formFieldInput.value.split("\n").map(t=>t.trim()).filter(t=>t),this.id=this.$formFieldInput.id,this.init()}init(){this.$formFieldNewInput=document.createElement("input"),this.$formFieldNewInput.classList.add("tna-text-input"),["id","aria-describedby"].forEach(t=>{this.$formFieldNewInput.setAttribute(t,this.$formFieldInput.getAttribute(t)),this.$formFieldInput.removeAttribute(t)}),this.$formFieldBody.appendChild(this.$formFieldNewInput),this.$formFieldInput.setAttribute("hidden",""),this.$formFieldInput.addEventListener("keyup",()=>this.updateList()),this.$formFieldNewInput.addEventListener("keypress",t=>{"Enter"===t.key&&this.appendValue(t.target.value)}),this.$formFieldNewInputAddButton=document.createElement("button"),this.$formFieldNewInputAddButton.setAttribute("type","button"),this.$formFieldNewInputAddButton.classList.add("tna-button","tna-button--small"),this.$formFieldNewInputAddButtonInner=document.createElement("span"),this.$formFieldNewInputAddButtonInner.innerText="Add",this.$formFieldNewInputAddButtonInnerExtra=document.createElement("span"),this.$formFieldNewInputAddButtonInnerExtra.classList.add("tna-visually-hidden"),this.$formFieldNewInputAddButtonInnerExtra.innerText=" to list",this.$formFieldNewInputAddButtonInner.appendChild(this.$formFieldNewInputAddButtonInnerExtra),this.$formFieldNewInputAddButton.appendChild(this.$formFieldNewInputAddButtonInner),this.$formFieldBody.appendChild(this.$formFieldNewInputAddButton),this.$formFieldNewInputAddButton.addEventListener("click",()=>{this.appendValue(this.$formFieldNewInput.value)}),this.$formFieldLiveAria=document.createElement("div"),this.$formFieldLiveAria.setAttribute("aria-live","polite"),this.$formFieldLiveAria.classList.add("tna-visually-hidden"),this.$module.appendChild(this.$formFieldLiveAria),this.$formFieldCounter=document.createElement("p"),this.$formFieldCounter.id=`${this.id}-list-helper`,this.$formFieldCounter.classList.add("tna-!--margin-top-xs"),this.$module.appendChild(this.$formFieldCounter),this.$formFieldNewInput.setAttribute("aria-describedby",`${this.$formFieldNewInput.getAttribute("aria-describedby")} ${this.$formFieldCounter.id}`),this.$valuesList=document.createElement("ul"),this.$valuesList.classList.add("tna-compound-filters","tna-!--margin-top-xs"),this.$valuesList.addEventListener("blur",()=>{this.$valuesList.removeAttribute("tabindex"),this.updateAriaText("")}),this.$module.appendChild(this.$valuesList),this.$formFieldInputHint||(this.$formFieldInputHint=document.createElement("p"),this.$formFieldInputHint.classList.add("tna-form-item__hint"),this.$formFieldBody.parentNode.insertBefore(this.$formFieldInputHint,this.$formFieldBody)),this.$formFieldInputHint.innerText=this.enhancedHint,this.updateList()}updateAriaText(t){this.$formFieldLiveAria.innerText=t}normaliseValue(t){return t.replace(/\s{2,}/u," ").trim()}isValueInList(t){return this.values.map(t=>this.normaliseValue(t).toLowerCase()).includes(t.toLowerCase().trim())}appendValue(t){const e=this.normaliseValue(t);e?this.isValueInList(e)?this.updateAriaText(`'${e}' already added`):(this.values.push(e),this.$formFieldInput.value=this.values.join("\n"),this.updateList(),this.updateAriaText(`'${e}' added`)):this.updateAriaText("Enter an item to add"),this.$formFieldNewInput.value="",this.$formFieldNewInput.focus()}removeValue(t){const e=this.normaliseValue(t);e&&this.isValueInList(e)&&(this.values=this.values.filter(t=>t!==e),this.$formFieldInput.value=this.values.join("\n"),this.updateList(),this.updateAriaText(`'${e}' removed`)),this.values.length?(this.$valuesList.setAttribute("tabindex","0"),this.$valuesList.focus()):this.$formFieldNewInput.focus()}updateList(){this.$valuesList.innerHTML="",this.values.map(t=>{const e=document.createElement("li");e.classList.add("tna-compound-filters__item");const i=document.createElement("span");i.innerText=t,e.appendChild(i);const r=document.createElement("button");return r.innerText=`Remove '${t}'`,r.setAttribute("type","button"),r.classList.add("tna-compound-filters__link"),r.addEventListener("click",()=>{this.removeValue(t)}),e.appendChild(r),e}).forEach(t=>this.$valuesList.appendChild(t));let t="item";1!==this.values.length&&(t+="s");const e=`${(new Intl.NumberFormat).format(this.values.length)} ${t} added`;this.$formFieldCounter.innerText=e}}}};const e={};function i(r){const n=e[r];if(void 0!==n)return n.exports;const s=e[r]={exports:{}};return t[r](s,s.exports,i),s.exports}i.d=(t,e)=>{for(var r in e)i.o(e,r)&&!i.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};let r={};i.r(r),i.d(r,{TextAreaCharacterCount:()=>n.default,TextAreaItemisedRows:()=>s.default});var n=i(740),s=i(371);return r})());
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("TNAFrontend",[],e):"object"==typeof exports?exports.TNAFrontend=e():t.TNAFrontend=e()}(self,()=>(()=>{"use strict";var t={740(t,e,i){i.d(e,{default:()=>r});class r{constructor(t,e={}){if(this.$module=t,this.$formFieldInput=this.$module&&this.$module.querySelector(".tna-textarea"),this.$formFieldCharacterCount=this.$module&&this.$module.querySelector(".tna-textarea-count"),this.$formFieldCharacterCountScreenReader=this.$module&&this.$module.querySelector(".tna-textarea-count__screen-reader-status"),this.max=parseInt(this.$formFieldInput?.dataset?.maxLength,10),!(this.$module&&this.$formFieldInput&&this.$formFieldCharacterCount&&this.$formFieldCharacterCountScreenReader&&this.max))return;const i={length:{labels:["character","characters"]},characters:{labels:["character","characters"],segmenterGranularity:"grapheme"},words:{labels:["word","words"],segmenterGranularity:"word"}};if(this.countType=this.$formFieldInput?.dataset?.countType||"length",!i[this.countType])throw new Error(`Unsupported count type: ${this.countType}`);this.config=i[this.countType],this.init(e)}init(t){if(this.segmenter=null,"undefined"!=typeof Intl&&"function"==typeof Intl.Segmenter&&this.config.segmenterGranularity){const e=t.language||navigator.language||"en";this.segmenter=new Intl.Segmenter(e,{granularity:this.config.segmenterGranularity})}this.threshold=t.threshold||parseInt(this.$formFieldInput?.dataset?.countThreshold,10)||0,this.debounceDuration=t.debounceDuration||parseInt(this.$formFieldInput?.dataset?.debounceDuration,10)||1e3,this.intervalChecker=t.intervalChecker||1e3,this.debounceTimeout=null,this.lastInputValue="",this.$formFieldInput.addEventListener("input",()=>{this.handleInput(),this.lastInputTimestamp=Date.now()}),this.$formFieldInput.addEventListener("focus",()=>{this.handleFocus()}),this.$formFieldInput.addEventListener("blur",()=>{this.handleBlur()}),this.updateVisualCharacterCount(),this.updateScreenReaderCharacterCount()}handleFocus(){this.valueChecker=window.setInterval(()=>{(!this.lastInputTimestamp||Date.now()-this.intervalChecker/2>=this.lastInputTimestamp)&&this.updateIfValueChanged()},this.intervalChecker)}handleBlur(){this.valueChecker&&window.clearInterval(this.valueChecker),this.updateScreenReaderCharacterCount()}updateIfValueChanged(){this.$formFieldInput.value!==this.lastInputValue&&(this.lastInputValue=this.$formFieldInput.value,this.updateVisualCharacterCount(),this.updateScreenReaderCharacterCount())}handleInput(){this.updateVisualCharacterCount(),clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{this.updateScreenReaderCharacterCount()},this.debounceDuration)}getCurrentLength(){const t=this.$formFieldInput.value;return"length"===this.countType?t.length:"characters"===this.countType?this.segmenter?Array.from(this.segmenter.segment(t)).length:Array.from(t).length:"words"===this.countType?this.segmenter?Array.from(this.segmenter.segment(t)).filter(t=>t.isWordLike).length:t.trim().split(/\s+/).length:0}getCurrentLengthMessage(){const t=this.getCurrentLength(),[e,i]=this.config.labels;let r=i;return 1===Math.abs(this.max-t)&&(r=e),t>this.max?`You have ${(new Intl.NumberFormat).format(t-this.max)} ${r} too many`:`You have ${(new Intl.NumberFormat).format(this.max-t)} ${r} remaining`}isOverThreshold(){return this.getCurrentLength()>this.max}updateVisualCharacterCount(){this.threshold&&(this.getCurrentLength()>this.max*(this.threshold/100)?this.showCharacterCount():this.hideCharacterCount()),this.$formFieldCharacterCount.innerText=this.getCurrentLengthMessage(),this.isOverThreshold()?(this.$formFieldInput.classList.add("tna-textarea--error"),this.$formFieldCharacterCount.classList.add("tna-textarea-count--error")):(this.$formFieldInput.classList.remove("tna-textarea--error"),this.$formFieldCharacterCount.classList.remove("tna-textarea-count--error"))}updateScreenReaderCharacterCount(){const t=this.getCurrentLengthMessage();this.$formFieldCharacterCountScreenReader.innerText=t}showCharacterCount(){this.$formFieldCharacterCount.removeAttribute("hidden"),this.$formFieldCharacterCountScreenReader.removeAttribute("aria-hidden")}hideCharacterCount(){this.$formFieldCharacterCount.setAttribute("hidden",""),this.$formFieldCharacterCountScreenReader.setAttribute("aria-hidden","true")}}},371(t,e,i){i.d(e,{default:()=>r});class r{constructor(t,e={}){if(this.$module=t,this.$formItemInput=this.$module&&this.$module.querySelector(".tna-textarea"),this.$formItemHeader=this.$module&&this.$module.querySelector(".tna-form-item__header"),this.$formItemInputHint=this.$module&&this.$module.querySelector(".tna-form-item__hint"),this.$formItemBody=this.$module&&this.$module.querySelector(".tna-form-item__body"),!(this.$module&&this.$formItemHeader&&this.$formItemInput&&this.$formItemBody&&null===this.$formItemInput.getAttribute("hidden")))return;if(!(this.$formItemInput instanceof HTMLTextAreaElement))throw new Error("Expected a textarea element");const{enhancedHint:i}=e;this.enhancedHint=i||"Enter an item and press enter",this.values=this.$formItemInput.value.split("\n").map(t=>t.trim()).filter(t=>t),this.id=this.$formItemInput.id,this.init()}init(){this.$formFieldNewInput=document.createElement("input"),this.$formFieldNewInput.classList.add("tna-text-input"),["id","aria-describedby"].forEach(t=>{this.$formFieldNewInput.setAttribute(t,this.$formItemInput.getAttribute(t)),this.$formItemInput.removeAttribute(t)}),this.$formItemBody.appendChild(this.$formFieldNewInput),this.$formItemInput.setAttribute("hidden",""),this.$formItemInput.addEventListener("keyup",()=>this.updateList()),this.$formFieldNewInput.addEventListener("keypress",t=>{"Enter"===t.key&&this.appendValue(t.target.value)}),this.$formFieldNewInputAddButton=document.createElement("button"),this.$formFieldNewInputAddButton.setAttribute("type","button"),this.$formFieldNewInputAddButton.classList.add("tna-button","tna-button--small"),this.$formFieldNewInputAddButton.innerText="Add",this.$formFieldNewInputAddButton.setAttribute("aria-label",`Add to list for '${this.$formItemHeader.innerText}'`),this.$formItemBody.appendChild(this.$formFieldNewInputAddButton),this.$formFieldNewInputAddButton.addEventListener("click",()=>{this.appendValue(this.$formFieldNewInput.value)}),this.$formFieldLiveAria=document.createElement("div"),this.$formFieldLiveAria.setAttribute("aria-live","polite"),this.$formFieldLiveAria.classList.add("tna-visually-hidden"),this.$module.appendChild(this.$formFieldLiveAria),this.$formFieldCounter=document.createElement("p"),this.$formFieldCounter.id=`${this.id}-list-helper`,this.$formFieldCounter.classList.add("tna-!--margin-top-xs"),this.$module.appendChild(this.$formFieldCounter),this.$formFieldNewInput.setAttribute("aria-describedby",`${this.$formFieldNewInput.getAttribute("aria-describedby")} ${this.$formFieldCounter.id}`),this.$valuesList=document.createElement("ul"),this.$valuesList.classList.add("tna-compound-filters","tna-!--margin-top-xs"),this.$valuesList.addEventListener("blur",()=>{this.$valuesList.removeAttribute("tabindex"),this.updateAriaText("")}),this.$module.appendChild(this.$valuesList),this.$formItemInputHint||(this.$formItemInputHint=document.createElement("p"),this.$formItemInputHint.classList.add("tna-form-item__hint"),this.$formItemBody.parentNode.insertBefore(this.$formItemInputHint,this.$formItemBody)),this.$formItemInputHint.innerText=this.enhancedHint,this.updateList()}updateAriaText(t){this.$formFieldLiveAria.innerText=t}normaliseValue(t){return t.replace(/\s{2,}/u," ").trim()}isValueInList(t){return this.values.map(t=>this.normaliseValue(t).toLowerCase()).includes(t.toLowerCase().trim())}appendValue(t){const e=this.normaliseValue(t);e?this.isValueInList(e)?this.updateAriaText(`'${e}' already added`):(this.values.push(e),this.$formItemInput.value=this.values.join("\n"),this.updateList(),this.updateAriaText(`'${e}' added`)):this.updateAriaText("Enter an item to add"),this.$formFieldNewInput.value="",this.$formFieldNewInput.focus()}removeValue(t){const e=this.normaliseValue(t);e&&this.isValueInList(e)&&(this.values=this.values.filter(t=>t!==e),this.$formItemInput.value=this.values.join("\n"),this.updateList(),this.updateAriaText(`'${e}' removed`)),this.values.length?(this.$valuesList.setAttribute("tabindex","0"),this.$valuesList.focus()):this.$formFieldNewInput.focus()}updateList(){this.$valuesList.innerHTML="",this.values.map(t=>{const e=document.createElement("li");e.classList.add("tna-compound-filters__item");const i=document.createElement("span");i.innerText=t,e.appendChild(i);const r=document.createElement("button");return r.innerText=`Remove '${t}'`,r.setAttribute("type","button"),r.classList.add("tna-compound-filters__link"),r.addEventListener("click",()=>{this.removeValue(t)}),e.appendChild(r),e}).forEach(t=>this.$valuesList.appendChild(t));let t="item";1!==this.values.length&&(t+="s");const e=`${(new Intl.NumberFormat).format(this.values.length)} ${t} added`;this.$formFieldCounter.innerText=e}}}};const e={};function i(r){const s=e[r];if(void 0!==s)return s.exports;const n=e[r]={exports:{}};return t[r](n,n.exports,i),n.exports}i.d=(t,e)=>{for(var r in e)i.o(e,r)&&!i.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};let r={};i.r(r),i.d(r,{TextAreaCharacterCount:()=>s.default,TextAreaItemisedRows:()=>n.default});var s=i(740),n=i(371);return r})());
2
2
  //# sourceMappingURL=textarea.js.map