@govuk-react/primitives 0.2.1 → 0.4.0
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.
- package/README.md +109 -25
- package/dist/accordion/element.d.ts +3 -0
- package/dist/accordion/element.js.map +1 -1
- package/dist/accordion/index.d.ts +3 -7
- package/dist/accordion/index.js +35 -33
- package/dist/accordion/index.js.map +1 -1
- package/dist/auto-focus/index.d.ts +3 -285
- package/dist/auto-focus/index.js +13 -3
- package/dist/auto-focus/index.js.map +1 -1
- package/dist/autocomplete/element.d.ts +7 -4
- package/dist/autocomplete/element.js +11 -11
- package/dist/autocomplete/element.js.map +1 -1
- package/dist/autocomplete/index.d.ts +7 -7
- package/dist/autocomplete/index.js +17 -25
- package/dist/autocomplete/index.js.map +1 -1
- package/dist/character-count/element.d.ts +5 -0
- package/dist/character-count/element.js +5 -5
- package/dist/character-count/element.js.map +1 -1
- package/dist/character-count/index.d.ts +8 -8
- package/dist/character-count/index.js +13 -14
- package/dist/character-count/index.js.map +1 -1
- package/dist/character-count/messages.d.ts +1 -1
- package/dist/character-count/messages.js +13 -13
- package/dist/character-count/messages.js.map +1 -1
- package/dist/character-count-text/index.d.ts +1 -0
- package/dist/character-count-text/index.js +6 -0
- package/dist/character-count-text/index.js.map +1 -0
- package/dist/choices/element.d.ts +5 -0
- package/dist/choices/element.js +6 -31
- package/dist/choices/element.js.map +1 -1
- package/dist/disclosure/element.d.ts +3 -0
- package/dist/disclosure/element.js +21 -12
- package/dist/disclosure/element.js.map +1 -1
- package/dist/disclosure/index.d.ts +6 -5
- package/dist/disclosure/index.js +21 -11
- package/dist/disclosure/index.js.map +1 -1
- package/dist/exit-this-page/element.d.ts +1 -1
- package/dist/exit-this-page/element.js +20 -21
- package/dist/exit-this-page/element.js.map +1 -1
- package/dist/exit-this-page/index.d.ts +11 -11
- package/dist/exit-this-page/index.js +7 -7
- package/dist/exit-this-page/index.js.map +1 -1
- package/dist/file-upload/element.d.ts +11 -6
- package/dist/file-upload/element.js +15 -15
- package/dist/file-upload/element.js.map +1 -1
- package/dist/file-upload/index.d.ts +9 -9
- package/dist/file-upload/index.js +11 -11
- package/dist/file-upload/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inline/accordion-element.js +1 -1
- package/dist/inline/auto-focus-element.js +1 -1
- package/dist/inline/autocomplete-element.js +1 -1
- package/dist/inline/character-count-element.js +1 -1
- package/dist/inline/choices-element.js +1 -1
- package/dist/inline/disclosure-element.js +1 -1
- package/dist/inline/exit-this-page-element.js +1 -1
- package/dist/inline/file-upload-element.js +1 -1
- package/dist/inline/focus-links-element.js +1 -1
- package/dist/inline/modal-element.js +1 -1
- package/dist/inline/password-input-element.js +1 -1
- package/dist/inline/tabs-element.js +1 -1
- package/dist/inline-script/index.js +12 -12
- package/dist/modal/element.js +126 -11
- package/dist/modal/element.js.map +1 -1
- package/dist/modal/index.d.ts +8 -3
- package/dist/modal/index.js +56 -20
- package/dist/modal/index.js.map +1 -1
- package/dist/password-input/element.js +27 -11
- package/dist/password-input/element.js.map +1 -1
- package/dist/password-input/index.d.ts +3 -3
- package/dist/password-input/index.js +4 -2
- package/dist/password-input/index.js.map +1 -1
- package/dist/styles.css +11 -0
- package/dist/tabs/element.d.ts +3 -0
- package/dist/tabs/element.js +17 -10
- package/dist/tabs/element.js.map +1 -1
- package/dist/tabs/index.d.ts +9 -18
- package/dist/tabs/index.js +48 -44
- package/dist/tabs/index.js.map +1 -1
- package/dist/utils/change-details.d.ts +11 -0
- package/dist/utils/change-details.js +3 -0
- package/dist/utils/change-details.js.map +1 -0
- package/dist/utils/on-property-change.d.ts +7 -0
- package/dist/utils/on-property-change.js +19 -0
- package/dist/utils/on-property-change.js.map +1 -0
- package/dist/utils/set-focus.js.map +1 -1
- package/dist/utils/slot.d.ts +5 -3
- package/dist/utils/slot.js +24 -2
- package/dist/utils/slot.js.map +1 -1
- package/package.json +8 -2
- package/dist/utils/on-property-set.d.ts +0 -9
- package/dist/utils/on-property-set.js +0 -38
- package/dist/utils/on-property-set.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/file-upload/element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EACL,SAAS,EACT,yBAAyB,EACzB,yBAAyB,GAE1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEnE,MAAM,CAAC,MAAM,OAAO,GAAG,yBAAyB,CAAC;AAOjD,qCAAqC;AACrC,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,gBAAgB,EAAE,gBAAgB;IAClC,uBAAuB,EAAE,EAAE,GAAG,EAAE,sBAAsB,EAAE,KAAK,EAAE,uBAAuB,EAAE;IACxF,mBAAmB,EAAE,mBAAmB;IACxC,gBAAgB,EAAE,gBAAgB;CACG,CAAC;AAExC,iDAAiD;AACjD,MAAM,UAAU,UAAU,CACxB,KAAkC,EAClC,QAAmF,EACnF,MAAe;;IAEf,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC,MAAA,QAAQ,CAAC,gBAAgB,CAAC,mCAAI,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;IAC9G,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7C,OAAO,SAAS,CAAC,MAAA,QAAQ,CAAC,uBAAuB,CAAC,mCAAI,QAAQ,CAAC,uBAAuB,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACjH,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,KAA2B,EAAE,EAAE,CAAC,KAAK,CAAC,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CAAC,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;YAC3F,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM;gBAAE,OAAO,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC3E,OAAO,IAAI,CAAC;QACd,CAAC;QAEO,eAAe,CAAC,KAAa;;YACnC,OAAO,CAAA,MAAA,IAAI,CAAC,KAAK,0CAAE,QAAQ,EAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC;QACxD,CAAC;KACF;IAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;AACzF,CAAC","sourcesContent":["/*\n * <govuk-react-file-upload>: a headless, light-DOM custom element that turns a file input into a\n * button and drop zone, with or without React, as govuk-frontend's improved file upload does.\n *\n * The input's files are the state. Without JavaScript the native file input shows and the button\n * stays hidden. On upgrade the element hides the input and shows the button, which opens the file\n * picker, says which files are chosen, and takes files dropped on it. The rendered markup is never\n * moved, so React can keep rendering it.\n *\n * As in govuk-frontend, the button takes the input's `id`, so its label names the button, and the\n * input's id gets `-input` added. The button also takes the input's `aria-describedby` and\n * `disabled`, and its accessible name is the label, the separator and its own text.\n *\n * Markup inside the element:\n * - `input[type=\"file\"]`: the field, with an `id` and a `label`. Hidden on upgrade.\n * - `button[data-file-upload-button]`: rendered `hidden`, with `type=\"button\"`.\n * - `[data-file-upload-status]`: which files are chosen.\n * - `[data-file-upload-separator]` (optional): between the label and the button's text in its\n * accessible name, such as a visually hidden comma.\n * - `[data-file-upload-drop-zone]` (optional): the area that shows dragging. The element itself\n * without one.\n * - `[data-file-upload-announcements]` (optional): a visually hidden live region for entering and\n * leaving the drop zone.\n *\n * The button gets `data-empty` while no file is chosen and `data-dragging` while files are dragged\n * over the drop zone, and the drop zone gets `data-disabled`.\n *\n * Attributes:\n * - `no-file-chosen`, `multiple-files-chosen`, `entered-drop-zone`, `left-drop-zone`: the text,\n * English by default, with `%{count}` for the number of files. Add a plural form to the name,\n * such as `multiple-files-chosen-one`, for a message for each form.\n * - `empty-class`, `dragging-class`: classes for the button while empty and while dragging.\n * - `disabled-class`: classes for the drop zone while the input is disabled.\n */\n\nimport {\n translate,\n translationAttributeNames,\n translationFromAttributes,\n type Translation,\n} from '../utils/translation.js';\nimport { classesOf, setText, setAttribute } from '../utils/dom.js';\n\nexport const tagName = 'govuk-react-file-upload';\n\nexport interface FileUploadElement extends HTMLElement {\n /** Updates the button from the input's files, such as after setting them. */\n update(): void;\n}\n\n/** govuk-frontend's English text. */\nexport const defaults = {\n 'no-file-chosen': 'No file chosen',\n 'multiple-files-chosen': { one: '%{count} file chosen', other: '%{count} files chosen' },\n 'entered-drop-zone': 'Entered drop zone',\n 'left-drop-zone': 'Left drop zone',\n} satisfies Record<string, Translation>;\n\n/** What the status says for the files chosen. */\nexport function statusText(\n files: ArrayLike<{ name: string }>,\n messages: { 'no-file-chosen'?: Translation; 'multiple-files-chosen'?: Translation },\n locale?: string\n) {\n if (files.length === 0) return translate(messages['no-file-chosen'] ?? defaults['no-file-chosen'], 0, locale);\n if (files.length === 1) return files[0].name;\n return translate(messages['multiple-files-chosen'] ?? defaults['multiple-files-chosen'], files.length, locale);\n}\n\nconst countFiles = (items: DataTransferItemList) => Array.from(items).filter((item) => item.kind === 'file').length;\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactFileUpload extends HTMLElement implements FileUploadElement {\n static get observedAttributes() {\n return [\n 'empty-class',\n 'dragging-class',\n 'disabled-class',\n ...Object.keys(defaults).flatMap(translationAttributeNames),\n ];\n }\n\n private input?: HTMLInputElement;\n\n private button?: HTMLButtonElement;\n\n private form?: HTMLFormElement | null;\n\n /** The input's id before upgrade, which the button takes. */\n private fieldId = '';\n\n private dragging = false;\n\n private enteredAnotherElement = false;\n\n private observer?: MutationObserver;\n\n private readonly onChange = () => this.update();\n\n private readonly onReset = () => window.setTimeout(() => this.update());\n\n private readonly onClick = () => this.input?.click();\n\n private readonly onDragOver = (event: DragEvent) => event.preventDefault();\n\n private readonly onDrop = (event: DragEvent) => {\n event.preventDefault();\n const { input } = this;\n const files = event.dataTransfer?.files;\n if (!input || !files || !this.matchesCapacity(files.length)) return;\n input.files = files;\n // Bubbles, unlike govuk-frontend's, so React's `onChange` hears dropped files too.\n input.dispatchEvent(new Event('input', { bubbles: true }));\n input.dispatchEvent(new Event('change', { bubbles: true }));\n this.setDragging(false);\n };\n\n private readonly onDocumentDragEnter = (event: DragEvent) => {\n this.enteredAnotherElement = true;\n if (!this.button || this.button.disabled || !(event.target instanceof Node)) return;\n if (this.dropZone.contains(event.target)) {\n if (event.dataTransfer && this.canDrop(event.dataTransfer) && !this.dragging) {\n this.setDragging(true);\n this.announce('entered-drop-zone');\n }\n } else if (this.dragging) {\n this.setDragging(false);\n this.announce('left-drop-zone');\n }\n };\n\n // Leaving the window, or dragging back out of it, fires `dragleave` with no `dragenter`.\n private readonly onDocumentDragLeave = () => {\n if (!this.enteredAnotherElement && this.dragging && !this.button?.disabled) {\n this.setDragging(false);\n this.announce('left-drop-zone');\n }\n this.enteredAnotherElement = false;\n };\n\n connectedCallback() {\n // The parts may be parsed or rendered later, and React can rewrite the input's attributes.\n this.observer = new MutationObserver(() => this.setup());\n this.observer.observe(this, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['class', 'disabled', 'id', 'aria-describedby'],\n });\n document.addEventListener('dragenter', this.onDocumentDragEnter);\n document.addEventListener('dragleave', this.onDocumentDragLeave);\n this.setup();\n }\n\n disconnectedCallback() {\n this.observer?.disconnect();\n document.removeEventListener('dragenter', this.onDocumentDragEnter);\n document.removeEventListener('dragleave', this.onDocumentDragLeave);\n this.unbind();\n }\n\n attributeChangedCallback() {\n // Wait for every attribute: React sets them one by one before connecting the element.\n if (this.isConnected) this.update();\n }\n\n private own<E extends Element>(selector: string) {\n return Array.from(this.querySelectorAll<E>(selector)).find((element) => element.closest(tagName) === this);\n }\n\n private get dropZone(): HTMLElement {\n return this.own<HTMLElement>('[data-file-upload-drop-zone]') ?? this;\n }\n\n private get locale() {\n return this.closest('[lang]')?.getAttribute('lang') || 'en';\n }\n\n private message(name: keyof typeof defaults) {\n return translationFromAttributes(this, name) ?? defaults[name];\n }\n\n private setup() {\n const input = this.own<HTMLInputElement>('input[type=\"file\"]');\n const button = this.own<HTMLButtonElement>('button[data-file-upload-button]');\n if (!input || !button) return;\n // A new input, or a new id from React, rather than the one the element gave it.\n if (input.id !== `${this.fieldId}-input`) this.fieldId = input.id;\n if (!this.fieldId) return;\n if (input !== this.input || button !== this.button) {\n this.unbind();\n this.input = input;\n this.button = button;\n this.form = input.form;\n input.addEventListener('change', this.onChange);\n this.form?.addEventListener('reset', this.onReset);\n button.addEventListener('click', this.onClick);\n button.addEventListener('dragover', this.onDragOver);\n button.addEventListener('drop', this.onDrop);\n }\n this.upgrade(input, button);\n this.update();\n }\n\n private unbind() {\n this.input?.removeEventListener('change', this.onChange);\n this.form?.removeEventListener('reset', this.onReset);\n this.button?.removeEventListener('click', this.onClick);\n this.button?.removeEventListener('dragover', this.onDragOver);\n this.button?.removeEventListener('drop', this.onDrop);\n this.input = undefined;\n this.button = undefined;\n this.form = undefined;\n }\n\n /** Moves the id to the button, names it, and swaps it for the input, as govuk-frontend does. */\n private upgrade(input: HTMLInputElement, button: HTMLButtonElement) {\n const id = this.fieldId;\n const root = this.getRootNode();\n const label =\n root instanceof Document || root instanceof ShadowRoot\n ? root.querySelector(`label[for=\"${CSS.escape(id)}\"]`)\n : null;\n if (label && !label.id) label.id = `${id}-label`;\n setAttribute(input, 'id', `${id}-input`);\n setAttribute(button, 'id', id);\n const separator = button.querySelector('[data-file-upload-separator]');\n if (separator) setAttribute(separator, 'id', `${id}-comma`);\n if (label) {\n setAttribute(button, 'aria-labelledby', [label.id, separator?.id, id].filter(Boolean).join(' '));\n }\n setAttribute(button, 'aria-describedby', input.getAttribute('aria-describedby'));\n setAttribute(input, 'hidden', 'hidden');\n if (button.hidden) button.hidden = false;\n this.dataset.upgraded = '';\n }\n\n update() {\n const { input, button } = this;\n if (!input || !button) return;\n const { files } = input;\n const empty = !files?.length;\n const status = button.querySelector('[data-file-upload-status]');\n if (status) {\n setText(\n status,\n statusText(\n files ?? [],\n {\n 'no-file-chosen': this.message('no-file-chosen'),\n 'multiple-files-chosen': this.message('multiple-files-chosen'),\n },\n this.locale\n )\n );\n }\n // `toggle` with force leaves a class that's already there alone, so the observer isn't woken.\n setAttribute(button, 'data-empty', empty ? '' : null);\n classesOf(this.getAttribute('empty-class')).forEach((name) => button.classList.toggle(name, empty));\n if (button.disabled !== input.disabled) button.disabled = input.disabled;\n const zone = this.dropZone;\n setAttribute(zone, 'data-disabled', input.disabled ? '' : null);\n classesOf(this.getAttribute('disabled-class')).forEach((name) => zone.classList.toggle(name, input.disabled));\n if (input.disabled) this.setDragging(false);\n else this.renderDragging();\n }\n\n private setDragging(dragging: boolean) {\n this.dragging = dragging;\n this.renderDragging();\n }\n\n private renderDragging() {\n const { button, dragging } = this;\n if (!button) return;\n setAttribute(button, 'data-dragging', dragging ? '' : null);\n classesOf(this.getAttribute('dragging-class')).forEach((name) => button.classList.toggle(name, dragging));\n }\n\n private announce(name: 'entered-drop-zone' | 'left-drop-zone') {\n const announcements = this.own('[data-file-upload-announcements]');\n // Replaces the text node every time, so screen readers hear the same message again.\n if (announcements) announcements.textContent = translate(this.message(name), 0, this.locale);\n }\n\n private canDrop(dataTransfer: DataTransfer) {\n if (dataTransfer.items.length) return this.matchesCapacity(countFiles(dataTransfer.items));\n if (dataTransfer.types.length) return dataTransfer.types.includes('Files');\n return true;\n }\n\n private matchesCapacity(count: number) {\n return this.input?.multiple ? count > 0 : count === 1;\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactFileUpload);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"element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AAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC3E,OAAO,IAAI,CAAC;QACd,CAAC;QAEO,eAAe,CAAC,KAAa;;YACnC,OAAO,CAAA,MAAA,IAAI,CAAC,KAAK,0CAAE,QAAQ,EAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC;QACxD,CAAC;KACF;IAED,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;AACzF,CAAC","sourcesContent":["/*\n * <govuk-react-file-upload>: a headless, light-DOM custom element that turns a file input into a\n * button and drop zone, with or without React, as govuk-frontend's improved file upload does.\n *\n * The input's files are the state. Without JavaScript the native file input shows and the button\n * stays hidden. On upgrade the element hides the input and shows the button, which opens the file\n * picker, says which files are chosen, and takes files dropped on it. The rendered markup is never\n * moved, so React can keep rendering it.\n *\n * As in govuk-frontend, the button takes the input's `id`, so its label names the button, and the\n * input's id gets `-input` added. The button also takes the input's `aria-describedby` and\n * `disabled`, and its accessible name is the label, the separator and its own text.\n *\n * Markup inside the element:\n * - `input[type=\"file\"]`: the field, with an `id` and a `label`. Hidden on upgrade.\n * - `button[data-file-upload-trigger]`: rendered `hidden`, with `type=\"button\"`.\n * - `[data-file-upload-status]`: which files are chosen.\n * - `[data-file-upload-separator]` (optional): between the label and the button's text in its\n * accessible name, such as a visually hidden comma.\n * - `[data-file-upload-drop-zone]` (optional): the area that shows dragging. The element itself\n * without one.\n * - `[data-file-upload-announcements]` (optional): a visually hidden live region for entering and\n * leaving the drop zone.\n *\n * The button gets `data-empty` while no file is chosen and `data-dragging` while files are dragged\n * over the drop zone, and the drop zone gets `data-disabled`.\n *\n * Attributes:\n * - `no-file-chosen-text`, `multiple-files-chosen-text`, `entered-drop-zone-announcement`, `left-drop-zone-announcement`: the text,\n * English by default, with `%{count}` for the number of files. Add a plural form to the name,\n * such as `multiple-files-chosen-text-one`, for a message for each form.\n * - `empty-class`, `dragging-class`: classes for the button while empty and while dragging.\n * - `disabled-class`: classes for the drop zone while the input is disabled.\n */\n\nimport {\n translate,\n translationAttributeNames,\n translationFromAttributes,\n type Translation,\n} from '../utils/translation.js';\nimport { classesOf, setText, setAttribute } from '../utils/dom.js';\n\nexport const tagName = 'govuk-react-file-upload';\n\nexport interface FileUploadElement extends HTMLElement {\n /** Updates the button from the input's files, such as after setting them. */\n update(): void;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'govuk-react-file-upload': FileUploadElement;\n }\n}\n\n/** govuk-frontend's English text. */\nexport const defaults = {\n 'no-file-chosen-text': 'No file chosen',\n 'multiple-files-chosen-text': { one: '%{count} file chosen', other: '%{count} files chosen' },\n 'entered-drop-zone-announcement': 'Entered drop zone',\n 'left-drop-zone-announcement': 'Left drop zone',\n} satisfies Record<string, Translation>;\n\n/** What the status says for the files chosen. */\nexport function statusText(\n files: ArrayLike<{ name: string }>,\n messages: { 'no-file-chosen-text'?: Translation; 'multiple-files-chosen-text'?: Translation },\n locale?: string\n) {\n if (files.length === 0)\n return translate(messages['no-file-chosen-text'] ?? defaults['no-file-chosen-text'], 0, locale);\n if (files.length === 1) return files[0].name;\n return translate(\n messages['multiple-files-chosen-text'] ?? defaults['multiple-files-chosen-text'],\n files.length,\n locale\n );\n}\n\nconst countFiles = (items: DataTransferItemList) => Array.from(items).filter((item) => item.kind === 'file').length;\n\nif (typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined') {\n class GovukReactFileUpload extends HTMLElement implements FileUploadElement {\n static get observedAttributes() {\n return [\n 'empty-class',\n 'dragging-class',\n 'disabled-class',\n ...Object.keys(defaults).flatMap(translationAttributeNames),\n ];\n }\n\n private input?: HTMLInputElement;\n\n private button?: HTMLButtonElement;\n\n private form?: HTMLFormElement | null;\n\n /** The input's id before upgrade, which the button takes. */\n private fieldId = '';\n\n private dragging = false;\n\n private enteredAnotherElement = false;\n\n private observer?: MutationObserver;\n\n private readonly onChange = () => this.update();\n\n private readonly onReset = () => window.setTimeout(() => this.update());\n\n private readonly onClick = () => this.input?.click();\n\n private readonly onDragOver = (event: DragEvent) => event.preventDefault();\n\n private readonly onDrop = (event: DragEvent) => {\n event.preventDefault();\n const { input } = this;\n const files = event.dataTransfer?.files;\n if (!input || !files || !this.matchesCapacity(files.length)) return;\n input.files = files;\n // Bubbles, unlike govuk-frontend's, so React's `onChange` hears dropped files too.\n input.dispatchEvent(new Event('input', { bubbles: true }));\n input.dispatchEvent(new Event('change', { bubbles: true }));\n this.setDragging(false);\n };\n\n private readonly onDocumentDragEnter = (event: DragEvent) => {\n this.enteredAnotherElement = true;\n if (!this.button || this.button.disabled || !(event.target instanceof Node)) return;\n if (this.dropZone.contains(event.target)) {\n if (event.dataTransfer && this.canDrop(event.dataTransfer) && !this.dragging) {\n this.setDragging(true);\n this.announce('entered-drop-zone-announcement');\n }\n } else if (this.dragging) {\n this.setDragging(false);\n this.announce('left-drop-zone-announcement');\n }\n };\n\n // Leaving the window, or dragging back out of it, fires `dragleave` with no `dragenter`.\n private readonly onDocumentDragLeave = () => {\n if (!this.enteredAnotherElement && this.dragging && !this.button?.disabled) {\n this.setDragging(false);\n this.announce('left-drop-zone-announcement');\n }\n this.enteredAnotherElement = false;\n };\n\n connectedCallback() {\n // The parts may be parsed or rendered later, and React can rewrite the input's attributes.\n this.observer = new MutationObserver(() => this.setup());\n this.observer.observe(this, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['class', 'disabled', 'id', 'aria-describedby'],\n });\n document.addEventListener('dragenter', this.onDocumentDragEnter);\n document.addEventListener('dragleave', this.onDocumentDragLeave);\n this.setup();\n }\n\n disconnectedCallback() {\n this.observer?.disconnect();\n document.removeEventListener('dragenter', this.onDocumentDragEnter);\n document.removeEventListener('dragleave', this.onDocumentDragLeave);\n this.unbind();\n }\n\n attributeChangedCallback() {\n // Wait for every attribute: React sets them one by one before connecting the element.\n if (this.isConnected) this.update();\n }\n\n private own<E extends Element>(selector: string) {\n return Array.from(this.querySelectorAll<E>(selector)).find((element) => element.closest(tagName) === this);\n }\n\n private get dropZone(): HTMLElement {\n return this.own<HTMLElement>('[data-file-upload-drop-zone]') ?? this;\n }\n\n private get locale() {\n return this.closest('[lang]')?.getAttribute('lang') || 'en';\n }\n\n private message(name: keyof typeof defaults) {\n return translationFromAttributes(this, name) ?? defaults[name];\n }\n\n private setup() {\n const input = this.own<HTMLInputElement>('input[type=\"file\"]');\n const button = this.own<HTMLButtonElement>('button[data-file-upload-trigger]');\n if (!input || !button) return;\n // A new input, or a new id from React, rather than the one the element gave it.\n if (input.id !== `${this.fieldId}-input`) this.fieldId = input.id;\n if (!this.fieldId) return;\n if (input !== this.input || button !== this.button) {\n this.unbind();\n this.input = input;\n this.button = button;\n this.form = input.form;\n input.addEventListener('change', this.onChange);\n this.form?.addEventListener('reset', this.onReset);\n button.addEventListener('click', this.onClick);\n button.addEventListener('dragover', this.onDragOver);\n button.addEventListener('drop', this.onDrop);\n }\n this.upgrade(input, button);\n this.update();\n }\n\n private unbind() {\n this.input?.removeEventListener('change', this.onChange);\n this.form?.removeEventListener('reset', this.onReset);\n this.button?.removeEventListener('click', this.onClick);\n this.button?.removeEventListener('dragover', this.onDragOver);\n this.button?.removeEventListener('drop', this.onDrop);\n this.input = undefined;\n this.button = undefined;\n this.form = undefined;\n }\n\n /** Moves the id to the button, names it, and swaps it for the input, as govuk-frontend does. */\n private upgrade(input: HTMLInputElement, button: HTMLButtonElement) {\n const id = this.fieldId;\n const root = this.getRootNode();\n const label =\n root instanceof Document || root instanceof ShadowRoot\n ? root.querySelector(`label[for=\"${CSS.escape(id)}\"]`)\n : null;\n if (label && !label.id) label.id = `${id}-label`;\n setAttribute(input, 'id', `${id}-input`);\n setAttribute(button, 'id', id);\n const separator = button.querySelector('[data-file-upload-separator]');\n if (separator) setAttribute(separator, 'id', `${id}-comma`);\n if (label) {\n setAttribute(button, 'aria-labelledby', [label.id, separator?.id, id].filter(Boolean).join(' '));\n }\n setAttribute(button, 'aria-describedby', input.getAttribute('aria-describedby'));\n setAttribute(input, 'hidden', 'hidden');\n if (button.hidden) button.hidden = false;\n this.dataset.upgraded = '';\n }\n\n update() {\n const { input, button } = this;\n if (!input || !button) return;\n const { files } = input;\n const empty = !files?.length;\n const status = button.querySelector('[data-file-upload-status]');\n if (status) {\n setText(\n status,\n statusText(\n files ?? [],\n {\n 'no-file-chosen-text': this.message('no-file-chosen-text'),\n 'multiple-files-chosen-text': this.message('multiple-files-chosen-text'),\n },\n this.locale\n )\n );\n }\n // `toggle` with force leaves a class that's already there alone, so the observer isn't woken.\n setAttribute(button, 'data-empty', empty ? '' : null);\n classesOf(this.getAttribute('empty-class')).forEach((name) => button.classList.toggle(name, empty));\n if (button.disabled !== input.disabled) button.disabled = input.disabled;\n const zone = this.dropZone;\n setAttribute(zone, 'data-disabled', input.disabled ? '' : null);\n classesOf(this.getAttribute('disabled-class')).forEach((name) => zone.classList.toggle(name, input.disabled));\n if (input.disabled) this.setDragging(false);\n else this.renderDragging();\n }\n\n private setDragging(dragging: boolean) {\n this.dragging = dragging;\n this.renderDragging();\n }\n\n private renderDragging() {\n const { button, dragging } = this;\n if (!button) return;\n setAttribute(button, 'data-dragging', dragging ? '' : null);\n classesOf(this.getAttribute('dragging-class')).forEach((name) => button.classList.toggle(name, dragging));\n }\n\n private announce(name: 'entered-drop-zone-announcement' | 'left-drop-zone-announcement') {\n const announcements = this.own('[data-file-upload-announcements]');\n // Replaces the text node every time, so screen readers hear the same message again.\n if (announcements) announcements.textContent = translate(this.message(name), 0, this.locale);\n }\n\n private canDrop(dataTransfer: DataTransfer) {\n if (dataTransfer.items.length) return this.matchesCapacity(countFiles(dataTransfer.items));\n if (dataTransfer.types.length) return dataTransfer.types.includes('Files');\n return true;\n }\n\n private matchesCapacity(count: number) {\n return this.input?.multiple ? count > 0 : count === 1;\n }\n }\n\n if (!customElements.get(tagName)) customElements.define(tagName, GovukReactFileUpload);\n}\n"]}
|
|
@@ -4,13 +4,13 @@ import { type Translation } from '../utils/translation.js';
|
|
|
4
4
|
export type { Translation } from '../utils/translation.js';
|
|
5
5
|
export type RootProps = React.HTMLAttributes<HTMLElement> & {
|
|
6
6
|
/** Shown while no file is chosen. Defaults to "No file chosen". */
|
|
7
|
-
|
|
7
|
+
noFileChosenText?: string;
|
|
8
8
|
/** Shown when more than one file is chosen. `%{count}` is the number. Defaults to "%{count} files chosen". */
|
|
9
|
-
|
|
9
|
+
multipleFilesChosenText?: Translation;
|
|
10
10
|
/** Announced when the user drags files into the drop zone. Defaults to "Entered drop zone". */
|
|
11
|
-
|
|
11
|
+
enteredDropZoneAnnouncement?: string;
|
|
12
12
|
/** Announced when the user drags files out of the drop zone. Defaults to "Left drop zone". */
|
|
13
|
-
|
|
13
|
+
leftDropZoneAnnouncement?: string;
|
|
14
14
|
/** Classes for the button while no file is chosen. */
|
|
15
15
|
emptyClass?: string;
|
|
16
16
|
/** Classes for the button while files are dragged over the drop zone. */
|
|
@@ -18,7 +18,7 @@ export type RootProps = React.HTMLAttributes<HTMLElement> & {
|
|
|
18
18
|
/** Classes for the drop zone while the input is disabled. */
|
|
19
19
|
disabledClass?: string;
|
|
20
20
|
};
|
|
21
|
-
export declare function Root({
|
|
21
|
+
export declare function Root({ noFileChosenText, multipleFilesChosenText, enteredDropZoneAnnouncement, leftDropZoneAnnouncement, emptyClass, draggingClass, disabledClass, ...props }: RootProps): React.JSX.Element;
|
|
22
22
|
type PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E> & {
|
|
23
23
|
/** Render the only child instead, with this part's props merged onto it. */
|
|
24
24
|
asChild?: boolean;
|
|
@@ -29,17 +29,17 @@ export declare function DropZone({ asChild, ...props }: DropZoneProps): React.JS
|
|
|
29
29
|
export type InputProps = Omit<PartProps<'input'>, 'type'>;
|
|
30
30
|
/** The file input, with an `id` and a `label`. Shown without JavaScript, and hidden on upgrade. */
|
|
31
31
|
export declare function Input({ asChild, ...props }: InputProps): React.JSX.Element;
|
|
32
|
-
export type
|
|
32
|
+
export type TriggerProps = PartProps<'button'>;
|
|
33
33
|
/**
|
|
34
34
|
* Opens the file picker, and takes dropped files. Hidden until the element upgrades, when it
|
|
35
35
|
* takes the input's id, so the input's label names it. Holds `Status`.
|
|
36
36
|
*/
|
|
37
|
-
export declare function
|
|
37
|
+
export declare function Trigger({ asChild, ...props }: TriggerProps): React.JSX.Element;
|
|
38
38
|
export type StatusProps = PartProps<'span'>;
|
|
39
|
-
/** Which files are chosen: "No file chosen", the file's name, or how many files. In `
|
|
39
|
+
/** Which files are chosen: "No file chosen", the file's name, or how many files. In `Trigger`. */
|
|
40
40
|
export declare function Status({ asChild, children, ...props }: StatusProps): React.JSX.Element;
|
|
41
41
|
export type SeparatorProps = PartProps<'span'>;
|
|
42
|
-
/** Between the label and the button's text in the button's accessible name. Defaults to ", ". In `
|
|
42
|
+
/** Between the label and the button's text in the button's accessible name. Defaults to ", ". In `Trigger`. */
|
|
43
43
|
export declare function Separator({ asChild, children, ...props }: SeparatorProps): React.JSX.Element;
|
|
44
44
|
export type AnnouncementsProps = PartProps<'span'>;
|
|
45
45
|
/** Announces entering and leaving the drop zone. Make it visually hidden. */
|
|
@@ -5,18 +5,18 @@ import { Slot } from '../utils/slot.js';
|
|
|
5
5
|
import { translationAttributes } from '../utils/translation.js';
|
|
6
6
|
import { defaults, statusText, tagName } from './element.js';
|
|
7
7
|
// What the status starts with, so the element only changes text React rendered.
|
|
8
|
-
const InitialStatus = createContext(defaults['no-file-chosen']);
|
|
9
|
-
export function Root({
|
|
8
|
+
const InitialStatus = createContext(defaults['no-file-chosen-text']);
|
|
9
|
+
export function Root({ noFileChosenText, multipleFilesChosenText, enteredDropZoneAnnouncement, leftDropZoneAnnouncement, emptyClass, draggingClass, disabledClass, ...props }) {
|
|
10
10
|
// Rendered once and then left to the element, so a re-render never puts back a stale status.
|
|
11
|
-
const [initial] = useState(() => statusText([], { 'no-file-chosen':
|
|
11
|
+
const [initial] = useState(() => statusText([], { 'no-file-chosen-text': noFileChosenText }, props.lang || 'en'));
|
|
12
12
|
return (React.createElement(InitialStatus.Provider, { value: initial }, React.createElement(tagName, {
|
|
13
13
|
...props,
|
|
14
14
|
// The element owns `data-upgraded`.
|
|
15
15
|
suppressHydrationWarning: true,
|
|
16
|
-
'no-file-chosen':
|
|
17
|
-
...translationAttributes('multiple-files-chosen',
|
|
18
|
-
'entered-drop-zone':
|
|
19
|
-
'left-drop-zone':
|
|
16
|
+
'no-file-chosen-text': noFileChosenText,
|
|
17
|
+
...translationAttributes('multiple-files-chosen-text', multipleFilesChosenText),
|
|
18
|
+
'entered-drop-zone-announcement': enteredDropZoneAnnouncement,
|
|
19
|
+
'left-drop-zone-announcement': leftDropZoneAnnouncement,
|
|
20
20
|
'empty-class': emptyClass,
|
|
21
21
|
'dragging-class': draggingClass,
|
|
22
22
|
'disabled-class': disabledClass,
|
|
@@ -38,19 +38,19 @@ export function Input({ asChild, ...props }) {
|
|
|
38
38
|
* Opens the file picker, and takes dropped files. Hidden until the element upgrades, when it
|
|
39
39
|
* takes the input's id, so the input's label names it. Holds `Status`.
|
|
40
40
|
*/
|
|
41
|
-
export function
|
|
41
|
+
export function Trigger({ asChild, ...props }) {
|
|
42
42
|
const Element = asChild ? Slot : 'button';
|
|
43
43
|
// The element owns `id`, `hidden`, `disabled`, its ARIA and its classes after upgrade.
|
|
44
|
-
return React.createElement(Element, { "data-file-upload-
|
|
44
|
+
return React.createElement(Element, { "data-file-upload-trigger": "", type: "button", hidden: true, suppressHydrationWarning: true, ...props });
|
|
45
45
|
}
|
|
46
|
-
/** Which files are chosen: "No file chosen", the file's name, or how many files. In `
|
|
46
|
+
/** Which files are chosen: "No file chosen", the file's name, or how many files. In `Trigger`. */
|
|
47
47
|
export function Status({ asChild, children, ...props }) {
|
|
48
48
|
const initial = useContext(InitialStatus);
|
|
49
49
|
const Element = asChild ? Slot : 'span';
|
|
50
50
|
// The element owns its text after upgrade.
|
|
51
51
|
return (React.createElement(Element, { "data-file-upload-status": "", "aria-live": "polite", suppressHydrationWarning: true, ...props }, children !== null && children !== void 0 ? children : initial));
|
|
52
52
|
}
|
|
53
|
-
/** Between the label and the button's text in the button's accessible name. Defaults to ", ". In `
|
|
53
|
+
/** Between the label and the button's text in the button's accessible name. Defaults to ", ". In `Trigger`. */
|
|
54
54
|
export function Separator({ asChild, children = ', ', ...props }) {
|
|
55
55
|
const Element = asChild ? Slot : 'span';
|
|
56
56
|
// The element owns its `id` after upgrade.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/file-upload/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAoB,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AA8B7D,gFAAgF;AAChF,MAAM,aAAa,GAAG,aAAa,CAAS,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/file-upload/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAoB,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AA8B7D,gFAAgF;AAChF,MAAM,aAAa,GAAG,a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EAAE,OAAO,EAAE,GAAG,KAAK,EAAsB;IACrE,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IACxC,2CAA2C;IAC3C,OAAO,oBAAC,OAAO,sCAAgC,EAAE,eAAW,WAAW,EAAC,wBAAwB,WAAK,KAAK,GAAI,CAAC;AACjH,CAAC","sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createContext, useContext, useState } from 'react';\nimport type { ComponentProps } from 'react';\nimport { Slot } from '../utils/slot.js';\nimport { translationAttributes, type Translation } from '../utils/translation.js';\nimport { defaults, statusText, tagName } from './element.js';\n\nexport type { Translation } from '../utils/translation.js';\n\n/*\n * Headless file upload: unstyled parts over the <govuk-react-file-upload> element (./element.ts),\n * which shows the button on upgrade, hides the input and handles dropped files. Every part except\n * Root takes `asChild`.\n *\n * The input's files are the state, owned by the browser, so there is nothing to control. Without\n * JavaScript the native file input shows and the button stays hidden.\n */\n\nexport type RootProps = React.HTMLAttributes<HTMLElement> & {\n /** Shown while no file is chosen. Defaults to \"No file chosen\". */\n noFileChosenText?: string;\n /** Shown when more than one file is chosen. `%{count}` is the number. Defaults to \"%{count} files chosen\". */\n multipleFilesChosenText?: Translation;\n /** Announced when the user drags files into the drop zone. Defaults to \"Entered drop zone\". */\n enteredDropZoneAnnouncement?: string;\n /** Announced when the user drags files out of the drop zone. Defaults to \"Left drop zone\". */\n leftDropZoneAnnouncement?: string;\n /** Classes for the button while no file is chosen. */\n emptyClass?: string;\n /** Classes for the button while files are dragged over the drop zone. */\n draggingClass?: string;\n /** Classes for the drop zone while the input is disabled. */\n disabledClass?: string;\n};\n\n// What the status starts with, so the element only changes text React rendered.\nconst InitialStatus = createContext<string>(defaults['no-file-chosen-text']);\n\nexport function Root({\n noFileChosenText,\n multipleFilesChosenText,\n enteredDropZoneAnnouncement,\n leftDropZoneAnnouncement,\n emptyClass,\n draggingClass,\n disabledClass,\n ...props\n}: RootProps) {\n // Rendered once and then left to the element, so a re-render never puts back a stale status.\n const [initial] = useState(() => statusText([], { 'no-file-chosen-text': noFileChosenText }, props.lang || 'en'));\n return (\n <InitialStatus.Provider value={initial}>\n {React.createElement(tagName, {\n ...props,\n // The element owns `data-upgraded`.\n suppressHydrationWarning: true,\n 'no-file-chosen-text': noFileChosenText,\n ...translationAttributes('multiple-files-chosen-text', multipleFilesChosenText),\n 'entered-drop-zone-announcement': enteredDropZoneAnnouncement,\n 'left-drop-zone-announcement': leftDropZoneAnnouncement,\n 'empty-class': emptyClass,\n 'dragging-class': draggingClass,\n 'disabled-class': disabledClass,\n })}\n </InitialStatus.Provider>\n );\n}\n\ntype PartProps<E extends keyof React.JSX.IntrinsicElements> = ComponentProps<E> & {\n /** Render the only child instead, with this part's props merged onto it. */\n asChild?: boolean;\n};\n\nexport type DropZoneProps = PartProps<'div'>;\n\n/** The area that shows files are being dragged over it. Holds the button and the input. */\nexport function DropZone({ asChild, ...props }: DropZoneProps) {\n const Element = asChild ? Slot : 'div';\n // The element owns its disabled classes after upgrade.\n return <Element data-file-upload-drop-zone=\"\" suppressHydrationWarning {...props} />;\n}\n\nexport type InputProps = Omit<PartProps<'input'>, 'type'>;\n\n/** The file input, with an `id` and a `label`. Shown without JavaScript, and hidden on upgrade. */\nexport function Input({ asChild, ...props }: InputProps) {\n const Element = asChild ? Slot : 'input';\n // The element owns `id` and `hidden` after upgrade.\n return <Element type=\"file\" suppressHydrationWarning {...props} />;\n}\n\nexport type TriggerProps = PartProps<'button'>;\n\n/**\n * Opens the file picker, and takes dropped files. Hidden until the element upgrades, when it\n * takes the input's id, so the input's label names it. Holds `Status`.\n */\nexport function Trigger({ asChild, ...props }: TriggerProps) {\n const Element = asChild ? Slot : 'button';\n // The element owns `id`, `hidden`, `disabled`, its ARIA and its classes after upgrade.\n return <Element data-file-upload-trigger=\"\" type=\"button\" hidden suppressHydrationWarning {...props} />;\n}\n\nexport type StatusProps = PartProps<'span'>;\n\n/** Which files are chosen: \"No file chosen\", the file's name, or how many files. In `Trigger`. */\nexport function Status({ asChild, children, ...props }: StatusProps) {\n const initial = useContext(InitialStatus);\n const Element = asChild ? Slot : 'span';\n // The element owns its text after upgrade.\n return (\n <Element data-file-upload-status=\"\" aria-live=\"polite\" suppressHydrationWarning {...props}>\n {children ?? initial}\n </Element>\n );\n}\n\nexport type SeparatorProps = PartProps<'span'>;\n\n/** Between the label and the button's text in the button's accessible name. Defaults to \", \". In `Trigger`. */\nexport function Separator({ asChild, children = ', ', ...props }: SeparatorProps) {\n const Element = asChild ? Slot : 'span';\n // The element owns its `id` after upgrade.\n return (\n <Element data-file-upload-separator=\"\" suppressHydrationWarning {...props}>\n {children}\n </Element>\n );\n}\n\nexport type AnnouncementsProps = PartProps<'span'>;\n\n/** Announces entering and leaving the drop zone. Make it visually hidden. */\nexport function Announcements({ asChild, ...props }: AnnouncementsProps) {\n const Element = asChild ? Slot : 'span';\n // The element owns its text after upgrade.\n return <Element data-file-upload-announcements=\"\" aria-live=\"assertive\" suppressHydrationWarning {...props} />;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * as Modal from './modal/index.js';
|
|
|
4
4
|
export * as PasswordInput from './password-input/index.js';
|
|
5
5
|
export * as Disclosure from './disclosure/index.js';
|
|
6
6
|
export * as CharacterCount from './character-count/index.js';
|
|
7
|
+
export * as CharacterCountText from './character-count-text/index.js';
|
|
7
8
|
export * as Choices from './choices/index.js';
|
|
8
9
|
export * as AutoFocus from './auto-focus/index.js';
|
|
9
10
|
export * as FocusLinks from './focus-links/index.js';
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export * as Modal from './modal/index.js';
|
|
|
4
4
|
export * as PasswordInput from './password-input/index.js';
|
|
5
5
|
export * as Disclosure from './disclosure/index.js';
|
|
6
6
|
export * as CharacterCount from './character-count/index.js';
|
|
7
|
+
export * as CharacterCountText from './character-count-text/index.js';
|
|
7
8
|
export * as Choices from './choices/index.js';
|
|
8
9
|
export * as AutoFocus from './auto-focus/index.js';
|
|
9
10
|
export * as FocusLinks from './focus-links/index.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,YAAY,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC","sourcesContent":["export * as Accordion from './accordion/index.js';\nexport * as Tabs from './tabs/index.js';\nexport * as Modal from './modal/index.js';\nexport * as PasswordInput from './password-input/index.js';\nexport * as Disclosure from './disclosure/index.js';\nexport * as CharacterCount from './character-count/index.js';\nexport * as Choices from './choices/index.js';\nexport * as AutoFocus from './auto-focus/index.js';\nexport * as FocusLinks from './focus-links/index.js';\nexport * as Button from './button/index.js';\nexport * as ExitThisPage from './exit-this-page/index.js';\nexport * as FileUpload from './file-upload/index.js';\nexport * as Autocomplete from './autocomplete/index.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAC1C,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,kBAAkB,MAAM,iCAAiC,CAAC;AACtE,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,YAAY,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC","sourcesContent":["export * as Accordion from './accordion/index.js';\nexport * as Tabs from './tabs/index.js';\nexport * as Modal from './modal/index.js';\nexport * as PasswordInput from './password-input/index.js';\nexport * as Disclosure from './disclosure/index.js';\nexport * as CharacterCount from './character-count/index.js';\nexport * as CharacterCountText from './character-count-text/index.js';\nexport * as Choices from './choices/index.js';\nexport * as AutoFocus from './auto-focus/index.js';\nexport * as FocusLinks from './focus-links/index.js';\nexport * as Button from './button/index.js';\nexport * as ExitThisPage from './exit-this-page/index.js';\nexport * as FileUpload from './file-upload/index.js';\nexport * as Autocomplete from './autocomplete/index.js';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var d=a=>a?.split(/\s+/).filter(Boolean)??[];function p(a,c){if(a.textContent===c)return;let{firstChild:u}=a;u instanceof Text&&a.childNodes.length===1?u.nodeValue=c:a.textContent=c}var g="govuk-react-accordion",
|
|
1
|
+
"use strict";(()=>{var d=a=>a?.split(/\s+/).filter(Boolean)??[];function p(a,c){if(a.textContent===c)return;let{firstChild:u}=a;u instanceof Text&&a.childNodes.length===1?u.nodeValue=c:a.textContent=c}var g="govuk-react-accordion",b={"show-section-text":"Show","hide-section-text":"Hide","show-section-label":"Show this section","hide-section-label":"Hide this section","show-all-sections-text":"Show all sections","hide-all-sections-text":"Hide all sections"},h=a=>a?.split(/\s+/).filter(Boolean);if(typeof HTMLElement<"u"&&typeof customElements<"u"){class a extends HTMLElement{constructor(){super(...arguments);this.open=new Set;this.upgraded=!1;this.controlled=!1;this.prepared=new WeakSet;this.onClick=t=>{let e=t.target instanceof Element?t.target:null,s=e?.closest("button[data-accordion-trigger]");if(s&&this.ownsElement(s)){let n=this.sectionOf(s)?.dataset.value;if(n===void 0)return;let r=new Set(this.open);r.has(n)?r.delete(n):r.add(n),this.change(r);return}let i=e?.closest("button[data-accordion-show-all]");if(i&&this.ownsElement(i)){let n=this.sections.map(r=>r.dataset.value??"");this.change(new Set(this.allOpen?[]:n))}};this.onBeforeMatch=t=>{let s=(t.target instanceof Element?this.sectionOf(t.target):void 0)?.dataset.value;s===void 0||this.open.has(s)||this.change(new Set([...this.open,s]),!0)}}static get observedAttributes(){return["value"]}get openValues(){return this.upgraded?[...this.open]:void 0}get pickedValue(){return this.picked}connectedCallback(){this.observer=new MutationObserver(t=>{if(!this.upgraded){this.setup();return}t.some(e=>e.type==="childList")&&this.sections.forEach(e=>this.prepare(e)),this.render()}),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class"]}),this.upgraded?(this.listen(),this.render()):this.setup()}disconnectedCallback(){this.observer?.disconnect(),this.removeEventListener("click",this.onClick),this.removeEventListener("beforematch",this.onBeforeMatch,!0)}attributeChangedCallback(){let t=h(this.getAttribute("value"));this.controlled=t!==void 0,t&&(this.open=new Set(t),this.render())}get sections(){return this.own("[data-accordion-section]")}get allOpen(){return this.sections.every(t=>this.open.has(t.dataset.value??""))}own(t){return Array.from(this.querySelectorAll(t)).filter(e=>this.ownsElement(e))}ownsElement(t){return t.closest(g)===this}sectionOf(t){let e=t.closest("[data-accordion-section]");return e&&this.ownsElement(e)?e:void 0}find(t,e){return Array.from(t.querySelectorAll(e)).find(s=>this.sectionOf(s)===t)}text(t){return this.getAttribute(t)??b[t]}get remember(){return this.getAttribute("remember-expanded")!=="false"}setup(){let t=this.sections;if(!t.some(i=>this.find(i,"button[data-accordion-trigger]")))return;this.upgraded=!0;let e=h(this.getAttribute("value"));this.controlled=e!==void 0,this.open=new Set(e??h(this.getAttribute("default-value"))),this.dataset.upgraded="";let s=d(this.getAttribute("upgraded-class"));s.length&&this.classList.add(...s),this.own("[data-accordion-controls]").forEach(i=>{i.hidden=!1}),t.forEach(i=>this.prepare(i)),this.listen(),this.render()}listen(){this.addEventListener("click",this.onClick),this.addEventListener("beforematch",this.onBeforeMatch,!0)}prepare(t){let e=this.find(t,"button[data-accordion-trigger]");if(!e||this.prepared.has(t))return;this.prepared.add(t);let s=t.dataset.value??"";if(!this.controlled){let n=h(this.getAttribute("default-value"));(n?n.includes(s):t.hasAttribute("data-expanded"))&&this.open.add(s),this.restore(t)}Array.from(t.querySelectorAll("[data-accordion-fallback]")).filter(n=>this.sectionOf(n)===t).forEach(n=>{n.hidden=!0}),e.hidden=!1;let i=this.find(t,"[data-accordion-content]");i?.id&&e.setAttribute("aria-controls",i.id)}restore(t){let e=this.find(t,"[data-accordion-content]")?.id,s=t.dataset.value;if(!(!this.remember||!e||s===void 0))try{let i=window.sessionStorage.getItem(e);i==="true"?this.open.add(s):i==="false"&&this.open.delete(s)}catch{}}store(t){this.remember&&this.sections.forEach(e=>{let s=e.dataset.value??"",i=this.find(e,"[data-accordion-content]")?.id;if(!(!i||t.has(s)===this.open.has(s)))try{window.sessionStorage.setItem(i,String(this.open.has(s)))}catch{}})}change(t,e=!1){let s=this.sections.map(i=>i.dataset.value??"").filter(i=>t.has(i));if(!this.controlled||e){let i=this.open;this.open=new Set(s),this.controlled||(this.picked=s,this.store(i)),this.render()}this.dispatchEvent(new CustomEvent("govuk-react-accordion:change",{detail:{value:s},bubbles:!0}))}render(){if(!this.upgraded)return;let t=d(this.getAttribute("expanded-section-class")),e=d(this.getAttribute("collapsed-icon-class")),s=(n,r)=>{Array.from(n.querySelectorAll("[data-accordion-icon]")).forEach(o=>{e.forEach(l=>o.classList.toggle(l,!r))})};this.sections.forEach(n=>{let r=this.open.has(n.dataset.value??""),o=this.find(n,"button[data-accordion-trigger]"),l=this.find(n,"[data-accordion-content]");if(n.dataset.state=r?"open":"closed",t.forEach(f=>n.classList.toggle(f,r)),l&&(r?l.removeAttribute("hidden"):l.setAttribute("hidden","until-found")),!o)return;o.setAttribute("aria-expanded",String(r));let m=Array.from(o.querySelectorAll("[data-accordion-label]")).map(f=>f.textContent?.trim()??"");o.setAttribute("aria-label",[...m,this.text(r?"hide-section-label":"show-section-label")].join(" , "));let v=o.querySelector("[data-accordion-toggle-text]");v&&p(v,this.text(r?"hide-section-text":"show-section-text")),s(o,r)});let i=this.allOpen;this.own("button[data-accordion-show-all]").forEach(n=>{n.setAttribute("aria-expanded",String(i));let r=n.querySelector("[data-accordion-show-all-text]");r&&p(r,this.text(i?"hide-all-sections-text":"show-all-sections-text")),s(n,i)})}}customElements.get(g)||customElements.define(g,a)}})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{function s(t,r,
|
|
1
|
+
"use strict";(()=>{function s(t,r,i){i.forEach(e=>t.classList.remove(e)),r&&t.removeAttribute("tabindex"),t.removeAttribute("data-focus-tabindex"),t.removeAttribute("autofocus")}var a=t=>!t.hasAttribute("tabindex")||t.hasAttribute("data-focus-tabindex")&&t.getAttribute("tabindex")==="-1";function c(t){s(t,t.hasAttribute("tabindex")&&a(t),[])}function u(t,{focusedClasses:r=[],preventScroll:i=!1}={}){let e=a(t);return t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),document.activeElement!==t&&(r.forEach(o=>t.classList.add(o)),t.focus({preventScroll:i})),document.activeElement!==t?(s(t,e,r),!1):(r.forEach(o=>t.classList.add(o)),t.addEventListener("blur",()=>s(t,e,r),{once:!0}),!0)}function d(t,r){if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(t,{childList:!0,subtree:!0}),i}var n="govuk-react-auto-focus";if(typeof HTMLElement<"u"&&typeof customElements<"u"){class t extends HTMLElement{constructor(){super(...arguments);this.focused=!1}connectedCallback(){this.observer=d(this,()=>this.focusTarget())}disconnectedCallback(){this.observer?.disconnect()}get target(){let e=Array.from(this.querySelectorAll("[data-auto-focus]")).find(o=>o.closest(n)===this)??this.firstElementChild;return e instanceof HTMLElement?e:void 0}focusTarget(){if(this.focused)return!0;let{target:e}=this;if(!e)return!1;if(this.focused=!0,this.hasAttribute("disabled"))return!0;if(e.hasAttribute("autofocus")){let o=document.activeElement;if(o===e)return u(e,{preventScroll:!0}),!0;if(o&&o!==document.body)return c(e),!0}return queueMicrotask(()=>{(!e.isConnected||!u(e))&&(this.focused=!1)}),!0}}customElements.get(n)||customElements.define(n,t)}})();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";(()=>{var E=["zero","one","two","few","many","other"];var L=s=>[s,...E.map(o=>`${s}-${o}`)];function w(s,o){let l=s.getAttribute(o);if(l!==null)return l;let t=E.flatMap(e=>{let n=s.getAttribute(`${o}-${e}`);return n===null?[]:[[e,n]]});return t.length?Object.fromEntries(t):void 0}function A(s){try{return s(void 0)}catch{return s("en")}}function v(s,o){try{return o(s)}catch{return A(o)}}function p(s,o,l){let t;if(typeof s=="string")t=s;else{let n=v(l,i=>new Intl.PluralRules(i)).select(o);t=s[n]??s.other}let e=v(l,n=>new Intl.NumberFormat(n)).format(o);return(t??"").replaceAll("%{count}",e)}function g(s,o){if(s.textContent===o)return;let{firstChild:l}=s;l instanceof Text&&s.childNodes.length===1?l.nodeValue=o:s.textContent=o}function u(s,o,l){l===null?s.removeAttribute(o):s.getAttribute(o)!==l&&s.setAttribute(o,l)}var b="govuk-react-autocomplete",M={"status-query-too-short":"Type in %{count} or more characters for results","status-no-results":"No search results","status-selected-option":"%{option} %{position} of %{count} is highlighted","status-results":{one:"%{count} result is available.",other:"%{count} results are available."}},I=1400,k=100,y=()=>typeof navigator<"u"&&/(iPod|iPhone|iPad)/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent),x=typeof HTMLInputElement>"u"?void 0:Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value")?.set;if(typeof HTMLElement<"u"&&typeof customElements<"u"){class s extends HTMLElement{constructor(){super(...arguments);this.focused=null;this.hovered=null;this.menuOpen=!1;this.options=[];this.currentQuery="";this.validChoiceMade=!1;this.selected=null;this.ariaHint=!0;this.lastFocused=null;this.settingValue=!1;this.bump=!1;this.generatedIds=0;this.onPoll=()=>{this.input&&this.input.value!==this.currentQuery&&this.handleInputChange(this.input.value)};this.onInput=()=>{this.input&&!this.settingValue&&this.handleInputChange(this.input.value)};this.onInputFocus=()=>{let t=!this.validChoiceMade&&this.queryLongEnough&&this.options.length>0;this.focused=-1,t&&(this.menuOpen=!0,this.selected=-1),this.render()};this.onFocusOut=t=>{let{target:e,relatedTarget:n}=t;if(e===this.input){if(this.focused!==-1)return;let m=y();this.handleComponentBlur({menuOpen:this.menuOpen&&m,query:m?this.currentQuery:this.valueOf(this.selectedOption)});return}if(!(e instanceof HTMLElement)||!e.isConnected)return;let i=this.options.indexOf(e);if(i===-1)return;let r=n===null,h=n===this.input,d=this.focused!==i&&this.focused!==-1;(!d&&r||!(d||h))&&this.handleComponentBlur({menuOpen:this.menuOpen&&y(),query:this.valueOf(this.selectedOption)})};this.onKeyDown=t=>{let{target:e}=t,n=e===this.input,i=e instanceof HTMLElement&&this.options.includes(e);if(!n&&!i)return;let r=this.selected??-1;switch(t.key){case"ArrowUp":t.preventDefault(),this.menuOpen&&r!==-1&&this.focusOption(r-1);break;case"ArrowDown":t.preventDefault(),this.menuOpen&&r!==this.options.length-1&&this.focusOption(r+1);break;case" ":this.focused!==null&&this.focused!==-1&&(t.preventDefault(),this.confirm(this.focused));break;case"Enter":if(!this.menuOpen)break;r>=0?(t.preventDefault(),this.confirm(r)):this.submitOnConfirm||t.preventDefault();break;case"Escape":i&&this.input?.focus(),this.handleComponentBlur({menuOpen:!1,query:this.currentQuery});break;default:i&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&(t.key.length===1||t.key==="Backspace")&&this.input?.focus()}};this.onOptionMouseDown=t=>{this.optionOf(t.target)!==-1&&t.preventDefault()};this.onOptionClick=t=>{let e=this.optionOf(t.target);e!==-1&&this.confirm(e)};this.onOptionMouseOver=t=>{let e=this.optionOf(t.target);e===-1||e===this.hovered||y()||(this.hovered=e,this.render())};this.onListMouseLeave=()=>{this.hovered!==null&&(this.hovered=null,this.render())}}static get observedAttributes(){return["min-length","filter","confirm-on-blur","submit-on-confirm",...Object.keys(M).flatMap(L)]}get query(){return this.input?this.currentQuery:void 0}connectedCallback(){this.observer=new MutationObserver(t=>this.onMutation(t)),this.observer.observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["aria-describedby","data-value"]}),this.setup()}disconnectedCallback(){this.observer?.disconnect(),this.unbind()}attributeChangedCallback(){this.isConnected&&(this.input?this.render():this.setup())}own(t){return this.ownAll(t)[0]}ownAll(t){return Array.from(this.querySelectorAll(t)).filter(e=>e.closest(b)===this)}get allOptions(){return this.ownAll("[data-autocomplete-option]")}get minLength(){let t=Number(this.getAttribute("min-length"));return Number.isFinite(t)&&t>0?t:0}get filterType(){let t=this.getAttribute("filter");return t==="starts-with"||t==="none"?t:"contains"}get confirmOnBlur(){return this.getAttribute("confirm-on-blur")!=="false"}get submitOnConfirm(){return this.hasAttribute("submit-on-confirm")}get locale(){return(this.input??this).closest("[lang]")?.getAttribute("lang")||"en"}setup(){let t=this.own("[data-autocomplete-input]"),e=this.own("[data-autocomplete-listbox]");if(!(t instanceof HTMLInputElement)||!t.id||!e){this.unbind(),delete this.dataset.upgraded;return}if(t===this.input&&e===this.listbox){this.render();return}this.unbind(),this.input=t,this.listbox=e,t.addEventListener("input",this.onInput),t.addEventListener("click",this.onInput),t.addEventListener("focus",this.onInputFocus),this.addEventListener("keydown",this.onKeyDown),this.addEventListener("focusout",this.onFocusOut),e.addEventListener("mousedown",this.onOptionMouseDown),e.addEventListener("click",this.onOptionClick),e.addEventListener("mouseover",this.onOptionMouseOver),e.addEventListener("mouseleave",this.onListMouseLeave),this.poll=window.setInterval(this.onPoll,k),this.currentQuery=t.value,this.ariaHint=t.value==="",this.options=this.queryLongEnough?this.matchingOptions():[],this.focused=document.activeElement===t?-1:null,this.lastFocused=this.focused,this.selected=null,this.menuOpen=!1,this.validChoiceMade=!1,this.dataset.upgraded="",this.render()}unbind(){let{input:t,listbox:e}=this;window.clearInterval(this.poll),window.clearTimeout(this.statusTimer),!(!t||!e)&&(t.removeEventListener("input",this.onInput),t.removeEventListener("click",this.onInput),t.removeEventListener("focus",this.onInputFocus),this.removeEventListener("keydown",this.onKeyDown),this.removeEventListener("focusout",this.onFocusOut),e.removeEventListener("mousedown",this.onOptionMouseDown),e.removeEventListener("click",this.onOptionClick),e.removeEventListener("mouseover",this.onOptionMouseOver),e.removeEventListener("mouseleave",this.onListMouseLeave),this.input=void 0,this.listbox=void 0)}onMutation(t){let e=this.own("[data-autocomplete-status]"),n=t.filter(i=>!(e?.contains(i.target)??!1)&&!(i.type==="attributes"&&i.target===this.input&&this.describedByIsCurrent()));if(n.length){if(!this.input?.isConnected||!this.listbox?.isConnected||!this.contains(this.input)){this.setup();return}n.some(i=>this.listbox?.contains(i.target))&&this.updateOptions(),this.render()}}updateOptions(){let t=this.selectedOption;if(!this.queryLongEnough||this.currentQuery===""){this.options=[];return}if(this.options=this.matchingOptions(),this.focused===null||this.validChoiceMade)return;this.menuOpen=this.options.length>0;let e=t?this.options.indexOf(t):-1;this.selected=e,this.focused>=0&&(this.focused=e)}get queryLongEnough(){return this.currentQuery.length>=this.minLength}valueOf(t){if(t)return t.dataset.value??t.textContent?.trim()??""}matchingOptions(){let t=this.currentQuery.toLowerCase(),e=this.filterType;return this.allOptions.filter(n=>{if(e==="none")return!0;let i=(this.valueOf(n)??"").toLowerCase();return e==="starts-with"?i.startsWith(t):i.includes(t)})}isQueryAnOption(t){return this.options.some(e=>this.valueOf(e)?.toLowerCase()===t.toLowerCase())}handleInputChange(t){let e=this.currentQuery!==t;this.currentQuery=t,this.ariaHint=t==="",t!==""&&e&&this.queryLongEnough?(this.dispatchEvent(new CustomEvent("govuk-react-autocomplete:query",{bubbles:!0,detail:{query:t}})),this.options=this.matchingOptions(),this.menuOpen=this.options.length>0,this.selected=-1,this.validChoiceMade=!1):(t===""||!this.queryLongEnough)&&(this.menuOpen=!1,this.options=[]),this.render()}get selectedOption(){return this.selected===null||this.selected<0?void 0:this.options[this.selected]}handleComponentBlur({menuOpen:t,query:e}){let n=this.currentQuery,i=this.selectedOption;this.confirmOnBlur&&(n=e||this.currentQuery,i&&this.confirmEvent(this.valueOf(i)??"")),this.focused=null,this.menuOpen=t,this.selected=null,this.validChoiceMade=this.isQueryAnOption(n),this.setQuery(n),this.render()}setQuery(t){this.currentQuery=t;let{input:e}=this;!e||e.value===t||(this.settingValue=!0,x?x.call(e,t):e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),this.settingValue=!1)}confirmEvent(t){return this.dispatchEvent(new CustomEvent("govuk-react-autocomplete:confirm",{bubbles:!0,cancelable:!0,detail:{value:t}}))}confirm(t){let e=this.options[t];if(!e)return;let n=this.valueOf(e)??"";this.focused=-1,this.hovered=null,this.menuOpen=!1,this.selected=-1,this.validChoiceMade=!0,this.setQuery(n),this.render();let i=this.confirmEvent(n),r=this.input?.form;i&&this.submitOnConfirm&&r&&window.setTimeout(()=>r.requestSubmit())}focusOption(t){this.focused=t,this.hovered=null,this.selected=t,this.render()}optionOf(t){if(!(t instanceof Element))return-1;let e=t.closest("[data-autocomplete-option]");return e?this.options.indexOf(e):-1}ensureId(t,e){return t.id||(this.generatedIds+=1,t.id=`${this.input?.id}__${e}${e.endsWith("--")?this.generatedIds:""}`),t.id}get hint(){return this.own("[data-autocomplete-hint]")}describedBy(){let{input:t}=this;if(!t)return null;let e=this.hint,n=e?this.ensureId(e,"assistiveHint"):void 0,i=(t.getAttribute("aria-describedby")??"").split(/\s+/).filter(r=>r&&r!==n);return this.ariaHint&&n&&i.push(n),i.length?i.join(" "):null}describedByIsCurrent(){return(this.input?.getAttribute("aria-describedby")??null)===this.describedBy()}render(){let{input:t,listbox:e}=this;if(!t||!e)return;let{focused:n,hovered:i,menuOpen:r,options:h,selected:d}=this,O=n===-1&&h.length===0&&this.currentQuery!==""&&this.queryLongEnough,T=n!==null&&n!==-1,C=this.ensureId(e,"listbox");u(e,"role","listbox"),e.hasAttribute("aria-labelledby")||e.setAttribute("aria-labelledby",t.id),e.hidden=!(r||O),this.allOptions.forEach(a=>{let c=h.indexOf(a);this.ensureId(a,"option--"),a.hidden=c===-1,u(a,"role","option"),u(a,"tabindex","-1"),u(a,"aria-selected",n===c&&c!==-1?"true":"false"),u(a,"aria-posinset",c===-1?null:String(c+1)),u(a,"aria-setsize",c===-1?null:String(h.length)),u(a,"data-focused",c!==-1&&(n===-1?d===c:n===c)&&i===null?"":null)});let f=this.own("[data-autocomplete-no-results]");if(f&&(f.hidden=!O,u(f,"role","option"),u(f,"aria-disabled","true")),u(t,"role","combobox"),u(t,"autocomplete","off"),u(t,"aria-autocomplete","list"),u(t,"aria-controls",C),u(t,"aria-expanded",r?"true":"false"),u(t,"aria-activedescendant",T?h[n]?.id??null:null),u(t,"aria-describedby",this.describedBy()),u(this,"data-focused",n===null?null:""),n!==this.lastFocused&&n!==null){let a=n===-1?t:h[n];a&&document.activeElement!==a&&a.focus(),n===-1&&this.lastFocused===null&&t.selectionStart!==null&&t.setSelectionRange(0,t.value.length)}this.lastFocused=n,this.scheduleStatus()}message(t){return w(this,t)??M[t]}statusText(){let{locale:t,options:e}=this;if(!this.queryLongEnough)return p(this.message("status-query-too-short"),this.minLength,t);if(e.length===0)return p(this.message("status-no-results"),0,t);let n=p(this.message("status-results"),e.length,t),i=this.valueOf(this.selectedOption);if(i===void 0||this.selected===null)return n;let r=v(t,d=>new Intl.NumberFormat(d)).format(this.selected+1),h=p(this.message("status-selected-option"),e.length,t).replaceAll("%{option}",()=>i).replaceAll("%{position}",()=>r);return`${n} ${h}`}scheduleStatus(){let t=this.ownAll("[data-autocomplete-status-region]");t.length&&(t.forEach(e=>g(e,"")),window.clearTimeout(this.statusTimer),this.statusTimer=window.setTimeout(()=>{this.bump=!this.bump;let n=this.focused===null||this.validChoiceMade?"":this.statusText();t.forEach((i,r)=>g(i,r===0===this.bump?n:""))},I))}}customElements.get(b)||customElements.define(b,s)}})();
|
|
1
|
+
"use strict";(()=>{var E=["zero","one","two","few","many","other"];var L=s=>[s,...E.map(o=>`${s}-${o}`)];function w(s,o){let l=s.getAttribute(o);if(l!==null)return l;let t=E.flatMap(e=>{let n=s.getAttribute(`${o}-${e}`);return n===null?[]:[[e,n]]});return t.length?Object.fromEntries(t):void 0}function A(s){try{return s(void 0)}catch{return s("en")}}function m(s,o){try{return o(s)}catch{return A(o)}}function p(s,o,l){let t;if(typeof s=="string")t=s;else{let n=m(l,i=>new Intl.PluralRules(i)).select(o);t=s[n]??s.other}let e=m(l,n=>new Intl.NumberFormat(n)).format(o);return(t??"").replaceAll("%{count}",e)}function g(s,o){if(s.textContent===o)return;let{firstChild:l}=s;l instanceof Text&&s.childNodes.length===1?l.nodeValue=o:s.textContent=o}function u(s,o,l){l===null?s.removeAttribute(o):s.getAttribute(o)!==l&&s.setAttribute(o,l)}var b="govuk-react-autocomplete",M={"query-too-short-announcement":"Type in %{count} or more characters for results","no-results-announcement":"No search results","selected-option-announcement":"%{option} %{position} of %{count} is highlighted","results-announcement":{one:"%{count} result is available.",other:"%{count} results are available."}},I=1400,k=100,y=()=>typeof navigator<"u"&&/(iPod|iPhone|iPad)/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent),T=typeof HTMLInputElement>"u"?void 0:Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value")?.set;if(typeof HTMLElement<"u"&&typeof customElements<"u"){class s extends HTMLElement{constructor(){super(...arguments);this.focused=null;this.hovered=null;this.menuOpen=!1;this.options=[];this.currentQuery="";this.validChoiceMade=!1;this.selected=null;this.ariaHint=!0;this.lastFocused=null;this.settingValue=!1;this.bump=!1;this.generatedIds=0;this.onPoll=()=>{this.input&&this.input.value!==this.currentQuery&&this.handleInputChange(this.input.value)};this.onInput=()=>{this.input&&!this.settingValue&&this.handleInputChange(this.input.value)};this.onInputFocus=()=>{let t=!this.validChoiceMade&&this.queryLongEnough&&this.options.length>0;this.focused=-1,t&&(this.menuOpen=!0,this.selected=-1),this.render()};this.onFocusOut=t=>{let{target:e,relatedTarget:n}=t;if(e===this.input){if(this.focused!==-1)return;let v=y();this.handleComponentBlur({menuOpen:this.menuOpen&&v,query:v?this.currentQuery:this.valueOf(this.selectedOption)});return}if(!(e instanceof HTMLElement)||!e.isConnected)return;let i=this.options.indexOf(e);if(i===-1)return;let r=n===null,h=n===this.input,d=this.focused!==i&&this.focused!==-1;(!d&&r||!(d||h))&&this.handleComponentBlur({menuOpen:this.menuOpen&&y(),query:this.valueOf(this.selectedOption)})};this.onKeyDown=t=>{let{target:e}=t,n=e===this.input,i=e instanceof HTMLElement&&this.options.includes(e);if(!n&&!i)return;let r=this.selected??-1;switch(t.key){case"ArrowUp":t.preventDefault(),this.menuOpen&&r!==-1&&this.focusOption(r-1);break;case"ArrowDown":t.preventDefault(),this.menuOpen&&r!==this.options.length-1&&this.focusOption(r+1);break;case" ":this.focused!==null&&this.focused!==-1&&(t.preventDefault(),this.confirm(this.focused));break;case"Enter":if(!this.menuOpen)break;r>=0?(t.preventDefault(),this.confirm(r)):this.submitOnConfirm||t.preventDefault();break;case"Escape":i&&this.input?.focus(),this.handleComponentBlur({menuOpen:!1,query:this.currentQuery});break;default:i&&!t.ctrlKey&&!t.metaKey&&!t.altKey&&(t.key.length===1||t.key==="Backspace")&&this.input?.focus()}};this.onOptionMouseDown=t=>{this.optionOf(t.target)!==-1&&t.preventDefault()};this.onOptionClick=t=>{let e=this.optionOf(t.target);e!==-1&&this.confirm(e)};this.onOptionMouseOver=t=>{let e=this.optionOf(t.target);e===-1||e===this.hovered||y()||(this.hovered=e,this.render())};this.onListMouseLeave=()=>{this.hovered!==null&&(this.hovered=null,this.render())}}static get observedAttributes(){return["min-length","filter","confirm-on-blur","submit-on-confirm",...Object.keys(M).flatMap(L)]}get query(){return this.input?this.currentQuery:void 0}connectedCallback(){this.observer=new MutationObserver(t=>this.onMutation(t)),this.observer.observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["aria-describedby","data-value"]}),this.setup()}disconnectedCallback(){this.observer?.disconnect(),this.unbind()}attributeChangedCallback(){this.isConnected&&(this.input?this.render():this.setup())}own(t){return this.ownAll(t)[0]}ownAll(t){return Array.from(this.querySelectorAll(t)).filter(e=>e.closest(b)===this)}get allOptions(){return this.ownAll("[data-autocomplete-option]")}get minLength(){let t=Number(this.getAttribute("min-length"));return Number.isFinite(t)&&t>0?t:0}get filterType(){let t=this.getAttribute("filter");return t==="starts-with"||t==="none"?t:"contains"}get confirmOnBlur(){return this.getAttribute("confirm-on-blur")!=="false"}get submitOnConfirm(){return this.hasAttribute("submit-on-confirm")}get locale(){return(this.input??this).closest("[lang]")?.getAttribute("lang")||"en"}setup(){let t=this.own("[data-autocomplete-input]"),e=this.own("[data-autocomplete-listbox]");if(!(t instanceof HTMLInputElement)||!t.id||!e){this.unbind(),delete this.dataset.upgraded;return}if(t===this.input&&e===this.listbox){this.render();return}this.unbind(),this.input=t,this.listbox=e,t.addEventListener("input",this.onInput),t.addEventListener("click",this.onInput),t.addEventListener("focus",this.onInputFocus),this.addEventListener("keydown",this.onKeyDown),this.addEventListener("focusout",this.onFocusOut),e.addEventListener("mousedown",this.onOptionMouseDown),e.addEventListener("click",this.onOptionClick),e.addEventListener("mouseover",this.onOptionMouseOver),e.addEventListener("mouseleave",this.onListMouseLeave),this.poll=window.setInterval(this.onPoll,k),this.currentQuery=t.value,this.ariaHint=t.value==="",this.options=this.queryLongEnough?this.matchingOptions():[],this.focused=document.activeElement===t?-1:null,this.lastFocused=this.focused,this.selected=null,this.menuOpen=!1,this.validChoiceMade=!1,this.dataset.upgraded="",this.render()}unbind(){let{input:t,listbox:e}=this;window.clearInterval(this.poll),window.clearTimeout(this.statusTimer),!(!t||!e)&&(t.removeEventListener("input",this.onInput),t.removeEventListener("click",this.onInput),t.removeEventListener("focus",this.onInputFocus),this.removeEventListener("keydown",this.onKeyDown),this.removeEventListener("focusout",this.onFocusOut),e.removeEventListener("mousedown",this.onOptionMouseDown),e.removeEventListener("click",this.onOptionClick),e.removeEventListener("mouseover",this.onOptionMouseOver),e.removeEventListener("mouseleave",this.onListMouseLeave),this.input=void 0,this.listbox=void 0)}onMutation(t){let e=this.own("[data-autocomplete-status]"),n=t.filter(i=>!(e?.contains(i.target)??!1)&&!(i.type==="attributes"&&i.target===this.input&&this.describedByIsCurrent()));if(n.length){if(!this.input?.isConnected||!this.listbox?.isConnected||!this.contains(this.input)){this.setup();return}n.some(i=>this.listbox?.contains(i.target))&&this.updateOptions(),this.render()}}updateOptions(){let t=this.selectedOption;if(!this.queryLongEnough||this.currentQuery===""){this.options=[];return}if(this.options=this.matchingOptions(),this.focused===null||this.validChoiceMade)return;this.menuOpen=this.options.length>0;let e=t?this.options.indexOf(t):-1;this.selected=e,this.focused>=0&&(this.focused=e)}get queryLongEnough(){return this.currentQuery.length>=this.minLength}valueOf(t){if(t)return t.dataset.value??t.textContent?.trim()??""}matchingOptions(){let t=this.currentQuery.toLowerCase(),e=this.filterType;return this.allOptions.filter(n=>{if(e==="none")return!0;let i=(this.valueOf(n)??"").toLowerCase();return e==="starts-with"?i.startsWith(t):i.includes(t)})}isQueryAnOption(t){return this.options.some(e=>this.valueOf(e)?.toLowerCase()===t.toLowerCase())}handleInputChange(t){let e=this.currentQuery!==t;this.currentQuery=t,this.ariaHint=t==="",t!==""&&e&&this.queryLongEnough?(this.dispatchEvent(new CustomEvent("govuk-react-autocomplete:query",{bubbles:!0,detail:{query:t}})),this.options=this.matchingOptions(),this.menuOpen=this.options.length>0,this.selected=-1,this.validChoiceMade=!1):(t===""||!this.queryLongEnough)&&(this.menuOpen=!1,this.options=[]),this.render()}get selectedOption(){return this.selected===null||this.selected<0?void 0:this.options[this.selected]}handleComponentBlur({menuOpen:t,query:e}){let n=this.currentQuery,i=this.selectedOption;this.confirmOnBlur&&(n=e||this.currentQuery,i&&this.confirmEvent(this.valueOf(i)??"")),this.focused=null,this.menuOpen=t,this.selected=null,this.validChoiceMade=this.isQueryAnOption(n),this.setQuery(n),this.render()}setQuery(t){this.currentQuery=t;let{input:e}=this;!e||e.value===t||(this.settingValue=!0,T?T.call(e,t):e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),this.settingValue=!1)}confirmEvent(t){return this.dispatchEvent(new CustomEvent("govuk-react-autocomplete:confirm",{bubbles:!0,cancelable:!0,detail:{value:t}}))}confirm(t){let e=this.options[t];if(!e)return;let n=this.valueOf(e)??"";this.focused=-1,this.hovered=null,this.menuOpen=!1,this.selected=-1,this.validChoiceMade=!0,this.setQuery(n),this.render();let i=this.confirmEvent(n),r=this.input?.form;i&&this.submitOnConfirm&&r&&window.setTimeout(()=>r.requestSubmit())}focusOption(t){this.focused=t,this.hovered=null,this.selected=t,this.render()}optionOf(t){if(!(t instanceof Element))return-1;let e=t.closest("[data-autocomplete-option]");return e?this.options.indexOf(e):-1}ensureId(t,e){return t.id||(this.generatedIds+=1,t.id=`${this.input?.id}__${e}${e.endsWith("--")?this.generatedIds:""}`),t.id}get hint(){return this.own("[data-autocomplete-hint]")}describedBy(){let{input:t}=this;if(!t)return null;let e=this.hint,n=e?this.ensureId(e,"assistiveHint"):void 0,i=(t.getAttribute("aria-describedby")??"").split(/\s+/).filter(r=>r&&r!==n);return this.ariaHint&&n&&i.push(n),i.length?i.join(" "):null}describedByIsCurrent(){return(this.input?.getAttribute("aria-describedby")??null)===this.describedBy()}render(){let{input:t,listbox:e}=this;if(!t||!e)return;let{focused:n,hovered:i,menuOpen:r,options:h,selected:d}=this,O=n===-1&&h.length===0&&this.currentQuery!==""&&this.queryLongEnough,x=n!==null&&n!==-1,C=this.ensureId(e,"listbox");u(e,"role","listbox"),e.hasAttribute("aria-labelledby")||e.setAttribute("aria-labelledby",t.id),e.hidden=!(r||O),this.allOptions.forEach(a=>{let c=h.indexOf(a);this.ensureId(a,"option--"),a.hidden=c===-1,u(a,"role","option"),u(a,"tabindex","-1"),u(a,"aria-selected",n===c&&c!==-1?"true":"false"),u(a,"aria-posinset",c===-1?null:String(c+1)),u(a,"aria-setsize",c===-1?null:String(h.length)),u(a,"data-focused",c!==-1&&(n===-1?d===c:n===c)&&i===null?"":null)});let f=this.own("[data-autocomplete-no-results]");if(f&&(f.hidden=!O,u(f,"role","option"),u(f,"aria-disabled","true")),u(t,"role","combobox"),u(t,"autocomplete","off"),u(t,"aria-autocomplete","list"),u(t,"aria-controls",C),u(t,"aria-expanded",r?"true":"false"),u(t,"aria-activedescendant",x?h[n]?.id??null:null),u(t,"aria-describedby",this.describedBy()),u(this,"data-focused",n===null?null:""),n!==this.lastFocused&&n!==null){let a=n===-1?t:h[n];a&&document.activeElement!==a&&a.focus(),n===-1&&this.lastFocused===null&&t.selectionStart!==null&&t.setSelectionRange(0,t.value.length)}this.lastFocused=n,this.scheduleStatus()}message(t){return w(this,t)??M[t]}statusText(){let{locale:t,options:e}=this;if(!this.queryLongEnough)return p(this.message("query-too-short-announcement"),this.minLength,t);if(e.length===0)return p(this.message("no-results-announcement"),0,t);let n=p(this.message("results-announcement"),e.length,t),i=this.valueOf(this.selectedOption);if(i===void 0||this.selected===null)return n;let r=m(t,d=>new Intl.NumberFormat(d)).format(this.selected+1),h=p(this.message("selected-option-announcement"),e.length,t).replaceAll("%{option}",()=>i).replaceAll("%{position}",()=>r);return`${n} ${h}`}scheduleStatus(){let t=this.ownAll("[data-autocomplete-status-region]");t.length&&(t.forEach(e=>g(e,"")),window.clearTimeout(this.statusTimer),this.statusTimer=window.setTimeout(()=>{this.bump=!this.bump;let n=this.focused===null||this.validChoiceMade?"":this.statusText();t.forEach((i,r)=>g(i,r===0===this.bump?n:""))},I))}}customElements.get(b)||customElements.define(b,s)}})();
|
|
2
2
|
/*! Based on accessible-autocomplete, Copyright (c) 2017 Crown Copyright (Government Digital Service), MIT licence: licences/accessible-autocomplete.txt */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{
|
|
1
|
+
"use strict";(()=>{function v(e,s){let i=e(),t=window.setInterval(()=>{let n=e();n!==i&&(i=n,s())},100);return()=>window.clearInterval(t)}var b=["zero","one","two","few","many","other"];var w=e=>[e,...b.map(s=>`${e}-${s}`)];function x(e,s){let i=e.getAttribute(s);if(i!==null)return i;let t=b.flatMap(n=>{let r=e.getAttribute(`${s}-${n}`);return r===null?[]:[[n,r]]});return t.length?Object.fromEntries(t):void 0}function C(e){try{return e(void 0)}catch{return e("en")}}function l(e,s){try{return s(e)}catch{return C(s)}}function y(e,s,i){let t;if(typeof e=="string")t=e;else{let r=l(i,a=>new Intl.PluralRules(a)).select(s);t=e[r]??e.other}let n=l(i,r=>new Intl.NumberFormat(r)).format(s);return(t??"").replaceAll("%{count}",n)}var p=["characters-under-limit-text","characters-at-limit-text","characters-over-limit-text","words-under-limit-text","words-at-limit-text","words-over-limit-text"],M={"characters-under-limit-text":{one:"You have %{count} character remaining",other:"You have %{count} characters remaining"},"characters-at-limit-text":"You have 0 characters remaining","characters-over-limit-text":{one:"You have %{count} character too many",other:"You have %{count} characters too many"},"words-under-limit-text":{one:"You have %{count} word remaining",other:"You have %{count} words remaining"},"words-at-limit-text":"You have 0 words remaining","words-over-limit-text":{one:"You have %{count} word too many",other:"You have %{count} words too many"}};var A=(e,s)=>x(e,s);function T(e,s,i){if(s==="length")return e.length;if(typeof Intl.Segmenter!="function")return s==="words"?e.match(/\S+/g)?.length??0:Array.from(e).length;let t=l(i,r=>new Intl.Segmenter(r,{granularity:s==="words"?"word":"grapheme"})),n=Array.from(t.segment(e));return s==="words"?n.filter(r=>r.isWordLike).length:n.length}function E(e,s,i,t){let n=e<0?"over":e===0?"at":"under",r=`${s==="words"?"words":"characters"}-${n}-limit-text`,a=i[r]??M[r];return{state:n,text:y(a,Math.abs(e),t)}}var u=e=>e?.split(/\s+/).filter(Boolean)??[];function m(e,s){if(e.textContent===s)return;let{firstChild:i}=e;i instanceof Text&&e.childNodes.length===1?i.nodeValue=s:e.textContent=s}var g="govuk-react-character-count",L={position:"absolute",width:"1px",height:"1px",margin:"0",padding:"0",overflow:"hidden",clip:"rect(0 0 0 0)","clip-path":"inset(50%)",border:"0","white-space":"nowrap"},I=e=>e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement;if(typeof HTMLElement<"u"&&typeof customElements<"u"){class e extends HTMLElement{constructor(){super(...arguments);this.currentCount=0;this.onInput=()=>{this.update(),this.lastInputTime=Date.now()};this.onFocus=()=>{window.clearInterval(this.checker),this.checker=window.setInterval(()=>{(!this.lastInputTime||Date.now()-500>=this.lastInputTime)&&this.announceIfChanged()},1e3)};this.onBlur=()=>window.clearInterval(this.checker);this.onReset=t=>{this.input&&t.target===this.input.form&&window.setTimeout(()=>this.update())};this.onPageShow=()=>{this.input&&(this.update(),this.announceIfChanged())}}static get observedAttributes(){return["maxlength","count-type","threshold","within-limit-class","over-limit-class","below-threshold-class","input-over-limit-class",...p.flatMap(w)]}get count(){return this.input?this.currentCount:void 0}connectedCallback(){this.observer=new MutationObserver(t=>{t.some(n=>n.type==="childList")?this.setup():this.update()}),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","maxlength"]}),window.addEventListener("pageshow",this.onPageShow),document.addEventListener("reset",this.onReset,!0),this.setup()}disconnectedCallback(){this.observer?.disconnect(),window.removeEventListener("pageshow",this.onPageShow),document.removeEventListener("reset",this.onReset,!0),window.clearInterval(this.checker),this.unbind()}attributeChangedCallback(){if(this.isConnected){if(!this.input){this.setup();return}if(this.maxLength===void 0){this.downgrade();return}this.lastAnnouncedValue=void 0,this.update()}}own(t){return Array.from(this.querySelectorAll(t)).find(n=>n.closest(g)===this)}get maxLength(){let t=Number(this.getAttribute("maxlength"));return this.hasAttribute("maxlength")&&Number.isFinite(t)?t:void 0}get countType(){let t=this.getAttribute("count-type");return t==="characters"||t==="words"?t:"length"}get locale(){return(this.input??this).closest("[lang]")?.getAttribute("lang")||"en"}setup(){let t=this.own("[data-character-count-input]");if(!I(t)||this.maxLength===void 0)return;let n=t!==this.input;n&&(this.unbind(),this.input=t,t.addEventListener("input",this.onInput),t.addEventListener("focus",this.onFocus),t.addEventListener("blur",this.onBlur),this.stopWatchingValue=v(()=>t.value,()=>this.update()),t.removeAttribute("maxlength"),this.lastAnnouncedValue=void 0),this.dataset.upgraded="";let r=this.own("[data-character-count-description]");r&&!this.hasAttribute("hidden-description-class")&&Object.entries(L).forEach(([a,h])=>r.style.setProperty(a,h)),[this.own("[data-character-count-status]"),this.own("[data-character-count-sr-status]")].forEach(a=>{a&&(a.hidden=!1)}),this.update(),n&&this.announceIfChanged()}unbind(){let{input:t}=this;t&&(t.removeEventListener("input",this.onInput),t.removeEventListener("focus",this.onFocus),t.removeEventListener("blur",this.onBlur),this.stopWatchingValue?.(),window.clearInterval(this.checker),this.input=void 0)}downgrade(){let{input:t}=this;if(!t)return;u(this.getAttribute("input-over-limit-class")).forEach(r=>t.classList.toggle(r,!1)),this.unbind(),delete this.dataset.upgraded;let n=this.own("[data-character-count-description]");n&&(this.hasAttribute("hidden-description-class")?u(this.getAttribute("hidden-description-class")).forEach(r=>n.classList.toggle(r,!1)):Object.keys(L).forEach(r=>n.style.removeProperty(r))),[this.own("[data-character-count-status]"),this.own("[data-character-count-sr-status]")].forEach(r=>{r&&(r.hidden=!0)})}update(){this.input&&(this.input.removeAttribute("maxlength"),this.currentCount=T(this.input.value,this.countType,this.locale),this.render())}message(){let t=Object.fromEntries(p.map(n=>[n,A(this,n)]));return E((this.maxLength??1/0)-this.currentCount,this.countType,t,this.locale)}get belowThreshold(){let t=Number(this.getAttribute("threshold"));return t?this.currentCount<(this.maxLength??1/0)*t/100:!1}render(){let{input:t}=this;if(!t)return;let{state:n,text:r}=this.message(),a=n==="over",h=this.own("[data-character-count-description]");u(this.getAttribute("hidden-description-class")).forEach(o=>h?.classList.toggle(o,!0)),u(this.getAttribute("input-over-limit-class")).forEach(o=>t.classList.toggle(o,a));let d=this.belowThreshold,f=this.own("[data-character-count-sr-status]");d?f?.setAttribute("aria-hidden","true"):f?.removeAttribute("aria-hidden");let c=this.own("[data-character-count-status]");c&&(c.dataset.state=n,c.toggleAttribute("data-below-threshold",d),u(this.getAttribute("below-threshold-class")).forEach(o=>c.classList.toggle(o,d)),u(this.getAttribute("within-limit-class")).forEach(o=>c.classList.toggle(o,!a)),u(this.getAttribute("over-limit-class")).forEach(o=>c.classList.toggle(o,a)),m(c,r))}announceIfChanged(){let{input:t}=this,n=this.own("[data-character-count-sr-status]");if(!t||!n||t.value===this.lastAnnouncedValue)return;this.lastAnnouncedValue=t.value;let{state:r,text:a}=this.message();n.dataset.state=r,m(n,a)}}customElements.get(g)||customElements.define(g,e)}})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var
|
|
1
|
+
"use strict";(()=>{var a=s=>s?.split(/\s+/).filter(Boolean)??[];function l(s,d){let c=s(),e=window.setInterval(()=>{let t=s();t!==c&&(c=t,d())},100);return()=>window.clearInterval(e)}var o="govuk-react-choices",h=s=>s instanceof HTMLInputElement&&(s.type==="radio"||s.type==="checkbox");if(typeof HTMLElement<"u"&&typeof customElements<"u"){class s extends HTMLElement{constructor(){super(...arguments);this.upgraded=!1;this.onClick=e=>{let t=e.target;if(!h(t)||!this.owns(t))return;if(t.type==="radio"){this.syncAll();return}if(this.syncInput(t),!t.checked)return;let n=t.hasAttribute("data-choices-exclusive"),r=this.inputsNamed(t).filter(i=>i!==t&&i.type==="checkbox"&&i.checked&&(n||i.hasAttribute("data-choices-exclusive")));window.setTimeout(()=>{r.filter(i=>i.checked).forEach(i=>{i.disabled?i.checked=!1:i.click()}),this.syncAll()})};this.onReset=e=>{e.target instanceof HTMLFormElement&&this.choices().some(t=>t.form===e.target)&&window.setTimeout(()=>this.sync())};this.onChange=e=>{h(e.target)&&this.owns(e.target)&&this.sync()};this.onPageShow=()=>this.sync()}connectedCallback(){this.observer=new MutationObserver(e=>{e.some(t=>t.type==="childList")?this.setup():(this.upgraded&&this.addUpgradedClasses(),this.sync())}),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class"]}),this.addEventListener("click",this.onClick),this.addEventListener("change",this.onChange),window.addEventListener("pageshow",this.onPageShow),document.addEventListener("reset",this.onReset,!0),this.stopWatchingChecked=l(()=>this.choices().map(e=>e.checked?1:0).join(""),()=>this.syncAll()),this.setup()}disconnectedCallback(){this.observer?.disconnect(),this.removeEventListener("click",this.onClick),this.removeEventListener("change",this.onChange),window.removeEventListener("pageshow",this.onPageShow),document.removeEventListener("reset",this.onReset,!0),this.stopWatchingChecked?.()}get root(){let e=this.getRootNode();return e instanceof Document||e instanceof ShadowRoot?e:document}inputsNamed(e){return Array.from(this.root.querySelectorAll("input")).filter(t=>t.type===e.type&&t.name===e.name&&t.form===e.form)}syncAll(){Array.from(this.root.querySelectorAll(o)).forEach(e=>{e instanceof s&&e.sync()})}owns(e){return e.closest(o)===this}choices(){return Array.from(this.querySelectorAll("input")).filter(e=>h(e)&&this.owns(e))}target(e){let t=e.getAttribute("data-choices-controls");if(!t)return;let n=this.getRootNode(),r=n instanceof Document||n instanceof ShadowRoot?n.getElementById(t):null;return r instanceof HTMLElement&&r.hasAttribute("data-choices-conditional")?r:void 0}setup(){this.choices().length&&(this.upgraded||(this.upgraded=!0,this.dataset.upgraded="",this.addUpgradedClasses()),this.sync())}addUpgradedClasses(){a(this.getAttribute("upgraded-class")).forEach(e=>this.classList.toggle(e,!0))}sync(){this.upgraded&&this.choices().forEach(e=>this.syncInput(e))}syncInput(e){let t=this.target(e);if(!t)return;e.setAttribute("aria-controls",t.id),e.setAttribute("aria-expanded",String(e.checked));let n=a(this.getAttribute("hidden-conditional-class"));n.length?n.forEach(r=>t.classList.toggle(r,!e.checked)):t.hidden=!e.checked}}customElements.get(o)||customElements.define(o,s)}})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{function a(r
|
|
1
|
+
"use strict";(()=>{function a(s,r){if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(s,{childList:!0,subtree:!0}),i}var o="govuk-react-disclosure";if(typeof HTMLElement<"u"&&typeof customElements<"u"){class s extends HTMLElement{constructor(){super(...arguments);this.isOpen=!1;this.controlled=!1;this.onClick=()=>{let e=!this.isOpen;this.hasAttribute("open")||(this.apply(e),this.controlled||(this.picked=e)),this.dispatchEvent(new CustomEvent("govuk-react-disclosure:change",{detail:{open:e},bubbles:!0}))};this.onModeChange=()=>this.render()}static get observedAttributes(){return["open","media"]}get expanded(){return this.toggle?this.isOpen:void 0}get pickedOpen(){return this.picked}connectedCallback(){this.observer=a(this,()=>this.setup())}disconnectedCallback(){this.observer?.disconnect(),this.toggle?.removeEventListener("click",this.onClick),this.mql?.removeEventListener("change",this.onModeChange),this.toggle=void 0,this.content=void 0,this.mql=void 0}attributeChangedCallback(e){if(e==="media"){this.toggle&&this.watchMedia();return}let t=this.getAttribute("open");t!==null&&(this.controlled=!0,this.apply(t==="true"))}own(e,t){let n=Array.from(this.querySelectorAll(e)).find(d=>d.closest(o)===this);return n instanceof t?n:void 0}setup(){if(this.toggle)return!0;let e=this.own("[data-disclosure-trigger]",HTMLButtonElement),t=this.own("[data-disclosure-content]",HTMLElement);if(!e||!t)return!1;this.toggle=e,this.content=t;let n=this.getAttribute("open");return this.isOpen=n===null?this.hasAttribute("default-open"):n==="true",this.dataset.upgraded="",e.addEventListener("click",this.onClick),this.watchMedia(),!0}watchMedia(){this.mql?.removeEventListener("change",this.onModeChange);let e=this.getAttribute("media");this.mql=e?window.matchMedia(e):void 0,this.mql?.addEventListener("change",this.onModeChange),this.render()}apply(e){e!==this.isOpen&&(this.isOpen=e,this.render())}render(){let{toggle:e,content:t}=this;if(!(!e||!t)){if(this.mql?.matches){t.hidden=!1,e.hidden=!0,e.setAttribute("aria-hidden","true"),e.removeAttribute("aria-expanded");return}e.hidden=!1,e.removeAttribute("aria-hidden"),e.setAttribute("aria-expanded",String(this.isOpen)),t.id&&e.setAttribute("aria-controls",t.id),t.hidden=!this.isOpen}}}customElements.get(o)||customElements.define(o,s)}})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var o=
|
|
1
|
+
"use strict";(()=>{var o=i=>i?.split(/\s+/).filter(Boolean)??[];function l(i,c){if(i.textContent===c)return;let{firstChild:d}=i;d instanceof Text&&i.childNodes.length===1?d.nodeValue=c:i.textContent=c}var u="govuk-react-exit-this-page",T=["activated-announcement","timed-out-announcement","press-two-more-times-announcement","press-one-more-time-announcement"],p={"activated-announcement":"Loading.","timed-out-announcement":"Exit this page expired.","press-two-more-times-announcement":"Shift, press 2 more times to exit.","press-one-more-time-announcement":"Shift, press 1 more time to exit."},m=5e3,g={position:"fixed",inset:"0","z-index":"2147483647",background:"white"};if(typeof HTMLElement<"u"&&typeof customElements<"u"){class i extends HTMLElement{constructor(){super(...arguments);this.presses=0;this.lastKeyWasModified=!1;this.onClick=e=>{if(e.defaultPrevented||e.button!==0)return;let t=e.target instanceof Element?e.target.closest("a"):null;if(!t)return;let n=t.matches("[data-exit-this-page-trigger]")&&t.closest(u)===this,s=t.matches("[data-exit-this-page-skiplink]")&&this.listening;!n&&!s||(e.preventDefault(),this.exit())};this.onKeyup=e=>{this.listening&&(e.key==="Shift"&&!this.lastKeyWasModified?(this.presses+=1,this.updateIndicator(),window.clearTimeout(this.messageTimeout),this.presses>=3?(this.presses=0,window.clearTimeout(this.pressTimeout),this.pressTimeout=void 0,this.exit()):(this.setStatus(this.message(this.presses===1?"press-two-more-times-announcement":"press-one-more-time-announcement")),window.clearTimeout(this.pressTimeout),this.pressTimeout=window.setTimeout(this.timeOut,m))):this.pressTimeout!==void 0&&this.timeOut(),this.lastKeyWasModified=e.shiftKey)};this.timeOut=()=>{window.clearTimeout(this.pressTimeout),this.pressTimeout=void 0,this.presses=0,this.setStatus(this.message("timed-out-announcement")),this.messageTimeout=window.setTimeout(()=>this.setStatus(""),m),this.updateIndicator()};this.reset=e=>{e.persisted&&(o(this.getAttribute("hide-content-class")).forEach(t=>document.body.classList.remove(t)),this.overlay?.remove(),this.overlay=void 0,this.presses=0,this.setStatus(""),this.updateIndicator(),this.clearTimers())}}connectedCallback(){this.dataset.upgraded="",document.addEventListener("keyup",this.onKeyup,!0),document.addEventListener("click",this.onClick),window.addEventListener("pageshow",this.reset)}disconnectedCallback(){document.removeEventListener("keyup",this.onKeyup,!0),document.removeEventListener("click",this.onClick),window.removeEventListener("pageshow",this.reset),this.clearTimers(),this.presses=0,this.setStatus(""),this.updateIndicator()}exit(){let e=this.own("[data-exit-this-page-trigger]"),t=e instanceof HTMLAnchorElement?e.href:void 0,n=t!==void 0&&this.dispatchEvent(new CustomEvent("govuk-react-exit-this-page:exit",{detail:{href:t},bubbles:!0,cancelable:!0}));if(!t||!n){this.setStatus(""),this.updateIndicator();return}this.setStatus(""),o(this.getAttribute("hide-content-class")).forEach(a=>document.body.classList.add(a)),this.overlay?.remove();let s=document.createElement("div");s.setAttribute("role","alert");let r=o(this.getAttribute("overlay-class"));r.length?s.classList.add(...r):Object.entries(g).forEach(([a,h])=>s.style.setProperty(a,h)),document.body.appendChild(s),s.textContent=this.message("activated-announcement"),this.overlay=s,window.location.href=t}get listening(){return document.querySelector(u)===this}own(e){return Array.from(this.querySelectorAll(e)).find(t=>t.closest(u)===this)}message(e){return this.getAttribute(e)??p[e]}setStatus(e){let t=this.own("[data-exit-this-page-status]");t&&l(t,e)}clearTimers(){window.clearTimeout(this.pressTimeout),window.clearTimeout(this.messageTimeout),this.pressTimeout=void 0,this.messageTimeout=void 0}updateIndicator(){let e=this.own("[data-exit-this-page-indicator]");if(!e)return;let t=this.presses>0;e.toggleAttribute("data-visible",t),o(this.getAttribute("indicator-visible-class")).forEach(n=>e.classList.toggle(n,t)),e.querySelectorAll("[data-exit-this-page-light]").forEach((n,s)=>{let r=s<this.presses;n.toggleAttribute("data-on",r),o(this.getAttribute("light-on-class")).forEach(a=>n.classList.toggle(a,r))})}}customElements.get(u)||customElements.define(u,i)}})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var m=["zero","one","two","few","many","other"];var b=n=>[n,...m.map(i=>`${n}-${i}`)];function v(n,i){let s=n.getAttribute(i);if(s!==null)return s;let t=m.flatMap(e=>{let r=n.getAttribute(`${i}-${e}`);return r===null?[]:[[e,r]]});return t.length?Object.fromEntries(t):void 0}function
|
|
1
|
+
"use strict";(()=>{var m=["zero","one","two","few","many","other"];var b=n=>[n,...m.map(i=>`${n}-${i}`)];function v(n,i){let s=n.getAttribute(i);if(s!==null)return s;let t=m.flatMap(e=>{let r=n.getAttribute(`${i}-${e}`);return r===null?[]:[[e,r]]});return t.length?Object.fromEntries(t):void 0}function L(n){try{return n(void 0)}catch{return n("en")}}function p(n,i){try{return i(n)}catch{return L(i)}}function u(n,i,s){let t;if(typeof n=="string")t=n;else{let r=p(s,a=>new Intl.PluralRules(a)).select(i);t=n[r]??n.other}let e=p(s,r=>new Intl.NumberFormat(r)).format(i);return(t??"").replaceAll("%{count}",e)}var c=n=>n?.split(/\s+/).filter(Boolean)??[];function E(n,i){if(n.textContent===i)return;let{firstChild:s}=n;s instanceof Text&&n.childNodes.length===1?s.nodeValue=i:n.textContent=i}function o(n,i,s){s===null?n.removeAttribute(i):n.getAttribute(i)!==s&&n.setAttribute(i,s)}var g="govuk-react-file-upload",h={"no-file-chosen-text":"No file chosen","multiple-files-chosen-text":{one:"%{count} file chosen",other:"%{count} files chosen"},"entered-drop-zone-announcement":"Entered drop zone","left-drop-zone-announcement":"Left drop zone"};function y(n,i,s){return n.length===0?u(i["no-file-chosen-text"]??h["no-file-chosen-text"],0,s):n.length===1?n[0].name:u(i["multiple-files-chosen-text"]??h["multiple-files-chosen-text"],n.length,s)}var D=n=>Array.from(n).filter(i=>i.kind==="file").length;if(typeof HTMLElement<"u"&&typeof customElements<"u"){class n extends HTMLElement{constructor(){super(...arguments);this.fieldId="";this.dragging=!1;this.enteredAnotherElement=!1;this.onChange=()=>this.update();this.onReset=()=>window.setTimeout(()=>this.update());this.onClick=()=>this.input?.click();this.onDragOver=t=>t.preventDefault();this.onDrop=t=>{t.preventDefault();let{input:e}=this,r=t.dataTransfer?.files;!e||!r||!this.matchesCapacity(r.length)||(e.files=r,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),this.setDragging(!1))};this.onDocumentDragEnter=t=>{this.enteredAnotherElement=!0,!(!this.button||this.button.disabled||!(t.target instanceof Node))&&(this.dropZone.contains(t.target)?t.dataTransfer&&this.canDrop(t.dataTransfer)&&!this.dragging&&(this.setDragging(!0),this.announce("entered-drop-zone-announcement")):this.dragging&&(this.setDragging(!1),this.announce("left-drop-zone-announcement")))};this.onDocumentDragLeave=()=>{!this.enteredAnotherElement&&this.dragging&&!this.button?.disabled&&(this.setDragging(!1),this.announce("left-drop-zone-announcement")),this.enteredAnotherElement=!1}}static get observedAttributes(){return["empty-class","dragging-class","disabled-class",...Object.keys(h).flatMap(b)]}connectedCallback(){this.observer=new MutationObserver(()=>this.setup()),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","disabled","id","aria-describedby"]}),document.addEventListener("dragenter",this.onDocumentDragEnter),document.addEventListener("dragleave",this.onDocumentDragLeave),this.setup()}disconnectedCallback(){this.observer?.disconnect(),document.removeEventListener("dragenter",this.onDocumentDragEnter),document.removeEventListener("dragleave",this.onDocumentDragLeave),this.unbind()}attributeChangedCallback(){this.isConnected&&this.update()}own(t){return Array.from(this.querySelectorAll(t)).find(e=>e.closest(g)===this)}get dropZone(){return this.own("[data-file-upload-drop-zone]")??this}get locale(){return this.closest("[lang]")?.getAttribute("lang")||"en"}message(t){return v(this,t)??h[t]}setup(){let t=this.own('input[type="file"]'),e=this.own("button[data-file-upload-trigger]");!t||!e||(t.id!==`${this.fieldId}-input`&&(this.fieldId=t.id),this.fieldId&&((t!==this.input||e!==this.button)&&(this.unbind(),this.input=t,this.button=e,this.form=t.form,t.addEventListener("change",this.onChange),this.form?.addEventListener("reset",this.onReset),e.addEventListener("click",this.onClick),e.addEventListener("dragover",this.onDragOver),e.addEventListener("drop",this.onDrop)),this.upgrade(t,e),this.update()))}unbind(){this.input?.removeEventListener("change",this.onChange),this.form?.removeEventListener("reset",this.onReset),this.button?.removeEventListener("click",this.onClick),this.button?.removeEventListener("dragover",this.onDragOver),this.button?.removeEventListener("drop",this.onDrop),this.input=void 0,this.button=void 0,this.form=void 0}upgrade(t,e){let r=this.fieldId,a=this.getRootNode(),l=a instanceof Document||a instanceof ShadowRoot?a.querySelector(`label[for="${CSS.escape(r)}"]`):null;l&&!l.id&&(l.id=`${r}-label`),o(t,"id",`${r}-input`),o(e,"id",r);let d=e.querySelector("[data-file-upload-separator]");d&&o(d,"id",`${r}-comma`),l&&o(e,"aria-labelledby",[l.id,d?.id,r].filter(Boolean).join(" ")),o(e,"aria-describedby",t.getAttribute("aria-describedby")),o(t,"hidden","hidden"),e.hidden&&(e.hidden=!1),this.dataset.upgraded=""}update(){let{input:t,button:e}=this;if(!t||!e)return;let{files:r}=t,a=!r?.length,l=e.querySelector("[data-file-upload-status]");l&&E(l,y(r??[],{"no-file-chosen-text":this.message("no-file-chosen-text"),"multiple-files-chosen-text":this.message("multiple-files-chosen-text")},this.locale)),o(e,"data-empty",a?"":null),c(this.getAttribute("empty-class")).forEach(f=>e.classList.toggle(f,a)),e.disabled!==t.disabled&&(e.disabled=t.disabled);let d=this.dropZone;o(d,"data-disabled",t.disabled?"":null),c(this.getAttribute("disabled-class")).forEach(f=>d.classList.toggle(f,t.disabled)),t.disabled?this.setDragging(!1):this.renderDragging()}setDragging(t){this.dragging=t,this.renderDragging()}renderDragging(){let{button:t,dragging:e}=this;t&&(o(t,"data-dragging",e?"":null),c(this.getAttribute("dragging-class")).forEach(r=>t.classList.toggle(r,e)))}announce(t){let e=this.own("[data-file-upload-announcements]");e&&(e.textContent=u(this.message(t),0,this.locale))}canDrop(t){return t.items.length?this.matchesCapacity(D(t.items)):t.types.length?t.types.includes("Files"):!0}matchesCapacity(t){return this.input?.multiple?t>0:t===1}}customElements.get(g)||customElements.define(g,n)}})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{function a(t,n,o){o.forEach(e=>t.classList.remove(e)),n&&t.removeAttribute("tabindex"),t.removeAttribute("data-focus-tabindex"),t.removeAttribute("autofocus")}var f=t=>!t.hasAttribute("tabindex")||t.hasAttribute("data-focus-tabindex")&&t.getAttribute("tabindex")==="-1";function u(t,{focusedClasses:n=[],preventScroll:o=!1}={}){let e=f(t);return t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),document.activeElement!==t&&(n.forEach(i=>t.classList.add(i)),t.focus({preventScroll:o})),document.activeElement!==t?(a(t,e,n),!1):(n.forEach(i=>t.classList.add(i)),t.addEventListener("blur",()=>a(t,e,n),{once:!0}),!0)}var l=t=>t?.split(/\s+/).filter(Boolean)??[];var d="govuk-react-focus-links",g=t=>t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement||t instanceof HTMLButtonElement;function
|
|
1
|
+
"use strict";(()=>{function a(t,n,o){o.forEach(e=>t.classList.remove(e)),n&&t.removeAttribute("tabindex"),t.removeAttribute("data-focus-tabindex"),t.removeAttribute("autofocus")}var f=t=>!t.hasAttribute("tabindex")||t.hasAttribute("data-focus-tabindex")&&t.getAttribute("tabindex")==="-1";function u(t,{focusedClasses:n=[],preventScroll:o=!1}={}){let e=f(t);return t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),document.activeElement!==t&&(n.forEach(i=>t.classList.add(i)),t.focus({preventScroll:o})),document.activeElement!==t?(a(t,e,n),!1):(n.forEach(i=>t.classList.add(i)),t.addEventListener("blur",()=>a(t,e,n),{once:!0}),!0)}var l=t=>t?.split(/\s+/).filter(Boolean)??[];var d="govuk-react-focus-links",g=t=>t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement||t instanceof HTMLButtonElement;function b(t){let n=t.closest("fieldset")?.getElementsByTagName("legend")[0];if(n){if(t instanceof HTMLInputElement&&(t.type==="checkbox"||t.type==="radio"))return n;let o=n.getBoundingClientRect().top,e=t.getBoundingClientRect();if(e.height&&window.innerHeight&&e.top+e.height-o<window.innerHeight/2)return n}return document.querySelector(`label[for="${CSS.escape(t.id)}"]`)??t.closest("label")}if(typeof HTMLElement<"u"&&typeof customElements<"u"){class t extends HTMLElement{constructor(){super(...arguments);this.onClick=e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey)return;let i=e.target instanceof Element?e.target.closest("a[href]"):null;if(!(i instanceof HTMLAnchorElement)||!this.contains(i)||!(i.getAttribute("href")?.startsWith("#")||i.origin===window.location.origin&&i.pathname===window.location.pathname&&i.search===window.location.search))return;let r=i.hash.slice(1);try{r=decodeURIComponent(r)}catch{}let s=r?document.getElementById(r):null;if(s){if(g(s)){let c=b(s);if(!c)return;e.preventDefault(),c.scrollIntoView(),s.focus({preventScroll:!0});return}u(s,{focusedClasses:l(this.getAttribute("focused-class"))})}}}connectedCallback(){this.addEventListener("click",this.onClick)}disconnectedCallback(){this.removeEventListener("click",this.onClick)}}customElements.get(d)||customElements.define(d,t)}})();
|