@nationalarchives/frontend 1.6.0 → 1.6.2

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(){if("words"===this.countType){const e=this.$formFieldInput.value.trim();return""===e?0:e.split(/\s+/).length}return this.$formFieldInput.value.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={}){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})());
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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AEA,0BAAAmB,GACMxB,KAAKW,YAEHX,KAAKiC,mBAAqBjC,KAAKK,KAAOL,KAAKW,UAAY,KACzDX,KAAKgD,qBAELhD,KAAKiD,sBAITjD,KAAKG,yBAAyB+C,UAAYlD,KAAKsC,0BAC3CtC,KAAK+C,mBACP/C,KAAKC,gBAAgBkD,UAAUC,IAAI,uBACnCpD,KAAKG,yBAAyBgD,UAAUC,IAAI,+BAE5CpD,KAAKC,gBAAgBkD,UAAUE,OAAO,uBACtCrD,KAAKG,yBAAyBgD,UAAUE,OACtC,6BAGN,CAEA,gCAAA5B,GACE,MAAM6B,EAAuBtD,KAAKsC,0BAClCtC,KAAKI,qCAAqC8C,UAAYI,CACxD,CAEA,kBAAAN,GACEhD,KAAKG,yBAAyBoD,gBAAgB,UAC9CvD,KAAKI,qCAAqCmD,gBAAgB,cAC5D,CAEA,kBAAAN,GACEjD,KAAKG,yBAAyBqD,aAAa,SAAU,IACrDxD,KAAKI,qCAAqCoD,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 if (this.countType === \"words\") {\n const trimmedValue = this.$formFieldInput.value.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 this.$formFieldInput.value.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","trimmedValue","trim","split","length","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,E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EA,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":""}
@@ -90,15 +90,16 @@ export default class TextAreaCharacterCount {
90
90
  }
91
91
 
92
92
  getCurrentLength() {
93
+ const rawValue = this.$formFieldInput.value;
93
94
  if (this.countType === "words") {
94
- const trimmedValue = this.$formFieldInput.value.trim();
95
+ const trimmedValue = rawValue.trim();
95
96
  if (trimmedValue === "") {
96
97
  /* eslint-disable-next-line no-magic-numbers */
97
98
  return 0;
98
99
  }
99
100
  return trimmedValue.split(/\s+/).length;
100
101
  }
101
- return this.$formFieldInput.value.length;
102
+ return Array.from(rawValue).length;
102
103
  }
103
104
 
104
105
  getCurrentLengthMessage() {
@@ -31,7 +31,7 @@
31
31
  "name": "feedback",
32
32
  "hint": "What did you think?"
33
33
  },
34
- "html": "<div class=\"tna-form-item\"><div class=\"tna-form-item__header\"><label class=\"tna-form-item__label tna-heading-m\" for=\"feedback\">Enter your feedback</label></div><p id=\"feedback-hint\" class=\"tna-form-item__hint\">What did you think?</p><div class=\"tna-form-item__body\"><textarea id=\"feedback\" class=\"tna-textarea\" name=\"feedback\" spellcheck=\"false\" autocapitalize=\"off\" autocorrect=\"off\" rows=\"5\" aria-describedby=\"feedback-hint \"></textarea></div></div>"
34
+ "html": "<div class=\"tna-form-item\"><div class=\"tna-form-item__header\"><label class=\"tna-form-item__label tna-heading-m\" for=\"feedback\">Enter your feedback</label></div><p id=\"feedback-hint\" class=\"tna-form-item__hint\">What did you think?</p><div class=\"tna-form-item__body\"><textarea id=\"feedback\" class=\"tna-textarea\" name=\"feedback\" spellcheck=\"false\" autocapitalize=\"off\" autocorrect=\"off\" rows=\"5\" aria-describedby=\"feedback-hint \"></textarea></div></div>"
35
35
  },
36
36
  {
37
37
  "name": "with an error",
@@ -44,7 +44,7 @@
44
44
  "text": "Enter some feedback"
45
45
  }
46
46
  },
47
- "html": "<div class=\"tna-form-item tna-form-item--error\"><div class=\"tna-form-item__header\"><label class=\"tna-form-item__label tna-heading-m\" for=\"feedback\">Enter your feedback</label></div><p id=\"feedback-error\" class=\"tna-form-item__error\"><span class=\"tna-visually-hidden\">Error:</span> Enter some feedback</p><div class=\"tna-form-item__body\"><textarea id=\"feedback\" class=\"tna-textarea\" name=\"feedback\" spellcheck=\"false\" autocapitalize=\"off\" autocorrect=\"off\" rows=\"5\" aria-describedby=\" feedback-error\"></textarea></div></div>"
47
+ "html": "<div class=\"tna-form-item tna-form-item--error\"><div class=\"tna-form-item__header\"><label class=\"tna-form-item__label tna-heading-m\" for=\"feedback\">Enter your feedback</label></div><p id=\"feedback-error\" class=\"tna-form-item__error\"><span class=\"tna-visually-hidden\">Error:</span> Enter some feedback</p><div class=\"tna-form-item__body\"><textarea id=\"feedback\" class=\"tna-textarea\" name=\"feedback\" spellcheck=\"false\" autocapitalize=\"off\" autocorrect=\"off\" rows=\"5\" aria-describedby=\" feedback-error \"></textarea></div></div>"
48
48
  },
49
49
  {
50
50
  "name": "textarea size",
@@ -134,7 +134,7 @@
134
134
  "max": 200
135
135
  }
136
136
  },
137
- "html": "<div class=\"tna-form-item\" data-module=\"tna-textarea-character-count\"><div class=\"tna-form-item__header\"><label class=\"tna-form-item__label tna-heading-m\" for=\"feedback\">Enter your feedback</label></div><div class=\"tna-form-item__body\"><textarea id=\"feedback\" class=\"tna-textarea\" name=\"feedback\" spellcheck=\"false\" autocapitalize=\"off\" autocorrect=\"off\" rows=\"5\" aria-describedby=\" \" data-max-length=\"200\"></textarea><div id=\"feedback-count\" class=\"tna-visually-hidden\">You can enter up to 200 characters</div><p class=\"tna-textarea-count\" aria-hidden=\"true\">You can enter up to 200 characters</p><div class=\"tna-textarea-count__screen-reader-status tna-visually-hidden\" aria-live=\"polite\">You can enter up to 200 characters</div></div></div>"
137
+ "html": "<div class=\"tna-form-item\" data-module=\"tna-textarea-character-count\"><div class=\"tna-form-item__header\"><label class=\"tna-form-item__label tna-heading-m\" for=\"feedback\">Enter your feedback</label></div><div class=\"tna-form-item__body\"><textarea id=\"feedback\" class=\"tna-textarea\" name=\"feedback\" spellcheck=\"false\" autocapitalize=\"off\" autocorrect=\"off\" rows=\"5\" aria-describedby=\" feedback-count\" data-max-length=\"200\"></textarea><div id=\"feedback-count\" class=\"tna-visually-hidden\">You can enter up to 200 characters</div><p class=\"tna-textarea-count\" aria-hidden=\"true\">You can enter up to 200 characters</p><div class=\"tna-textarea-count__screen-reader-status tna-visually-hidden\" aria-live=\"polite\">You can enter up to 200 characters</div></div></div>"
138
138
  },
139
139
  {
140
140
  "name": "with word count",
@@ -148,7 +148,7 @@
148
148
  "countType": "words"
149
149
  }
150
150
  },
