All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.vscode-radio-group.vscode-radio-group.js.map Maven / Gradle / Ivy

The newest version!
{"version":3,"file":"vscode-radio-group.js","sourceRoot":"","sources":["../../src/vscode-radio-group/vscode-radio-group.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAC,IAAI,EAAiB,MAAM,KAAK,CAAC;AACzC,OAAO,EACL,aAAa,EACb,QAAQ,EACR,qBAAqB,EACrB,KAAK,GACN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,UAAU,EAAC,MAAM,2BAA2B,CAAC;AAErD,OAAO,MAAM,MAAM,gCAAgC,CAAC;AAG7C,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,UAAU;IAAzC;;QAIL,YAAO,GAA8B,YAAY,CAAC;QAElD,gBAAgB;QAEhB,SAAI,GAAG,YAAY,CAAC;QAkBZ,kBAAa,GAAG,CAAC,CAAC,CAAC;QAGnB,kBAAa,GAAG,CAAC,CAAC,CAAC;QAEnB,wBAAmB,GAAG,KAAK,CAAC;QAwE5B,oBAAe,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAqDvD,CAAC;IAlJC,iBAAiB;QACf,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAE1B,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;IACzD,CAAC;IAED,oBAAoB;QAClB,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAE7B,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;IAC5D,CAAC;IAaO,uBAAuB,CAAC,WAAmB,EAAE,WAAmB;QACtE,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;YACvB,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,GAAG,KAAK,CAAC;QAC5C,CAAC;QAED,IAAI,WAAW,KAAK,CA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AAC,OAAO,CAAC,OAAO,CAClB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACP,mEAAmE;YACnE,IAAI,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC5B,CAAC,CAAC,QAAQ,GAAG,CAAC,KAAK,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YAChD,CAAC;iBAAM,CAAC;gBACN,CAAC,CAAC,QAAQ,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAChC,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAA;;;wBAGS,IAAI,CAAC,aAAa;wBAClB,IAAI,CAAC,SAAS;;;KAGjC,CAAC;IACJ,CAAC;;AA1JM,uBAAM,GAAG,MAAM,AAAT,CAAU;AAGvB;IADC,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;iDACwB;AAIlD;IADC,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;8CACN;AAeZ;IADP,qBAAqB,CAAC,EAAC,QAAQ,EAAE,cAAc,EAAC,CAAC;iDAClB;AAGxB;IADP,KAAK,EAAE;uDACmB;AAGnB;IADP,KAAK,EAAE;uDACmB;AA7BhB,gBAAgB;IAD5B,aAAa,CAAC,oBAAoB,CAAC;GACvB,gBAAgB,CA4J5B","sourcesContent":["import {html, TemplateResult} from 'lit';\nimport {\n  customElement,\n  property,\n  queryAssignedElements,\n  state,\n} from 'lit/decorators.js';\nimport {VscElement} from '../includes/VscElement.js';\nimport {VscodeRadio} from '../vscode-radio/index.js';\nimport styles from './vscode-radio-group.styles.js';\n\n@customElement('vscode-radio-group')\nexport class VscodeRadioGroup extends VscElement {\n  static styles = styles;\n\n  @property({reflect: true})\n  variant: 'horizontal' | 'vertical' = 'horizontal';\n\n  /** @internal */\n  @property({reflect: true})\n  role = 'radiogroup';\n\n  connectedCallback(): void {\n    super.connectedCallback();\n\n    this.addEventListener('keydown', this._onKeyDownBound);\n  }\n\n  disconnectedCallback(): void {\n    super.disconnectedCallback();\n\n    this.removeEventListener('keydown', this._onKeyDownBound);\n  }\n\n  @queryAssignedElements({selector: 'vscode-radio'})\n  private _radios!: VscodeRadio[];\n\n  @state()\n  private _focusedRadio = -1;\n\n  @state()\n  private _checkedRadio = -1;\n\n  private _firstContentLoaded = false;\n\n  private _uncheckPreviousChecked(prevChecked: number, prevFocused: number) {\n    if (prevChecked !== -1) {\n      this._radios[prevChecked].checked = false;\n    }\n\n    if (prevFocused !== -1) {\n      this._radios[prevFocused].tabIndex = -1;\n    }\n  }\n\n  private _afterCheck() {\n    this._focusedRadio = this._checkedRadio;\n    this._radios[this._checkedRadio].checked = true;\n    this._radios[this._checkedRadio].tabIndex = 0;\n    this._radios[this._checkedRadio].focus();\n  }\n\n  private _checkPrev() {\n    const prevChecked = this._radios.findIndex((r) => r.checked);\n    const prevFocused = this._radios.findIndex((r) => r.focused);\n    const startPos = prevFocused !== -1 ? prevFocused : prevChecked;\n\n    this._uncheckPreviousChecked(prevChecked, prevFocused);\n\n    if (startPos === -1) {\n      this._checkedRadio = this._radios.length - 1;\n    } else if (startPos - 1 >= 0) {\n      this._checkedRadio = startPos - 1;\n    } else {\n      this._checkedRadio = this._radios.length - 1;\n    }\n\n    this._afterCheck();\n  }\n\n  private _checkNext() {\n    const prevChecked = this._radios.findIndex((r) => r.checked);\n    const prevFocused = this._radios.findIndex((r) => r.focused);\n    const startPos = prevFocused !== -1 ? prevFocused : prevChecked;\n\n    this._uncheckPreviousChecked(prevChecked, prevFocused);\n\n    if (startPos === -1) {\n      this._checkedRadio = 0;\n    } else if (startPos + 1 < this._radios.length) {\n      this._checkedRadio = startPos + 1;\n    } else {\n      this._checkedRadio = 0;\n    }\n\n    this._afterCheck();\n  }\n\n  private _onKeyDown(ev: KeyboardEvent) {\n    const {key} = ev;\n    const listenedKeys = ['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'];\n\n    if (listenedKeys.includes(key)) {\n      ev.preventDefault();\n    }\n\n    if (key === 'ArrowRight' || key === 'ArrowDown') {\n      this._checkNext();\n    }\n\n    if (key === 'ArrowLeft' || key === 'ArrowUp') {\n      this._checkPrev();\n    }\n  }\n\n  private _onKeyDownBound = this._onKeyDown.bind(this);\n\n  private _onChange(ev: CustomEvent) {\n    const clickedIndex = this._radios.findIndex((r) => r === ev.target);\n\n    if (clickedIndex !== -1) {\n      if (this._focusedRadio !== -1) {\n        this._radios[this._focusedRadio].tabIndex = -1;\n      }\n\n      if (this._checkedRadio !== -1 && this._checkedRadio !== clickedIndex) {\n        this._radios[this._checkedRadio].checked = false;\n      }\n\n      this._focusedRadio = clickedIndex;\n      this._checkedRadio = clickedIndex;\n      this._radios[clickedIndex].tabIndex = 0;\n    }\n  }\n\n  private _onSlotChange() {\n    if (!this._firstContentLoaded) {\n      const autoFocusedRadio = this._radios.findIndex((r) => r.autofocus);\n\n      if (autoFocusedRadio > -1) {\n        this._focusedRadio = autoFocusedRadio;\n      }\n\n      this._firstContentLoaded = true;\n    }\n\n    this._radios.forEach(\n      (r, i) => {\n        // if _focusedRadio is not set, the first radio should be focusable\n        if (this._focusedRadio > -1) {\n          r.tabIndex = i === this._focusedRadio ? 0 : -1\n        } else {\n          r.tabIndex = i === 0 ? 0 : -1;\n        }\n      }\n    );\n  }\n\n  render(): TemplateResult {\n    return html`\n      
\n \n
\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'vscode-radio-group': VscodeRadioGroup;\n }\n}\n"]}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy