@repobit/dex-system-design 4.0.0 → 4.1.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/CHANGELOG.md +8 -0
- package/dist/src/components/input/input.js +13 -13
- package/dist/src/components/input/input.js.map +1 -1
- package/dist/src/components/logo-marquee/logo-marquee.d.ts +14 -0
- package/dist/src/components/logo-marquee/logo-marquee.js +8 -8
- package/dist/src/components/logo-marquee/logo-marquee.js.map +1 -1
- package/dist/src/components/select/select.d.ts +7 -0
- package/dist/src/components/select/select.js +10 -9
- package/dist/src/components/select/select.js.map +1 -1
- package/dist/src/components/shared/form-control.d.ts +8 -0
- package/dist/src/components/shared/form-control.js +1 -1
- package/dist/src/components/shared/form-control.js.map +1 -1
- package/package.json +2 -2
- package/schemas/component-manifest.json +14 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.1.0](https://github.com/bitdefender/dex-core/compare/@repobit/dex-system-design@4.0.0...@repobit/dex-system-design@4.1.0) (2026-11-11)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **DEX-29547:** bd-logo-marquee takes without-pause-button
|
|
11
|
+
* **DEX-29547:** bd-select takes aria-label for a name it does not draw
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [4.0.0](https://github.com/bitdefender/dex-core/compare/@repobit/dex-system-design@3.1.2...@repobit/dex-system-design@4.0.0) (2026-11-11)
|
|
7
15
|
|
|
8
16
|
### ⚠ BREAKING CHANGES
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import{defineElement as e}from"../shared/define-element.js";import"../../tokens/tokens.js";import{SIZES as t,isOneOf as n}from"../shared/prop-vocabulary.js";import r from"../../_bundled/oxc-project_runtime/helpers/esm/decorate.js";import{SlotController as i}from"../shared/controller.slot.js";import{CONTROL_ID as a,FIELD_SLOTS as o,ValueControl as s,describedBy as c,fieldHint as l,fieldLabel as u,omitEmpty as
|
|
1
|
+
import{defineElement as e}from"../shared/define-element.js";import"../../tokens/tokens.js";import{SIZES as t,isOneOf as n}from"../shared/prop-vocabulary.js";import r from"../../_bundled/oxc-project_runtime/helpers/esm/decorate.js";import{SlotController as i}from"../shared/controller.slot.js";import{CONTROL_ID as a,FIELD_SLOTS as o,ValueControl as s,describedBy as c,fieldHint as l,fieldLabel as u,fieldName as d,omitEmpty as f}from"../shared/form-control.js";import p from"./input.css.js";import m from"../shared/form-field.css.js";import{LitElement as h,html as g,nothing as _}from"lit";import{property as v}from"lit/decorators.js";import{keyed as y}from"lit/directives/keyed.js";var b=class extends s(h){constructor(...e){super(...e),this.type=`text`,this.size=`md`,this.placeholder=``,this.required=!1,this.focused=!1,this.invalid=!1,this.validated=!1,this.disabled=!1,this.value=``,this.name=``,this.inputmode=``,this.autocomplete=``,this.enterkeyhint=``,this.fieldSpellcheck=null,this.fieldLabel=``,this._slots=new i(this,{slots:[...o,`end`],text:[`label`]})}static{this.styles=[m,p]}get _control(){return this.renderRoot?.querySelector?.(`input`)}get _accessibleName(){return d(this._slots,this.fieldLabel,this._internals.labels)}_onInput(e){this.value=e.target.value,this._sync()}_onChange(e){this.value=e.target.value,this._relayChange()}willUpdate(e){e.has(`size`)&&!n(t,this.size)&&(this.size=`md`)}updated(e){this._sync(),this._followFocused(e);for(let e of this._slots.elements(`end`))e.requestUpdate?.()}_followFocused(e){if(!e.has(`focused`))return;let t=this.shadowRoot.querySelector(`input`),n=this.shadowRoot.activeElement===t;this.focused&&!n&&t?.focus(),!this.focused&&n&&t?.blur()}render(){let e=this.disabled||this._formDisabled,t=e?`form-input--disabled`:this.invalid?`form-input--error`:this.validated?`form-input--success`:``,n=this.invalid?`error`:this.validated?`success`:`default`,r=this._slots.has(`end`);return g`
|
|
2
2
|
<div class="input-container">
|
|
3
|
-
${u(this._slots,{size:this.size,required:this.required},
|
|
3
|
+
${u(this._slots,{size:this.size,required:this.required},g`<slot name="label"></slot>`)}
|
|
4
4
|
<div class="control-row">
|
|
5
|
-
${
|
|
5
|
+
${y(this._resets,g`<input
|
|
6
6
|
id=${a}
|
|
7
7
|
part="input"
|
|
8
8
|
class="form-input-bd input-${this.size} ${t} ${this._attempted?`form-input--attempted`:``} ${r?`form-input--with-end`:``}"
|
|
9
9
|
type=${this.type}
|
|
10
|
-
name=${this.name||
|
|
11
|
-
placeholder=${this.placeholder||
|
|
10
|
+
name=${this.name||_}
|
|
11
|
+
placeholder=${this.placeholder||_}
|
|
12
12
|
.value=${this.value}
|
|
13
|
-
inputmode=${this.inputmode||
|
|
14
|
-
autocomplete=${this.autocomplete||
|
|
15
|
-
spellcheck=${this.fieldSpellcheck??
|
|
16
|
-
enterkeyhint=${this.enterkeyhint||
|
|
13
|
+
inputmode=${this.inputmode||_}
|
|
14
|
+
autocomplete=${this.autocomplete||_}
|
|
15
|
+
spellcheck=${this.fieldSpellcheck??_}
|
|
16
|
+
enterkeyhint=${this.enterkeyhint||_}
|
|
17
17
|
?required=${this.required}
|
|
18
18
|
?disabled=${e}
|
|
19
|
-
aria-label=${this._accessibleName||
|
|
20
|
-
aria-invalid=${this.invalid?`true`:
|
|
19
|
+
aria-label=${this._accessibleName||_}
|
|
20
|
+
aria-invalid=${this.invalid?`true`:_}
|
|
21
21
|
aria-describedby=${c(this._slots)}
|
|
22
22
|
@focus=${()=>{this.focused=!0}}
|
|
23
23
|
@blur=${()=>{this.focused=!1}}
|
|
@@ -27,7 +27,7 @@ import{defineElement as e}from"../shared/define-element.js";import"../../tokens/
|
|
|
27
27
|
/>`)}
|
|
28
28
|
<span class="end" part="end" ?hidden=${!r}><slot name="end"></slot></span>
|
|
29
29
|
</div>
|
|
30
|
-
${l(this._slots,n,
|
|
30
|
+
${l(this._slots,n,g`<slot name="hint"></slot>`)}
|
|
31
31
|
</div>
|
|
32
|
-
`}};r([
|
|
32
|
+
`}};r([v({type:String})],b.prototype,`type`,void 0),r([v({type:String,reflect:!0})],b.prototype,`size`,void 0),r([v({type:String})],b.prototype,`placeholder`,void 0),r([v({type:Boolean})],b.prototype,`required`,void 0),r([v({type:Boolean,reflect:!0})],b.prototype,`focused`,void 0),r([v({type:Boolean})],b.prototype,`invalid`,void 0),r([v({type:Boolean,reflect:!0})],b.prototype,`validated`,void 0),r([v({type:Boolean,reflect:!0})],b.prototype,`disabled`,void 0),r([v({type:String})],b.prototype,`value`,void 0),r([v({type:String,reflect:!0,converter:f})],b.prototype,`name`,void 0),r([v({type:String})],b.prototype,`inputmode`,void 0),r([v({type:String})],b.prototype,`autocomplete`,void 0),r([v({type:String})],b.prototype,`enterkeyhint`,void 0),r([v({type:String,attribute:`spellcheck`})],b.prototype,`fieldSpellcheck`,void 0),r([v({type:String,attribute:`aria-label`})],b.prototype,`fieldLabel`,void 0),b=r([e(`bd-input`)],b);export{b as BdInput};
|
|
33
33
|
//# sourceMappingURL=input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","names":["inputCSS","_decorate","__decorate","input_css_default","formFieldCSS","BdInput","ValueControl","LitElement","_args","SlotController","FIELD_SLOTS","l","changed","isOneOf","SIZES","el","input","has","disabled","inputStateClass","tone","end","fieldLabel","keyed","CONTROL_ID","nothing","describedBy","fieldHint","property","omitEmpty","defineElement"],"sources":["../../../../src/components/input/input.ts"],"sourcesContent":["import { LitElement, html, nothing, type PropertyValues, type ReactiveElement } from \"lit\";\nimport { property } from \"lit/decorators.js\";\nimport { keyed } from \"lit/directives/keyed.js\";\nimport { defineElement } from \"#shared/define-element.ts\";\n// Installs the design tokens into document scope; see src/tokens/tokens.ts\nimport \"#tokens/tokens.ts\";\nimport { formFieldCSS } from \"#shared/form-field.css.ts\";\nimport inputCSS from \"./input.css.ts\";\nimport { SIZES, isOneOf, type Size } from \"#shared/prop-vocabulary.ts\";\nimport { CONTROL_ID, FIELD_SLOTS, ValueControl, describedBy, fieldHint, fieldLabel, omitEmpty } from \"#shared/form-control.ts\";\nimport { SlotController } from \"#shared/controller.slot.ts\";\n\n/**\n * A one-line text field.\n *\n * <bd-input name=\"key\" spellcheck=\"false\" required>\n * <span slot=\"label\">Licence key</span>\n * <span slot=\"hint\">It is in the email we sent you.</span>\n * <bd-paste-button slot=\"end\" label=\"Paste from clipboard\"></bd-paste-button>\n * </bd-input>\n *\n * The label and the hint are the page's, in the `label` and `hint` slots, and\n * name and describe the native <input> through references that stay inside\n * this shadow root (shared/form-control.ts). The `end` slot sits over the\n * field's trailing edge, which is where 3.x's clipboard field drew its paste\n * button: that field is this one now, with a bd-paste-button the page writes\n * there.\n *\n * Form-associated (shared/form-control.ts): a <form> around it submits\n * name=value, resets it to its value attribute, holds an empty `required` one\n * and leaves it out under a <fieldset disabled>. It sends the native `input`\n * and `change`, with no detail; a listener reads event.target.value.\n */\n@defineElement(\"bd-input\")\nexport class BdInput extends ValueControl(LitElement) {\n static styles = [formFieldCSS, inputCSS];\n\n @property({ type: String })\n type = \"text\";\n @property({ type: String, reflect: true })\n size: Size = \"md\";\n @property({ type: String })\n placeholder = \"\";\n @property({ type: Boolean })\n required = false;\n @property({ type: Boolean, reflect: true })\n focused = false;\n @property({ type: Boolean })\n invalid = false;\n @property({ type: Boolean, reflect: true })\n validated = false;\n @property({ type: Boolean, reflect: true })\n disabled = false;\n /* The current value. The value ATTRIBUTE is the default a form reset\n returns to, as on a native input: the property does not reflect, so the\n attribute keeps what the page wrote. See ValueControl. */\n @property({ type: String })\n value = \"\";\n // reflected, because a form reads the name off the element\n @property({ type: String, reflect: true, converter: omitEmpty })\n name = \"\";\n // mobile keyboard controls — see the story\n @property({ type: String })\n inputmode = \"\";\n @property({ type: String })\n autocomplete = \"\";\n @property({ type: String })\n enterkeyhint = \"\";\n /* Passed to the <input>: a key or a code usually wants spellcheck=\"false\".\n The attribute is the global one, under its own name; the property is\n not, because HTMLElement already has a spellcheck, a boolean about the\n element itself. Named as fieldLabel is: what is passed to the field. */\n @property({ type: String, attribute: \"spellcheck\" })\n fieldSpellcheck: string | null = null;\n /* The field's name when there is no visible label: aria-label on the\n element is passed to the <input>, which is what a screen reader\n focuses -- on the element itself it named nothing. */\n @property({ type: String, attribute: \"aria-label\" })\n fieldLabel = \"\";\n\n protected _slots = new SlotController(this, { slots: [...FIELD_SLOTS, \"end\"], text: [\"label\"] });\n\n protected get _control(): HTMLInputElement | null {\n return this.renderRoot?.querySelector?.(\"input\");\n }\n\n /* With no label in the label slot, the <input> is named by aria-label on\n the element, or else by the text of a <label for> pointing at the element\n -- FACE gives the element its labels, but a label outside cannot name the\n <input> inside. Past both, the browser falls back on the placeholder. */\n get _accessibleName() {\n if (this._slots.has(\"label\")) return \"\";\n if (this.fieldLabel) return this.fieldLabel;\n return [...(this._internals.labels ?? [])].map(l => l.textContent!.trim()).filter(Boolean)\n .join(\" \");\n }\n\n /**\n * The value follows the <input> before anything hears of it. The native\n * input event is composed: it leaves the shadow root on its own, retargeted\n * to this element, and its listeners on the page run after this one, which\n * runs on the <input> itself -- so event.target.value is what was just\n * typed. It is not sent again; change is (shared/form-control.ts).\n */\n _onInput(e: Event & { target: HTMLInputElement }) {\n this.value = e.target.value;\n // before the event reaches the page, so a handler asking the form about\n // it gets the answer for what was just typed\n this._sync();\n }\n\n _onChange(e: Event & { target: HTMLInputElement }) {\n this.value = e.target.value;\n this._relayChange();\n }\n\n willUpdate(changed: PropertyValues<this>) {\n if (changed.has(\"size\") && !isOneOf(SIZES, this.size)) this.size = \"md\";\n }\n\n /* focused is the field's real focus, both ways. Setting it moves keyboard\n focus into the <input> and clearing it blurs the field; focusing or\n leaving the field by hand sets it, and it reflects, so the attribute says\n whether the field has focus. It used to add a .focused class that painted\n the focus ring on a field that did not have focus -- a second, false\n indicator on any page that set it. The ring is now only the browser's\n :focus-visible, which a text field shows whenever it is focused. */\n updated(changed: PropertyValues<this>) {\n this._sync();\n this._followFocused(changed);\n /* What sits in the end slot reads this field -- a bd-paste-button is\n disabled with it and described by its label -- and renders only when\n its own properties change. So it is told to look again whenever this\n field renders, which is when either can have moved. A few elements at\n most; nothing cascades back. */\n for (const el of this._slots.elements(\"end\")) (el as Partial<ReactiveElement>).requestUpdate?.();\n }\n\n _followFocused(changed: PropertyValues<this>) {\n if (!changed.has(\"focused\")) return;\n const input = this.shadowRoot!.querySelector(\"input\");\n const has = this.shadowRoot!.activeElement === input;\n if (this.focused && !has) input?.focus();\n if (!this.focused && has) input?.blur();\n }\n\n render() {\n const disabled = this.disabled || this._formDisabled;\n const inputStateClass = disabled\n ? \"form-input--disabled\"\n : this.invalid\n ? \"form-input--error\"\n : this.validated\n ? \"form-input--success\"\n : \"\";\n const tone = this.invalid ? \"error\" : this.validated ? \"success\" : \"default\";\n const end = this._slots.has(\"end\");\n\n // The hint is the field's description, and the state is announced, not\n // only drawn: invalid used to be a red border alone and the hint was never\n // pointed at, so the reason a field was invalid reached a screen reader\n // not at all.\n return html`\n <div class=\"input-container\">\n ${fieldLabel(this._slots, { size: this.size, required: this.required }, html`<slot name=\"label\"></slot>`)}\n <div class=\"control-row\">\n ${keyed(this._resets, html`<input\n id=${CONTROL_ID}\n part=\"input\"\n class=\"form-input-bd input-${this.size} ${inputStateClass} ${this._attempted ? \"form-input--attempted\" : \"\"} ${end ? \"form-input--with-end\" : \"\"}\"\n type=${this.type}\n name=${this.name || nothing}\n placeholder=${this.placeholder || nothing}\n .value=${this.value}\n inputmode=${this.inputmode || nothing}\n autocomplete=${this.autocomplete || nothing}\n spellcheck=${this.fieldSpellcheck ?? nothing}\n enterkeyhint=${this.enterkeyhint || nothing}\n ?required=${this.required}\n ?disabled=${disabled}\n aria-label=${this._accessibleName || nothing}\n aria-invalid=${this.invalid ? \"true\" : nothing}\n aria-describedby=${describedBy(this._slots)}\n @focus=${() => { this.focused = true; }}\n @blur=${() => { this.focused = false; }}\n @input=${this._onInput}\n @change=${this._onChange}\n @keydown=${this._onFieldKeydown}\n />`)}\n <span class=\"end\" part=\"end\" ?hidden=${!end}><slot name=\"end\"></slot></span>\n </div>\n ${fieldHint(this._slots, tone, html`<slot name=\"hint\"></slot>`)}\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"bd-input\": BdInput;\n }\n}\n"],"mappings":"A,4pBAkCO,IAAMK,EAAN,cAAsBC,EAAaC,CAAU,CAAC,AAAC,C,8BAI7C,KAAA,KAAA,OAEM,KAAA,KAAA,KAEC,KAAA,YAAA,GAEH,KAAA,SAAA,GAED,KAAA,QAAA,GAEA,KAAA,QAAA,GAEE,KAAA,UAAA,GAED,KAAA,SAAA,GAKH,KAAA,MAAA,GAGD,KAAA,KAAA,GAGK,KAAA,UAAA,GAEG,KAAA,aAAA,GAEA,KAAA,aAAA,GAMkB,KAAA,gBAAA,KAKpB,KAAA,WAAA,GAEM,KAAA,OAAA,IAAIE,EAAe,KAAM,CAAE,MAAO,CAAC,GAAGC,EAAa,KAAK,EAAG,KAAM,CAAC,OAAO,CAAE,CAAC,C,QA7C/E,KAAA,OAAA,CAACN,EAAcJ,CAAQ,C,CA+CvC,IAAc,UAAoC,CAChD,OAAO,KAAK,YAAY,gBAAgB,OAAO,CACjD,CAMA,IAAI,iBAAkB,CAGpB,OAFI,KAAK,OAAO,IAAI,OAAO,EAAU,GACjC,KAAK,WAAmB,KAAK,WAC1B,CAAC,GAAI,KAAK,WAAW,QAAU,CAAC,CAAE,CAAC,CAAC,IAAI,GAAKW,EAAE,YAAa,KAAK,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,CACvF,KAAK,GAAG,CACb,CASA,SAAS,EAAyC,CAChD,KAAK,MAAQ,EAAE,OAAO,MAGtB,KAAK,MAAM,CACb,CAEA,UAAU,EAAyC,CACjD,KAAK,MAAQ,EAAE,OAAO,MACtB,KAAK,aAAa,CACpB,CAEA,WAAW,EAA+B,CACpCC,EAAQ,IAAI,MAAM,GAAK,CAACC,EAAQC,EAAO,KAAK,IAAI,IAAG,KAAK,KAAO,KACr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AAA,EAAA,EAG9DJ,EAAA,CAAA2B,EAAS,CAAE,KAAM,MAAO,CAAC,CAAA,EAAAvB,EAAA,UAAA,YAAA,IAAA,EAAA,EAEzBJ,EAAA,CAAA2B,EAAS,CAAE,KAAM,MAAO,CAAC,CAAA,EAAAvB,EAAA,UAAA,eAAA,IAAA,EAAA,EAEzBJ,EAAA,CAAA2B,EAAS,CAAE,KAAM,MAAO,CAAC,CAAA,EAAAvB,EAAA,UAAA,eAAA,IAAA,EAAA,EAMzBJ,EAAA,CAAA2B,EAAS,CAAE,KAAM,OAAQ,UAAW,YAAa,CAAC,CAAA,EAAAvB,EAAA,UAAA,kBAAA,IAAA,EAAA,EAKlDJ,EAAA,CAAA2B,EAAS,CAAE,KAAM,OAAQ,UAAW,YAAa,CAAC,CAAA,EAAAvB,EAAA,UAAA,aAAA,IAAA,EAAA,EA5CpD,EAAAJ,EAAA,CAAA6B,EAAc,UAAU,CAAA,EAAAzB,CAAA,E"}
|
|
1
|
+
{"version":3,"file":"input.js","names":["inputCSS","_decorate","__decorate","input_css_default","formFieldCSS","BdInput","ValueControl","LitElement","_args","SlotController","FIELD_SLOTS","fieldName","changed","isOneOf","SIZES","el","input","has","disabled","inputStateClass","tone","end","fieldLabel","keyed","CONTROL_ID","nothing","describedBy","fieldHint","property","omitEmpty","defineElement"],"sources":["../../../../src/components/input/input.ts"],"sourcesContent":["import { LitElement, html, nothing, type PropertyValues, type ReactiveElement } from \"lit\";\nimport { property } from \"lit/decorators.js\";\nimport { keyed } from \"lit/directives/keyed.js\";\nimport { defineElement } from \"#shared/define-element.ts\";\n// Installs the design tokens into document scope; see src/tokens/tokens.ts\nimport \"#tokens/tokens.ts\";\nimport { formFieldCSS } from \"#shared/form-field.css.ts\";\nimport inputCSS from \"./input.css.ts\";\nimport { SIZES, isOneOf, type Size } from \"#shared/prop-vocabulary.ts\";\nimport { CONTROL_ID, FIELD_SLOTS, ValueControl, describedBy, fieldHint, fieldLabel, fieldName, omitEmpty } from \"#shared/form-control.ts\";\nimport { SlotController } from \"#shared/controller.slot.ts\";\n\n/**\n * A one-line text field.\n *\n * <bd-input name=\"key\" spellcheck=\"false\" required>\n * <span slot=\"label\">Licence key</span>\n * <span slot=\"hint\">It is in the email we sent you.</span>\n * <bd-paste-button slot=\"end\" label=\"Paste from clipboard\"></bd-paste-button>\n * </bd-input>\n *\n * The label and the hint are the page's, in the `label` and `hint` slots, and\n * name and describe the native <input> through references that stay inside\n * this shadow root (shared/form-control.ts). The `end` slot sits over the\n * field's trailing edge, which is where 3.x's clipboard field drew its paste\n * button: that field is this one now, with a bd-paste-button the page writes\n * there.\n *\n * Form-associated (shared/form-control.ts): a <form> around it submits\n * name=value, resets it to its value attribute, holds an empty `required` one\n * and leaves it out under a <fieldset disabled>. It sends the native `input`\n * and `change`, with no detail; a listener reads event.target.value.\n */\n@defineElement(\"bd-input\")\nexport class BdInput extends ValueControl(LitElement) {\n static styles = [formFieldCSS, inputCSS];\n\n @property({ type: String })\n type = \"text\";\n @property({ type: String, reflect: true })\n size: Size = \"md\";\n @property({ type: String })\n placeholder = \"\";\n @property({ type: Boolean })\n required = false;\n @property({ type: Boolean, reflect: true })\n focused = false;\n @property({ type: Boolean })\n invalid = false;\n @property({ type: Boolean, reflect: true })\n validated = false;\n @property({ type: Boolean, reflect: true })\n disabled = false;\n /* The current value. The value ATTRIBUTE is the default a form reset\n returns to, as on a native input: the property does not reflect, so the\n attribute keeps what the page wrote. See ValueControl. */\n @property({ type: String })\n value = \"\";\n // reflected, because a form reads the name off the element\n @property({ type: String, reflect: true, converter: omitEmpty })\n name = \"\";\n // mobile keyboard controls — see the story\n @property({ type: String })\n inputmode = \"\";\n @property({ type: String })\n autocomplete = \"\";\n @property({ type: String })\n enterkeyhint = \"\";\n /* Passed to the <input>: a key or a code usually wants spellcheck=\"false\".\n The attribute is the global one, under its own name; the property is\n not, because HTMLElement already has a spellcheck, a boolean about the\n element itself. Named as fieldLabel is: what is passed to the field. */\n @property({ type: String, attribute: \"spellcheck\" })\n fieldSpellcheck: string | null = null;\n /* The field's name when there is no visible label: aria-label on the\n element is passed to the <input>, which is what a screen reader\n focuses -- on the element itself it named nothing. */\n @property({ type: String, attribute: \"aria-label\" })\n fieldLabel = \"\";\n\n protected _slots = new SlotController(this, { slots: [...FIELD_SLOTS, \"end\"], text: [\"label\"] });\n\n protected get _control(): HTMLInputElement | null {\n return this.renderRoot?.querySelector?.(\"input\");\n }\n\n /* With no label in the label slot, the <input> is named by aria-label on\n the element, or else by the text of a <label for> pointing at the element\n (fieldName, shared/form-control.ts). Past both, the browser falls back on\n the placeholder. */\n get _accessibleName() {\n return fieldName(this._slots, this.fieldLabel, this._internals.labels);\n }\n\n /**\n * The value follows the <input> before anything hears of it. The native\n * input event is composed: it leaves the shadow root on its own, retargeted\n * to this element, and its listeners on the page run after this one, which\n * runs on the <input> itself -- so event.target.value is what was just\n * typed. It is not sent again; change is (shared/form-control.ts).\n */\n _onInput(e: Event & { target: HTMLInputElement }) {\n this.value = e.target.value;\n // before the event reaches the page, so a handler asking the form about\n // it gets the answer for what was just typed\n this._sync();\n }\n\n _onChange(e: Event & { target: HTMLInputElement }) {\n this.value = e.target.value;\n this._relayChange();\n }\n\n willUpdate(changed: PropertyValues<this>) {\n if (changed.has(\"size\") && !isOneOf(SIZES, this.size)) this.size = \"md\";\n }\n\n /* focused is the field's real focus, both ways. Setting it moves keyboard\n focus into the <input> and clearing it blurs the field; focusing or\n leaving the field by hand sets it, and it reflects, so the attribute says\n whether the field has focus. It used to add a .focused class that painted\n the focus ring on a field that did not have focus -- a second, false\n indicator on any page that set it. The ring is now only the browser's\n :focus-visible, which a text field shows whenever it is focused. */\n updated(changed: PropertyValues<this>) {\n this._sync();\n this._followFocused(changed);\n /* What sits in the end slot reads this field -- a bd-paste-button is\n disabled with it and described by its label -- and renders only when\n its own properties change. So it is told to look again whenever this\n field renders, which is when either can have moved. A few elements at\n most; nothing cascades back. */\n for (const el of this._slots.elements(\"end\")) (el as Partial<ReactiveElement>).requestUpdate?.();\n }\n\n _followFocused(changed: PropertyValues<this>) {\n if (!changed.has(\"focused\")) return;\n const input = this.shadowRoot!.querySelector(\"input\");\n const has = this.shadowRoot!.activeElement === input;\n if (this.focused && !has) input?.focus();\n if (!this.focused && has) input?.blur();\n }\n\n render() {\n const disabled = this.disabled || this._formDisabled;\n const inputStateClass = disabled\n ? \"form-input--disabled\"\n : this.invalid\n ? \"form-input--error\"\n : this.validated\n ? \"form-input--success\"\n : \"\";\n const tone = this.invalid ? \"error\" : this.validated ? \"success\" : \"default\";\n const end = this._slots.has(\"end\");\n\n // The hint is the field's description, and the state is announced, not\n // only drawn: invalid used to be a red border alone and the hint was never\n // pointed at, so the reason a field was invalid reached a screen reader\n // not at all.\n return html`\n <div class=\"input-container\">\n ${fieldLabel(this._slots, { size: this.size, required: this.required }, html`<slot name=\"label\"></slot>`)}\n <div class=\"control-row\">\n ${keyed(this._resets, html`<input\n id=${CONTROL_ID}\n part=\"input\"\n class=\"form-input-bd input-${this.size} ${inputStateClass} ${this._attempted ? \"form-input--attempted\" : \"\"} ${end ? \"form-input--with-end\" : \"\"}\"\n type=${this.type}\n name=${this.name || nothing}\n placeholder=${this.placeholder || nothing}\n .value=${this.value}\n inputmode=${this.inputmode || nothing}\n autocomplete=${this.autocomplete || nothing}\n spellcheck=${this.fieldSpellcheck ?? nothing}\n enterkeyhint=${this.enterkeyhint || nothing}\n ?required=${this.required}\n ?disabled=${disabled}\n aria-label=${this._accessibleName || nothing}\n aria-invalid=${this.invalid ? \"true\" : nothing}\n aria-describedby=${describedBy(this._slots)}\n @focus=${() => { this.focused = true; }}\n @blur=${() => { this.focused = false; }}\n @input=${this._onInput}\n @change=${this._onChange}\n @keydown=${this._onFieldKeydown}\n />`)}\n <span class=\"end\" part=\"end\" ?hidden=${!end}><slot name=\"end\"></slot></span>\n </div>\n ${fieldHint(this._slots, tone, html`<slot name=\"hint\"></slot>`)}\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementT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A,eAAA,IAAA,EAAA,EAMzBJ,EAAA,CAAA2B,EAAS,CAAE,KAAM,OAAQ,UAAW,YAAa,CAAC,CAAA,EAAAvB,EAAA,UAAA,kBAAA,IAAA,EAAA,EAKlDJ,EAAA,CAAA2B,EAAS,CAAE,KAAM,OAAQ,UAAW,YAAa,CAAC,CAAA,EAAAvB,EAAA,UAAA,aAAA,IAAA,EAAA,EA5CpD,EAAAJ,EAAA,CAAA6B,EAAc,UAAU,CAAA,EAAAzB,CAAA,E"}
|
|
@@ -22,6 +22,17 @@ import "../icons/play.js";
|
|
|
22
22
|
* still holds it. Under prefers-reduced-motion it never moves -- the set
|
|
23
23
|
* wraps in place instead, so nothing is hidden behind the fade -- and the
|
|
24
24
|
* button goes with the motion.
|
|
25
|
+
*
|
|
26
|
+
* `without-pause-button` leaves the button out, and that is the page's call,
|
|
27
|
+
* never the default: it takes away the one control that stops the motion,
|
|
28
|
+
* which WCAG 2.2.2 (Pause, Stop, Hide, level A) asks of anything that moves
|
|
29
|
+
* on its own for more than five seconds. What stays does not replace it. The
|
|
30
|
+
* pointer on the row holds it only while it is there, focus only if the row
|
|
31
|
+
* holds something focusable (a row of images holds nothing), and reduced
|
|
32
|
+
* motion only for a reader who has asked their system for it. `paused` still
|
|
33
|
+
* stops it, so a page that leaves the button out and stays within 2.2.2 gives
|
|
34
|
+
* the reader its own control that sets `paused`; without one, the row no
|
|
35
|
+
* longer meets 2.2.2.
|
|
25
36
|
*/
|
|
26
37
|
export declare class LogoMarquee extends LitElement {
|
|
27
38
|
label: string;
|
|
@@ -30,6 +41,9 @@ export declare class LogoMarquee extends LitElement {
|
|
|
30
41
|
paused: boolean;
|
|
31
42
|
pauseLabel: string;
|
|
32
43
|
playLabel: string;
|
|
44
|
+
/** No pause button: the page takes the WCAG 2.2.2 control away, and owns
|
|
45
|
+
stopping the motion from then on (see the class comment). */
|
|
46
|
+
withoutPauseButton: boolean;
|
|
33
47
|
_copies: number;
|
|
34
48
|
_resize: ResizeObserver;
|
|
35
49
|
_frame: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{spacing as e}from"../shared/token-scales.js";import{defineElement as t}from"../shared/define-element.js";import"../../tokens/tokens.js";import n from"../../_bundled/oxc-project_runtime/helpers/esm/decorate.js";import{ensembleCSS as r}from"../shared/ensemble.css.js";import"../button/button.js";import"../icons/pause.js";import"../icons/play.js";import{logoMarqueeCSS as i}from"./logo-marquee.css.js";import{LitElement as a,html as o}from"lit";import{property as
|
|
1
|
+
import{spacing as e}from"../shared/token-scales.js";import{defineElement as t}from"../shared/define-element.js";import"../../tokens/tokens.js";import n from"../../_bundled/oxc-project_runtime/helpers/esm/decorate.js";import{ensembleCSS as r}from"../shared/ensemble.css.js";import"../button/button.js";import"../icons/pause.js";import"../icons/play.js";import{logoMarqueeCSS as i}from"./logo-marquee.css.js";import{LitElement as a,html as o,nothing as s}from"lit";import{property as c,state as l}from"lit/decorators.js";var u=class extends a{static{this.styles=[r,i]}constructor(){super(),this.label=``,this.duration=35,this.gap=`48`,this.paused=!1,this.pauseLabel=`Pause the moving logos`,this.playLabel=`Play the moving logos`,this.withoutPauseButton=!1,this._copies=1,this._frame=0,this._resize=new ResizeObserver(()=>{cancelAnimationFrame(this._frame),this._frame=requestAnimationFrame(()=>this._measure())})}connectedCallback(){super.connectedCallback(),this.hasUpdated&&this._observe()}disconnectedCallback(){super.disconnectedCallback(),this._resize.disconnect(),cancelAnimationFrame(this._frame)}firstUpdated(){this._observe()}_observe(){this._resize.observe(this.renderRoot.querySelector(`.viewport`)),this._resize.observe(this.renderRoot.querySelector(`.group`))}_measure(){let e=this.renderRoot.querySelector(`.viewport`),t=this.renderRoot.querySelector(`.group`);if(!e||!t||!t.offsetWidth)return;let n=Math.max(1,Math.ceil(e.offsetWidth/t.offsetWidth));n!==this._copies&&(this._copies=n)}_onSlotChange(){this._fillCopies(),this._measure()}_fillCopies(){let e=this.renderRoot.querySelector(`slot`);if(!e)return;let t=e.assignedElements({flatten:!0});for(let e of this.renderRoot.querySelectorAll(`.copy`))e.replaceChildren(...t.map(e=>e.cloneNode(!0)))}updated(e){e.has(`_copies`)&&this._fillCopies()}_toggle(){this.paused=!this.paused}render(){let t=Array.from({length:this._copies});return o`
|
|
2
2
|
<section
|
|
3
3
|
class="bd-ensemble root"
|
|
4
4
|
aria-label="${this.label}"
|
|
@@ -10,12 +10,12 @@ import{spacing as e}from"../shared/token-scales.js";import{defineElement as t}fr
|
|
|
10
10
|
${t.map(()=>o`<div class="group copy" aria-hidden="true" inert></div>`)}
|
|
11
11
|
</div>
|
|
12
12
|
</div>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
${this.withoutPauseButton?s:o`<bd-button
|
|
14
|
+
class="toggle"
|
|
15
|
+
appearance="ghost"
|
|
16
|
+
size="sm"
|
|
17
|
+
@click=${this._toggle}
|
|
18
|
+
>${this.paused?o`<bd-icon name="play" size="sm" label="${this.playLabel}"></bd-icon>`:o`<bd-icon name="pause" size="sm" label="${this.pauseLabel}"></bd-icon>`}</bd-button>`}
|
|
19
19
|
</section>
|
|
20
|
-
`}};n([
|
|
20
|
+
`}};n([c({type:String})],u.prototype,`label`,void 0),n([c({type:Number})],u.prototype,`duration`,void 0),n([c({type:String})],u.prototype,`gap`,void 0),n([c({type:Boolean,reflect:!0})],u.prototype,`paused`,void 0),n([c({type:String,attribute:`pause-label`})],u.prototype,`pauseLabel`,void 0),n([c({type:String,attribute:`play-label`})],u.prototype,`playLabel`,void 0),n([c({type:Boolean,attribute:`without-pause-button`})],u.prototype,`withoutPauseButton`,void 0),n([l()],u.prototype,`_copies`,void 0),u=n([t(`bd-logo-marquee`)],u);export{u as LogoMarquee};
|
|
21
21
|
//# sourceMappingURL=logo-marquee.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logo-marquee.js","names":["_decorate","__decorate","LogoMarquee","LitElement","ensembleCSS","logoMarqueeCSS","viewport","group","copies","slot","items","copy","item","changed","spacing","property","state","defineElement"],"sources":["../../../../src/components/logo-marquee/logo-marquee.ts"],"sourcesContent":["import { LitElement, html, type PropertyValues } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\nimport { defineElement } from \"#shared/define-element.ts\";\n// Installs the design tokens into document scope; see src/tokens/tokens.ts\nimport \"#tokens/tokens.ts\";\nimport \"#components/button/button.ts\";\nimport \"#components/icons/pause.ts\";\nimport \"#components/icons/play.ts\";\nimport { ensembleCSS } from \"#shared/ensemble.css.ts\";\nimport { spacing } from \"#shared/token-scales.ts\";\nimport { logoMarqueeCSS } from \"./logo-marquee.css.ts\";\n\n/**\n * A row of logos sliding sideways behind an edge fade: the homepage's trusted\n * line (\"#1 most awarded\" and the partner marks) and the award strip under\n * Proven. Drawn in the foundation Figma file as Logo marquee.\n *\n * The logos are the page's: slot them as they are (an <img> with its width\n * and height, an icon, a label). To loop without a seam the row has to be\n * longer than the window, so this element clones the slotted set into its\n * own shadow root as many times as the width needs and moves the whole track\n * by one copy -- the jump back is then exactly one repeat, and invisible. The\n * copies are aria-hidden and inert: a screen reader reads the set once.\n *\n * It moves on its own for longer than five seconds, so it has a pause button\n * (WCAG 2.2.2): holding it on hover or focus was not enough, because the\n * logos are usually images and nothing in the row takes focus. The button\n * sets `paused`, which a page can also set. The pointer or focus on the row\n * still holds it. Under prefers-reduced-motion it never moves -- the set\n * wraps in place instead, so nothing is hidden behind the fade -- and the\n * button goes with the motion.\n */\n@defineElement(\"bd-logo-marquee\")\nexport class LogoMarquee extends LitElement {\n @property({ type: String })\n label = \"\";\n // seconds for one copy to pass: 35 for the partners and the awards alike\n @property({ type: Number })\n duration = 35;\n // a step on the spacing scale, between two logos\n @property({ type: String })\n gap = \"48\";\n @property({ type: Boolean, reflect: true })\n paused = false;\n @property({ type: String, attribute: \"pause-label\" })\n pauseLabel = \"Pause the moving logos\";\n @property({ type: String, attribute: \"play-label\" })\n playLabel = \"Play the moving logos\";\n // copies of the set after the original; at least one, or there is no loop\n @state()\n _copies = 1;\n\n _resize: ResizeObserver;\n _frame = 0;\n\n static styles = [ensembleCSS, logoMarqueeCSS];\n\n /* A resize is measured on the next frame, not inside the observer's\n delivery. A new copy count re-renders the track, and in WebKit that\n resizes a box this observer watches while the delivery is still running:\n Safari reported \"ResizeObserver loop completed with undelivered\n notifications\" on every homepage load. Measured a frame later, the new\n size is an ordinary delivery of its own. */\n constructor() {\n super();\n this._resize = new ResizeObserver(() => {\n cancelAnimationFrame(this._frame);\n this._frame = requestAnimationFrame(() => this._measure());\n });\n }\n\n connectedCallback() {\n super.connectedCallback();\n if (this.hasUpdated) this._observe();\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this._resize.disconnect();\n cancelAnimationFrame(this._frame);\n }\n\n firstUpdated() {\n this._observe();\n }\n\n _observe() {\n this._resize.observe(this.renderRoot.querySelector(\".viewport\")!);\n this._resize.observe(this.renderRoot.querySelector(\".group\")!);\n }\n\n /* One copy must cover the window on its own while the original slides out,\n so a set narrower than the window takes more than one. */\n _measure() {\n const viewport = this.renderRoot.querySelector<HTMLElement>(\".viewport\");\n const group = this.renderRoot.querySelector<HTMLElement>(\".group\");\n if (!viewport || !group || !group.offsetWidth) return;\n const copies = Math.max(1, Math.ceil(viewport.offsetWidth / group.offsetWidth));\n if (copies !== this._copies) this._copies = copies;\n }\n\n _onSlotChange() {\n this._fillCopies();\n this._measure();\n }\n\n _fillCopies() {\n const slot = this.renderRoot.querySelector(\"slot\");\n if (!slot) return;\n const items = slot.assignedElements({ flatten: true });\n for (const copy of this.renderRoot.querySelectorAll(\".copy\")) {\n copy.replaceChildren(...items.map(item => item.cloneNode(true)));\n }\n }\n\n updated(changed: PropertyValues<this>) {\n if (changed.has(\"_copies\")) this._fillCopies();\n }\n\n _toggle() {\n this.paused = !this.paused;\n }\n\n render() {\n const copies = Array.from({ length: this._copies });\n return html`\n <section\n class=\"bd-ensemble root\"\n aria-label=\"${this.label}\"\n style=\"--bd-logo-marquee-gap: ${spacing(this.gap) || \"var(--spacing-48)\"}; --bd-logo-marquee-duration: ${this.duration}s; --bd-logo-marquee-copies: ${this._copies + 1};\"\n >\n <div class=\"viewport\">\n <div class=\"track\">\n <div class=\"group\"><slot @slotchange=${this._onSlotChange}></slot></div>\n ${copies.map(() => html`<div class=\"group copy\" aria-hidden=\"true\" inert></div>`)}\n </div>\n </div>\n
|
|
1
|
+
{"version":3,"file":"logo-marquee.js","names":["_decorate","__decorate","LogoMarquee","LitElement","ensembleCSS","logoMarqueeCSS","viewport","group","copies","slot","items","copy","item","changed","spacing","nothing","property","state","defineElement"],"sources":["../../../../src/components/logo-marquee/logo-marquee.ts"],"sourcesContent":["import { LitElement, html, nothing, type PropertyValues } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\nimport { defineElement } from \"#shared/define-element.ts\";\n// Installs the design tokens into document scope; see src/tokens/tokens.ts\nimport \"#tokens/tokens.ts\";\nimport \"#components/button/button.ts\";\nimport \"#components/icons/pause.ts\";\nimport \"#components/icons/play.ts\";\nimport { ensembleCSS } from \"#shared/ensemble.css.ts\";\nimport { spacing } from \"#shared/token-scales.ts\";\nimport { logoMarqueeCSS } from \"./logo-marquee.css.ts\";\n\n/**\n * A row of logos sliding sideways behind an edge fade: the homepage's trusted\n * line (\"#1 most awarded\" and the partner marks) and the award strip under\n * Proven. Drawn in the foundation Figma file as Logo marquee.\n *\n * The logos are the page's: slot them as they are (an <img> with its width\n * and height, an icon, a label). To loop without a seam the row has to be\n * longer than the window, so this element clones the slotted set into its\n * own shadow root as many times as the width needs and moves the whole track\n * by one copy -- the jump back is then exactly one repeat, and invisible. The\n * copies are aria-hidden and inert: a screen reader reads the set once.\n *\n * It moves on its own for longer than five seconds, so it has a pause button\n * (WCAG 2.2.2): holding it on hover or focus was not enough, because the\n * logos are usually images and nothing in the row takes focus. The button\n * sets `paused`, which a page can also set. The pointer or focus on the row\n * still holds it. Under prefers-reduced-motion it never moves -- the set\n * wraps in place instead, so nothing is hidden behind the fade -- and the\n * button goes with the motion.\n *\n * `without-pause-button` leaves the button out, and that is the page's call,\n * never the default: it takes away the one control that stops the motion,\n * which WCAG 2.2.2 (Pause, Stop, Hide, level A) asks of anything that moves\n * on its own for more than five seconds. What stays does not replace it. The\n * pointer on the row holds it only while it is there, focus only if the row\n * holds something focusable (a row of images holds nothing), and reduced\n * motion only for a reader who has asked their system for it. `paused` still\n * stops it, so a page that leaves the button out and stays within 2.2.2 gives\n * the reader its own control that sets `paused`; without one, the row no\n * longer meets 2.2.2.\n */\n@defineElement(\"bd-logo-marquee\")\nexport class LogoMarquee extends LitElement {\n @property({ type: String })\n label = \"\";\n // seconds for one copy to pass: 35 for the partners and the awards alike\n @property({ type: Number })\n duration = 35;\n // a step on the spacing scale, between two logos\n @property({ type: String })\n gap = \"48\";\n @property({ type: Boolean, reflect: true })\n paused = false;\n @property({ type: String, attribute: \"pause-label\" })\n pauseLabel = \"Pause the moving logos\";\n @property({ type: String, attribute: \"play-label\" })\n playLabel = \"Play the moving logos\";\n /** No pause button: the page takes the WCAG 2.2.2 control away, and owns\n stopping the motion from then on (see the class comment). */\n @property({ type: Boolean, attribute: \"without-pause-button\" })\n withoutPauseButton = false;\n // copies of the set after the original; at least one, or there is no loop\n @state()\n _copies = 1;\n\n _resize: ResizeObserver;\n _frame = 0;\n\n static styles = [ensembleCSS, logoMarqueeCSS];\n\n /* A resize is measured on the next frame, not inside the observer's\n delivery. A new copy count re-renders the track, and in WebKit that\n resizes a box this observer watches while the delivery is still running:\n Safari reported \"ResizeObserver loop completed with undelivered\n notifications\" on every homepage load. Measured a frame later, the new\n size is an ordinary delivery of its own. */\n constructor() {\n super();\n this._resize = new ResizeObserver(() => {\n cancelAnimationFrame(this._frame);\n this._frame = requestAnimationFrame(() => this._measure());\n });\n }\n\n connectedCallback() {\n super.connectedCallback();\n if (this.hasUpdated) this._observe();\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this._resize.disconnect();\n cancelAnimationFrame(this._frame);\n }\n\n firstUpdated() {\n this._observe();\n }\n\n _observe() {\n this._resize.observe(this.renderRoot.querySelector(\".viewport\")!);\n this._resize.observe(this.renderRoot.querySelector(\".group\")!);\n }\n\n /* One copy must cover the window on its own while the original slides out,\n so a set narrower than the window takes more than one. */\n _measure() {\n const viewport = this.renderRoot.querySelector<HTMLElement>(\".viewport\");\n const group = this.renderRoot.querySelector<HTMLElement>(\".group\");\n if (!viewport || !group || !group.offsetWidth) return;\n const copies = Math.max(1, Math.ceil(viewport.offsetWidth / group.offsetWidth));\n if (copies !== this._copies) this._copies = copies;\n }\n\n _onSlotChange() {\n this._fillCopies();\n this._measure();\n }\n\n _fillCopies() {\n const slot = this.renderRoot.querySelector(\"slot\");\n if (!slot) return;\n const items = slot.assignedElements({ flatten: true });\n for (const copy of this.renderRoot.querySelectorAll(\".copy\")) {\n copy.replaceChildren(...items.map(item => item.cloneNode(true)));\n }\n }\n\n updated(changed: PropertyValues<this>) {\n if (changed.has(\"_copies\")) this._fillCopies();\n }\n\n _toggle() {\n this.paused = !this.paused;\n }\n\n render() {\n const copies = Array.from({ length: this._copies });\n return html`\n <section\n class=\"bd-ensemble root\"\n aria-label=\"${this.label}\"\n style=\"--bd-logo-marquee-gap: ${spacing(this.gap) || \"var(--spacing-48)\"}; --bd-logo-marquee-duration: ${this.duration}s; --bd-logo-marquee-copies: ${this._copies + 1};\"\n >\n <div class=\"viewport\">\n <div class=\"track\">\n <div class=\"group\"><slot @slotchange=${this._onSlotChange}></slot></div>\n ${copies.map(() => html`<div class=\"group copy\" aria-hidden=\"true\" inert></div>`)}\n </div>\n </div>\n ${this.withoutPauseButton\n ? nothing\n : html`<bd-button\n class=\"toggle\"\n appearance=\"ghost\"\n size=\"sm\"\n @click=${this._toggle}\n >${this.paused\n ? html`<bd-icon name=\"play\" size=\"sm\" label=\"${this.playLabel}\"></bd-icon>`\n : html`<bd-icon name=\"pause\" size=\"sm\" label=\"${this.pauseLabel}\"></bd-icon>`}</bd-button>`}\n </section>\n `;\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AAA,EAAA,EAEnDF,EAAA,CAAAgB,EAAS,CAAE,KAAM,OAAQ,UAAW,YAAa,CAAC,CAAA,EAAAd,EAAA,UAAA,YAAA,IAAA,EAAA,EAIlDF,EAAA,CAAAgB,EAAS,CAAE,KAAM,QAAS,UAAW,sBAAuB,CAAC,CAAA,EAAAd,EAAA,UAAA,qBAAA,IAAA,EAAA,EAG7DF,EAAA,CAAAiB,EAAM,CAAA,EAAAf,EAAA,UAAA,UAAA,IAAA,EAAA,EArBR,EAAAF,EAAA,CAAAkB,EAAc,iBAAiB,CAAA,EAAAhB,CAAA,E"}
|
|
@@ -32,6 +32,11 @@ declare const BdSelect_base: (new (...args: any[]) => import("../shared/form-con
|
|
|
32
32
|
* It is 3.x's bd-custom-dropdown, whose options were a JSON array attribute;
|
|
33
33
|
* the label and hint are slots, as on bd-input. It sends the native `input`
|
|
34
34
|
* and `change`, once each for a choice; a listener reads event.target.value.
|
|
35
|
+
*
|
|
36
|
+
* A select with no visible label is named by `aria-label` on the element,
|
|
37
|
+
* which is passed to the <select>, as on bd-input:
|
|
38
|
+
*
|
|
39
|
+
* <bd-select name="plan" aria-label="Plan">…</bd-select>
|
|
35
40
|
*/
|
|
36
41
|
export declare class BdSelect extends BdSelect_base {
|
|
37
42
|
static styles: import("lit").CSSResult[];
|
|
@@ -43,12 +48,14 @@ export declare class BdSelect extends BdSelect_base {
|
|
|
43
48
|
value: string;
|
|
44
49
|
name: string;
|
|
45
50
|
placeholder: string;
|
|
51
|
+
fieldLabel: string;
|
|
46
52
|
_open: boolean;
|
|
47
53
|
_onWindowFocus: () => void;
|
|
48
54
|
_onDocPointerDown: (e: PointerEvent) => void;
|
|
49
55
|
protected _slots: SlotController<"label" | "hint">;
|
|
50
56
|
protected _options: ObserverController<MutationObserver>;
|
|
51
57
|
protected get _control(): HTMLSelectElement | null;
|
|
58
|
+
get _accessibleName(): string;
|
|
52
59
|
/** The bd-select-option children, in order: the choices. */
|
|
53
60
|
get options(): BdSelectOption[];
|
|
54
61
|
get _choices(): Choice[];
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import{defineElement as e}from"../shared/define-element.js";import"../../tokens/tokens.js";import{SIZES as t,isOneOf as n}from"../shared/prop-vocabulary.js";import r from"../../_bundled/oxc-project_runtime/helpers/esm/decorate.js";import{ObserverController as i}from"../shared/controller.observer.js";import{flatText as a}from"../shared/flat-text.js";import{SlotController as o}from"../shared/controller.slot.js";import"../icons/arrow-down.js";import{CONTROL_ID as s,FIELD_SLOTS as c,ValueControl as l,describedBy as u,fieldHint as d,fieldLabel as f,omitEmpty as
|
|
1
|
+
import{defineElement as e}from"../shared/define-element.js";import"../../tokens/tokens.js";import{SIZES as t,isOneOf as n}from"../shared/prop-vocabulary.js";import r from"../../_bundled/oxc-project_runtime/helpers/esm/decorate.js";import{ObserverController as i}from"../shared/controller.observer.js";import{flatText as a}from"../shared/flat-text.js";import{SlotController as o}from"../shared/controller.slot.js";import"../icons/arrow-down.js";import{CONTROL_ID as s,FIELD_SLOTS as c,ValueControl as l,describedBy as u,fieldHint as d,fieldLabel as f,fieldName as p,omitEmpty as m}from"../shared/form-control.js";import h from"../shared/form-field.css.js";import"./select-option.js";import g from"./select.css.js";import{LitElement as _,html as v,nothing as y}from"lit";import{property as b,state as x}from"lit/decorators.js";import{keyed as S}from"lit/directives/keyed.js";var C={childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:[`value`,`selected`,`disabled`]},w=class extends l(_){constructor(...e){super(...e),this.size=`md`,this.required=!1,this.invalid=!1,this.validated=!1,this.disabled=!1,this.value=``,this.name=``,this.placeholder=``,this.fieldLabel=``,this._open=!1,this._slots=new o(this,{slots:c}),this._options=new i(this,()=>new MutationObserver(()=>this.requestUpdate()),e=>e.observe(this,C))}static{this.styles=[h,g]}get _control(){return this.renderRoot?.querySelector?.(`select`)}get _accessibleName(){return p(this._slots,this.fieldLabel,this._internals.labels)}get options(){return[...this.children].filter(e=>e.localName===`bd-select-option`)}get _choices(){return this.options.map(e=>{let t=a(e);return{value:e.getAttribute(`value`)??t,text:t,disabled:e.hasAttribute(`disabled`)}})}get _values(){return[...this.placeholder?[``]:[],...this._choices.map(e=>e.value)]}_defaultValue(){let e=this._values,t=this.getAttribute(`value`);if(t!==null&&e.includes(t))return t;let n=this._choices,r=this.options.findIndex(e=>e.hasAttribute(`selected`));return r>=0?n[r].value:this.placeholder?``:(n.find(e=>!e.disabled)??n[0])?.value??``}connectedCallback(){super.connectedCallback(),this._onWindowFocus=()=>{this._open&&=!1},this._onDocPointerDown=e=>{this._open&&e.composedPath()[0]!==this.shadowRoot?.querySelector(`select`)&&(this._open=!1)},window.addEventListener(`focus`,this._onWindowFocus),document.addEventListener(`pointerdown`,this._onDocPointerDown,!0),this.hasUpdated&&this.requestUpdate()}disconnectedCallback(){window.removeEventListener(`focus`,this._onWindowFocus),document.removeEventListener(`pointerdown`,this._onDocPointerDown,!0),super.disconnectedCallback()}_onSelectMouseDown(){this._open=!this._open}_onSelectKeyDown(e){(e.key===`Enter`||e.key===` `||e.altKey&&(e.key===`ArrowDown`||e.key===`ArrowUp`))&&(this._open=!0)}_closePicker(){this._open=!1}willUpdate(e){e.has(`size`)&&!n(t,this.size)&&(this.size=`md`),!this.hasUpdated&&this.value===``&&!this.hasAttribute(`value`)&&(this.value=this._defaultValue()),this._values.includes(this.value)||(this.value=this._defaultValue())}updated(){let e=this.shadowRoot.querySelector(`select`);e&&e.value!==this.value&&(e.value=this.value),this._sync()}_onInput(e){this.value=e.target.value,this._sync()}_onChange(e){this._closePicker(),this.value=e.target.value,this._relayChange()}render(){let e=this.disabled||this._formDisabled,t=e?`form-input--disabled`:this.invalid?`form-input--error`:this.validated?`form-input--success`:``,n=this.invalid?`error`:this.validated?`success`:`default`;return v`
|
|
2
2
|
<div class="input-container">
|
|
3
|
-
${f(this._slots,{size:this.size,required:this.required},
|
|
3
|
+
${f(this._slots,{size:this.size,required:this.required},v`<slot name="label"></slot>`)}
|
|
4
4
|
<div class="select-wrap">
|
|
5
|
-
${
|
|
5
|
+
${S(this._resets,v`<select
|
|
6
6
|
id=${s}
|
|
7
7
|
part="select"
|
|
8
8
|
class="form-input-bd input-${this.size} ${t} ${this._attempted?`form-input--attempted`:``} ${this.placeholder&&this.value===``?`form-input--placeholder`:``}"
|
|
9
|
-
name=${this.name||
|
|
9
|
+
name=${this.name||y}
|
|
10
10
|
?required=${this.required}
|
|
11
11
|
?disabled=${e}
|
|
12
|
-
aria-
|
|
12
|
+
aria-label=${this._accessibleName||y}
|
|
13
|
+
aria-invalid=${this.invalid?`true`:y}
|
|
13
14
|
aria-describedby=${u(this._slots)}
|
|
14
15
|
@mousedown=${this._onSelectMouseDown}
|
|
15
16
|
@keydown=${this._onSelectKeyDown}
|
|
@@ -17,8 +18,8 @@ import{defineElement as e}from"../shared/define-element.js";import"../../tokens/
|
|
|
17
18
|
@change=${this._onChange}
|
|
18
19
|
@blur=${this._closePicker}
|
|
19
20
|
>
|
|
20
|
-
${this.placeholder?
|
|
21
|
-
${this._choices.map(e=>
|
|
21
|
+
${this.placeholder?v`<option value="" ?selected=${this.value===``}>${this.placeholder}</option>`:y}
|
|
22
|
+
${this._choices.map(e=>v`<option
|
|
22
23
|
value=${e.value}
|
|
23
24
|
?selected=${e.value===this.value}
|
|
24
25
|
?disabled=${e.disabled}
|
|
@@ -29,7 +30,7 @@ import{defineElement as e}from"../shared/define-element.js";import"../../tokens/
|
|
|
29
30
|
class="select-caret ${this._open?`select-caret--open`:``}"
|
|
30
31
|
></bd-icon>
|
|
31
32
|
</div>
|
|
32
|
-
${d(this._slots,n,
|
|
33
|
+
${d(this._slots,n,v`<slot name="hint"></slot>`)}
|
|
33
34
|
</div>
|
|
34
|
-
`}};r([
|
|
35
|
+
`}};r([b({type:String,reflect:!0})],w.prototype,`size`,void 0),r([b({type:Boolean})],w.prototype,`required`,void 0),r([b({type:Boolean})],w.prototype,`invalid`,void 0),r([b({type:Boolean})],w.prototype,`validated`,void 0),r([b({type:Boolean,reflect:!0})],w.prototype,`disabled`,void 0),r([b({type:String})],w.prototype,`value`,void 0),r([b({type:String,reflect:!0,converter:m})],w.prototype,`name`,void 0),r([b({type:String})],w.prototype,`placeholder`,void 0),r([b({type:String,attribute:`aria-label`})],w.prototype,`fieldLabel`,void 0),r([x()],w.prototype,`_open`,void 0),w=r([e(`bd-select`)],w);export{w as BdSelect};
|
|
35
36
|
//# sourceMappingURL=select.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","names":["selectCSS","_decorate","__decorate","formFieldCSS","select_css_default","OPTIONS","BdSelect","ValueControl","LitElement","_args","SlotController","FIELD_SLOTS","ObserverController","observer","el","text","flatText","option","c","values","attribute","choices","selected","o","changed","isOneOf","SIZES","select","disabled","inputStateClass","tone","fieldLabel","keyed","CONTROL_ID","nothing","describedBy","choice","fieldHint","property","omitEmpty","state","defineElement"],"sources":["../../../../src/components/select/select.ts"],"sourcesContent":["import { LitElement, html, nothing, type PropertyValues } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\nimport { keyed } from \"lit/directives/keyed.js\";\nimport { defineElement } from \"#shared/define-element.ts\";\n// Installs the design tokens into document scope; see src/tokens/tokens.ts\nimport \"#tokens/tokens.ts\";\nimport \"#components/icons/arrow-down.ts\";\nimport { formFieldCSS } from \"#shared/form-field.css.ts\";\nimport selectCSS from \"./select.css.ts\";\nimport { SIZES, isOneOf, type Size } from \"#shared/prop-vocabulary.ts\";\nimport { CONTROL_ID, FIELD_SLOTS, ValueControl, describedBy, fieldHint, fieldLabel, omitEmpty } from \"#shared/form-control.ts\";\nimport { SlotController } from \"#shared/controller.slot.ts\";\nimport { ObserverController } from \"#shared/controller.observer.ts\";\nimport { flatText } from \"#shared/flat-text.ts\";\n// registers bd-select-option too: the ./select export is the pair\nimport \"./select-option.ts\";\nimport type { BdSelectOption } from \"./select-option.ts\";\n\n/* An option as the native <select> is handed it. */\ninterface Choice {\n value : string;\n text : string;\n disabled: boolean;\n}\n\n/* What the options say changed: one added or removed, its words edited, its\n value, selected or disabled set. */\nconst OPTIONS: MutationObserverInit = {\n childList : true,\n subtree : true,\n characterData : true,\n attributes : true,\n attributeFilter: [\"value\", \"selected\", \"disabled\"]\n};\n\n/**\n * A select: a native <select>, drawn as a field, whose options are the\n * bd-select-option children the page writes.\n *\n * <bd-select name=\"country\" placeholder=\"Choose a country\" required>\n * <span slot=\"label\">Country</span>\n * <span slot=\"hint\">Where the licence is used.</span>\n * <bd-select-option value=\"ro\" selected>Romania</bd-select-option>\n * <bd-select-option value=\"de\">Germany</bd-select-option>\n * </bd-select>\n *\n * The options are data, not slotted content: a native <select> takes only\n * <option>s of its own tree, so each bd-select-option becomes one, with the\n * option's words copied in (contract rule 8, docs/adr/0003-copy-in-light-dom.md)\n * and followed when the page edits them. Keeping the native control keeps the\n * operating system's own picker, its keyboard, and the browser's validation.\n *\n * It is 3.x's bd-custom-dropdown, whose options were a JSON array attribute;\n * the label and hint are slots, as on bd-input. It sends the native `input`\n * and `change`, once each for a choice; a listener reads event.target.value.\n */\n@defineElement(\"bd-select\")\nexport class BdSelect extends ValueControl(LitElement) {\n static styles = [formFieldCSS, selectCSS];\n\n @property({ type: String, reflect: true })\n size: Size = \"md\";\n @property({ type: Boolean })\n required = false;\n @property({ type: Boolean })\n invalid = false;\n @property({ type: Boolean })\n validated = false;\n /* Reflected, as on the other fields: a form-associated element is left\n out of a submit by its disabled ATTRIBUTE, so a disabled set as a\n property has to reach it. */\n @property({ type: Boolean, reflect: true })\n disabled = false;\n /* The chosen option's value. It always names an option that can be chosen:\n unset, or set to one that is not there, it is the default -- see\n _defaultValue. The value attribute, when there is one, is that default. */\n @property({ type: String })\n value = \"\";\n /* The name it submits under in a form; reflected, because a form reads it\n off the element. */\n @property({ type: String, reflect: true, converter: omitEmpty })\n name = \"\";\n /* A first option with no value, standing for \"nothing chosen yet\". It is\n what makes `required` mean anything here: a select is missing a value\n only while that option is the chosen one. Without it the first real\n option is chosen from the start, and required can never fail. */\n @property({ type: String })\n placeholder = \"\";\n /* Whether the native picker is showing. A best effort, not a fact: a\n <select> renders its popup in the OS, so the page is never told when it\n opens or closes. See _onSelectMouseDown. */\n @state()\n _open = false;\n\n _onWindowFocus! : () => void;\n _onDocPointerDown!: (e: PointerEvent) => void;\n\n protected _slots = new SlotController(this, { slots: FIELD_SLOTS });\n /* The options are not slotted, so no slotchange reports them: a mutation\n observer on the host does, for as long as it is connected. */\n protected _options = new ObserverController(this,\n () => new MutationObserver(() => this.requestUpdate()),\n observer => observer.observe(this, OPTIONS));\n\n protected get _control(): HTMLSelectElement | null {\n return this.renderRoot?.querySelector?.(\"select\");\n }\n\n /** The bd-select-option children, in order: the choices. */\n get options(): BdSelectOption[] {\n return [...this.children].filter((el): el is BdSelectOption => el.localName === \"bd-select-option\");\n }\n\n /* Each option as the <select> gets it. An option with no value is chosen\n by its words, as a native <option> is. */\n get _choices(): Choice[] {\n return this.options.map(option => {\n const text = flatText(option);\n return { value: option.getAttribute(\"value\") ?? text, text, disabled: option.hasAttribute(\"disabled\") };\n });\n }\n\n /** The values the select can hold, in order: the placeholder's, then the options'. */\n get _values() {\n return [...(this.placeholder ? [\"\"] : []), ...this._choices.map(c => c.value)];\n }\n\n /* What a reset returns to, and what an unset or unknown value lands on: the\n value attribute, when it names an option; else the first option marked\n `selected`, as on a native select; else the placeholder's, when there is\n one; else the first option that can be chosen -- a native select skips a\n disabled one there, or a form would submit a value nobody could pick --\n and only when every option is disabled, the first. */\n protected _defaultValue() {\n const values = this._values;\n const attribute = this.getAttribute(\"value\");\n if (attribute !== null && values.includes(attribute)) return attribute;\n const choices = this._choices;\n const selected = this.options.findIndex(o => o.hasAttribute(\"selected\"));\n if (selected >= 0) return choices[selected].value;\n if (this.placeholder) return \"\";\n return (choices.find(c => !c.disabled) ?? choices[0])?.value ?? \"\";\n }\n\n /* WHY THIS IS APPROXIMATED RATHER THAN OBSERVED.\n A native select's picker is drawn by the operating system, so there is no\n event for \"opened\" and no state to read. Chrome 152 does support\n `select:open` and a `toggle` event, but only for a CUSTOMIZABLE select\n (appearance: base-select) -- this field is appearance: none, and Safari and\n Firefox have neither, so a CSS-only answer does not ship.\n\n What is left is inference from the interactions that open a picker, plus\n every signal that proves one has CLOSED. Opening is easy; closing is where\n this gets hard, because dismissing a picker without choosing consumes the\n click inside the popup. The page never sees it and the select keeps focus,\n so `blur` does not arrive until the NEXT click somewhere -- which showed up\n as a chevron stuck pointing up. Hence three closing signals, not one:\n\n change a value was chosen\n blur focus left the field\n window focus the picker is a separate native window, so the browser\n window becomes key again when it closes. This is the\n one that catches dismiss-without-choosing.\n pointerdown anywhere outside this element, capture phase\n\n The last two can only ever fire when the picker is already shut, so they\n add no false closes. Escape remains unobservable on macOS, which does not\n deliver that keystroke to the page while the popup holds the keyboard; the\n window-focus signal covers it only if focus actually moved. */\n connectedCallback() {\n super.connectedCallback();\n this._onWindowFocus = () => { if (this._open) this._open = false; };\n this._onDocPointerDown = e => {\n if (this._open && e.composedPath()[0] !== this.shadowRoot?.querySelector(\"select\")) this._open = false;\n };\n window.addEventListener(\"focus\", this._onWindowFocus);\n document.addEventListener(\"pointerdown\", this._onDocPointerDown, true);\n // the options may have changed while it was out of the page, unobserved\n if (this.hasUpdated) this.requestUpdate();\n }\n\n disconnectedCallback() {\n window.removeEventListener(\"focus\", this._onWindowFocus);\n document.removeEventListener(\"pointerdown\", this._onDocPointerDown, true);\n super.disconnectedCallback();\n }\n\n _onSelectMouseDown() {\n /* clicking an open picker closes it, so this toggles rather than sets */\n this._open = !this._open;\n }\n\n _onSelectKeyDown(e: KeyboardEvent) {\n if (e.key === \"Enter\" || e.key === \" \" || (e.altKey && (e.key === \"ArrowDown\" || e.key === \"ArrowUp\"))) {\n this._open = true;\n }\n }\n\n _closePicker() {\n this._open = false;\n }\n\n willUpdate(changed: PropertyValues<this>) {\n if (changed.has(\"size\") && !isOneOf(SIZES, this.size)) this.size = \"md\";\n /* It starts on its default unless the page chose: a value attribute, or\n a value set from script before the first render. The placeholder's \"\"\n is also the property's own default, so it cannot say which. */\n if (!this.hasUpdated && this.value === \"\" && !this.hasAttribute(\"value\")) this.value = this._defaultValue();\n if (!this._values.includes(this.value)) this.value = this._defaultValue();\n }\n\n /* The select is told its value after its options exist. A binding on the\n <select> would be committed before the options inside it rendered, and\n an option's selected attribute stops counting once a visitor has chosen,\n so neither could move the selection when value is set from outside. */\n updated() {\n const select = this.shadowRoot!.querySelector(\"select\");\n if (select && select.value !== this.value) select.value = this.value;\n this._sync();\n }\n\n /* ONE CHOICE, ONE input AND ONE change.\n A select commits the moment an option is chosen, and the native control\n fires both. input is composed and reaches the page by itself, retargeted\n to this element; the value follows the <select> here first, on the\n <select> itself, so a listener on the page reads the new\n event.target.value. change is not composed, so it is sent again from the\n host (shared/form-control.ts). 3.x sent bd-input and bd-change instead,\n each with a { value, name } detail. */\n _onInput(e: Event & { target: HTMLSelectElement }) {\n this.value = e.target.value;\n this._sync();\n }\n\n _onChange(e: Event & { target: HTMLSelectElement }) {\n this._closePicker();\n this.value = e.target.value;\n this._relayChange();\n }\n\n render() {\n const disabled = this.disabled || this._formDisabled;\n const inputStateClass = disabled\n ? \"form-input--disabled\"\n : this.invalid\n ? \"form-input--error\"\n : this.validated\n ? \"form-input--success\"\n : \"\";\n const tone = this.invalid ? \"error\" : this.validated ? \"success\" : \"default\";\n\n // The hint is the select's description, and the state is announced, not\n // only drawn, as on bd-input.\n return html`\n <div class=\"input-container\">\n ${fieldLabel(this._slots, { size: this.size, required: this.required }, html`<slot name=\"label\"></slot>`)}\n <div class=\"select-wrap\">\n ${keyed(this._resets, html`<select\n id=${CONTROL_ID}\n part=\"select\"\n class=\"form-input-bd input-${this.size} ${inputStateClass} ${this._attempted ? \"form-input--attempted\" : \"\"} ${this.placeholder && this.value === \"\" ? \"form-input--placeholder\" : \"\"}\"\n name=${this.name || nothing}\n ?required=${this.required}\n ?disabled=${disabled}\n aria-invalid=${this.invalid ? \"true\" : nothing}\n aria-describedby=${describedBy(this._slots)}\n @mousedown=${this._onSelectMouseDown}\n @keydown=${this._onSelectKeyDown}\n @input=${this._onInput}\n @change=${this._onChange}\n @blur=${this._closePicker}\n >\n ${this.placeholder\n ? html`<option value=\"\" ?selected=${this.value === \"\"}>${this.placeholder}</option>`\n : nothing}\n ${this._choices.map(choice => html`<option\n value=${choice.value}\n ?selected=${choice.value === this.value}\n ?disabled=${choice.disabled}\n >${choice.text}</option>`)}\n </select>`)}\n <bd-icon name=\"arrow-down\"\n size=\"sm\"\n class=\"select-caret ${this._open ? \"select-caret--open\" : \"\"}\"\n ></bd-icon>\n </div>\n ${fieldHint(this._slots, tone, html`<slot name=\"hint\"></slot>`)}\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"bd-select\": BdSelect;\n }\n}\n"],"mappings":"A,01BA2BA,IAAMK,EAAgC,CACpC,UAAiB,GACjB,QAAiB,GACjB,cAAiB,GACjB,WAAiB,GACjB,gBAAiB,CAAC,QAAS,WAAY,UAAU,CACnD,EAwBaC,EAAN,cAAuBC,EAAaC,CAAU,CAAC,AAAC,C,8BAIxC,KAAA,KAAA,KAEF,KAAA,SAAA,GAED,KAAA,QAAA,GAEE,KAAA,UAAA,GAKD,KAAA,SAAA,GAKH,KAAA,MAAA,GAID,KAAA,KAAA,GAMO,KAAA,YAAA,GAKN,KAAA,MAAA,GAKW,KAAA,OAAA,IAAIE,EAAe,KAAM,CAAE,MAAOC,CAAY,CAAC,EAG7C,KAAA,SAAA,IAAIC,EAAmB,SACpC,IAAI,qBAAuB,KAAK,cAAc,CAAC,EACrD,GAAYC,EAAS,QAAQ,KAAMR,CAAO,CAAC,C,QA5C7B,KAAA,OAAA,CAACF,EAAcH,CAAS,C,CA8CxC,IAAc,UAAqC,CACjD,OAAO,KAAK,YAAY,gBAAgB,QAAQ,CAClD,CAGA,IAAI,SAA4B,CAC9B,MAAO,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,OAAQ,GAA6Bc,EAAG,YAAc,kBAAkB,CACpG,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AAA,UAAA,OAAA,IAAA,EAAA,EAM9DL,EAAA,CAAAqC,EAAS,CAAE,KAAM,MAAO,CAAC,CAAA,EAAAhC,EAAA,UAAA,cAAA,IAAA,EAAA,EAKzBL,EAAA,CAAAuC,EAAM,CAAA,EAAAlC,EAAA,UAAA,QAAA,IAAA,EAAA,EAnCR,EAAAL,EAAA,CAAAwC,EAAc,WAAW,CAAA,EAAAnC,CAAA,E"}
|
|
1
|
+
{"version":3,"file":"select.js","names":["selectCSS","_decorate","__decorate","formFieldCSS","select_css_default","OPTIONS","BdSelect","ValueControl","LitElement","_args","SlotController","FIELD_SLOTS","ObserverController","observer","fieldName","el","text","flatText","option","c","values","attribute","choices","selected","o","changed","isOneOf","SIZES","select","disabled","inputStateClass","tone","fieldLabel","keyed","CONTROL_ID","nothing","describedBy","choice","fieldHint","property","omitEmpty","state","defineElement"],"sources":["../../../../src/components/select/select.ts"],"sourcesContent":["import { LitElement, html, nothing, type PropertyValues } from \"lit\";\nimport { property, state } from \"lit/decorators.js\";\nimport { keyed } from \"lit/directives/keyed.js\";\nimport { defineElement } from \"#shared/define-element.ts\";\n// Installs the design tokens into document scope; see src/tokens/tokens.ts\nimport \"#tokens/tokens.ts\";\nimport \"#components/icons/arrow-down.ts\";\nimport { formFieldCSS } from \"#shared/form-field.css.ts\";\nimport selectCSS from \"./select.css.ts\";\nimport { SIZES, isOneOf, type Size } from \"#shared/prop-vocabulary.ts\";\nimport { CONTROL_ID, FIELD_SLOTS, ValueControl, describedBy, fieldHint, fieldLabel, fieldName, omitEmpty } from \"#shared/form-control.ts\";\nimport { SlotController } from \"#shared/controller.slot.ts\";\nimport { ObserverController } from \"#shared/controller.observer.ts\";\nimport { flatText } from \"#shared/flat-text.ts\";\n// registers bd-select-option too: the ./select export is the pair\nimport \"./select-option.ts\";\nimport type { BdSelectOption } from \"./select-option.ts\";\n\n/* An option as the native <select> is handed it. */\ninterface Choice {\n value : string;\n text : string;\n disabled: boolean;\n}\n\n/* What the options say changed: one added or removed, its words edited, its\n value, selected or disabled set. */\nconst OPTIONS: MutationObserverInit = {\n childList : true,\n subtree : true,\n characterData : true,\n attributes : true,\n attributeFilter: [\"value\", \"selected\", \"disabled\"]\n};\n\n/**\n * A select: a native <select>, drawn as a field, whose options are the\n * bd-select-option children the page writes.\n *\n * <bd-select name=\"country\" placeholder=\"Choose a country\" required>\n * <span slot=\"label\">Country</span>\n * <span slot=\"hint\">Where the licence is used.</span>\n * <bd-select-option value=\"ro\" selected>Romania</bd-select-option>\n * <bd-select-option value=\"de\">Germany</bd-select-option>\n * </bd-select>\n *\n * The options are data, not slotted content: a native <select> takes only\n * <option>s of its own tree, so each bd-select-option becomes one, with the\n * option's words copied in (contract rule 8, docs/adr/0003-copy-in-light-dom.md)\n * and followed when the page edits them. Keeping the native control keeps the\n * operating system's own picker, its keyboard, and the browser's validation.\n *\n * It is 3.x's bd-custom-dropdown, whose options were a JSON array attribute;\n * the label and hint are slots, as on bd-input. It sends the native `input`\n * and `change`, once each for a choice; a listener reads event.target.value.\n *\n * A select with no visible label is named by `aria-label` on the element,\n * which is passed to the <select>, as on bd-input:\n *\n * <bd-select name=\"plan\" aria-label=\"Plan\">…</bd-select>\n */\n@defineElement(\"bd-select\")\nexport class BdSelect extends ValueControl(LitElement) {\n static styles = [formFieldCSS, selectCSS];\n\n @property({ type: String, reflect: true })\n size: Size = \"md\";\n @property({ type: Boolean })\n required = false;\n @property({ type: Boolean })\n invalid = false;\n @property({ type: Boolean })\n validated = false;\n /* Reflected, as on the other fields: a form-associated element is left\n out of a submit by its disabled ATTRIBUTE, so a disabled set as a\n property has to reach it. */\n @property({ type: Boolean, reflect: true })\n disabled = false;\n /* The chosen option's value. It always names an option that can be chosen:\n unset, or set to one that is not there, it is the default -- see\n _defaultValue. The value attribute, when there is one, is that default. */\n @property({ type: String })\n value = \"\";\n /* The name it submits under in a form; reflected, because a form reads it\n off the element. */\n @property({ type: String, reflect: true, converter: omitEmpty })\n name = \"\";\n /* A first option with no value, standing for \"nothing chosen yet\". It is\n what makes `required` mean anything here: a select is missing a value\n only while that option is the chosen one. Without it the first real\n option is chosen from the start, and required can never fail. */\n @property({ type: String })\n placeholder = \"\";\n /* The select's name when there is no visible label: aria-label on the\n element is passed to the <select>, which is what a screen reader\n focuses -- on the element itself it named nothing. A name that never\n renders, so an attribute (contract rule 6, docs/adr/0003-copy-in-light-dom.md),\n and the same one bd-input takes. */\n @property({ type: String, attribute: \"aria-label\" })\n fieldLabel = \"\";\n /* Whether the native picker is showing. A best effort, not a fact: a\n <select> renders its popup in the OS, so the page is never told when it\n opens or closes. See _onSelectMouseDown. */\n @state()\n _open = false;\n\n _onWindowFocus! : () => void;\n _onDocPointerDown!: (e: PointerEvent) => void;\n\n protected _slots = new SlotController(this, { slots: FIELD_SLOTS });\n /* The options are not slotted, so no slotchange reports them: a mutation\n observer on the host does, for as long as it is connected. */\n protected _options = new ObserverController(this,\n () => new MutationObserver(() => this.requestUpdate()),\n observer => observer.observe(this, OPTIONS));\n\n protected get _control(): HTMLSelectElement | null {\n return this.renderRoot?.querySelector?.(\"select\");\n }\n\n /* With no label in the label slot, the <select> is named by aria-label on\n the element, or else by the text of a <label for> pointing at the element\n (fieldName, shared/form-control.ts). Past both it has no name. */\n get _accessibleName() {\n return fieldName(this._slots, this.fieldLabel, this._internals.labels);\n }\n\n /** The bd-select-option children, in order: the choices. */\n get options(): BdSelectOption[] {\n return [...this.children].filter((el): el is BdSelectOption => el.localName === \"bd-select-option\");\n }\n\n /* Each option as the <select> gets it. An option with no value is chosen\n by its words, as a native <option> is. */\n get _choices(): Choice[] {\n return this.options.map(option => {\n const text = flatText(option);\n return { value: option.getAttribute(\"value\") ?? text, text, disabled: option.hasAttribute(\"disabled\") };\n });\n }\n\n /** The values the select can hold, in order: the placeholder's, then the options'. */\n get _values() {\n return [...(this.placeholder ? [\"\"] : []), ...this._choices.map(c => c.value)];\n }\n\n /* What a reset returns to, and what an unset or unknown value lands on: the\n value attribute, when it names an option; else the first option marked\n `selected`, as on a native select; else the placeholder's, when there is\n one; else the first option that can be chosen -- a native select skips a\n disabled one there, or a form would submit a value nobody could pick --\n and only when every option is disabled, the first. */\n protected _defaultValue() {\n const values = this._values;\n const attribute = this.getAttribute(\"value\");\n if (attribute !== null && values.includes(attribute)) return attribute;\n const choices = this._choices;\n const selected = this.options.findIndex(o => o.hasAttribute(\"selected\"));\n if (selected >= 0) return choices[selected].value;\n if (this.placeholder) return \"\";\n return (choices.find(c => !c.disabled) ?? choices[0])?.value ?? \"\";\n }\n\n /* WHY THIS IS APPROXIMATED RATHER THAN OBSERVED.\n A native select's picker is drawn by the operating system, so there is no\n event for \"opened\" and no state to read. Chrome 152 does support\n `select:open` and a `toggle` event, but only for a CUSTOMIZABLE select\n (appearance: base-select) -- this field is appearance: none, and Safari and\n Firefox have neither, so a CSS-only answer does not ship.\n\n What is left is inference from the interactions that open a picker, plus\n every signal that proves one has CLOSED. Opening is easy; closing is where\n this gets hard, because dismissing a picker without choosing consumes the\n click inside the popup. The page never sees it and the select keeps focus,\n so `blur` does not arrive until the NEXT click somewhere -- which showed up\n as a chevron stuck pointing up. Hence three closing signals, not one:\n\n change a value was chosen\n blur focus left the field\n window focus the picker is a separate native window, so the browser\n window becomes key again when it closes. This is the\n one that catches dismiss-without-choosing.\n pointerdown anywhere outside this element, capture phase\n\n The last two can only ever fire when the picker is already shut, so they\n add no false closes. Escape remains unobservable on macOS, which does not\n deliver that keystroke to the page while the popup holds the keyboard; the\n window-focus signal covers it only if focus actually moved. */\n connectedCallback() {\n super.connectedCallback();\n this._onWindowFocus = () => { if (this._open) this._open = false; };\n this._onDocPointerDown = e => {\n if (this._open && e.composedPath()[0] !== this.shadowRoot?.querySelector(\"select\")) this._open = false;\n };\n window.addEventListener(\"focus\", this._onWindowFocus);\n document.addEventListener(\"pointerdown\", this._onDocPointerDown, true);\n // the options may have changed while it was out of the page, unobserved\n if (this.hasUpdated) this.requestUpdate();\n }\n\n disconnectedCallback() {\n window.removeEventListener(\"focus\", this._onWindowFocus);\n document.removeEventListener(\"pointerdown\", this._onDocPointerDown, true);\n super.disconnectedCallback();\n }\n\n _onSelectMouseDown() {\n /* clicking an open picker closes it, so this toggles rather than sets */\n this._open = !this._open;\n }\n\n _onSelectKeyDown(e: KeyboardEvent) {\n if (e.key === \"Enter\" || e.key === \" \" || (e.altKey && (e.key === \"ArrowDown\" || e.key === \"ArrowUp\"))) {\n this._open = true;\n }\n }\n\n _closePicker() {\n this._open = false;\n }\n\n willUpdate(changed: PropertyValues<this>) {\n if (changed.has(\"size\") && !isOneOf(SIZES, this.size)) this.size = \"md\";\n /* It starts on its default unless the page chose: a value attribute, or\n a value set from script before the first render. The placeholder's \"\"\n is also the property's own default, so it cannot say which. */\n if (!this.hasUpdated && this.value === \"\" && !this.hasAttribute(\"value\")) this.value = this._defaultValue();\n if (!this._values.includes(this.value)) this.value = this._defaultValue();\n }\n\n /* The select is told its value after its options exist. A binding on the\n <select> would be committed before the options inside it rendered, and\n an option's selected attribute stops counting once a visitor has chosen,\n so neither could move the selection when value is set from outside. */\n updated() {\n const select = this.shadowRoot!.querySelector(\"select\");\n if (select && select.value !== this.value) select.value = this.value;\n this._sync();\n }\n\n /* ONE CHOICE, ONE input AND ONE change.\n A select commits the moment an option is chosen, and the native control\n fires both. input is composed and reaches the page by itself, retargeted\n to this element; the value follows the <select> here first, on the\n <select> itself, so a listener on the page reads the new\n event.target.value. change is not composed, so it is sent again from the\n host (shared/form-control.ts). 3.x sent bd-input and bd-change instead,\n each with a { value, name } detail. */\n _onInput(e: Event & { target: HTMLSelectElement }) {\n this.value = e.target.value;\n this._sync();\n }\n\n _onChange(e: Event & { target: HTMLSelectElement }) {\n this._closePicker();\n this.value = e.target.value;\n this._relayChange();\n }\n\n render() {\n const disabled = this.disabled || this._formDisabled;\n const inputStateClass = disabled\n ? \"form-input--disabled\"\n : this.invalid\n ? \"form-input--error\"\n : this.validated\n ? \"form-input--success\"\n : \"\";\n const tone = this.invalid ? \"error\" : this.validated ? \"success\" : \"default\";\n\n // The hint is the select's description, and the state is announced, not\n // only drawn, as on bd-input.\n return html`\n <div class=\"input-container\">\n ${fieldLabel(this._slots, { size: this.size, required: this.required }, html`<slot name=\"label\"></slot>`)}\n <div class=\"select-wrap\">\n ${keyed(this._resets, html`<select\n id=${CONTROL_ID}\n part=\"select\"\n class=\"form-input-bd input-${this.size} ${inputStateClass} ${this._attempted ? \"form-input--attempted\" : \"\"} ${this.placeholder && this.value === \"\" ? \"form-input--placeholder\" : \"\"}\"\n name=${this.name || nothing}\n ?required=${this.required}\n ?disabled=${disabled}\n aria-label=${this._accessibleName || nothing}\n aria-invalid=${this.invalid ? \"true\" : nothing}\n aria-describedby=${describedBy(this._slots)}\n @mousedown=${this._onSelectMouseDown}\n @keydown=${this._onSelectKeyDown}\n @input=${this._onInput}\n @change=${this._onChange}\n @blur=${this._closePicker}\n >\n ${this.placeholder\n ? html`<option value=\"\" ?selected=${this.value === \"\"}>${this.placeholder}</option>`\n : nothing}\n ${this._choices.map(choice => html`<option\n value=${choice.value}\n ?selected=${choice.value === this.value}\n ?disabled=${choice.disabled}\n >${choice.text}</option>`)}\n </select>`)}\n <bd-icon name=\"arrow-down\"\n size=\"sm\"\n class=\"select-caret ${this._open ? \"select-caret--open\" : \"\"}\"\n ></bd-icon>\n </div>\n ${fieldHint(this._slots, tone, html`<slot name=\"hint\"></slot>`)}\n </div>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"bd-select\": BdSelect;\n }\n}\n"],"mappings":"A,y2BA2BA,IAAMK,EAAgC,CACpC,UAAiB,GACjB,QAAiB,GACjB,cAAiB,GACjB,WAAiB,GACjB,gBAAiB,CAAC,QAAS,WAAY,UAAU,CACnD,EA6BaC,EAAN,cAAuBC,EAAaC,CAAU,CAAC,AAAC,C,8BAIxC,KAAA,KAAA,KAEF,KAAA,SAAA,GAED,KAAA,QAAA,GAEE,KAAA,UAAA,GAKD,KAAA,SAAA,GAKH,KAAA,MAAA,GAID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,EAAA,CAAAsC,EAAS,CAAE,KAAM,OAAQ,CAAC,CAAA,EAAAjC,EAAA,UAAA,WAAA,IAAA,EAAA,EAE1BL,EAAA,CAAAsC,EAAS,CAAE,KAAM,OAAQ,CAAC,CAAA,EAAAjC,EAAA,UAAA,UAAA,IAAA,EAAA,EAE1BL,EAAA,CAAAsC,EAAS,CAAE,KAAM,OAAQ,CAAC,CAAA,EAAAjC,EAAA,UAAA,YAAA,IAAA,EAAA,EAK1BL,EAAA,CAAAsC,EAAS,CAAE,KAAM,QAAS,QAAS,EAAK,CAAC,CAAA,EAAAjC,EAAA,UAAA,WAAA,IAAA,EAAA,EAKzCL,EAAA,CAAAsC,EAAS,CAAE,KAAM,MAAO,CAAC,CAAA,EAAAjC,EAAA,UAAA,QAAA,IAAA,EAAA,EAIzBL,EAAA,CAAAsC,EAAS,CAAE,KAAM,OAAQ,QAAS,GAAM,UAAWC,CAAU,CAAC,CAAA,EAAAlC,EAAA,UAAA,OAAA,IAAA,EAAA,EAM9DL,EAAA,CAAAsC,EAAS,CAAE,KAAM,MAAO,CAAC,CAAA,EAAAjC,EAAA,UAAA,cAAA,IAAA,EAAA,EAOzBL,EAAA,CAAAsC,EAAS,CAAE,KAAM,OAAQ,UAAW,YAAa,CAAC,CAAA,EAAAjC,EAAA,UAAA,aAAA,IAAA,EAAA,EAKlDL,EAAA,CAAAwC,EAAM,CAAA,EAAAnC,EAAA,UAAA,QAAA,IAAA,EAAA,EA1CR,EAAAL,EAAA,CAAAyC,EAAc,WAAW,CAAA,EAAApC,CAAA,E"}
|
|
@@ -87,4 +87,12 @@ export declare function fieldLabel(slots: Slots, { size, required }: {
|
|
|
87
87
|
export declare function fieldHint(slots: Slots, tone: 'default' | 'error' | 'success', slot: TemplateResult): TemplateResult<1>;
|
|
88
88
|
/** The control's aria-describedby: the hint, while there is one. */
|
|
89
89
|
export declare const describedBy: (slots: Slots) => "hint" | typeof nothing;
|
|
90
|
+
/**
|
|
91
|
+
* The aria-label a field gives its native control: '' while the label slot
|
|
92
|
+
* holds something, else `label` (the field's `aria-label` attribute), else
|
|
93
|
+
* the words of the `<label for>`s pointing at the field.
|
|
94
|
+
*
|
|
95
|
+
* aria-label=${fieldName(this._slots, this.fieldLabel, this._internals.labels) || nothing}
|
|
96
|
+
*/
|
|
97
|
+
export declare function fieldName(slots: Slots, label: string, labels: NodeList | null | undefined): string;
|
|
90
98
|
export {};
|
|
@@ -8,5 +8,5 @@ import e from"../../_bundled/oxc-project_runtime/helpers/esm/decorate.js";import
|
|
|
8
8
|
part="hint"
|
|
9
9
|
class="form-help-text form-help-text--${n}"
|
|
10
10
|
?hidden=${!e.has(`hint`)}
|
|
11
|
-
>${r}</div>`}var p=e=>e.has(`hint`)?l:n;export{c as CONTROL_ID,u as FIELD_SLOTS,o as FormControl,l as HINT_ID,s as ValueControl,p as describedBy,f as fieldHint,d as fieldLabel,i as omitEmpty};
|
|
11
|
+
>${r}</div>`}var p=e=>e.has(`hint`)?l:n;function m(e,t,n){return e.has(`label`)?``:t||[...n??[]].map(e=>e.textContent.trim()).filter(Boolean).join(` `)}export{c as CONTROL_ID,u as FIELD_SLOTS,o as FormControl,l as HINT_ID,s as ValueControl,p as describedBy,f as fieldHint,d as fieldLabel,m as fieldName,i as omitEmpty};
|
|
12
12
|
//# sourceMappingURL=form-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-control.js","names":["__decorate","omitEmpty","value","BLOCKS_IMPLICIT_SUBMISSION","FormControl","FormControlElement","Base","args","r","form","elements","button","el","disabled","control","state","ValueControl","ValueControlElement","_args","CONTROL_ID","HINT_ID","FIELD_SLOTS","fieldLabel","size","slots","slot","required","nothing","fieldHint","tone","describedBy"],"sources":["../../../../src/components/shared/form-control.ts"],"sourcesContent":["import { html, nothing, type ComplexAttributeConverter, type LitElement, type TemplateResult } from 'lit';\nimport { state } from 'lit/decorators.js';\n\n/**\n * What makes a bd-* control take part in a <form>.\n *\n * Every control in this package renders its native element inside a shadow\n * root, and a native control there has no form owner: the <form> around the\n * element could not see it. A form submitted none of them, reset none of them\n * and let a required one through empty. Form-associated custom elements are\n * the platform's answer -- Baseline Widely available since 2023 -- so the\n * host joins the form itself through ElementInternals, the way the guide in\n * .claude/skills/modern-web-guidance/guides/html/form-associated-custom-elements.md\n * lays out, with no hidden input.\n *\n * This is the part every control shares: the opt-in, the internals, the\n * read-only surface a native control has (form, validity, checkValidity...),\n * and the two states a control cannot see from inside its shadow root -- a\n * <fieldset disabled> around it, and a submit that failed. What a control\n * submits, when it is valid and what reset puts back are its own.\n *\n * class BdThing extends FormControl(LitElement) { ... }\n */\n\n/* For `name`, which reflects: FACE submits under the host's name ATTRIBUTE, so\n a name set as a property -- what every framework binding does -- has to\n reach it. An empty name submits nothing either way, so it is left off the\n element rather than written as name=\"\" on every control on the page. */\nexport const omitEmpty: ComplexAttributeConverter<string> = { toAttribute: value => value || null };\n\n/* The input types that block implicit submission (HTML, \"implicit\n submission\"): a form with no submit button submits on Enter only while it\n has at most one field of these. A text field here says which type it is\n through its own `type`, so it is counted the same way. */\nconst BLOCKS_IMPLICIT_SUBMISSION = new Set<string | undefined>([\n 'text', 'search', 'url', 'tel', 'email', 'password', 'date', 'month', 'week', 'time',\n 'datetime-local', 'number'\n]);\n\n// Lit's mixin pattern: the class a mixin returns is typed by the declared\n// interfaces below, so its members reach the elements built on it without the\n// anonymous class itself leaking into the published declarations.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor<T = object> = new (...args: any[]) => T;\n\n/** The native element a control renders and stands in for. */\ntype NativeControl = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | HTMLButtonElement;\n\n/* The members a control's own code reaches are protected: they are how the\n elements built on the mixin talk to it, not part of what a page may call. */\nexport declare class FormControlInterface {\n protected _internals : ElementInternals;\n protected _formDisabled: boolean;\n protected _attempted : boolean;\n protected _fromOutside(e: MouseEvent): boolean;\n protected get _control(): NativeControl | null;\n protected _activate(): void;\n get form(): HTMLFormElement | null;\n get labels(): NodeList;\n get validity(): ValidityState;\n get validationMessage(): string;\n get willValidate(): boolean;\n checkValidity(): boolean;\n reportValidity(): boolean;\n protected _submitImplicitly(): void;\n protected _relayChange(): void;\n formDisabledCallback(disabled: boolean): void;\n formResetCallback(): void;\n protected _mirrorValidity(control: NativeControl | null | undefined): void;\n}\n\nexport declare class ValueControlInterface {\n protected _resets: number;\n value : string;\n protected _sync(): void;\n protected _defaultValue(): string;\n formStateRestoreCallback(state: string | File | FormData | null): void;\n protected _onFieldKeydown(e: KeyboardEvent): void;\n}\n\nexport const FormControl = <T extends Constructor<LitElement>>(Base: T) => {\n class FormControlElement extends Base {\n static formAssociated = true;\n\n /* Disabled as the form sees it: the control's own `disabled`, or a\n <fieldset disabled> it sits in. The platform reports both through\n formDisabledCallback. It is kept here and never written to the host's\n attribute, or a fieldset re-enabled later could not re-enable it. */\n @state() protected _formDisabled = false;\n /* A submit has been tried and found this control invalid. A native\n control turns :user-invalid then, but the native element in here has\n no form owner, so it never learns of the attempt; the `invalid` event\n the form fires at the host is how it hears. checkValidity() fires the\n same event, so a silent check counts too. Reset clears it. */\n @state() protected _attempted = false;\n protected _internals: ElementInternals;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- a mixin constructor must take any[]\n constructor(...args: any[]) {\n super(...args);\n this._internals = this.attachInternals();\n this.addEventListener('invalid', () => { this._attempted = true; });\n /* An outside activation is passed on to the native control, whose own\n click then reaches this element like any other. This one stops here, so\n a click listener on the element hears one click, not two -- one\n el.click() is one click on a native control. Registered in the\n constructor, it runs before any listener the page adds. */\n this.addEventListener('click', e => {\n if (e.composedPath()[0] !== this || !this._fromOutside(e)) return;\n e.stopImmediatePropagation();\n this._activate();\n });\n }\n\n /* A click on the host itself, not on anything inside it, is one of three\n things. A <label for> pointing at this element sends one carrying the\n label's position, and el.click() an untrusted one: the two ways a native\n control is activated from outside, and both activate this one. The third\n is a real click inside the host's own box but on nothing in it -- the\n slack beside a short label when a column stretches the host -- and that\n did nothing before and still does not, or a wide row would toggle from\n across the page. */\n protected _fromOutside(e: MouseEvent) {\n if (!e.isTrusted) return true;\n const r = this.getBoundingClientRect();\n return e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom;\n }\n\n /** The native element inside; each control says which. */\n protected get _control(): NativeControl | null {\n return null;\n }\n\n /** What an outside activation does: a field takes focus, a checkable control overrides this to toggle. */\n protected _activate() {\n this._control?.focus();\n }\n\n get form() { return this._internals.form; }\n get labels() { return this._internals.labels; }\n get validity() { return this._internals.validity; }\n get validationMessage() { return this._internals.validationMessage; }\n get willValidate() { return this._internals.willValidate; }\n checkValidity() { return this._internals.checkValidity(); }\n reportValidity() { return this._internals.reportValidity(); }\n\n /* Enter in a native text field, checkbox, radio or switch submits its\n form -- implicit submission: the form's default button is clicked, or,\n with none, the form is submitted, unless more than one of its fields\n blocks that (BLOCKS_IMPLICIT_SUBMISSION above). Enter never toggles;\n Space does. The native control in here has no form, so the host does it.\n The default button is the form's first submit button, and a bd-button\n with type=\"submit\" is one: it is in form.elements and its type says so.\n A disabled default button means no submission, as natively. */\n protected _submitImplicitly() {\n const form = this.form;\n if (!form) return;\n const elements = [...form.elements] as Array<HTMLElement & { type?: string }>;\n const button = elements.find(el => el.type === 'submit' || el.type === 'image');\n if (button) {\n if (!button.matches(':disabled')) button.click();\n return;\n }\n const blocking = elements.filter(el => BLOCKS_IMPLICIT_SUBMISSION.has(el.type)).length;\n if (blocking <= 1) form.requestSubmit();\n }\n\n /* THE NATIVE EVENTS, AND WHICH ONE HAS TO BE SENT AGAIN.\n A control sends what its native control sends -- `input` as the value\n moves, `change` when it is committed -- with no detail: a listener reads\n event.target.value, or .checked, off the element, as it would off an\n <input>. (3.x sent bd-input and bd-change with a detail; v4 drops both,\n N8 in docs/adr/0004-web-awesome-naming.md.)\n\n The two do not leave the shadow root alike. `input` is composed, so the\n native one already reaches the page, retargeted to this element, and is\n not sent again: a second would make one keystroke two events. `change`\n is not composed and stops at the shadow root, so the element sends its\n own, once, after its state has followed the native control's. Composed,\n as `input` is, so a form handler above an enclosing component's shadow\n root hears both. */\n protected _relayChange() {\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));\n }\n\n formDisabledCallback(disabled: boolean) {\n this._formDisabled = disabled;\n }\n\n formResetCallback() {\n this._attempted = false;\n }\n\n /* The native control already knows whether it is valid, and says so in the\n browser's own words and language, so the host repeats it rather than\n re-deriving it. The control is the anchor: reportValidity() and a failed\n submit focus it and point the message at it. A disabled control is out\n of validation altogether, and says so with an empty message that\n setValidity() would refuse; the host is disabled with it. */\n protected _mirrorValidity(control: NativeControl | null | undefined) {\n if (!control?.willValidate || control.validity.valid) {\n this._internals.setValidity({});\n } else {\n this._internals.setValidity(control.validity, control.validationMessage, control);\n }\n }\n }\n return FormControlElement as unknown as Constructor<FormControlInterface> & T;\n};\n\n/**\n * What a control holding a typed or chosen value adds to FormControl --\n * bd-input, bd-textarea and bd-select.\n *\n * The `value` property is the current value and the value ATTRIBUTE is the\n * default a reset returns to, as on a native field (bd-select also takes a\n * `selected` option; see _defaultValue there). A reset also rebuilds the\n * native control -- the subclass keys it on `_resets` -- because it has to\n * forget that the reader touched it (:user-invalid), and only the form it\n * belongs to could tell it that; the control in here has none.\n *\n * class BdField extends ValueControl(LitElement) { ... }\n */\nexport const ValueControl = <T extends Constructor<LitElement>>(Base: T) => {\n class ValueControlElement extends FormControl(Base) {\n @state() protected _resets = 0;\n declare value: string;\n\n /* What a form sees: the value, and whether the native control finds it\n valid -- required, type, and anything else it checks -- in its own\n words. Called after every update, and before a field's own events, so a\n handler asking the form gets the answer for what was just typed. */\n protected _sync() {\n this._internals.setFormValue(this.value);\n this._mirrorValidity(this._control);\n }\n\n /** What a reset returns to: the value attribute, as on a native field. */\n protected _defaultValue() {\n return this.getAttribute('value') ?? '';\n }\n\n formResetCallback() {\n super.formResetCallback();\n this.value = this._defaultValue();\n this._resets++;\n }\n\n formStateRestoreCallback(state: string | File | FormData | null) {\n this.value = state as string;\n }\n\n /* Enter in a one-line field submits its form, as from a native <input>.\n Not mid-composition: there Enter commits the IME's candidate. */\n protected _onFieldKeydown(e: KeyboardEvent) {\n if (e.key === 'Enter' && !e.isComposing) this._submitImplicitly();\n }\n }\n return ValueControlElement as unknown as Constructor<ValueControlInterface> & Constructor<FormControlInterface> & T;\n};\n\n/* ---------- the field's label and hint ----------\n bd-input, bd-select and bd-textarea draw one field: a label, the control\n and a hint under it. The copy is the page's, in two slots (contract rule 4,\n docs/adr/0003-copy-in-light-dom.md):\n\n <bd-input name=\"email\" type=\"email\" required>\n <span slot=\"label\">Email</span>\n <span slot=\"hint\">Where we send the licence.</span>\n </bd-input>\n\n Each slot is always rendered, and its wrapper hidden while it is empty, so\n an unlabelled field draws no label box and no gap.\n\n The names reach the control inside without copying any text. The label\n slot sits in the <label for> of the native control, and the hint slot in\n the box its aria-describedby names: both references stay inside this\n shadow root, and name computation reads the flattened tree, so the slotted\n words are the control's name and description. The description is only\n pointed at while the hint holds something -- an empty one would describe\n the field as nothing. ids are scoped to the shadow root, so fixed ones are\n safe.\n\n The wrappers are drawn here, once; each field writes its own <slot> into\n them, so the slots a component renders stay in its render, where\n check:manifest reads them:\n\n ${fieldLabel(this._slots, { size, required }, html`<slot name=\"label\"></slot>`)} */\n\n/** The id of the native control a field renders, which its <label for> names. */\nexport const CONTROL_ID = 'control';\n/** The id of the box around the hint slot, which aria-describedby names. */\nexport const HINT_ID = 'hint';\n/** The slots every field renders. */\nexport const FIELD_SLOTS = ['label', 'hint'] as const;\n\n/** What a field asks of the SlotController that follows its slots. */\ninterface Slots { has(name: string): boolean }\n\n/** The size step a field's label class is named for. */\ntype FieldSize = 'sm' | 'md' | 'lg';\n\n/** The field's label: its label slot, inside a <label for> the native control. */\nexport function fieldLabel(slots: Slots, { size, required }: { size: FieldSize; required: boolean }, slot: TemplateResult) {\n return html`<label\n for=${CONTROL_ID}\n part=\"label\"\n class=\"form-label label-${size}\"\n ?hidden=${!slots.has('label')}\n >${slot}${required\n ? html`<span class=\"form-label__required\" aria-hidden=\"true\">*</span>`\n : nothing}</label>`;\n}\n\n/** The field's hint: its hint slot, in the box the control is described by. */\nexport function fieldHint(slots: Slots, tone: 'default' | 'error' | 'success', slot: TemplateResult) {\n return html`<div\n id=${HINT_ID}\n part=\"hint\"\n class=\"form-help-text form-help-text--${tone}\"\n ?hidden=${!slots.has('hint')}\n >${slot}</div>`;\n}\n\n/** The control's aria-describedby: the hint, while there is one. */\nexport const describedBy = (slots: Slots) => (slots.has('hint') ? HINT_ID : nothing);\n"],"mappings":"A,4JA4BA,IAAaC,EAA+C,CAAE,YAAa,GAASC,GAAS,IAAK,EAM5FC,kBAA6B,IAAI,IAAwB,CAC7D,OAAQ,SAAU,MAAO,MAAO,QAAS,WAAY,OAAQ,QAAS,OAAQ,OAC9E,iBAAkB,QACpB,CAAC,EA2CYC,EAAkD,GAAY,CACzE,MAAMC,UAA2BC,CAAK,C,OACZ,KAAA,eAAA,E,CAgBxB,YAAY,GAAGC,EAAa,CAC1B,MAAM,GAAGA,CAAI,EAXoB,KAAA,cAAA,GAMH,KAAA,WAAA,GAM9B,KAAK,WAAa,KAAK,gBAAgB,EACvC,KAAK,iBAAiB,cAAiB,CAAE,KAAK,WAAa,EAAM,CAAC,EAMlE,KAAK,iBAAiB,QAAS,GAAK,CAC9B,EAAE,aAAa,CAAC,CAAC,KAAO,MAAS,KAAK,aAAa,CAAC,IACxD,EAAE,yBAAyB,EAC3B,KAAK,UAAU,EACjB,CAAC,CACH,CAUA,aAAuB,EAAe,CACpC,GAAI,CAAC,EAAE,UAAW,MAAO,GACzB,IAAMC,EAAI,KAAK,sBAAsB,EACrC,OAAO,EAAE,QAAUA,EAAE,MAAQ,EAAE,QAAUA,EAAE,OAAS,EAAE,QAAUA,EAAE,KAAO,EAAE,QAAUA,EAAE,MACzF,CAGA,IAAc,UAAiC,CAC7C,OAAO,IACT,CAGA,WAAsB,CACpB,KAAK,UAAU,MAAM,CACvB,CAEA,IAA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MC,UAA4Bb,EAAYE,CAAI,CAAC,AAAC,C,8BACrB,KAAA,QAAA,C,CAO7B,OAAkB,CAChB,KAAK,WAAW,aAAa,KAAK,KAAK,EACvC,KAAK,gBAAgB,KAAK,QAAQ,CACpC,CAGA,eAA0B,CACxB,OAAO,KAAK,aAAa,OAAO,GAAK,EACvC,CAEA,mBAAoB,CAClB,MAAM,kBAAkB,EACxB,KAAK,MAAQ,KAAK,cAAc,EAChC,KAAK,SACP,CAEA,yBAAyB,EAAwC,CAC/D,KAAK,MAAQS,CACf,CAIA,gBAA0B,EAAkB,CACtC,EAAE,MAAQ,SAAW,CAAC,EAAE,aAAa,KAAK,kBAAkB,CAClE,CACF,CACA,OAjCGf,EAAA,CAAAe,EAAM,CAAA,EAAAE,EAAA,UAAA,UAAA,IAAA,EAAA,EAiCFA,CACT,EA+BaE,EAAa,UAEbC,EAAU,OAEVC,EAAc,CAAC,QAAS,MAAM,EAS3C,SAAgBC,EAAW,EAAc,CAAE,OAAM,YAAoD,EAAsB,CACzH,MAAO,EAAI;UACHH,EAAW;;8BAESI,EAAK;cACrB,CAACC,EAAM,IAAI,OAAO,EAAE;KAC7BC,IAAOC,EACN,CAAI,iEACJC,EAAQ,SACd,CAGA,SAAgBC,EAAU,EAAc,EAAuC,EAAsB,CACnG,MAAO,EAAI;SACJR,EAAQ;;4CAE2BS,EAAK;cACnC,CAACL,EAAM,IAAI,MAAM,EAAE;KAC5BC,EAAK,OACV,CAGA,IAAaK,EAAe,GAAkBN,EAAM,IAAI,MAAM,EAAIJ,EAAUO,E"}
|
|
1
|
+
{"version":3,"file":"form-control.js","names":["__decorate","omitEmpty","value","BLOCKS_IMPLICIT_SUBMISSION","FormControl","FormControlElement","Base","args","r","form","elements","button","el","disabled","control","state","ValueControl","ValueControlElement","_args","CONTROL_ID","HINT_ID","FIELD_SLOTS","fieldLabel","size","slots","slot","required","nothing","fieldHint","tone","describedBy","fieldName","label","labels","l"],"sources":["../../../../src/components/shared/form-control.ts"],"sourcesContent":["import { html, nothing, type ComplexAttributeConverter, type LitElement, type TemplateResult } from 'lit';\nimport { state } from 'lit/decorators.js';\n\n/**\n * What makes a bd-* control take part in a <form>.\n *\n * Every control in this package renders its native element inside a shadow\n * root, and a native control there has no form owner: the <form> around the\n * element could not see it. A form submitted none of them, reset none of them\n * and let a required one through empty. Form-associated custom elements are\n * the platform's answer -- Baseline Widely available since 2023 -- so the\n * host joins the form itself through ElementInternals, the way the guide in\n * .claude/skills/modern-web-guidance/guides/html/form-associated-custom-elements.md\n * lays out, with no hidden input.\n *\n * This is the part every control shares: the opt-in, the internals, the\n * read-only surface a native control has (form, validity, checkValidity...),\n * and the two states a control cannot see from inside its shadow root -- a\n * <fieldset disabled> around it, and a submit that failed. What a control\n * submits, when it is valid and what reset puts back are its own.\n *\n * class BdThing extends FormControl(LitElement) { ... }\n */\n\n/* For `name`, which reflects: FACE submits under the host's name ATTRIBUTE, so\n a name set as a property -- what every framework binding does -- has to\n reach it. An empty name submits nothing either way, so it is left off the\n element rather than written as name=\"\" on every control on the page. */\nexport const omitEmpty: ComplexAttributeConverter<string> = { toAttribute: value => value || null };\n\n/* The input types that block implicit submission (HTML, \"implicit\n submission\"): a form with no submit button submits on Enter only while it\n has at most one field of these. A text field here says which type it is\n through its own `type`, so it is counted the same way. */\nconst BLOCKS_IMPLICIT_SUBMISSION = new Set<string | undefined>([\n 'text', 'search', 'url', 'tel', 'email', 'password', 'date', 'month', 'week', 'time',\n 'datetime-local', 'number'\n]);\n\n// Lit's mixin pattern: the class a mixin returns is typed by the declared\n// interfaces below, so its members reach the elements built on it without the\n// anonymous class itself leaking into the published declarations.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Constructor<T = object> = new (...args: any[]) => T;\n\n/** The native element a control renders and stands in for. */\ntype NativeControl = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | HTMLButtonElement;\n\n/* The members a control's own code reaches are protected: they are how the\n elements built on the mixin talk to it, not part of what a page may call. */\nexport declare class FormControlInterface {\n protected _internals : ElementInternals;\n protected _formDisabled: boolean;\n protected _attempted : boolean;\n protected _fromOutside(e: MouseEvent): boolean;\n protected get _control(): NativeControl | null;\n protected _activate(): void;\n get form(): HTMLFormElement | null;\n get labels(): NodeList;\n get validity(): ValidityState;\n get validationMessage(): string;\n get willValidate(): boolean;\n checkValidity(): boolean;\n reportValidity(): boolean;\n protected _submitImplicitly(): void;\n protected _relayChange(): void;\n formDisabledCallback(disabled: boolean): void;\n formResetCallback(): void;\n protected _mirrorValidity(control: NativeControl | null | undefined): void;\n}\n\nexport declare class ValueControlInterface {\n protected _resets: number;\n value : string;\n protected _sync(): void;\n protected _defaultValue(): string;\n formStateRestoreCallback(state: string | File | FormData | null): void;\n protected _onFieldKeydown(e: KeyboardEvent): void;\n}\n\nexport const FormControl = <T extends Constructor<LitElement>>(Base: T) => {\n class FormControlElement extends Base {\n static formAssociated = true;\n\n /* Disabled as the form sees it: the control's own `disabled`, or a\n <fieldset disabled> it sits in. The platform reports both through\n formDisabledCallback. It is kept here and never written to the host's\n attribute, or a fieldset re-enabled later could not re-enable it. */\n @state() protected _formDisabled = false;\n /* A submit has been tried and found this control invalid. A native\n control turns :user-invalid then, but the native element in here has\n no form owner, so it never learns of the attempt; the `invalid` event\n the form fires at the host is how it hears. checkValidity() fires the\n same event, so a silent check counts too. Reset clears it. */\n @state() protected _attempted = false;\n protected _internals: ElementInternals;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- a mixin constructor must take any[]\n constructor(...args: any[]) {\n super(...args);\n this._internals = this.attachInternals();\n this.addEventListener('invalid', () => { this._attempted = true; });\n /* An outside activation is passed on to the native control, whose own\n click then reaches this element like any other. This one stops here, so\n a click listener on the element hears one click, not two -- one\n el.click() is one click on a native control. Registered in the\n constructor, it runs before any listener the page adds. */\n this.addEventListener('click', e => {\n if (e.composedPath()[0] !== this || !this._fromOutside(e)) return;\n e.stopImmediatePropagation();\n this._activate();\n });\n }\n\n /* A click on the host itself, not on anything inside it, is one of three\n things. A <label for> pointing at this element sends one carrying the\n label's position, and el.click() an untrusted one: the two ways a native\n control is activated from outside, and both activate this one. The third\n is a real click inside the host's own box but on nothing in it -- the\n slack beside a short label when a column stretches the host -- and that\n did nothing before and still does not, or a wide row would toggle from\n across the page. */\n protected _fromOutside(e: MouseEvent) {\n if (!e.isTrusted) return true;\n const r = this.getBoundingClientRect();\n return e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom;\n }\n\n /** The native element inside; each control says which. */\n protected get _control(): NativeControl | null {\n return null;\n }\n\n /** What an outside activation does: a field takes focus, a checkable control overrides this to toggle. */\n protected _activate() {\n this._control?.focus();\n }\n\n get form() { return this._internals.form; }\n get labels() { return this._internals.labels; }\n get validity() { return this._internals.validity; }\n get validationMessage() { return this._internals.validationMessage; }\n get willValidate() { return this._internals.willValidate; }\n checkValidity() { return this._internals.checkValidity(); }\n reportValidity() { return this._internals.reportValidity(); }\n\n /* Enter in a native text field, checkbox, radio or switch submits its\n form -- implicit submission: the form's default button is clicked, or,\n with none, the form is submitted, unless more than one of its fields\n blocks that (BLOCKS_IMPLICIT_SUBMISSION above). Enter never toggles;\n Space does. The native control in here has no form, so the host does it.\n The default button is the form's first submit button, and a bd-button\n with type=\"submit\" is one: it is in form.elements and its type says so.\n A disabled default button means no submission, as natively. */\n protected _submitImplicitly() {\n const form = this.form;\n if (!form) return;\n const elements = [...form.elements] as Array<HTMLElement & { type?: string }>;\n const button = elements.find(el => el.type === 'submit' || el.type === 'image');\n if (button) {\n if (!button.matches(':disabled')) button.click();\n return;\n }\n const blocking = elements.filter(el => BLOCKS_IMPLICIT_SUBMISSION.has(el.type)).length;\n if (blocking <= 1) form.requestSubmit();\n }\n\n /* THE NATIVE EVENTS, AND WHICH ONE HAS TO BE SENT AGAIN.\n A control sends what its native control sends -- `input` as the value\n moves, `change` when it is committed -- with no detail: a listener reads\n event.target.value, or .checked, off the element, as it would off an\n <input>. (3.x sent bd-input and bd-change with a detail; v4 drops both,\n N8 in docs/adr/0004-web-awesome-naming.md.)\n\n The two do not leave the shadow root alike. `input` is composed, so the\n native one already reaches the page, retargeted to this element, and is\n not sent again: a second would make one keystroke two events. `change`\n is not composed and stops at the shadow root, so the element sends its\n own, once, after its state has followed the native control's. Composed,\n as `input` is, so a form handler above an enclosing component's shadow\n root hears both. */\n protected _relayChange() {\n this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));\n }\n\n formDisabledCallback(disabled: boolean) {\n this._formDisabled = disabled;\n }\n\n formResetCallback() {\n this._attempted = false;\n }\n\n /* The native control already knows whether it is valid, and says so in the\n browser's own words and language, so the host repeats it rather than\n re-deriving it. The control is the anchor: reportValidity() and a failed\n submit focus it and point the message at it. A disabled control is out\n of validation altogether, and says so with an empty message that\n setValidity() would refuse; the host is disabled with it. */\n protected _mirrorValidity(control: NativeControl | null | undefined) {\n if (!control?.willValidate || control.validity.valid) {\n this._internals.setValidity({});\n } else {\n this._internals.setValidity(control.validity, control.validationMessage, control);\n }\n }\n }\n return FormControlElement as unknown as Constructor<FormControlInterface> & T;\n};\n\n/**\n * What a control holding a typed or chosen value adds to FormControl --\n * bd-input, bd-textarea and bd-select.\n *\n * The `value` property is the current value and the value ATTRIBUTE is the\n * default a reset returns to, as on a native field (bd-select also takes a\n * `selected` option; see _defaultValue there). A reset also rebuilds the\n * native control -- the subclass keys it on `_resets` -- because it has to\n * forget that the reader touched it (:user-invalid), and only the form it\n * belongs to could tell it that; the control in here has none.\n *\n * class BdField extends ValueControl(LitElement) { ... }\n */\nexport const ValueControl = <T extends Constructor<LitElement>>(Base: T) => {\n class ValueControlElement extends FormControl(Base) {\n @state() protected _resets = 0;\n declare value: string;\n\n /* What a form sees: the value, and whether the native control finds it\n valid -- required, type, and anything else it checks -- in its own\n words. Called after every update, and before a field's own events, so a\n handler asking the form gets the answer for what was just typed. */\n protected _sync() {\n this._internals.setFormValue(this.value);\n this._mirrorValidity(this._control);\n }\n\n /** What a reset returns to: the value attribute, as on a native field. */\n protected _defaultValue() {\n return this.getAttribute('value') ?? '';\n }\n\n formResetCallback() {\n super.formResetCallback();\n this.value = this._defaultValue();\n this._resets++;\n }\n\n formStateRestoreCallback(state: string | File | FormData | null) {\n this.value = state as string;\n }\n\n /* Enter in a one-line field submits its form, as from a native <input>.\n Not mid-composition: there Enter commits the IME's candidate. */\n protected _onFieldKeydown(e: KeyboardEvent) {\n if (e.key === 'Enter' && !e.isComposing) this._submitImplicitly();\n }\n }\n return ValueControlElement as unknown as Constructor<ValueControlInterface> & Constructor<FormControlInterface> & T;\n};\n\n/* ---------- the field's label and hint ----------\n bd-input, bd-select and bd-textarea draw one field: a label, the control\n and a hint under it. The copy is the page's, in two slots (contract rule 4,\n docs/adr/0003-copy-in-light-dom.md):\n\n <bd-input name=\"email\" type=\"email\" required>\n <span slot=\"label\">Email</span>\n <span slot=\"hint\">Where we send the licence.</span>\n </bd-input>\n\n Each slot is always rendered, and its wrapper hidden while it is empty, so\n an unlabelled field draws no label box and no gap.\n\n The names reach the control inside without copying any text. The label\n slot sits in the <label for> of the native control, and the hint slot in\n the box its aria-describedby names: both references stay inside this\n shadow root, and name computation reads the flattened tree, so the slotted\n words are the control's name and description. The description is only\n pointed at while the hint holds something -- an empty one would describe\n the field as nothing. ids are scoped to the shadow root, so fixed ones are\n safe.\n\n The wrappers are drawn here, once; each field writes its own <slot> into\n them, so the slots a component renders stay in its render, where\n check:manifest reads them:\n\n ${fieldLabel(this._slots, { size, required }, html`<slot name=\"label\"></slot>`)} */\n\n/** The id of the native control a field renders, which its <label for> names. */\nexport const CONTROL_ID = 'control';\n/** The id of the box around the hint slot, which aria-describedby names. */\nexport const HINT_ID = 'hint';\n/** The slots every field renders. */\nexport const FIELD_SLOTS = ['label', 'hint'] as const;\n\n/** What a field asks of the SlotController that follows its slots. */\ninterface Slots { has(name: string): boolean }\n\n/** The size step a field's label class is named for. */\ntype FieldSize = 'sm' | 'md' | 'lg';\n\n/** The field's label: its label slot, inside a <label for> the native control. */\nexport function fieldLabel(slots: Slots, { size, required }: { size: FieldSize; required: boolean }, slot: TemplateResult) {\n return html`<label\n for=${CONTROL_ID}\n part=\"label\"\n class=\"form-label label-${size}\"\n ?hidden=${!slots.has('label')}\n >${slot}${required\n ? html`<span class=\"form-label__required\" aria-hidden=\"true\">*</span>`\n : nothing}</label>`;\n}\n\n/** The field's hint: its hint slot, in the box the control is described by. */\nexport function fieldHint(slots: Slots, tone: 'default' | 'error' | 'success', slot: TemplateResult) {\n return html`<div\n id=${HINT_ID}\n part=\"hint\"\n class=\"form-help-text form-help-text--${tone}\"\n ?hidden=${!slots.has('hint')}\n >${slot}</div>`;\n}\n\n/** The control's aria-describedby: the hint, while there is one. */\nexport const describedBy = (slots: Slots) => (slots.has('hint') ? HINT_ID : nothing);\n\n/* A field with no visible label still needs a name, and the two ways a page\n gives one without drawing it reach the host, not the native control a\n screen reader focuses: aria-label on the host names nothing there, and a\n <label for> outside the shadow root cannot name the control inside it --\n FACE hands the host its labels, nothing more. So the field passes either\n on, as the control's own aria-label. The label slot wins: while it holds\n something, the <label for> above already names the control, and a second\n source for the name could only disagree with the words on the screen. */\n\n/**\n * The aria-label a field gives its native control: '' while the label slot\n * holds something, else `label` (the field's `aria-label` attribute), else\n * the words of the `<label for>`s pointing at the field.\n *\n * aria-label=${fieldName(this._slots, this.fieldLabel, this._internals.labels) || nothing}\n */\nexport function fieldName(slots: Slots, label: string, labels: NodeList | null | undefined) {\n if (slots.has('label')) return '';\n if (label) return label;\n return [...(labels ?? [])].map(l => l.textContent!.trim()).filter(Boolean)\n .join(' ');\n}\n"],"mappings":"A,4JA4BA,IAAaC,EAA+C,CAAE,YAAa,GAASC,GAAS,IAAK,EAM5FC,kBAA6B,IAAI,IAAwB,CAC7D,OAAQ,SAAU,MAAO,MAAO,QAAS,WAAY,OAAQ,QAAS,OAAQ,OAC9E,iBAAkB,QACpB,CAAC,EA2CYC,EAAkD,GAAY,CACzE,MAAMC,UAA2BC,CAAK,C,OACZ,KAAA,eA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EAAc,CAAE,OAAM,YAAoD,EAAsB,CACzH,MAAO,EAAI;UACHH,EAAW;;8BAESI,EAAK;cACrB,CAACC,EAAM,IAAI,OAAO,EAAE;KAC7BC,IAAOC,EACN,CAAI,iEACJC,EAAQ,SACd,CAGA,SAAgBC,EAAU,EAAc,EAAuC,EAAsB,CACnG,MAAO,EAAI;SACJR,EAAQ;;4CAE2BS,EAAK;cACnC,CAACL,EAAM,IAAI,MAAM,EAAE;KAC5BC,EAAK,OACV,CAGA,IAAaK,EAAe,GAAkBN,EAAM,IAAI,MAAM,EAAIJ,EAAUO,EAkB5E,SAAgBI,EAAU,EAAc,EAAe,EAAqC,CAG1F,OAFIP,EAAM,IAAI,OAAO,EAAU,GAC3BQ,GACG,CAAC,GAAIC,GAAU,CAAC,CAAE,CAAC,CAAC,IAAI,GAAKC,EAAE,YAAa,KAAK,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,CACvE,KAAK,GAAG,CACb,C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repobit/dex-system-design",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Design system based on Web Components.",
|
|
5
5
|
"author": "Iordache Matei Cezar <miordache@bitdefender.com>",
|
|
6
6
|
"homepage": "https://github.com/bitdefender/dex-core#readme",
|
|
@@ -490,5 +490,5 @@
|
|
|
490
490
|
"volta": {
|
|
491
491
|
"node": "24.22.1"
|
|
492
492
|
},
|
|
493
|
-
"gitHead": "
|
|
493
|
+
"gitHead": "197e395aa71b084cbe5d20e04e58a405ae730302"
|
|
494
494
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifestVersion": 1,
|
|
3
3
|
"package": "@repobit/dex-system-design",
|
|
4
|
-
"packageVersion": "4.
|
|
4
|
+
"packageVersion": "4.1.0",
|
|
5
5
|
"generatedFrom": [
|
|
6
6
|
"package.json exports",
|
|
7
7
|
"Lit reactive properties (static properties or @property/@state)",
|
|
@@ -1112,6 +1112,12 @@
|
|
|
1112
1112
|
"name": "name",
|
|
1113
1113
|
"type": "string",
|
|
1114
1114
|
"description": "The name it submits under in a form: the element is form-associated, so a <form> around it submits name=value."
|
|
1115
|
+
},
|
|
1116
|
+
{
|
|
1117
|
+
"name": "fieldLabel",
|
|
1118
|
+
"type": "string",
|
|
1119
|
+
"attributeName": "aria-label",
|
|
1120
|
+
"description": "The select's accessible name when the label slot is empty: aria-label on the element is passed to the <select>. Without either, a <label for> pointing at the element names it. For a select whose label is elsewhere on the page."
|
|
1115
1121
|
}
|
|
1116
1122
|
],
|
|
1117
1123
|
"events": [
|
|
@@ -4435,6 +4441,13 @@
|
|
|
4435
4441
|
"type": "string",
|
|
4436
4442
|
"attributeName": "play-label",
|
|
4437
4443
|
"description": "The button's accessible name while the logos are paused."
|
|
4444
|
+
},
|
|
4445
|
+
{
|
|
4446
|
+
"name": "withoutPauseButton",
|
|
4447
|
+
"type": "boolean",
|
|
4448
|
+
"attributeName": "without-pause-button",
|
|
4449
|
+
"default": false,
|
|
4450
|
+
"description": "No pause button. It takes away the control WCAG 2.2.2 asks for on motion longer than five seconds, so it is the page's decision, never the default: the pointer and focus on the row still hold it and reduced motion keeps it still, but a page that sets it gives the reader its own control that sets paused, or the row no longer meets 2.2.2."
|
|
4438
4451
|
}
|
|
4439
4452
|
]
|
|
4440
4453
|
},
|