151
- "html": "<div class=\"tna-form-item\" data-module=\"tna-textarea-character-count\"><div class=\"tna-form-item__header\"><label class=\"tna-form-item__label tna-heading-m\" for=\"feedback\">Enter your feedback</label></div><div class=\"tna-form-item__body\"><textarea id=\"feedback\" class=\"tna-textarea\" name=\"feedback\" spellcheck=\"false\" autocapitalize=\"off\" autocorrect=\"off\" rows=\"5\" aria-describedby=\" \" data-max-length=\"200\" data-count-type=\"words\"></textarea><div id=\"feedback-count\" class=\"tna-visually-hidden\">You can enter up to 200 words</div><p class=\"tna-textarea-count\" aria-hidden=\"true\">You can enter up to 200 words</p><div class=\"tna-textarea-count__screen-reader-status tna-visually-hidden\" aria-live=\"polite\">You can enter up to 200 words</div></div></div>"
151
+ "html": "<div class=\"tna-form-item\" data-module=\"tna-textarea-character-count\"><div class=\"tna-form-item__header\"><label class=\"tna-form-item__label tna-heading-m\" for=\"feedback\">Enter your feedback</label></div><div class=\"tna-form-item__body\"><textarea id=\"feedback\" class=\"tna-textarea\" name=\"feedback\" spellcheck=\"false\" autocapitalize=\"off\" autocorrect=\"off\" rows=\"5\" aria-describedby=\" feedback-count\" data-max-length=\"200\" data-count-type=\"words\"></textarea><div id=\"feedback-count\" class=\"tna-visually-hidden\">You can enter up to 200 words</div><p class=\"tna-textarea-count\" aria-hidden=\"true\">You can enter up to 200 words</p><div class=\"tna-textarea-count__screen-reader-status tna-visually-hidden\" aria-live=\"polite\">You can enter up to 200 words</div></div></div>"
152
152
  },
153
153
  {
154
154
  "name": "with character count and custom debounce duration",
@@ -162,7 +162,7 @@
162
162
  "debounceDuration": 500
163
163
  }
164
164
  },
165
- "html": "<div class=\"tna-form-item\" data-module=\"tna-textarea-character-count\"><div class=\"tna-form-item__header\"><label class=\"tna-form-item__label tna-heading-m\" for=\"feedback\">Enter your feedback</label></div><div class=\"tna-form-item__body\"><textarea id=\"feedback\" class=\"tna-textarea\" name=\"feedback\" spellcheck=\"false\" autocapitalize=\"off\" autocorrect=\"off\" rows=\"5\" aria-describedby=\" \" data-max-length=\"200\" data-debounce-duration=\"500\"></textarea><div id=\"feedback-count\" class=\"tna-visually-hidden\">You can enter up to 200 characters</div><p class=\"tna-textarea-count\" aria-hidden=\"true\">You can enter up to 200 characters</p><div class=\"tna-textarea-count__screen-reader-status tna-visually-hidden\" aria-live=\"polite\">You can enter up to 200 characters</div></div></div>"
165
+ "html": "<div class=\"tna-form-item\" data-module=\"tna-textarea-character-count\"><div class=\"tna-form-item__header\"><label class=\"tna-form-item__label tna-heading-m\" for=\"feedback\">Enter your feedback</label></div><div class=\"tna-form-item__body\"><textarea id=\"feedback\" class=\"tna-textarea\" name=\"feedback\" spellcheck=\"false\" autocapitalize=\"off\" autocorrect=\"off\" rows=\"5\" aria-describedby=\" feedback-count\" data-max-length=\"200\" data-debounce-duration=\"500\"></textarea><div id=\"feedback-count\" class=\"tna-visually-hidden\">You can enter up to 200 characters</div><p class=\"tna-textarea-count\" aria-hidden=\"true\">You can enter up to 200 characters</p><div class=\"tna-textarea-count__screen-reader-status tna-visually-hidden\" aria-live=\"polite\">You can enter up to 200 characters</div></div></div>"
166
166
  },
167
167
  {
168
168
  "name": "with classes",
@@ -11,8 +11,12 @@
11
11
  attributes: params.formItemAttributes
12
12
  }, 'tna-textarea-character-count' if params.characterCount else ('tna-textarea-itemised-rows' if params.itemiseRows else '')) %}
13
13
  <textarea id="{{ params.id }}" class="tna-textarea{% if params.size %} tna-textarea--{{ params.size }}{% endif %}{% if params.classes %} {{ params.classes }}{% endif %}" name="{{ params.name }}" spellcheck="{{ params.spellcheck if params.spellcheck else false }}" autocapitalize="{{ params.autocapitalize if params.autocapitalize else 'off' }}" autocorrect="{{ 'on' if params.autocorrect else 'off' }}" rows="{{ params.rows if params.rows else 5 }}"
14
- {%- if params.hint or params.error or params.characterCount %} aria-describedby="{%- if params.hint -%}{{ params.id }}-hint{%- endif %} {% if params.error -%}{{ params.id }}-error{%- endif -%} {% if params.params.characterCount -%}{{ params.id }}-count{%- endif -%}"{%- endif %}
15
- {%- if params.characterCount %} data-max-length="{{ params.characterCount.max }}"{%- if params.characterCount.countType %} data-count-type="{{ params.characterCount.countType }}"{%- endif %}{%- if params.characterCount.threshold %} data-count-threshold="{{ params.characterCount.threshold }}"{%- endif %}{%- if params.characterCount.debounceDuration %} data-debounce-duration="{{ params.characterCount.debounceDuration }}"{%- endif %}{%- endif %}
14
+ {%- if params.hint or params.error or params.characterCount %} aria-describedby="{%- if params.hint -%}{{ params.id }}-hint{%- endif %} {% if params.error -%}{{ params.id }}-error{%- endif %} {% if params.characterCount -%}{{ params.id }}-count{%- endif -%}"{%- endif %}
15
+ {%- if params.characterCount %} data-max-length="{{ params.characterCount.max }}"
16
+ {%- if params.characterCount.countType %} data-count-type="{{ params.characterCount.countType }}"{%- endif %}
17
+ {%- if params.characterCount.threshold %} data-count-threshold="{{ params.characterCount.threshold }}"{%- endif %}
18
+ {%- if params.characterCount.debounceDuration %} data-debounce-duration="{{ params.characterCount.debounceDuration }}"{%- endif %}
19
+ {%- endif %}
16
20
  {%- for attribute, value in params.attributes %} {{ attribute }}{% if value !== '' %}="{{ value }}"{% endif %}{% endfor %}>{{ params.value }}</textarea>
17
21
  {%- if params.characterCount %}
18
22
  {%- set characterCountMessage %}
@@ -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(){if("words"===this.countType){const t=this.$formFieldInput.value.trim();return""===t?0:t.split(/\s+/).length}return this.$formFieldInput.value.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={}){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})());
2
2
  //# sourceMappingURL=textarea.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"components/textarea/textarea.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,4DCTc,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,IAAAW,CAAKX,GACHC,KAAKW,UACHZ,EAAQY,WACRL,SAASN,KAAKC,iBAAiBM,SAASK,eAAgB,KAExD,EACFZ,KAAKa,iBACHd,EAAQc,kBACRP,SAASN,KAAKC,iBAAiBM,SAASM,iBAAkB,KAE1D,IAEFb,KAAKc,gBAAkBf,EAAQe,iBAAmB,IAClDd,KAAKe,gBAAkB,KACvBf,KAAKgB,eAAiB,GAEtBhB,KAAKC,gBAAgBgB,iBAAiB,QAAS,KAC7CjB,KAAKkB,cACLlB,KAAKmB,mBAAqBC,KAAKC,QAEjCrB,KAAKC,gBAAgBgB,iBAAiB,QAAS,KAC7CjB,KAAKsB,gBAEPtB,KAAKC,gBAAgBgB,i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AD,EACA,OAAAA,EAAAvH,QAGA,MAAAC,EAAAmH,EAAAE,GAAA,CAGAtH,QAAA,IAOA,OAHAyH,EAAAH,GAAArH,EAAAA,EAAAD,QAAAqH,GAGApH,EAAAD,OACA,CCrBAqH,EAAAK,EAAA,CAAA1H,EAAA2H,KACA,QAAArC,KAAAqC,EACAN,EAAAO,EAAAD,EAAArC,KAAA+B,EAAAO,EAAA5H,EAAAsF,IACAuC,OAAAC,eAAA9H,EAAAsF,EAAA,CAAyCyC,YAAA,EAAAC,IAAAL,EAAArC,MCJzC+B,EAAAO,EAAA,CAAAK,EAAAC,IAAAL,OAAAM,UAAAC,eAAAC,KAAAJ,EAAAC,GCCAb,EAAAiB,EAAAtI,IACA6H,OAAAC,eAAA9H,EAAAuI,OAAAC,YAAA,CAAsDhG,MAAA,WACtDqF,OAAAC,eAAA9H,EAAA,cAAgDwC,OAAA,K","sources":["webpack://TNAFrontend/webpack/universalModuleDefinition","webpack://TNAFrontend/./src/nationalarchives/components/textarea/TextAreaCharacterCount.mjs","webpack://TNAFrontend/./src/nationalarchives/components/textarea/TextAreaItemisedRows.mjs","webpack://TNAFrontend/webpack/bootstrap","webpack://TNAFrontend/webpack/runtime/define property getters","webpack://TNAFrontend/webpack/runtime/hasOwnProperty shorthand","webpack://TNAFrontend/webpack/runtime/make namespace object"],"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 ","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 if (this.countType === \"words\") {\n const trimmedValue = this.$formFieldInput.value.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 this.$formFieldInput.value.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","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","// The module cache\nconst __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tconst cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tconst module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\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};"],"names":["root","factory","exports","module","define","amd","self","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","value","clearTimeout","setTimeout","getCurrentLength","trimmedValue","trim","split","length","getCurrentLengthMessage","currentLength","typeLabel","Math","abs","replace","Intl","NumberFormat","format","isOverThreshold","showCharacterCount","hideCharacterCount","innerText","classList","add","remove","currentLengthMessage","removeAttribute","setAttribute","TextAreaItemisedRows","$formFieldInputHint","$formFieldBody","getAttribute","HTMLTextAreaElement","Error","enhancedHint","values","map","filter","id","$formFieldNewInput","document","createElement","forEach","attribute","appendChild","updateList","event","key","appendValue","target","$formFieldNewInputAddButton","$formFieldNewInputAddButtonInner","$formFieldNewInputAddButtonInnerExtra","$formFieldLiveAria","$formFieldCounter","$valuesList","updateAriaText","parentNode","insertBefore","content","normaliseValue","isValueInList","eachValue","toLowerCase","includes","newValue","push","join","focus","removeValue","existingValue","innerHTML","$item","$itemLabel","$removeItemButton","innerTextItemValue","innerTextValue","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag"],"sourceRoot":""}
1
+ {"version":3,"file":"components/textarea/textarea.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,4DCTc,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,IAAAW,CAAKX,GACHC,KAAKW,UACHZ,EAAQY,WACRL,SAASN,KAAKC,iBAAiBM,SAASK,eAAgB,KAExD,EACFZ,KAAKa,iBACHd,EAAQc,kBACRP,SAASN,KAAK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8B,GAAUzG,KAAKwF,YAAYX,YAAY4B,IAEnD,IAAIG,EAAqB,OAEE,IAAvB5G,KAAKoE,OAAO7B,SACdqE,GAAsB,KAExB,MAAMC,EAAiB,IAAG,IAAI7D,KAAKC,cAAeC,OAAOlD,KAAKoE,OAAO7B,WAAWqE,UAChF5G,KAAKuF,kBAAkBjC,UAAYuD,CACrC,E,GCvMF,MAAAC,EAAA,GAGA,SAAAC,EAAAC,GAEA,MAAAC,EAAAH,EAAAE,GACA,QAAAE,IAAAD,EACA,OAAAA,EAAA1H,QAGA,MAAAC,EAAAsH,EAAAE,GAAA,CAGAzH,QAAA,IAOA,OAHA4H,EAAAH,GAAAxH,EAAAA,EAAAD,QAAAwH,GAGAvH,EAAAD,OACA,CCrBAwH,EAAAK,EAAA,CAAA7H,EAAA8H,KACA,QAAArC,KAAAqC,EACAN,EAAAO,EAAAD,EAAArC,KAAA+B,EAAAO,EAAA/H,EAAAyF,IACAuC,OAAAC,eAAAjI,EAAAyF,EAAA,CAAyCyC,YAAA,EAAAC,IAAAL,EAAArC,MCJzC+B,EAAAO,EAAA,CAAAK,EAAAC,IAAAL,OAAAM,UAAAC,eAAAC,KAAAJ,EAAAC,GCCAb,EAAAiB,EAAAzI,IACAgI,OAAAC,eAAAjI,EAAA0I,OAAAC,YAAA,CAAsDnG,MAAA,WACtDwF,OAAAC,eAAAjI,EAAA,cAAgDwC,OAAA,K","sources":["webpack://TNAFrontend/webpack/universalModuleDefinition","webpack://TNAFrontend/./src/nationalarchives/components/textarea/TextAreaCharacterCount.mjs","webpack://TNAFrontend/./src/nationalarchives/components/textarea/TextAreaItemisedRows.mjs","webpack://TNAFrontend/webpack/bootstrap","webpack://TNAFrontend/webpack/runtime/define property getters","webpack://TNAFrontend/webpack/runtime/hasOwnProperty shorthand","webpack://TNAFrontend/webpack/runtime/make namespace object"],"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 ","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","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","// The module cache\nconst __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tconst cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tconst module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\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};"],"names":["root","factory","exports","module","define","amd","self","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","value","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","TextAreaItemisedRows","$formFieldInputHint","$formFieldBody","getAttribute","HTMLTextAreaElement","Error","enhancedHint","values","map","filter","id","$formFieldNewInput","document","createElement","forEach","attribute","appendChild","updateList","event","key","appendValue","target","$formFieldNewInputAddButton","$formFieldNewInputAddButtonInner","$formFieldNewInputAddButtonInnerExtra","$formFieldLiveAria","$formFieldCounter","$valuesList","updateAriaText","parentNode","insertBefore","content","normaliseValue","isValueInList","eachValue","toLowerCase","includes","newValue","push","join","focus","removeValue","existingValue","innerHTML","$item","$itemLabel","$removeItemButton","innerTextItemValue","innerTextValue","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag"],"sourceRoot":""}
@@ -5,13 +5,13 @@
5
5
  {%- from "nationalarchives/components/header/macro.njk" import tnaHeader -%}
6
6
  {%- from "nationalarchives/components/skip-link/macro.njk" import tnaSkipLink -%}
7
7
 
8
- {%- from "nationalarchives/templates/macros/title.njk" import title -%}
8
+ {%- from "nationalarchives/templates/macros/page-site-title-display.njk" import tnaPageSiteTitleDisplay -%}
9
9
 
10
10
  <!DOCTYPE html>
11
11
  <html lang="{{ htmlLang | default('en') }}" class="tna-template{% if theme and theme != 'light' %} tna-template--{{ theme }}-theme{% endif %}{% if themeAccent %} tna-template--{{ themeAccent }}-accent{% endif %}{% if htmlClasses %} {{ htmlClasses }}{% endif %}"{% for attribute, value in htmlAttributes %} {{ attribute }}{% if value !== '' %}="{{ value }}"{% endif %}{% endfor %}>
12
12
  <head>
13
13
  <meta charset="utf-8">
14
- <title>{% block pageTitle %}{{ title(pageTitle, siteTitle) }}{% endblock pageTitle %}</title>
14
+ <title>{% block pageTitle %}{{ tnaPageSiteTitleDisplay(pageTitle, siteTitle) }}{% endblock pageTitle %}</title>
15
15
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
16
16
  <meta name="theme-color" content="{{ themeColor | default('#010101') }}">
17
17
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -1,4 +1,4 @@
1
- {% macro title(pageTitle, siteTitle, maxTitleLength, separator, ellipsis) %}
1
+ {% macro tnaPageSiteTitleDisplay(pageTitle, siteTitle, maxTitleLength, separator, ellipsis) %}
2
2
  {#-
3
3
  Truncate any pageTitle that would cause the length of the <title> to exceed 70 characters
4
4
  See https://html-validate.org/rules/long-title.html
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nationalarchives/frontend",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "The National Archives frontend styles",
5
5
  "scripts": {
6
6
  "start": "storybook dev -p 6006",