@aceshooting/lyra-ui 30.5.0 → 30.8.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 +93 -0
- package/README.md +1 -1
- package/dist/components/agent-tools/artifact-panel/artifact-panel.class.d.ts +7 -4
- package/dist/components/agent-tools/artifact-panel/artifact-panel.class.js +5 -5
- package/dist/components/conversation/code-block/onig.provenance.json +1 -1
- package/dist/components/conversation/markdown/markdown-base.class.d.ts +1 -1
- package/dist/components/conversation/markdown/markdown-base.class.js +1 -1
- package/dist/components/conversation/markdown/markdown-core.class.d.ts +11 -1
- package/dist/components/conversation/markdown/markdown-core.class.js +1 -1
- package/dist/components/conversation/markdown/markdown-progressive.js +2 -2
- package/dist/components/conversation/markdown/markdown-shared.d.ts +7 -2
- package/dist/components/conversation/markdown/markdown-shared.js +3 -3
- package/dist/components/conversation/markdown/markdown.class.d.ts +11 -1
- package/dist/components/conversation/markdown/markdown.class.js +1 -1
- package/dist/components/conversation/message-parts/message-parts.class.d.ts +1 -1
- package/dist/components/conversation/message-parts/message-parts.class.js +1 -1
- package/dist/components/conversation/message-parts/message-parts.d.ts +1 -1
- package/dist/components/conversation/model-select/model-select.class.d.ts +8 -1
- package/dist/components/conversation/model-select/model-select.class.js +2 -2
- package/dist/components/conversation/streaming-text/streaming-text-base.class.d.ts +5 -0
- package/dist/components/conversation/streaming-text/streaming-text-base.class.js +2 -2
- package/dist/components/conversation/streaming-text/streaming-text-core.class.d.ts +1 -1
- package/dist/components/conversation/streaming-text/streaming-text-core.class.js +1 -0
- package/dist/components/conversation/streaming-text/streaming-text.class.d.ts +1 -1
- package/dist/components/conversation/streaming-text/streaming-text.class.js +1 -0
- package/dist/components/conversation/suggestion-chips/suggestion-chips.class.d.ts +6 -0
- package/dist/components/conversation/suggestion-chips/suggestion-chips.styles.js +1 -1
- package/dist/components/conversation/voice-picker/voice-picker.class.d.ts +9 -2
- package/dist/components/conversation/voice-picker/voice-picker.class.js +2 -2
- package/dist/components/conversation/widget-renderer/default-registry.js +1 -1
- package/dist/components/conversation/widget-renderer/registry.d.ts +1 -27
- package/dist/components/conversation/widget-renderer/registry.js +1 -1
- package/dist/components/conversation/widget-renderer/resolve.d.ts +1 -29
- package/dist/components/conversation/widget-renderer/resolve.js +1 -1
- package/dist/components/conversation/widget-renderer/widget-renderer.class.d.ts +1 -1
- package/dist/components/conversation/widget-renderer/widget-renderer.class.js +1 -1
- package/dist/components/forms/catalog-picker-base.d.ts +3 -1
- package/dist/components/forms/catalog-picker-base.js +3 -3
- package/dist/components/forms/combobox/combobox.class.d.ts +9 -2
- package/dist/components/forms/combobox/combobox.class.js +2 -2
- package/dist/components/forms/date-picker/date-input.class.d.ts +9 -2
- package/dist/components/forms/date-picker/date-input.class.js +2 -2
- package/dist/components/forms/input/input-shared.d.ts +9 -2
- package/dist/components/forms/input/input-shared.js +2 -2
- package/dist/components/forms/input/time-input.class.d.ts +9 -2
- package/dist/components/forms/input/time-input.class.js +2 -2
- package/dist/components/forms/input/time-input.styles.js +1 -1
- package/dist/components/forms/locale-picker/locale-picker.class.d.ts +18 -3
- package/dist/components/forms/locale-picker/locale-picker.class.js +2 -2
- package/dist/components/forms/phone-input/phone-input.class.d.ts +9 -2
- package/dist/components/forms/phone-input/phone-input.class.js +2 -2
- package/dist/components/forms/phone-input/phone-input.styles.js +1 -1
- package/dist/components/forms/select/select.class.d.ts +9 -2
- package/dist/components/forms/select/select.class.js +2 -2
- package/dist/components/forms/textarea/textarea.class.d.ts +9 -2
- package/dist/components/forms/textarea/textarea.class.js +2 -2
- package/dist/components/forms/token-input/token-input.class.d.ts +9 -2
- package/dist/components/forms/token-input/token-input.class.js +2 -2
- package/dist/components/forms/token-input/token-input.styles.js +1 -1
- package/dist/components/layout/dock-panel/dock-panel.class.d.ts +35 -7
- package/dist/components/layout/dock-panel/dock-panel.class.js +8 -5
- package/dist/components/layout/dock-panel/dock-panel.styles.js +1 -1
- package/dist/components/layout/menu/menu-item.class.d.ts +7 -4
- package/dist/components/layout/menu/menu-item.class.js +3 -2
- package/dist/components/layout/multi-split/multi-split.class.d.ts +73 -6
- package/dist/components/layout/multi-split/multi-split.class.js +4 -4
- package/dist/components/layout/multi-split/multi-split.styles.js +1 -1
- package/dist/components/layout/page/page.class.d.ts +7 -0
- package/dist/components/layout/page/page.styles.js +1 -1
- package/dist/components/media/flag/language-map.js +1 -1
- package/dist/components/media/image-viewer/image-viewer-panorama.d.ts +1 -5
- package/dist/components/media/image-viewer/image-viewer-panorama.js +1 -8
- package/dist/components/media/image-viewer/image-viewer.class.d.ts +1 -1
- package/dist/components/media/image-viewer/image-viewer.class.js +1 -1
- package/dist/components/media/map/map-control-options.d.ts +7 -3
- package/dist/components/media/map/map-control-options.js +1 -1
- package/dist/components/media/map/map-controls-lifecycle.js +1 -1
- package/dist/components/media/map/map-feature-loader.js +1 -1
- package/dist/components/media/map/map-loader.d.ts +10 -4
- package/dist/components/media/map/map-loader.js +1 -1
- package/dist/components/media/map/map-scene-admission.js +1 -0
- package/dist/components/media/map/map-scene-completion-adapter.js +1 -0
- package/dist/components/media/map/map-scene-completion-camera.js +1 -0
- package/dist/components/media/map/map-scene-configuration-controller.js +1 -0
- package/dist/components/media/map/map-scene-configuration.d.ts +15 -0
- package/dist/components/media/map/map-scene-configuration.js +1 -0
- package/dist/components/media/map/map-scene-controls.js +1 -0
- package/dist/components/media/map/map-scene-elevated-lines.js +36 -0
- package/dist/components/media/map/map-scene-errors.js +1 -0
- package/dist/components/media/map/map-scene-line-encoding.js +1 -0
- package/dist/components/media/map/map-scene-line-layer.js +1 -0
- package/dist/components/media/map/map-scene-lines.js +1 -0
- package/dist/components/media/map/map-scene-owner.js +1 -0
- package/dist/components/media/map/map-scene-position-registry.js +1 -0
- package/dist/components/media/map/map-scene-render-controller.js +1 -0
- package/dist/components/media/map/map-scene-render-input.js +1 -0
- package/dist/components/media/map/map-scene-source-snapshot.js +1 -0
- package/dist/components/media/map/map-scene-status.js +1 -0
- package/dist/components/media/map/map-scene-types.d.ts +60 -0
- package/dist/components/media/map/map.class.d.ts +60 -12
- package/dist/components/media/map/map.class.js +23 -6
- package/dist/components/media/map/map.styles.js +1 -1
- package/dist/components/media/sequence-playback/sequence-playback.class.d.ts +1 -1
- package/dist/components/media/sequence-playback/sequence-playback.class.js +1 -1
- package/dist/components/media/video/video.class.d.ts +1 -1
- package/dist/components/media/video/video.class.js +1 -1
- package/dist/components/retrieval/graph/graph-builtin-3d-engine.js +1 -1
- package/dist/components/retrieval/graph/graph-curvature.js +1 -0
- package/dist/components/retrieval/graph/graph-engine-columns.js +1 -1
- package/dist/components/retrieval/graph/graph-model.d.ts +4 -0
- package/dist/components/retrieval/graph/graph-node-renderer.d.ts +13 -0
- package/dist/components/retrieval/graph/graph-node-renderer.js +1 -0
- package/dist/components/retrieval/graph/graph-source-controller.js +1 -1
- package/dist/components/retrieval/graph/graph-spatial-controller.js +3 -1
- package/dist/components/retrieval/graph/graph-spatial.js +1 -1
- package/dist/components/retrieval/graph/graph-webgl-engine.js +1 -1
- package/dist/components/retrieval/graph/graph.class.d.ts +11 -3
- package/dist/components/retrieval/graph/graph.class.js +4 -4
- package/dist/components/retrieval/knowledge-graph-explorer/knowledge-graph-explorer.class.d.ts +8 -2
- package/dist/components/retrieval/knowledge-graph-explorer/knowledge-graph-explorer.class.js +4 -2
- package/dist/events.d.ts +36 -1
- package/dist/framework-types.d.ts +1 -1
- package/dist/internal/collection-policy.js +1 -0
- package/dist/internal/collection-snapshot.js +1 -1
- package/dist/internal/default-strings/media.generated.js +1 -1
- package/dist/internal/default-strings/retrieval.generated.js +1 -1
- package/dist/internal/engine-3d-loader.d.ts +8 -2
- package/dist/internal/engine-3d-loader.js +1 -1
- package/dist/internal/form-control.styles.js +1 -1
- package/dist/internal/locale-loaders.generated.js +1 -1
- package/dist/internal/localization-runtime.js +1 -1
- package/dist/internal/localization-types.d.ts +1 -1
- package/dist/internal/localization.js +1 -1
- package/dist/internal/map-camera-follow-controller.d.ts +9 -0
- package/dist/internal/map-camera-follow-controller.js +1 -0
- package/dist/internal/map-camera-follow-data.js +1 -0
- package/dist/internal/map-camera-follow-scene.js +1 -0
- package/dist/internal/map-camera-session-controller.d.ts +59 -0
- package/dist/internal/map-camera-session-controller.js +1 -0
- package/dist/internal/map-camera-session-data.d.ts +16 -0
- package/dist/internal/map-camera-session-data.js +1 -0
- package/dist/internal/map-camera-session.js +1 -0
- package/dist/internal/map-custom-layer-attachment.js +1 -0
- package/dist/internal/map-custom-layer-controller.js +1 -0
- package/dist/internal/map-custom-layer-types.d.ts +63 -0
- package/dist/internal/map-scene-layer-runtime.js +1 -0
- package/dist/internal/map-scene-session.js +1 -0
- package/dist/internal/media-panorama.d.ts +5 -0
- package/dist/internal/media-panorama.js +8 -0
- package/dist/internal/package-metadata.js +1 -1
- package/dist/internal/sequence-playback-binding.js +1 -0
- package/dist/internal/typed-columns.d.ts +3 -1
- package/dist/internal/typed-columns.js +1 -1
- package/dist/internal/variants.d.ts +7 -0
- package/dist/internal/widget-default-registry.js +1 -0
- package/dist/internal/widget-document.d.ts +29 -0
- package/dist/internal/widget-document.js +1 -0
- package/dist/internal/widget-type-registry.d.ts +27 -0
- package/dist/internal/widget-type-registry.js +1 -0
- package/dist/lyra.d.ts +1 -1
- package/dist/lyra.js +1 -1
- package/dist/map-camera-session.d.ts +10 -0
- package/dist/map-camera-session.js +1 -0
- package/dist/map-custom-layers.d.ts +16 -0
- package/dist/map-custom-layers.js +1 -0
- package/dist/sequence-time-binding.d.ts +3 -0
- package/dist/sequence-time-binding.js +1 -0
- package/dist/simulation-clock.d.ts +3 -0
- package/dist/simulation-clock.js +1 -0
- package/dist/time-index.d.ts +3 -0
- package/dist/time-index.js +1 -0
- package/llms/components/lr-artifact-panel.md +8 -3
- package/llms/components/lr-combobox.md +2 -0
- package/llms/components/lr-country-picker.md +2 -0
- package/llms/components/lr-currency-picker.md +2 -0
- package/llms/components/lr-date-picker.md +2 -0
- package/llms/components/lr-dock-panel.md +28 -10
- package/llms/components/lr-graph.md +121 -3
- package/llms/components/lr-input.md +2 -0
- package/llms/components/lr-knowledge-graph-explorer.md +6 -1
- package/llms/components/lr-locale-picker.md +8 -1
- package/llms/components/lr-map.md +401 -7
- package/llms/components/lr-markdown-core.md +2 -1
- package/llms/components/lr-markdown.md +12 -1
- package/llms/components/lr-menu.md +5 -2
- package/llms/components/lr-model-select.md +2 -0
- package/llms/components/lr-multi-split.md +53 -4
- package/llms/components/lr-native-time-input.md +2 -0
- package/llms/components/lr-number-input.md +2 -0
- package/llms/components/lr-page.md +9 -1
- package/llms/components/lr-phone-input.md +2 -0
- package/llms/components/lr-select.md +2 -0
- package/llms/components/lr-sequence-playback.md +44 -0
- package/llms/components/lr-streaming-text-core.md +3 -2
- package/llms/components/lr-streaming-text.md +4 -1
- package/llms/components/lr-suggestion-chips.md +6 -2
- package/llms/components/lr-textarea.md +2 -0
- package/llms/components/lr-time-input.md +2 -0
- package/llms/components/lr-time-zone-picker.md +2 -0
- package/llms/components/lr-token-input.md +2 -0
- package/llms/components/lr-unit-picker.md +2 -0
- package/llms/components/lr-voice-picker.md +2 -0
- package/llms/peers.md +7 -7
- package/llms/shared/imports-and-registration.md +1 -1
- package/llms/shared/localization-and-rtl.md +15 -1
- package/llms/shared/testing-and-utilities.md +261 -0
- package/llms/shared.md +277 -2
- package/locales.json +1 -1
- package/package.json +41 -21
- package/registrations.json +1 -1
- package/skills/lyra-ui/lyra-gen.md +2 -0
- /package/dist/{components/media/image-viewer/image-viewer-panorama.styles.js → internal/media-panorama.styles.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate}from"tslib";import{ref}from"lit/directives/ref.js";import{repeat}from"lit/directives/repeat.js";import{finiteCount}from"../../../internal/numbers.js";import{getNumberFormat}from"../../../internal/intl-cache.js";import{setNativeRangeText,nativeAutocorrectAttribute}from"../../../internal/native-text-control.js";import{installFormControlLabelSupport}from"../../../internal/form-control-labels.js";import{FormControlController,reflectFormName}from"../../../internal/form-control-controller.js";import{html,nothing}from"lit";import{property,query,state}from"lit/decorators.js";import{LyraElement}from"../../../internal/lyra-element.js";import{LyraFormControlElement}from"../../../internal/form-control-element.js";import{shadowFocusTarget}from"../../../internal/active-element.js";import{acquireResolvedAriaRelationship}from"../../../internal/aria-controls.js";import{captureComposedFocusRepair,applyComposedFocusRepair}from"../../../internal/focus-navigation.js";import{VALIDITY_ANCHOR}from"../../../internal/anchored-validity.js";import{syncValidityStates}from"../../../internal/custom-states.js";import{SlotPresenceController}from"../../../internal/slot-presence-controller.js";import{nextId}from"../../../internal/a11y.js";import{closeIcon}from"../../../internal/icons.js";import{autocorrectConverter,normalizeAutocorrect,spellcheckConverter}from"../../../internal/converters.js";import{submitOnEnter}from"../../../internal/submit-on-enter.js";import{dispatchNativeEvent,dispatchNativeInputEvent,relayNativeEvent}from"../../../internal/native-event-relay.js";import{sizes}from"../../../internal/sizes.styles.js";import{styles}from"./token-input.styles.js";import{createStringArrayFormDataState,getFormOwner,isBarredFromValidation,readStringArrayFormDataState,setFormOwner}from"../../../internal/form-associated.js";import{LYRA_DEFAULT_selectSelectedOverflow,LYRA_DEFAULT_tokenInputEditWithContext,LYRA_DEFAULT_tokenInputRequired}from"../../../internal/default-strings/forms.generated.js";import{LYRA_DEFAULT_fieldRequired,LYRA_DEFAULT_removeWithContext}from"../../../internal/default-strings/shared.generated.js";installFormControlLabelSupport();const delimiterConverter={fromAttribute:value=>value===null?",":value===""||value==="none"?null:value};function normalizeStringArray(value){if(!Array.isArray(value))return Object.freeze([]);try{const normalized=[];for(const entry of value)typeof entry=="string"&&normalized.push(entry);return Object.freeze(normalized)}catch{return Object.freeze([])}}const stringArrayConverter={fromAttribute:value=>{if(value===null)return null;try{const parsed=JSON.parse(value);return normalizeStringArray(parsed)}catch{return[]}},toAttribute:value=>value==null?null:JSON.stringify(value)};class LyraTokenInput extends LyraFormControlElement{static{this.defaultStrings={...super.defaultStrings,fieldRequired:LYRA_DEFAULT_fieldRequired,removeWithContext:LYRA_DEFAULT_removeWithContext,selectSelectedOverflow:LYRA_DEFAULT_selectSelectedOverflow,tokenInputEditWithContext:LYRA_DEFAULT_tokenInputEditWithContext,tokenInputRequired:LYRA_DEFAULT_tokenInputRequired}}static{this.formAssociated=!0}static{this.styles=[LyraElement.styles,sizes,styles]}static{this.properties={customError:{attribute:"custom-error",reflect:!0,noAccessor:!0},name:{reflect:!0,noAccessor:!0},required:{type:Boolean,reflect:!0,noAccessor:!0},disabled:{type:Boolean,reflect:!0,noAccessor:!0},readonly:{type:Boolean,reflect:!0,noAccessor:!0},defaultValue:{attribute:"value",reflect:!0,useDefault:!0,converter:stringArrayConverter,noAccessor:!0}}}get autocorrect(){return this.autocorrectValue}set autocorrect(next){this.autocorrectValue=normalizeAutocorrect(next),this.requestUpdate()}get editable(){return this._editable}set editable(next){const old=this._editable;this._editable=!!next,this._editable||this.discardTransientState(!1),this.requestUpdate("editable",old)}tokenElement(index){return[...this.renderRoot.querySelectorAll('[part="token"]')].find(element=>this.tokenIndices.get(element)===index)}get visibleTokenEntries(){if(this.tokenEntriesFor!==this.value){this.tokenEntriesFor=this.value;const occurrences=new Map;this.tokenEntries=this.value.map((token,index)=>{const count=occurrences.get(token)??0;return occurrences.set(token,count+1),{token,index,key:`${token.length}:${token}:${count}`}})}const limit=finiteCount(this.maxTokensVisible,0);if(!limit||this.tokenEntries.length<=limit)return this.tokenEntries;const retained=new Set,focused=shadowFocusTarget(this)?.closest('[part="token"]'),focusedIndex=focused?this.tokenIndices.get(focused)??-1:-1;for(const index of[this.editingIndex,this.focusTokenPending,this.tokenFocusRepairPending?.index??-1,this.editable?this.activeTokenIndex:-1,focusedIndex])index>=0&&index<this.value.length&&retained.size<limit&&retained.add(index);for(let index=0;index<limit&&retained.size<limit;index++)retained.add(index);return[...retained].sort((a,b)=>a-b).map(index=>this.tokenEntries[index])}tokenEventIndex(event){const token=event.composedPath().find(target=>target.nodeType===1&&target.getAttribute("part")==="token");return token?this.tokenIndices.get(token)??-1:-1}syncExternalDescription(){const target=this.isConnected?this.inputEl:void 0;if(!target){this.releaseExternalDescription();return}this.externalDescriptionLease?this.externalDescriptionLease.update(target):this.externalDescriptionLease=acquireResolvedAriaRelationship(this,target,"aria-describedby")}releaseExternalDescription(){this.externalDescriptionLease?.release(),this.externalDescriptionLease=void 0}get value(){return this._value}set value(next){const old=this._value;this.settingDefaultValue||(this._valueDirty=!0);const normalized=normalizeStringArray(next);this.captureTokenFocusRepair(normalized),this.editingIndex>=0&&normalized!==old&&(this.editingIndex=-1,this.editDraft="",this.focusEditorPending=!1),this._value=normalized,this.requestUpdate("value",old),this.internals&&this.syncValidity()}get defaultValue(){return this._defaultValue}set defaultValue(next){if(this.reflectingDefaultValue)return;const old=this._defaultValue;this._defaultValue=normalizeStringArray(next),this.reflectingDefaultValue=!0;try{next==null?this.removeAttribute("value"):this.setAttribute("value",JSON.stringify(this._defaultValue))}finally{this.reflectingDefaultValue=!1}this._valueDirty||this.restoreLiveValueFromDefault(),this.requestUpdate("defaultValue",old)}get name(){return this._name}set name(next){const old=this._name;this._name=next??"",reflectFormName(this,this._name),this.syncValidity(),this.requestUpdate("name",old)}get required(){return this._required}set required(next){const old=this._required;this._required=!!next,this.toggleAttribute("required",this._required),this.syncValidity(),this.requestUpdate("required",old)}get disabled(){return this._disabled}set disabled(next){const old=this._disabled,wasEffectivelyDisabled=this.effectiveDisabled;this._disabled=!!next,!wasEffectivelyDisabled&&this.effectiveDisabled&&this.retireDisabledInteraction(),this.toggleAttribute("disabled",this._disabled),this._fieldsetDisabled=this.validityController?.fieldsetDisabled(this._fieldsetDisabled)??this._fieldsetDisabled,this.syncValidity(),this.requestUpdate("disabled",old)}get readonly(){return this._readonly}set readonly(next){const old=this._readonly,nextValue=!!next;!old&&nextValue&&this.discardTransientState(!0),this._readonly=nextValue,this.toggleAttribute("readonly",this._readonly),this.syncValidity(),this.requestUpdate("readonly",old)}constructor(){super(),this.label="",this.hint="",this.errorText="",this.placeholder="",this.spellcheck=!0,this.autocapitalize="",this.autocorrectValue=!0,this.accessibleLabel="",this.size="m",this.pill=!1,this.allowDuplicates=!1,this._editable=!1,this.delimiter=",",this.maxTokensVisible=0,this.tokenIndices=new WeakMap,this.tokenEntries=[],this.renderedTokenValues=[],this.onTokenClick=event=>{const index=this.tokenEventIndex(event);if(index<0)return;const target=event.composedPath().find(target2=>target2.nodeType===1&&(target2.getAttribute("part")==="remove"||target2.getAttribute("part")==="token-label"));target?.getAttribute("part")==="remove"?this.removeToken(index):target&&this.startEdit(index)},this.onTokenFocus=event=>{const index=this.tokenEventIndex(event);index>=0&&this.rovingIndex!==index&&(this.rovingIndex=index)},this.onTokenKey=event=>{if(event.target.getAttribute("part")!=="token-label")return;const index=this.tokenEventIndex(event);index>=0&&this.onTokenKeyDown(event,index)},this.draft="",this.touched=!1,this.editingIndex=-1,this.editDraft="",this.rovingIndex=0,this.focusEditorPending=!1,this.focusTokenPending=-1,this.editorBlurRelayed=!1,this.slotPresence=new SlotPresenceController(this),this.labelId=nextId("token-input-label"),this.hintId=nextId("token-input-hint"),this.errorId=nextId("token-input-error"),this._value=Object.freeze([]),this._defaultValue=Object.freeze([]),this._valueDirty=!1,this.settingDefaultValue=!1,this.reflectingDefaultValue=!1,this._fieldsetDisabled=!1,this._name="",this._required=!1,this._disabled=!1,this._readonly=!1,this.markInteracted=()=>{this.touched||(this.touched=!0,this.syncValidity())},this.onEditInput=event=>{event.stopPropagation(),!(this.liveDisabled||this.readonly)&&(this.editDraft=event.target.value)},this.onEditFocus=event=>{if(this.liveDisabled){event.stopPropagation();return}this.editorBlurRelayed=!1,relayNativeEvent(this,event)},this.onEditKeyDown=event=>{event.isComposing||event.keyCode===229||(event.key==="Enter"?(event.preventDefault(),this.commitEdit(!0)):event.key==="Escape"&&(event.preventDefault(),event.stopPropagation(),this.cancelEdit()))},this.onEditBlur=event=>{if(this.editorBlurRelayed){event.stopPropagation();return}this.editorBlurRelayed=!0,event.stopPropagation(),queueMicrotask(()=>{!this.isConnected||!this.editable||this.liveDisabled?this.discardTransientState(!1):this.commitEdit(!1),relayNativeEvent(this,event)})},this.onInput=event=>{event.stopPropagation(),!(this.liveDisabled||this.readonly)&&(this.draft=event.target.value)},this.onKeyDown=event=>{event.isComposing||event.keyCode===229||this.liveDisabled||(event.key==="Enter"||this.delimiter!==null&&event.key===this.delimiter?this.draft.trim()?(event.preventDefault(),this.addDraft()):event.key==="Enter"&&submitOnEnter(this,event):event.key==="Tab"?this.draft.trim()&&this.addDraft():event.key==="Backspace"&&!this.draft&&this.value.length&&this.editingIndex<0&&this.removeToken(this.value.length-1))},this.onBlur=event=>{this.liveDisabled||(this.draft.trim()&&this.addDraft(),this.touched=!0),this.syncValidity(),relayNativeEvent(this,event)},this.onFocus=event=>{if(this.liveDisabled){event.stopPropagation();return}relayNativeEvent(this,event)},this.validityController=new FormControlController(this,{invalid:init=>this.emit("lr-invalid",null,init),interacted:this.markInteracted,customError:()=>this.validityController.customValidityMessage}),this.internals=this.validityController.formInternals}connectedCallback(){super.connectedCallback(),this.hasUpdated&&this.syncExternalDescription(),this.syncValidity()}disconnectedCallback(){this.releaseExternalDescription(),this.tokenFocusRepairPending=void 0,this.discardTransientState(!0),super.disconnectedCallback()}adoptedCallback(){super.adoptedCallback(),this.releaseExternalDescription(),this.isConnected&&this.hasUpdated&&this.syncExternalDescription()}get form(){return getFormOwner(this.internals)}set form(owner){setFormOwner(this,owner)}get effectiveDisabled(){return this.disabled||this._fieldsetDisabled}formDisabledCallback(disabled){if(this.validityController?.reflectingDisabled)return;const wasEffectivelyDisabled=this.effectiveDisabled;this._fieldsetDisabled=disabled,!wasEffectivelyDisabled&&this.effectiveDisabled&&this.retireDisabledInteraction(),this.syncValidity(),this.requestUpdate()}[VALIDITY_ANCHOR](){return this.inputEl??this.renderRoot?.querySelector('[part="input-wrapper"]')??null}checkValidity(){return this.validityController.checkValidity()}reportValidity(){return this.validityController.syncConstraints(),this.touched=!0,this.syncValidity(),this.internals.reportValidity()}setCustomValidity(message){this.validityController.setCustomValidity(message??""),this.syncValidity()}get liveDisabled(){return this.effectiveDisabled||this.matches(":disabled")}focus(options){this.liveDisabled||this.inputEl?.focus(options)}blur(){const active=shadowFocusTarget(this);active&&typeof active.blur=="function"&&active.blur()}click(){this.liveDisabled||this.inputEl?.focus()}select(){this.inputEl?.select()}get selectionStart(){return this.inputEl?.selectionStart??null}set selectionStart(value){this.inputEl&&(this.inputEl.selectionStart=value??0)}get selectionEnd(){return this.inputEl?.selectionEnd??null}set selectionEnd(value){this.inputEl&&(this.inputEl.selectionEnd=value??0)}get selectionDirection(){return this.inputEl?.selectionDirection??null}set selectionDirection(value){this.inputEl&&(this.inputEl.selectionDirection=value??"none")}setSelectionRange(selectionStart,selectionEnd,selectionDirection="none"){this.inputEl?.setSelectionRange(selectionStart,selectionEnd,selectionDirection??"none")}setRangeText(replacement,start,end,selectMode="preserve"){const input=this.inputEl;input&&(setNativeRangeText(input,replacement,start,end,selectMode),this.draft=input.value)}get barredFromValidation(){return isBarredFromValidation(this,this.internals)}syncValidity(){const barred=this.barredFromValidation,missing=!barred&&this.required&&this.value.length===0;this.validityController.setValidity(missing?{valueMissing:!0}:{},missing?this.localize("tokenInputRequired"):""),this.toggleAttribute("data-invalid",!barred&&this.touched&&!this.internals.validity.valid),syncValidityStates(this.internals,{required:this.required,hasInteracted:this.touched,barred});const data=new FormData;this.name&&this.value.forEach(token=>data.append(this.name,token)),this.internals.setFormValue(this.name?data:null,createStringArrayFormDataState(this.name,this.value))}updateValue(next){const previousValue=Object.freeze([...this.value]);this.value=next,this.syncValidity();const detail=()=>Object.freeze({value:Object.freeze([...this.value]),previousValue});dispatchNativeInputEvent(this),this.emit("lr-input",detail()),dispatchNativeEvent(this,"change"),this.emit("lr-change",detail())}addDraft(){if(this.liveDisabled||this.readonly)return;const candidates=(this.delimiter?this.draft.split(this.delimiter):[this.draft]).map(token=>token.trim()).filter(Boolean),next=[...this.value],seen=this.allowDuplicates?null:new Set(next),added=[];for(const token of candidates)seen?.has(token)||(seen?.add(token),next.push(token),added.push(token));if(added.length===0){this.draft="";return}const addDetail=()=>Object.freeze({value:added[added.length-1],values:Object.freeze([...added])});this.emit("lr-token-add-request",addDetail(),{cancelable:!0}).defaultPrevented||(this.updateValue(next),this.draft="")}discardTransientState(clearDraft){this.editingIndex=-1,this.editDraft="",this.focusEditorPending=!1,this.focusTokenPending=-1,clearDraft&&(this.draft="",this.inputEl&&(this.inputEl.value=""))}retireDisabledInteraction(){this.tokenFocusRepairPending=void 0,this.discardTransientState(!0);const active=shadowFocusTarget(this);active&&typeof active.blur=="function"&&active.blur()}captureTokenFocusRepair(next){this.tokenFocusRepairPending=void 0;const active=shadowFocusTarget(this),token=typeof active?.closest=="function"?active.closest('[part~="token"]'):null;if(!active||!token)return;const index=this.tokenIndices.get(token)??-1;if(!Number.isInteger(index)||index<0||next.length>=this.renderedTokenValues.length&&next[index]===this.renderedTokenValues[index])return;const repair=captureComposedFocusRepair(this,active);if(!repair)return;const targetIndex=Math.min(index,Math.max(0,next.length-1));this.rovingIndex=targetIndex,this.tokenFocusRepairPending={index:targetIndex,surface:active.matches('[part~="remove"]')?"remove":"label",repair}}removeToken(index){if(this.liveDisabled||this.readonly)return;const removed=this.value[index];removed===void 0||this.emit("lr-token-remove-request",{value:removed,index},{cancelable:!0}).defaultPrevented||(this.editingIndex>=0&&(this.editingIndex=-1,this.editDraft=""),this.updateValue(this.value.filter((_token,i)=>i!==index)))}get activeTokenIndex(){return this.value.length?Math.min(Math.max(this.rovingIndex,0),this.value.length-1):-1}startEdit(index){this.liveDisabled||this.readonly||!this.editable||index<0||index>=this.value.length||(this.editingIndex=index,this.editDraft=this.value[index],this.rovingIndex=index,this.editorBlurRelayed=!1,this.focusEditorPending=!0)}cancelEdit(){this.editingIndex<0||(this.focusTokenPending=this.editingIndex,this.editingIndex=-1,this.editDraft="")}commitEdit(restoreFocus){if(this.liveDisabled||this.readonly){this.discardTransientState(!1);return}const index=this.editingIndex;if(index<0)return;const previousValue=this.value[index],next=this.editDraft.trim();if(previousValue===void 0||!next||next===previousValue||!this.allowDuplicates&&this.value.some((token,i)=>i!==index&&token===next)){restoreFocus&&(this.focusTokenPending=index),this.editingIndex=-1,this.editDraft="";return}this.emit("lr-token-edit-request",{value:next,previousValue,index},{cancelable:!0}).defaultPrevented||(restoreFocus&&(this.focusTokenPending=index),this.editingIndex=-1,this.editDraft="",this.updateValue(this.value.map((token,i)=>i===index?next:token)))}moveRovingFocus(index){if(!this.value.length)return;const clamped=Math.min(Math.max(index,0),this.value.length-1);this.rovingIndex=clamped,this.focusTokenPending=clamped}onTokenKeyDown(event,index){if(this.liveDisabled)return;const rtl=this.effectiveDirection==="rtl",forward=rtl?"ArrowLeft":"ArrowRight",backward=rtl?"ArrowRight":"ArrowLeft";event.key==="Enter"||event.key===" "||event.key==="F2"?(event.preventDefault(),this.startEdit(index)):event.key===forward?(event.preventDefault(),this.moveRovingFocus(index+1)):event.key===backward?(event.preventDefault(),this.moveRovingFocus(index-1)):event.key==="Home"?(event.preventDefault(),this.moveRovingFocus(0)):event.key==="End"&&(event.preventDefault(),this.moveRovingFocus(this.value.length-1))}stopInternalChange(event){event.stopPropagation()}formResetCallback(){this.restoreLiveValueFromDefault(),this.discardTransientState(!0),this.rovingIndex=0,this.touched=!1,this.syncValidity()}restoreLiveValueFromDefault(){this.settingDefaultValue=!0;try{this.value=[...this._defaultValue]}finally{this.settingDefaultValue=!1}this._valueDirty=!1}formStateRestoreCallback(state2,_mode){this.value=readStringArrayFormDataState(state2),this.discardTransientState(!0),this.rovingIndex=0,this.touched=!1,this.syncValidity()}updated(changed){if(super.updated(changed),this.syncExternalDescription(),this.focusEditorPending){this.focusEditorPending=!1;const editor=this.renderRoot?.querySelector('[part="token-editor"]');editor?.focus(),editor?.select()}if(this.focusTokenPending>=0){const index=this.focusTokenPending;this.focusTokenPending=-1;const label=this.tokenElement(index)?.querySelector('[part="token-label"]');label?.focus(),label?.scrollIntoView({block:"nearest",inline:"nearest"})}const pending=this.tokenFocusRepairPending;if(this.tokenFocusRepairPending=void 0,pending){const token=this.tokenElement(pending.index),target=(pending.surface==="remove"?token?.querySelector('[part~="remove"]'):token?.querySelector('[part~="token-label"]'))??token?.querySelector('[part~="remove"]')??this.inputEl??null;applyComposedFocusRepair(pending.repair,target)&&target?.scrollIntoView({block:"nearest",inline:"nearest"})}}renderRemoveButton(token){return html`<button
|
|
1
|
+
import{__decorate}from"tslib";import{ref}from"lit/directives/ref.js";import{repeat}from"lit/directives/repeat.js";import{finiteCount}from"../../../internal/numbers.js";import{getNumberFormat}from"../../../internal/intl-cache.js";import{setNativeRangeText,nativeAutocorrectAttribute}from"../../../internal/native-text-control.js";import{installFormControlLabelSupport}from"../../../internal/form-control-labels.js";import{FormControlController,reflectFormName}from"../../../internal/form-control-controller.js";import{html,nothing}from"lit";import{property,query,state}from"lit/decorators.js";import{LyraElement}from"../../../internal/lyra-element.js";import{LyraFormControlElement}from"../../../internal/form-control-element.js";import{shadowFocusTarget}from"../../../internal/active-element.js";import{acquireResolvedAriaRelationship}from"../../../internal/aria-controls.js";import{captureComposedFocusRepair,applyComposedFocusRepair}from"../../../internal/focus-navigation.js";import{VALIDITY_ANCHOR}from"../../../internal/anchored-validity.js";import{syncValidityStates}from"../../../internal/custom-states.js";import{SlotPresenceController}from"../../../internal/slot-presence-controller.js";import{nextId}from"../../../internal/a11y.js";import{closeIcon}from"../../../internal/icons.js";import{autocorrectConverter,normalizeAutocorrect,spellcheckConverter}from"../../../internal/converters.js";import{submitOnEnter}from"../../../internal/submit-on-enter.js";import{dispatchNativeEvent,dispatchNativeInputEvent,relayNativeEvent}from"../../../internal/native-event-relay.js";import{sizes}from"../../../internal/sizes.styles.js";import{styles}from"./token-input.styles.js";import{createStringArrayFormDataState,getFormOwner,isBarredFromValidation,readStringArrayFormDataState,setFormOwner}from"../../../internal/form-associated.js";import{LYRA_DEFAULT_selectSelectedOverflow,LYRA_DEFAULT_tokenInputEditWithContext,LYRA_DEFAULT_tokenInputRequired}from"../../../internal/default-strings/forms.generated.js";import{LYRA_DEFAULT_fieldRequired,LYRA_DEFAULT_removeWithContext}from"../../../internal/default-strings/shared.generated.js";installFormControlLabelSupport();const delimiterConverter={fromAttribute:value=>value===null?",":value===""||value==="none"?null:value};function normalizeStringArray(value){if(!Array.isArray(value))return Object.freeze([]);try{const normalized=[];for(const entry of value)typeof entry=="string"&&normalized.push(entry);return Object.freeze(normalized)}catch{return Object.freeze([])}}const stringArrayConverter={fromAttribute:value=>{if(value===null)return null;try{const parsed=JSON.parse(value);return normalizeStringArray(parsed)}catch{return[]}},toAttribute:value=>value==null?null:JSON.stringify(value)};class LyraTokenInput extends LyraFormControlElement{static{this.defaultStrings={...super.defaultStrings,fieldRequired:LYRA_DEFAULT_fieldRequired,removeWithContext:LYRA_DEFAULT_removeWithContext,selectSelectedOverflow:LYRA_DEFAULT_selectSelectedOverflow,tokenInputEditWithContext:LYRA_DEFAULT_tokenInputEditWithContext,tokenInputRequired:LYRA_DEFAULT_tokenInputRequired}}static{this.formAssociated=!0}static{this.styles=[LyraElement.styles,sizes,styles]}static{this.properties={customError:{attribute:"custom-error",reflect:!0,noAccessor:!0},name:{reflect:!0,noAccessor:!0},required:{type:Boolean,reflect:!0,noAccessor:!0},disabled:{type:Boolean,reflect:!0,noAccessor:!0},readonly:{type:Boolean,reflect:!0,noAccessor:!0},defaultValue:{attribute:"value",reflect:!0,useDefault:!0,converter:stringArrayConverter,noAccessor:!0}}}get autocorrect(){return this.autocorrectValue}set autocorrect(next){this.autocorrectValue=normalizeAutocorrect(next),this.requestUpdate()}get editable(){return this._editable}set editable(next){const old=this._editable;this._editable=!!next,this._editable||this.discardTransientState(!1),this.requestUpdate("editable",old)}tokenElement(index){return[...this.renderRoot.querySelectorAll('[part="token"]')].find(element=>this.tokenIndices.get(element)===index)}get visibleTokenEntries(){if(this.tokenEntriesFor!==this.value){this.tokenEntriesFor=this.value;const occurrences=new Map;this.tokenEntries=this.value.map((token,index)=>{const count=occurrences.get(token)??0;return occurrences.set(token,count+1),{token,index,key:`${token.length}:${token}:${count}`}})}const limit=finiteCount(this.maxTokensVisible,0);if(!limit||this.tokenEntries.length<=limit)return this.tokenEntries;const retained=new Set,focused=shadowFocusTarget(this)?.closest('[part="token"]'),focusedIndex=focused?this.tokenIndices.get(focused)??-1:-1;for(const index of[this.editingIndex,this.focusTokenPending,this.tokenFocusRepairPending?.index??-1,this.editable?this.activeTokenIndex:-1,focusedIndex])index>=0&&index<this.value.length&&retained.size<limit&&retained.add(index);for(let index=0;index<limit&&retained.size<limit;index++)retained.add(index);return[...retained].sort((a,b)=>a-b).map(index=>this.tokenEntries[index])}tokenEventIndex(event){const token=event.composedPath().find(target=>target.nodeType===1&&target.getAttribute("part")==="token");return token?this.tokenIndices.get(token)??-1:-1}syncExternalDescription(){const target=this.isConnected?this.inputEl:void 0;if(!target){this.releaseExternalDescription();return}this.externalDescriptionLease?this.externalDescriptionLease.update(target):this.externalDescriptionLease=acquireResolvedAriaRelationship(this,target,"aria-describedby")}releaseExternalDescription(){this.externalDescriptionLease?.release(),this.externalDescriptionLease=void 0}get value(){return this._value}set value(next){const old=this._value;this.settingDefaultValue||(this._valueDirty=!0);const normalized=normalizeStringArray(next);this.captureTokenFocusRepair(normalized),this.editingIndex>=0&&normalized!==old&&(this.editingIndex=-1,this.editDraft="",this.focusEditorPending=!1),this._value=normalized,this.requestUpdate("value",old),this.internals&&this.syncValidity()}get defaultValue(){return this._defaultValue}set defaultValue(next){if(this.reflectingDefaultValue)return;const old=this._defaultValue;this._defaultValue=normalizeStringArray(next),this.reflectingDefaultValue=!0;try{next==null?this.removeAttribute("value"):this.setAttribute("value",JSON.stringify(this._defaultValue))}finally{this.reflectingDefaultValue=!1}this._valueDirty||this.restoreLiveValueFromDefault(),this.requestUpdate("defaultValue",old)}get name(){return this._name}set name(next){const old=this._name;this._name=next??"",reflectFormName(this,this._name),this.syncValidity(),this.requestUpdate("name",old)}get required(){return this._required}set required(next){const old=this._required;this._required=!!next,this.toggleAttribute("required",this._required),this.syncValidity(),this.requestUpdate("required",old)}get disabled(){return this._disabled}set disabled(next){const old=this._disabled,wasEffectivelyDisabled=this.effectiveDisabled;this._disabled=!!next,!wasEffectivelyDisabled&&this.effectiveDisabled&&this.retireDisabledInteraction(),this.toggleAttribute("disabled",this._disabled),this._fieldsetDisabled=this.validityController?.fieldsetDisabled(this._fieldsetDisabled)??this._fieldsetDisabled,this.syncValidity(),this.requestUpdate("disabled",old)}get readonly(){return this._readonly}set readonly(next){const old=this._readonly,nextValue=!!next;!old&&nextValue&&this.discardTransientState(!0),this._readonly=nextValue,this.toggleAttribute("readonly",this._readonly),this.syncValidity(),this.requestUpdate("readonly",old)}constructor(){super(),this.label="",this.labelDisplay="visible",this.hint="",this.errorText="",this.placeholder="",this.spellcheck=!0,this.autocapitalize="",this.autocorrectValue=!0,this.accessibleLabel="",this.size="m",this.pill=!1,this.allowDuplicates=!1,this._editable=!1,this.delimiter=",",this.maxTokensVisible=0,this.tokenIndices=new WeakMap,this.tokenEntries=[],this.renderedTokenValues=[],this.onTokenClick=event=>{const index=this.tokenEventIndex(event);if(index<0)return;const target=event.composedPath().find(target2=>target2.nodeType===1&&(target2.getAttribute("part")==="remove"||target2.getAttribute("part")==="token-label"));target?.getAttribute("part")==="remove"?this.removeToken(index):target&&this.startEdit(index)},this.onTokenFocus=event=>{const index=this.tokenEventIndex(event);index>=0&&this.rovingIndex!==index&&(this.rovingIndex=index)},this.onTokenKey=event=>{if(event.target.getAttribute("part")!=="token-label")return;const index=this.tokenEventIndex(event);index>=0&&this.onTokenKeyDown(event,index)},this.draft="",this.touched=!1,this.editingIndex=-1,this.editDraft="",this.rovingIndex=0,this.focusEditorPending=!1,this.focusTokenPending=-1,this.editorBlurRelayed=!1,this.slotPresence=new SlotPresenceController(this),this.labelId=nextId("token-input-label"),this.hintId=nextId("token-input-hint"),this.errorId=nextId("token-input-error"),this._value=Object.freeze([]),this._defaultValue=Object.freeze([]),this._valueDirty=!1,this.settingDefaultValue=!1,this.reflectingDefaultValue=!1,this._fieldsetDisabled=!1,this._name="",this._required=!1,this._disabled=!1,this._readonly=!1,this.markInteracted=()=>{this.touched||(this.touched=!0,this.syncValidity())},this.onEditInput=event=>{event.stopPropagation(),!(this.liveDisabled||this.readonly)&&(this.editDraft=event.target.value)},this.onEditFocus=event=>{if(this.liveDisabled){event.stopPropagation();return}this.editorBlurRelayed=!1,relayNativeEvent(this,event)},this.onEditKeyDown=event=>{event.isComposing||event.keyCode===229||(event.key==="Enter"?(event.preventDefault(),this.commitEdit(!0)):event.key==="Escape"&&(event.preventDefault(),event.stopPropagation(),this.cancelEdit()))},this.onEditBlur=event=>{if(this.editorBlurRelayed){event.stopPropagation();return}this.editorBlurRelayed=!0,event.stopPropagation(),queueMicrotask(()=>{!this.isConnected||!this.editable||this.liveDisabled?this.discardTransientState(!1):this.commitEdit(!1),relayNativeEvent(this,event)})},this.onInput=event=>{event.stopPropagation(),!(this.liveDisabled||this.readonly)&&(this.draft=event.target.value)},this.onKeyDown=event=>{event.isComposing||event.keyCode===229||this.liveDisabled||(event.key==="Enter"||this.delimiter!==null&&event.key===this.delimiter?this.draft.trim()?(event.preventDefault(),this.addDraft()):event.key==="Enter"&&submitOnEnter(this,event):event.key==="Tab"?this.draft.trim()&&this.addDraft():event.key==="Backspace"&&!this.draft&&this.value.length&&this.editingIndex<0&&this.removeToken(this.value.length-1))},this.onBlur=event=>{this.liveDisabled||(this.draft.trim()&&this.addDraft(),this.touched=!0),this.syncValidity(),relayNativeEvent(this,event)},this.onFocus=event=>{if(this.liveDisabled){event.stopPropagation();return}relayNativeEvent(this,event)},this.validityController=new FormControlController(this,{invalid:init=>this.emit("lr-invalid",null,init),interacted:this.markInteracted,customError:()=>this.validityController.customValidityMessage}),this.internals=this.validityController.formInternals}connectedCallback(){super.connectedCallback(),this.hasUpdated&&this.syncExternalDescription(),this.syncValidity()}disconnectedCallback(){this.releaseExternalDescription(),this.tokenFocusRepairPending=void 0,this.discardTransientState(!0),super.disconnectedCallback()}adoptedCallback(){super.adoptedCallback(),this.releaseExternalDescription(),this.isConnected&&this.hasUpdated&&this.syncExternalDescription()}get form(){return getFormOwner(this.internals)}set form(owner){setFormOwner(this,owner)}get effectiveDisabled(){return this.disabled||this._fieldsetDisabled}formDisabledCallback(disabled){if(this.validityController?.reflectingDisabled)return;const wasEffectivelyDisabled=this.effectiveDisabled;this._fieldsetDisabled=disabled,!wasEffectivelyDisabled&&this.effectiveDisabled&&this.retireDisabledInteraction(),this.syncValidity(),this.requestUpdate()}[VALIDITY_ANCHOR](){return this.inputEl??this.renderRoot?.querySelector('[part="input-wrapper"]')??null}checkValidity(){return this.validityController.checkValidity()}reportValidity(){return this.validityController.syncConstraints(),this.touched=!0,this.syncValidity(),this.internals.reportValidity()}setCustomValidity(message){this.validityController.setCustomValidity(message??""),this.syncValidity()}get liveDisabled(){return this.effectiveDisabled||this.matches(":disabled")}focus(options){this.liveDisabled||this.inputEl?.focus(options)}blur(){const active=shadowFocusTarget(this);active&&typeof active.blur=="function"&&active.blur()}click(){this.liveDisabled||this.inputEl?.focus()}select(){this.inputEl?.select()}get selectionStart(){return this.inputEl?.selectionStart??null}set selectionStart(value){this.inputEl&&(this.inputEl.selectionStart=value??0)}get selectionEnd(){return this.inputEl?.selectionEnd??null}set selectionEnd(value){this.inputEl&&(this.inputEl.selectionEnd=value??0)}get selectionDirection(){return this.inputEl?.selectionDirection??null}set selectionDirection(value){this.inputEl&&(this.inputEl.selectionDirection=value??"none")}setSelectionRange(selectionStart,selectionEnd,selectionDirection="none"){this.inputEl?.setSelectionRange(selectionStart,selectionEnd,selectionDirection??"none")}setRangeText(replacement,start,end,selectMode="preserve"){const input=this.inputEl;input&&(setNativeRangeText(input,replacement,start,end,selectMode),this.draft=input.value)}get barredFromValidation(){return isBarredFromValidation(this,this.internals)}syncValidity(){const barred=this.barredFromValidation,missing=!barred&&this.required&&this.value.length===0;this.validityController.setValidity(missing?{valueMissing:!0}:{},missing?this.localize("tokenInputRequired"):""),this.toggleAttribute("data-invalid",!barred&&this.touched&&!this.internals.validity.valid),syncValidityStates(this.internals,{required:this.required,hasInteracted:this.touched,barred});const data=new FormData;this.name&&this.value.forEach(token=>data.append(this.name,token)),this.internals.setFormValue(this.name?data:null,createStringArrayFormDataState(this.name,this.value))}updateValue(next){const previousValue=Object.freeze([...this.value]);this.value=next,this.syncValidity();const detail=()=>Object.freeze({value:Object.freeze([...this.value]),previousValue});dispatchNativeInputEvent(this),this.emit("lr-input",detail()),dispatchNativeEvent(this,"change"),this.emit("lr-change",detail())}addDraft(){if(this.liveDisabled||this.readonly)return;const candidates=(this.delimiter?this.draft.split(this.delimiter):[this.draft]).map(token=>token.trim()).filter(Boolean),next=[...this.value],seen=this.allowDuplicates?null:new Set(next),added=[];for(const token of candidates)seen?.has(token)||(seen?.add(token),next.push(token),added.push(token));if(added.length===0){this.draft="";return}const addDetail=()=>Object.freeze({value:added[added.length-1],values:Object.freeze([...added])});this.emit("lr-token-add-request",addDetail(),{cancelable:!0}).defaultPrevented||(this.updateValue(next),this.draft="")}discardTransientState(clearDraft){this.editingIndex=-1,this.editDraft="",this.focusEditorPending=!1,this.focusTokenPending=-1,clearDraft&&(this.draft="",this.inputEl&&(this.inputEl.value=""))}retireDisabledInteraction(){this.tokenFocusRepairPending=void 0,this.discardTransientState(!0);const active=shadowFocusTarget(this);active&&typeof active.blur=="function"&&active.blur()}captureTokenFocusRepair(next){this.tokenFocusRepairPending=void 0;const active=shadowFocusTarget(this),token=typeof active?.closest=="function"?active.closest('[part~="token"]'):null;if(!active||!token)return;const index=this.tokenIndices.get(token)??-1;if(!Number.isInteger(index)||index<0||next.length>=this.renderedTokenValues.length&&next[index]===this.renderedTokenValues[index])return;const repair=captureComposedFocusRepair(this,active);if(!repair)return;const targetIndex=Math.min(index,Math.max(0,next.length-1));this.rovingIndex=targetIndex,this.tokenFocusRepairPending={index:targetIndex,surface:active.matches('[part~="remove"]')?"remove":"label",repair}}removeToken(index){if(this.liveDisabled||this.readonly)return;const removed=this.value[index];removed===void 0||this.emit("lr-token-remove-request",{value:removed,index},{cancelable:!0}).defaultPrevented||(this.editingIndex>=0&&(this.editingIndex=-1,this.editDraft=""),this.updateValue(this.value.filter((_token,i)=>i!==index)))}get activeTokenIndex(){return this.value.length?Math.min(Math.max(this.rovingIndex,0),this.value.length-1):-1}startEdit(index){this.liveDisabled||this.readonly||!this.editable||index<0||index>=this.value.length||(this.editingIndex=index,this.editDraft=this.value[index],this.rovingIndex=index,this.editorBlurRelayed=!1,this.focusEditorPending=!0)}cancelEdit(){this.editingIndex<0||(this.focusTokenPending=this.editingIndex,this.editingIndex=-1,this.editDraft="")}commitEdit(restoreFocus){if(this.liveDisabled||this.readonly){this.discardTransientState(!1);return}const index=this.editingIndex;if(index<0)return;const previousValue=this.value[index],next=this.editDraft.trim();if(previousValue===void 0||!next||next===previousValue||!this.allowDuplicates&&this.value.some((token,i)=>i!==index&&token===next)){restoreFocus&&(this.focusTokenPending=index),this.editingIndex=-1,this.editDraft="";return}this.emit("lr-token-edit-request",{value:next,previousValue,index},{cancelable:!0}).defaultPrevented||(restoreFocus&&(this.focusTokenPending=index),this.editingIndex=-1,this.editDraft="",this.updateValue(this.value.map((token,i)=>i===index?next:token)))}moveRovingFocus(index){if(!this.value.length)return;const clamped=Math.min(Math.max(index,0),this.value.length-1);this.rovingIndex=clamped,this.focusTokenPending=clamped}onTokenKeyDown(event,index){if(this.liveDisabled)return;const rtl=this.effectiveDirection==="rtl",forward=rtl?"ArrowLeft":"ArrowRight",backward=rtl?"ArrowRight":"ArrowLeft";event.key==="Enter"||event.key===" "||event.key==="F2"?(event.preventDefault(),this.startEdit(index)):event.key===forward?(event.preventDefault(),this.moveRovingFocus(index+1)):event.key===backward?(event.preventDefault(),this.moveRovingFocus(index-1)):event.key==="Home"?(event.preventDefault(),this.moveRovingFocus(0)):event.key==="End"&&(event.preventDefault(),this.moveRovingFocus(this.value.length-1))}stopInternalChange(event){event.stopPropagation()}formResetCallback(){this.restoreLiveValueFromDefault(),this.discardTransientState(!0),this.rovingIndex=0,this.touched=!1,this.syncValidity()}restoreLiveValueFromDefault(){this.settingDefaultValue=!0;try{this.value=[...this._defaultValue]}finally{this.settingDefaultValue=!1}this._valueDirty=!1}formStateRestoreCallback(state2,_mode){this.value=readStringArrayFormDataState(state2),this.discardTransientState(!0),this.rovingIndex=0,this.touched=!1,this.syncValidity()}updated(changed){if(super.updated(changed),this.syncExternalDescription(),this.focusEditorPending){this.focusEditorPending=!1;const editor=this.renderRoot?.querySelector('[part="token-editor"]');editor?.focus(),editor?.select()}if(this.focusTokenPending>=0){const index=this.focusTokenPending;this.focusTokenPending=-1;const label=this.tokenElement(index)?.querySelector('[part="token-label"]');label?.focus(),label?.scrollIntoView({block:"nearest",inline:"nearest"})}const pending=this.tokenFocusRepairPending;if(this.tokenFocusRepairPending=void 0,pending){const token=this.tokenElement(pending.index),target=(pending.surface==="remove"?token?.querySelector('[part~="remove"]'):token?.querySelector('[part~="token-label"]'))??token?.querySelector('[part~="remove"]')??this.inputEl??null;applyComposedFocusRepair(pending.repair,target)&&target?.scrollIntoView({block:"nearest",inline:"nearest"})}}renderRemoveButton(token){return html`<button
|
|
2
2
|
part="remove"
|
|
3
3
|
type="button"
|
|
4
4
|
aria-label=${this.localize("removeWithContext",void 0,{label:token})}
|
|
@@ -88,4 +88,4 @@ import{__decorate}from"tslib";import{ref}from"lit/directives/ref.js";import{repe
|
|
|
88
88
|
<div part="error" id=${this.errorId} ?hidden=${!hasError}>
|
|
89
89
|
${this.errorText}<slot name="error"></slot>
|
|
90
90
|
</div>
|
|
91
|
-
</div>`}}__decorate([property()],LyraTokenInput.prototype,"label",void 0),__decorate([property()],LyraTokenInput.prototype,"hint",void 0),__decorate([property({attribute:"error-text"})],LyraTokenInput.prototype,"errorText",void 0),__decorate([property()],LyraTokenInput.prototype,"placeholder",void 0),__decorate([property({converter:spellcheckConverter})],LyraTokenInput.prototype,"spellcheck",void 0),__decorate([property()],LyraTokenInput.prototype,"autocapitalize",void 0),__decorate([property({converter:autocorrectConverter})],LyraTokenInput.prototype,"autocorrect",null),__decorate([property({attribute:"aria-label"})],LyraTokenInput.prototype,"accessibleLabel",void 0),__decorate([property({reflect:!0})],LyraTokenInput.prototype,"size",void 0),__decorate([property({type:Boolean,reflect:!0})],LyraTokenInput.prototype,"pill",void 0),__decorate([property({attribute:"allow-duplicates",type:Boolean})],LyraTokenInput.prototype,"allowDuplicates",void 0),__decorate([property({attribute:"editable",type:Boolean,reflect:!0})],LyraTokenInput.prototype,"editable",null),__decorate([property({attribute:"delimiter",converter:delimiterConverter})],LyraTokenInput.prototype,"delimiter",void 0),__decorate([property({type:Number,attribute:"max-tokens-visible"})],LyraTokenInput.prototype,"maxTokensVisible",void 0),__decorate([state()],LyraTokenInput.prototype,"draft",void 0),__decorate([state()],LyraTokenInput.prototype,"touched",void 0),__decorate([state()],LyraTokenInput.prototype,"editingIndex",void 0),__decorate([state()],LyraTokenInput.prototype,"editDraft",void 0),__decorate([state()],LyraTokenInput.prototype,"rovingIndex",void 0),__decorate([query("#input")],LyraTokenInput.prototype,"inputEl",void 0),__decorate([property({attribute:!1})],LyraTokenInput.prototype,"value",null);export{LyraTokenInput};
|
|
91
|
+
</div>`}}__decorate([property()],LyraTokenInput.prototype,"label",void 0),__decorate([property({attribute:"label-display",reflect:!0})],LyraTokenInput.prototype,"labelDisplay",void 0),__decorate([property()],LyraTokenInput.prototype,"hint",void 0),__decorate([property({attribute:"error-text"})],LyraTokenInput.prototype,"errorText",void 0),__decorate([property()],LyraTokenInput.prototype,"placeholder",void 0),__decorate([property({converter:spellcheckConverter})],LyraTokenInput.prototype,"spellcheck",void 0),__decorate([property()],LyraTokenInput.prototype,"autocapitalize",void 0),__decorate([property({converter:autocorrectConverter})],LyraTokenInput.prototype,"autocorrect",null),__decorate([property({attribute:"aria-label"})],LyraTokenInput.prototype,"accessibleLabel",void 0),__decorate([property({reflect:!0})],LyraTokenInput.prototype,"size",void 0),__decorate([property({type:Boolean,reflect:!0})],LyraTokenInput.prototype,"pill",void 0),__decorate([property({attribute:"allow-duplicates",type:Boolean})],LyraTokenInput.prototype,"allowDuplicates",void 0),__decorate([property({attribute:"editable",type:Boolean,reflect:!0})],LyraTokenInput.prototype,"editable",null),__decorate([property({attribute:"delimiter",converter:delimiterConverter})],LyraTokenInput.prototype,"delimiter",void 0),__decorate([property({type:Number,attribute:"max-tokens-visible"})],LyraTokenInput.prototype,"maxTokensVisible",void 0),__decorate([state()],LyraTokenInput.prototype,"draft",void 0),__decorate([state()],LyraTokenInput.prototype,"touched",void 0),__decorate([state()],LyraTokenInput.prototype,"editingIndex",void 0),__decorate([state()],LyraTokenInput.prototype,"editDraft",void 0),__decorate([state()],LyraTokenInput.prototype,"rovingIndex",void 0),__decorate([query("#input")],LyraTokenInput.prototype,"inputEl",void 0),__decorate([property({attribute:!1})],LyraTokenInput.prototype,"value",null);export{LyraTokenInput};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{iconHitTarget,focusRing}from"../../../internal/interactive-control.styles.js";import{css}from"lit";import{formControlTextWrap,formControlFocusHalo,formControlRequiredMarker}from"../../../internal/form-control.styles.js";const styles=css` :host { display: block; min-inline-size: 0; max-inline-size: 100%; box-sizing: border-box; --_lr-token-input-min-input-inline-size: var(--lr-size-4rem); --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-space-xs); --_lr-token-input-font-size: var(--lr-font-size-md-sm); --_lr-token-input-token-padding: var(--lr-space-2xs) var(--lr-space-xs); --_lr-token-input-gap: var(--lr-space-xs); --_lr-token-input-token-gap: var(--lr-space-2xs); --_lr-token-input-radius: var(--lr-radius); --_lr-token-input-control-min-height: var(--lr-form-control-height); --_lr-form-control-focus-shadow: var(--lr-form-control-focus-shadow, none); } :host([pill]) { --_lr-token-input-radius: var(--lr-radius-pill); } :host([size="2xs"]) { --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-size-0-0625rem); --_lr-token-input-font-size: var(--lr-font-size-2xs); --_lr-token-input-token-padding: 0 var(--lr-space-2xs); } :host([size="xs"]) { --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-size-0-125rem); --_lr-token-input-font-size: var(--lr-font-size-xs); --_lr-token-input-token-padding: var(--lr-size-1px) var(--lr-space-2xs); } :host([size="s"]), :host([size="small"]) { --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-space-xs); --_lr-token-input-font-size: var(--lr-font-size-sm); --_lr-token-input-token-padding: var(--lr-space-2xs) var(--lr-space-xs); } :host([size="l"]), :host([size="large"]) { --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-space-m); --_lr-token-input-font-size: var(--lr-font-size-lg); --_lr-token-input-token-padding: var(--lr-space-xs) var(--lr-space-s); } :host([size="xl"]) { --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-space-l); --_lr-token-input-font-size: var(--lr-font-size-xl); --_lr-token-input-token-padding: var(--lr-space-s) var(--lr-space-m); } [part="form-control"] { display: grid; min-inline-size: 0; max-inline-size: 100%; gap: var(--lr-token-input-gap, var(--_lr-token-input-gap)); } [part="form-control-label"] { color: var(--lr-color-text); font-weight: var(--lr-font-weight-semibold); } :host([required]) [part="form-control-label"] > span[aria-hidden="true"] { display: none; } ${formControlRequiredMarker} [part='input-wrapper'] { display: flex; flex-wrap: wrap; min-inline-size: 0; max-inline-size: 100%; overflow-x: hidden; overflow-y: auto; align-items: center; gap: var(--lr-token-input-gap, var(--_lr-token-input-gap)); min-block-size: var( --lr-token-input-control-height, var( --lr-token-input-control-min-height, var(--_lr-token-input-control-min-height) ) ); block-size: var(--lr-token-input-control-height, auto); padding: var(--lr-token-input-padding, var(--_lr-token-input-padding)); font-size: var( --lr-token-input-font-size, var(--_lr-token-input-font-size) ); border: var(--lr-border-width-thin) solid var(--lr-token-input-border-color, var(--lr-color-border)); border-radius: var(--lr-token-input-radius, var(--_lr-token-input-radius)); background: var(--lr-token-input-fill, var(--lr-color-surface)); } [part="input-wrapper"]:focus-within { border-color: var( --lr-token-input-focus-border-color, var(--lr-color-brand) ); ${focusRing} ${formControlFocusHalo} } [part="input"] { flex: 1 1 var(--lr-token-input-input-inline-size, var(--lr-size-8rem)); min-inline-size: var( --lr-token-input-min-input-inline-size, var(--_lr-token-input-min-input-inline-size) ); padding-block: 0; border: 0; outline: 0; background: transparent; color: var(--lr-color-text); font: inherit; } [part="input"]::placeholder { color: var(--lr-color-text-quiet); } [part="start"], [part="end"] { flex: 0 0 auto; display: inline-flex; align-items: center; color: var(--lr-color-text-quiet); } [part="start"][hidden], [part="end"][hidden] { display: none; } [part="token"] { display: inline-flex; min-inline-size: 0; max-inline-size: 100%; overflow: hidden; align-items: center; gap: var(--lr-token-input-token-gap, var(--_lr-token-input-token-gap)); padding: var( --lr-token-input-token-padding, var(--_lr-token-input-token-padding) ); border-radius: var(--lr-token-input-radius, var(--_lr-token-input-radius)); background: var(--lr-token-input-token-bg, var(--lr-color-brand-quiet)); color: var(--lr-color-text); } [part="token"] > span:first-child { min-inline-size: 0; } [part="token"] > span:first-child, [part="token-label"] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } [part="remove"] { display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center; ${iconHitTarget} border: 0; padding: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; transition: background-color var(--lr-transition-fast); } [part="remove"]:hover { background: var( --lr-token-input-remove-hover-bg, var(--lr-token-input-action-hover-bg, var(--lr-color-brand-quiet)) ); } [part="remove"]:active { background: var( --lr-token-input-remove-pressed-bg, color-mix( in oklab, var( --lr-token-input-remove-hover-bg, var(--lr-token-input-action-hover-bg, var(--lr-color-brand-quiet)) ), var(--lr-color-mix-partner) var(--lr-color-mix-active) ) ); } [part="remove"]:focus-visible { ${focusRing} } [part="remove"][aria-disabled="true"] { cursor: default; opacity: var(--lr-opacity-disabled); } [part="remove"][aria-disabled="true"]:hover, [part="remove"][aria-disabled="true"]:active { background: transparent; } [part="token-label"] { align-content: center; ${iconHitTarget} border-radius: var(--lr-token-input-radius, var(--_lr-token-input-radius)); cursor: pointer; transition: background-color var(--lr-transition-fast); } :host(:where(:not(:disabled))) [part="token-label"]:hover { background: var( --lr-token-input-edit-hover-bg, var(--lr-token-input-action-hover-bg, var(--lr-color-brand-quiet)) ); } :host(:where(:not(:disabled))) [part="token-label"]:active { background: var( --lr-token-input-edit-pressed-bg, color-mix( in oklab, var( --lr-token-input-edit-hover-bg, var(--lr-token-input-action-hover-bg, var(--lr-color-brand-quiet)) ), var(--lr-color-mix-partner) var(--lr-color-mix-active) ) ); } [part="token-label"]:focus-visible { ${focusRing} } :host(:disabled) [part="token-label"] { cursor: default; } [part="token-editor"] { inline-size: var(--lr-token-input-editor-inline-size, var(--lr-size-6rem)); max-inline-size: 100%; border: 0; outline: 0; padding: 0; background: transparent; color: inherit; font: inherit; } [part="token-editor"]::placeholder { color: var(--lr-color-text-quiet); } [part="hint"], [part="error"] { color: var(--lr-color-text-quiet); font-size: var(--lr-font-size-sm); } [part="error"] { color: var(--lr-color-danger); } :host([data-invalid]) [part="input-wrapper"] { border-color: var( --lr-token-input-invalid-border-color, var(--lr-color-danger) ); } :host(:disabled) { opacity: var(--lr-opacity-disabled); } [part="form-control-label"], [part="hint"], [part="error"] { ${formControlTextWrap} } `;export{styles};
|
|
1
|
+
import{iconHitTarget,focusRing}from"../../../internal/interactive-control.styles.js";import{css}from"lit";import{formControlTextWrap,formControlFocusHalo,formControlRequiredMarker,formControlLabelDisplay}from"../../../internal/form-control.styles.js";const styles=css` :host { display: block; min-inline-size: 0; max-inline-size: 100%; box-sizing: border-box; --_lr-token-input-min-input-inline-size: var(--lr-size-4rem); --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-space-xs); --_lr-token-input-font-size: var(--lr-font-size-md-sm); --_lr-token-input-token-padding: var(--lr-space-2xs) var(--lr-space-xs); --_lr-token-input-gap: var(--lr-space-xs); --_lr-token-input-token-gap: var(--lr-space-2xs); --_lr-token-input-radius: var(--lr-radius); --_lr-token-input-control-min-height: var(--lr-form-control-height); --_lr-form-control-focus-shadow: var(--lr-form-control-focus-shadow, none); } :host([pill]) { --_lr-token-input-radius: var(--lr-radius-pill); } :host([size="2xs"]) { --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-size-0-0625rem); --_lr-token-input-font-size: var(--lr-font-size-2xs); --_lr-token-input-token-padding: 0 var(--lr-space-2xs); } :host([size="xs"]) { --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-size-0-125rem); --_lr-token-input-font-size: var(--lr-font-size-xs); --_lr-token-input-token-padding: var(--lr-size-1px) var(--lr-space-2xs); } :host([size="s"]), :host([size="small"]) { --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-space-xs); --_lr-token-input-font-size: var(--lr-font-size-sm); --_lr-token-input-token-padding: var(--lr-space-2xs) var(--lr-space-xs); } :host([size="l"]), :host([size="large"]) { --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-space-m); --_lr-token-input-font-size: var(--lr-font-size-lg); --_lr-token-input-token-padding: var(--lr-space-xs) var(--lr-space-s); } :host([size="xl"]) { --_lr-token-input-padding: var(--lr-form-control-padding-block) var(--lr-space-l); --_lr-token-input-font-size: var(--lr-font-size-xl); --_lr-token-input-token-padding: var(--lr-space-s) var(--lr-space-m); } [part="form-control"] { display: grid; min-inline-size: 0; max-inline-size: 100%; gap: var(--lr-token-input-gap, var(--_lr-token-input-gap)); } [part="form-control-label"] { color: var(--lr-color-text); font-weight: var(--lr-font-weight-semibold); } :host([required]) [part="form-control-label"] > span[aria-hidden="true"] { display: none; } ${formControlRequiredMarker} ${formControlLabelDisplay} [part='input-wrapper'] { display: flex; flex-wrap: wrap; min-inline-size: 0; max-inline-size: 100%; overflow-x: hidden; overflow-y: auto; align-items: center; gap: var(--lr-token-input-gap, var(--_lr-token-input-gap)); min-block-size: var( --lr-token-input-control-height, var( --lr-token-input-control-min-height, var(--_lr-token-input-control-min-height) ) ); block-size: var(--lr-token-input-control-height, auto); padding: var(--lr-token-input-padding, var(--_lr-token-input-padding)); font-size: var( --lr-token-input-font-size, var(--_lr-token-input-font-size) ); border: var(--lr-border-width-thin) solid var(--lr-token-input-border-color, var(--lr-color-border)); border-radius: var(--lr-token-input-radius, var(--_lr-token-input-radius)); background: var(--lr-token-input-fill, var(--lr-color-surface)); } [part="input-wrapper"]:focus-within { border-color: var( --lr-token-input-focus-border-color, var(--lr-color-brand) ); ${focusRing} ${formControlFocusHalo} } [part="input"] { flex: 1 1 var(--lr-token-input-input-inline-size, var(--lr-size-8rem)); min-inline-size: var( --lr-token-input-min-input-inline-size, var(--_lr-token-input-min-input-inline-size) ); padding-block: 0; border: 0; outline: 0; background: transparent; color: var(--lr-color-text); font: inherit; } [part="input"]::placeholder { color: var(--lr-color-text-quiet); } [part="start"], [part="end"] { flex: 0 0 auto; display: inline-flex; align-items: center; color: var(--lr-color-text-quiet); } [part="start"][hidden], [part="end"][hidden] { display: none; } [part="token"] { display: inline-flex; min-inline-size: 0; max-inline-size: 100%; overflow: hidden; align-items: center; gap: var(--lr-token-input-token-gap, var(--_lr-token-input-token-gap)); padding: var( --lr-token-input-token-padding, var(--_lr-token-input-token-padding) ); border-radius: var(--lr-token-input-radius, var(--_lr-token-input-radius)); background: var(--lr-token-input-token-bg, var(--lr-color-brand-quiet)); color: var(--lr-color-text); } [part="token"] > span:first-child { min-inline-size: 0; } [part="token"] > span:first-child, [part="token-label"] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } [part="remove"] { display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center; ${iconHitTarget} border: 0; padding: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; transition: background-color var(--lr-transition-fast); } [part="remove"]:hover { background: var( --lr-token-input-remove-hover-bg, var(--lr-token-input-action-hover-bg, var(--lr-color-brand-quiet)) ); } [part="remove"]:active { background: var( --lr-token-input-remove-pressed-bg, color-mix( in oklab, var( --lr-token-input-remove-hover-bg, var(--lr-token-input-action-hover-bg, var(--lr-color-brand-quiet)) ), var(--lr-color-mix-partner) var(--lr-color-mix-active) ) ); } [part="remove"]:focus-visible { ${focusRing} } [part="remove"][aria-disabled="true"] { cursor: default; opacity: var(--lr-opacity-disabled); } [part="remove"][aria-disabled="true"]:hover, [part="remove"][aria-disabled="true"]:active { background: transparent; } [part="token-label"] { align-content: center; ${iconHitTarget} border-radius: var(--lr-token-input-radius, var(--_lr-token-input-radius)); cursor: pointer; transition: background-color var(--lr-transition-fast); } :host(:where(:not(:disabled))) [part="token-label"]:hover { background: var( --lr-token-input-edit-hover-bg, var(--lr-token-input-action-hover-bg, var(--lr-color-brand-quiet)) ); } :host(:where(:not(:disabled))) [part="token-label"]:active { background: var( --lr-token-input-edit-pressed-bg, color-mix( in oklab, var( --lr-token-input-edit-hover-bg, var(--lr-token-input-action-hover-bg, var(--lr-color-brand-quiet)) ), var(--lr-color-mix-partner) var(--lr-color-mix-active) ) ); } [part="token-label"]:focus-visible { ${focusRing} } :host(:disabled) [part="token-label"] { cursor: default; } [part="token-editor"] { inline-size: var(--lr-token-input-editor-inline-size, var(--lr-size-6rem)); max-inline-size: 100%; border: 0; outline: 0; padding: 0; background: transparent; color: inherit; font: inherit; } [part="token-editor"]::placeholder { color: var(--lr-color-text-quiet); } [part="hint"], [part="error"] { color: var(--lr-color-text-quiet); font-size: var(--lr-font-size-sm); } [part="error"] { color: var(--lr-color-danger); } :host([data-invalid]) [part="input-wrapper"] { border-color: var( --lr-token-input-invalid-border-color, var(--lr-color-danger) ); } :host(:disabled) { opacity: var(--lr-opacity-disabled); } [part="form-control-label"], [part="hint"], [part="error"] { ${formControlTextWrap} } `;export{styles};
|
|
@@ -49,8 +49,22 @@ readonly expanded:boolean;}export interface LyraDockPanelEventMap{'lr-resize-req
|
|
|
49
49
|
* collapsed, so re-expanding restores what it was unless the live container
|
|
50
50
|
* bounds now require a smaller or larger valid extent.
|
|
51
51
|
*
|
|
52
|
+
* Elements in the `rail` slot show in that rail only while collapsed -- typically one icon button
|
|
53
|
+
* per section the panel holds -- stacked after the toggle (in a column on `start`/`end`, in a row
|
|
54
|
+
* on `top`/`bottom`), and the rail grows past `--lr-dock-panel-collapsed-size` to fit them. A rail
|
|
55
|
+
* item usually calls `expand()`; `expand()`, `collapse()` and `toggle()` drive the fold from any
|
|
56
|
+
* consumer-owned control through the same cancelable `lr-toggle-request`/`lr-toggle` pair as the
|
|
57
|
+
* built-in toggle, so a panel without `collapsible` can place its own control in its content.
|
|
58
|
+
* Collapsing while focus is inside moves it to the built-in toggle, else to the first focusable rail
|
|
59
|
+
* item, else to the host; expanding while focus is on a rail item moves it to the toggle or the host.
|
|
60
|
+
*
|
|
52
61
|
* @customElement lr-dock-panel
|
|
53
62
|
* @slot - The panel's own content.
|
|
63
|
+
* @slot rail - Shown in the collapsed rail only while `collapsed`, after the collapse toggle.
|
|
64
|
+
* @slot collapse-icon - Decorative glyph for the expanded panel's collapse toggle, replacing the
|
|
65
|
+
* chevron. The toggle keeps its localized accessible name and the glyph is not rotated.
|
|
66
|
+
* @slot expand-icon - Decorative glyph for the collapsed panel's expand toggle, replacing the
|
|
67
|
+
* chevron. The toggle keeps its localized accessible name and the glyph is not rotated.
|
|
54
68
|
* @event lr-resize-request - Cancelable proposed `detail: { extent }` before each pointer or
|
|
55
69
|
* keyboard resize step. Preventing it leaves the current extent unchanged.
|
|
56
70
|
* @event lr-resize - Accepted pointer or keyboard step with frozen `detail: { extent }`.
|
|
@@ -60,16 +74,18 @@ readonly expanded:boolean;}export interface LyraDockPanelEventMap{'lr-resize-req
|
|
|
60
74
|
* least one accepted value transition, and after each accepted keyboard step. Pointer
|
|
61
75
|
* cancellation, lost capture, policy/geometry mutation, no-op attempts, and a prevented
|
|
62
76
|
* `lr-resize-request` all emit nothing.
|
|
63
|
-
* @event lr-toggle-request - Cancelable proposed `detail: { expanded }` before the built-in toggle
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
77
|
+
* @event lr-toggle-request - Cancelable proposed `detail: { expanded }` before the built-in toggle,
|
|
78
|
+
* `expand()`, `collapse()` or `toggle()` commits. Call `preventDefault()` to keep `collapsed`
|
|
79
|
+
* unchanged. Not fired when a consumer sets `collapsed` directly.
|
|
80
|
+
* @event lr-toggle - Accepted disclosure change from the built-in toggle or one of those methods, with
|
|
81
|
+
* `detail: { expanded }`. Not fired when a consumer sets `collapsed` directly.
|
|
67
82
|
* @csspart base - The panel root.
|
|
68
83
|
* @csspart content - The wrapper around the default slot; hidden while `collapsed`.
|
|
69
84
|
* @csspart handle - The draggable resize handle on the panel's inner edge. Its numeric ARIA range
|
|
70
85
|
* remains in CSS pixels while `aria-valuetext` reports the current extent through the effective
|
|
71
86
|
* locale. Only rendered when not `without-resize` and not `collapsed`.
|
|
72
87
|
* @csspart collapse-toggle - The collapse/expand toggle button. Only rendered when `collapsible`.
|
|
88
|
+
* @csspart rail - The wrapper around the `rail` slot; hidden unless `collapsed`.
|
|
73
89
|
* @cssprop [--lr-dock-panel-collapsed-size=var(--lr-icon-button-size)] - The extent the panel
|
|
74
90
|
* keeps along its resize axis while `collapsed` -- enough to still host the toggle button that
|
|
75
91
|
* re-expands it.
|
|
@@ -83,8 +99,11 @@ readonly expanded:boolean;}export interface LyraDockPanelEventMap{'lr-resize-req
|
|
|
83
99
|
* (drag affordance vs. button feedback).
|
|
84
100
|
* @cssprop [--lr-dock-panel-handle-active-color=color-mix(in oklab, var(--lr-dock-panel-handle-hover-color, var(--lr-color-brand)), var(--lr-color-mix-partner) var(--lr-color-mix-active))] -
|
|
85
101
|
* Background of `handle` while actively dragged/pressed.
|
|
86
|
-
* @cssprop [--lr-dock-panel-handle-hit-area=var(--lr-space-m)] -
|
|
87
|
-
*
|
|
102
|
+
* @cssprop [--lr-dock-panel-handle-hit-area=var(--lr-space-m)] - Resize target width along the
|
|
103
|
+
* panel's inner edge, inside its clipped box and over its content. Precise pointers get exactly
|
|
104
|
+
* this width, so content beside the edge stays clickable (set it to the visible line, e.g. `3px`,
|
|
105
|
+
* to give the content every pixel); coarse or hover-less pointers get at least
|
|
106
|
+
* `--lr-icon-button-size`.
|
|
88
107
|
* @status stable
|
|
89
108
|
* @since 4.0.0
|
|
90
109
|
*/
|
|
@@ -106,4 +125,13 @@ minExtent:string;
|
|
|
106
125
|
* its container. */
|
|
107
126
|
maxExtent:string;collapsible:boolean;private readonly toggleWriteGuard;private _collapsed;get collapsed():boolean;set collapsed(next:boolean);
|
|
108
127
|
/** When set, no drag handle renders at all and the panel is a fixed size.*/
|
|
109
|
-
withoutResize:boolean;private drag;private readonly resizeWriteGuard;private resizeRequestSequence;private renderBounds?;private renderSizePx?;private readonly dragController;private readonly contentId;private containerResizeObserver?;connectedCallback():void;disconnectedCallback():void;adoptedCallback():void;private armContainerResizeObserver;private get container();private relocateFocus;protected willUpdate(changed:PropertyValues):void;private get axis();private get growSign();private applyHostSize;private containerPx;private resolveBoundsPx;private currentSizePx;private resizeValueText;private reconcileLiveExtent;private resolveProposal;private applyProposal;private requestResize;private emitResize;private dragSnapshotIsCurrent;private onPointerDown;private onPointerMove;private onPointerUp;private onPointerCancel;private endDrag;private onHandleKeyDown;
|
|
128
|
+
withoutResize:boolean;private drag;private readonly resizeWriteGuard;private resizeRequestSequence;private renderBounds?;private renderSizePx?;private readonly dragController;private readonly contentId;private hasRail;private pendingRailFocus;private containerResizeObserver?;connectedCallback():void;disconnectedCallback():void;adoptedCallback():void;private armContainerResizeObserver;private get container();private railElements;private onRailSlotChange;private focusRail;private relocateFocus;private focusHost;protected willUpdate(changed:PropertyValues):void;protected updated(changed:PropertyValues):void;private get axis();private get growSign();private applyHostSize;private collapsedFloor;private containerPx;private resolveBoundsPx;private currentSizePx;private resizeValueText;private reconcileLiveExtent;private resolveProposal;private applyProposal;private requestResize;private emitResize;private dragSnapshotIsCurrent;private onPointerDown;private onPointerMove;private onPointerUp;private onPointerCancel;private endDrag;private onHandleKeyDown;
|
|
129
|
+
/** Expands the panel through the cancelable `lr-toggle-request`/`lr-toggle` pair, exactly as the
|
|
130
|
+
* built-in toggle does. Returns whether the panel is expanded afterwards. */
|
|
131
|
+
expand():boolean;
|
|
132
|
+
/** Collapses the panel through the cancelable `lr-toggle-request`/`lr-toggle` pair, exactly as the
|
|
133
|
+
* built-in toggle does. Returns whether the panel is collapsed afterwards. */
|
|
134
|
+
collapse():boolean;
|
|
135
|
+
/** Flips the fold through the cancelable `lr-toggle-request`/`lr-toggle` pair, exactly as the
|
|
136
|
+
* built-in toggle does. Returns whether the panel is expanded afterwards. */
|
|
137
|
+
toggle():boolean;private dispatchingToggle;private toggleCollapsed;private get topBottomChevronDeg();private handleTemplate;private collapseToggleTemplate;render():TemplateResult;}declare global{interface HTMLElementTagNameMap{'lr-dock-panel':LyraDockPanel;}}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate}from"tslib";import{html,nothing}from"lit";import{property}from"lit/decorators.js";import{LyraElement}from"../../../internal/lyra-element.js";import{isRtl}from"../../../internal/rtl.js";import{nextId}from"../../../internal/a11y.js";import{chevronIcon}from"../../../internal/icons.js";import{flattenedParentElement}from"../../../internal/composed-tree.js";import{styles}from"./dock-panel.styles.js";import{resolveCssLength}from"../../../internal/css-length.js";import{getNumberFormat}from"../../../internal/intl-cache.js";import{SeparatorDragController,separatorArrowDirection,separatorCoordinate}from"../../../internal/separator-drag.js";import{markVetoGuardWrite,VetoWriteGuard}from"../../../internal/veto-write-guard.js";import{requestThenCommit}from"../../../internal/request-commit.js";import{shadowFocusTarget}from"../../../internal/active-element.js";import{LYRA_DEFAULT_dockPanelCollapse,LYRA_DEFAULT_dockPanelExpand,LYRA_DEFAULT_dockPanelResize}from"../../../internal/default-strings/layout.generated.js";import{LYRA_DEFAULT_resizeValuePixels}from"../../../internal/default-strings/shared.generated.js";const KEYBOARD_STEP_PX=16;class LyraDockPanel extends LyraElement{constructor(){super(...arguments),this.placement="end",this._extent="280px",this.minExtent="160px",this.maxExtent="",this.collapsible=!1,this.toggleWriteGuard=new VetoWriteGuard,this._collapsed=!1,this.withoutResize=!1,this.drag=null,this.resizeWriteGuard=new VetoWriteGuard,this.resizeRequestSequence=0,this.dragController=new SeparatorDragController(this,event=>this.onPointerMove(event),event=>event.type==="pointerup"?this.onPointerUp(event):this.onPointerCancel(event)),this.contentId=nextId("dock-panel-content"),this.onPointerDown=e=>{if(!e.isPrimary||e.button!==0||this.withoutResize||this.collapsed||this.drag)return;const handle=e.currentTarget;if(!this.dragController.start(e,handle))return;const axis=this.axis,growSign=this.growSign,containerPx=this.containerPx(),startSizePx=this.currentSizePx();this.drag={pointerId:e.pointerId,startPos:separatorCoordinate(e,axis),startSizePx,axis,growSign,placement:this.placement,minExtent:this.minExtent,maxExtent:this.maxExtent,containerPx,bounds:this.resolveBoundsPx(containerPx),currentSizePx:startSizePx,expectedExtent:this.extent,finalExtent:this.extent,acceptedResize:!1}},this.onPointerMove=e=>{const drag=this.drag;if(!drag||e.pointerId!==drag.pointerId)return;if(this.withoutResize||this.collapsed||this.placement!==drag.placement||this.axis!==drag.axis||this.growSign!==drag.growSign||this.extent!==drag.expectedExtent||this.minExtent!==drag.minExtent||this.maxExtent!==drag.maxExtent){this.endDrag();return}const pos=separatorCoordinate(e,drag.axis),delta=drag.growSign*(pos-drag.startPos),proposal=this.resolveProposal(drag.startSizePx+delta,drag.bounds,drag.currentSizePx);if(!proposal)return;const extent=this.requestResize(proposal.bounds,proposal.nextExtent);!extent||this.drag!==drag||(drag.expectedExtent=extent,drag.finalExtent=extent,drag.currentSizePx=parseFloat(extent),drag.acceptedResize=!0,this.emitResize("lr-resize",extent),!(this.drag!==drag||this.extent!==extent||this.collapsed||this.withoutResize)&&this.emitResize("lr-resize-input",extent))},this.onPointerUp=e=>{const drag=this.drag;if(!drag||e.pointerId!==drag.pointerId)return;const shouldCommit=drag.acceptedResize&&this.dragSnapshotIsCurrent(drag),finalExtent=drag.finalExtent;this.endDrag(),shouldCommit&&this.emitResize("lr-resize-change",finalExtent)},this.onPointerCancel=e=>{!this.drag||e.pointerId!==this.drag.pointerId||this.endDrag()},this.onHandleKeyDown=e=>{if(this.withoutResize||this.collapsed||e.altKey||e.ctrlKey||e.metaKey||e.isComposing)return;const arrowDirection=separatorArrowDirection(e,this.axis,!1);let proposal;if(e.key==="Home"||e.key==="End"){e.preventDefault();const{minPx,maxPx}=this.resolveBoundsPx();proposal=this.resolveProposal(e.key==="Home"?minPx:maxPx)}else arrowDirection===1?(e.preventDefault(),proposal=this.resolveProposal(this.currentSizePx()+this.growSign*KEYBOARD_STEP_PX)):arrowDirection===-1&&(e.preventDefault(),proposal=this.resolveProposal(this.currentSizePx()-this.growSign*KEYBOARD_STEP_PX));if(!proposal)return;const extent=this.requestResize(proposal.bounds,proposal.nextExtent);extent&&(this.emitResize("lr-resize",extent),!(this.extent!==extent||this.collapsed||this.withoutResize)&&(this.emitResize("lr-resize-input",extent),!(this.extent!==extent||this.collapsed||this.withoutResize)&&this.emitResize("lr-resize-change",extent)))},this.dispatchingToggle=!1,this.toggleCollapsed=()=>{if(this.dispatchingToggle)return;const previous=this.collapsed,detail=()=>Object.freeze({expanded:previous});this.dispatchingToggle=!0;try{requestThenCommit({requestDetail:detail(),emitRequest:(proposal,init)=>this.emit("lr-toggle-request",proposal,init),guard:this.toggleWriteGuard,commit:()=>{this.collapsed===previous&&(this.collapsed=!previous,this.emit("lr-toggle",detail()))}})}finally{this.dispatchingToggle=!1}}}static{this.defaultStrings={...super.defaultStrings,dockPanelCollapse:LYRA_DEFAULT_dockPanelCollapse,dockPanelExpand:LYRA_DEFAULT_dockPanelExpand,dockPanelResize:LYRA_DEFAULT_dockPanelResize,resizeValuePixels:LYRA_DEFAULT_resizeValuePixels}}static{this.styles=[LyraElement.styles,styles]}get extent(){return this._extent}set extent(value){const old=this._extent;this._extent=value,markVetoGuardWrite(this.resizeWriteGuard),this.requestUpdate("extent",old)}get collapsed(){return this._collapsed}set collapsed(next){const old=this._collapsed;this._collapsed=next,markVetoGuardWrite(this.toggleWriteGuard),this.requestUpdate("collapsed",old)}connectedCallback(){super.connectedCallback(),this.renderBounds=void 0,this.renderSizePx=void 0,this.applyHostSize(),this.armContainerResizeObserver()}disconnectedCallback(){super.disconnectedCallback(),this.endDrag(),this.containerResizeObserver?.disconnect(),this.containerResizeObserver=void 0}adoptedCallback(){super.adoptedCallback(),this.renderBounds=void 0,this.renderSizePx=void 0,this.endDrag(),this.containerResizeObserver?.disconnect(),this.containerResizeObserver=void 0}armContainerResizeObserver(){const ResizeObserverCtor=this.ownerDocument.defaultView?.ResizeObserver,container=this.container;!container||!ResizeObserverCtor||(this.containerResizeObserver??=new ResizeObserverCtor(()=>{this.isConnected&&(this.drag&&!this.dragSnapshotIsCurrent(this.drag)&&this.endDrag(),this.reconcileLiveExtent(),this.requestUpdate())}),this.containerResizeObserver.observe(container),this.containerResizeObserver.observe(this))}get container(){let parent=flattenedParentElement(this);for(;parent?.localName==="slot";)parent=flattenedParentElement(parent);return parent}relocateFocus(){const toggle=this.renderRoot.querySelector('[part="collapse-toggle"]');if(toggle){toggle.focus();return}this.hasAttribute("tabindex")||(this.tabIndex=-1,this.addEventListener("blur",()=>this.removeAttribute("tabindex"),{once:!0})),this.focus()}willUpdate(changed){super.willUpdate(changed),this.hasUpdated&&(changed.has("collapsed")&&this.collapsed&&this.matches(":focus-within")||changed.has("withoutResize")&&this.withoutResize&&shadowFocusTarget(this)?.matches('[part="handle"]'))&&this.relocateFocus(),changed.has("extent")||changed.has("minExtent")||changed.has("maxExtent")||changed.has("collapsed")||changed.has("placement")?(this.drag&&!this.dragSnapshotIsCurrent(this.drag)&&this.endDrag(),this.reconcileLiveExtent()):this.drag&&(changed.has("withoutResize")&&this.withoutResize||changed.has("collapsed")&&this.collapsed)&&this.endDrag()}get axis(){return this.placement==="start"||this.placement==="end"?"inline":"block"}get growSign(){if(this.placement==="top")return 1;if(this.placement==="bottom")return-1;const rtl=isRtl(this);return this.placement==="start"?rtl?-1:1:rtl?1:-1}applyHostSize(bounds=this.resolveBoundsPx()){const value=this.collapsed?"var(--lr-dock-panel-collapsed-size, var(--_lr-dock-panel-collapsed-size))":this.extent;this.axis==="inline"?(this.style.inlineSize=value,this.style.blockSize="",this.style.minBlockSize="",this.style.maxBlockSize="",this.style.minInlineSize=this.collapsed?"":`${bounds.minPx}px`,this.style.maxInlineSize=this.collapsed?"":`${bounds.maxPx}px`):(this.style.blockSize=value,this.style.inlineSize="",this.style.minInlineSize="",this.style.maxInlineSize="",this.style.minBlockSize=this.collapsed?"":`${bounds.minPx}px`,this.style.maxBlockSize=this.collapsed?"":`${bounds.maxPx}px`)}containerPx(){const rect=this.container?.getBoundingClientRect(),ownerWindow=this.ownerDocument.defaultView;return this.axis==="inline"?rect?.width??ownerWindow?.innerWidth??0:rect?.height??ownerWindow?.innerHeight??0}resolveBoundsPx(containerSize=this.containerPx()){const containerPx=Math.max(0,containerSize),lengthContext={host:this,percentBase:containerPx,viewportBasis:this.ownerDocument.defaultView??void 0},authoredMax=Math.max(0,resolveCssLength(this.maxExtent,lengthContext)??containerPx),maxPx=Math.min(containerPx,authoredMax),authoredMin=Math.max(0,resolveCssLength(this.minExtent,lengthContext)??0);return{minPx:Math.min(authoredMin,maxPx),maxPx}}currentSizePx(){const rect=this.getBoundingClientRect();return this.axis==="inline"?rect.width:rect.height}resizeValueText(sizePx){return this.localize("resizeValuePixels",void 0,{value:getNumberFormat(this.effectiveLocale).format(Math.round(sizePx))})}reconcileLiveExtent(){const containerPx=this.containerPx(),bounds=this.resolveBoundsPx(containerPx);if(this.applyHostSize(bounds),this.renderBounds=bounds,this.collapsed)return;const authoredPx=resolveCssLength(this.extent,{host:this,percentBase:containerPx,viewportBasis:this.ownerDocument.defaultView??void 0}),renderedPx=this.currentSizePx();this.renderSizePx=renderedPx;const candidate=authoredPx??renderedPx;if(!Number.isFinite(candidate))return;const clamped=Math.min(Math.max(candidate,bounds.minPx),bounds.maxPx),renderedOutsideBounds=Number.isFinite(renderedPx)&&(renderedPx<bounds.minPx-.5||renderedPx>bounds.maxPx+.5);if(Math.abs(candidate-clamped)<=.5&&!renderedOutsideBounds)return;const nextExtent=`${Math.round(clamped)}px`;this.extent!==nextExtent&&(this.extent=nextExtent),this.applyHostSize(bounds),this.renderSizePx=this.currentSizePx()}resolveProposal(px,bounds=this.resolveBoundsPx(),currentSizePx=this.currentSizePx()){const clamped=Math.min(Math.max(px,bounds.minPx),bounds.maxPx),nextExtent=`${Math.round(clamped)}px`,currentExtent=`${Math.round(currentSizePx)}px`;if(nextExtent!==currentExtent)return{bounds,nextExtent}}applyProposal(bounds,nextExtent){this.extent=nextExtent,this.applyHostSize(bounds)}requestResize(bounds,extent){const requestSequence=++this.resizeRequestSequence,snapshot={drag:this.drag,extent:this.extent,placement:this.placement,collapsed:this.collapsed,withoutResize:this.withoutResize,minExtent:this.minExtent,maxExtent:this.maxExtent,growSign:this.growSign,containerPx:this.drag?.containerPx??this.containerPx()};let committed;return requestThenCommit({requestDetail:Object.freeze({extent}),emitRequest:(detail,init)=>this.emit("lr-resize-request",detail,init),guard:this.resizeWriteGuard,commit:()=>{const currentBounds=this.resolveBoundsPx(snapshot.containerPx);if(this.drag!==snapshot.drag||this.collapsed||this.collapsed!==snapshot.collapsed||this.resizeRequestSequence!==requestSequence||this.withoutResize||this.withoutResize!==snapshot.withoutResize||this.extent!==snapshot.extent||this.placement!==snapshot.placement||this.minExtent!==snapshot.minExtent||this.maxExtent!==snapshot.maxExtent||this.growSign!==snapshot.growSign||Math.abs(this.containerPx()-snapshot.containerPx)>.5||Math.abs(currentBounds.minPx-bounds.minPx)>.5||Math.abs(currentBounds.maxPx-bounds.maxPx)>.5){snapshot.drag&&this.drag===snapshot.drag&&this.endDrag();return}this.applyProposal(bounds,extent),committed=this.extent}}),committed}emitResize(type,extent){this.emit(type,Object.freeze({extent}))}dragSnapshotIsCurrent(drag){return!this.withoutResize&&!this.collapsed&&this.placement===drag.placement&&this.axis===drag.axis&&this.growSign===drag.growSign&&this.extent===drag.expectedExtent&&this.minExtent===drag.minExtent&&this.maxExtent===drag.maxExtent&&Math.abs(this.containerPx()-drag.containerPx)<=.5}endDrag(){const pointerId=this.drag?.pointerId;this.drag=null,pointerId!=null&&this.dragController.end(pointerId)}get topBottomChevronDeg(){if(this.placement==="top")return this.collapsed?90:-90;if(this.placement==="bottom")return this.collapsed?-90:90}handleTemplate(){if(this.withoutResize||this.collapsed)return nothing;const{minPx,maxPx}=this.renderBounds??this.resolveBoundsPx(),nowPx=Math.min(Math.max(this.renderSizePx??this.currentSizePx(),minPx),maxPx);return html`<div
|
|
1
|
+
import{__decorate}from"tslib";import{html,nothing}from"lit";import{property}from"lit/decorators.js";import{LyraElement}from"../../../internal/lyra-element.js";import{isRtl}from"../../../internal/rtl.js";import{nextId}from"../../../internal/a11y.js";import{chevronIcon}from"../../../internal/icons.js";import{flattenedParentElement}from"../../../internal/composed-tree.js";import{styles}from"./dock-panel.styles.js";import{resolveCssLength}from"../../../internal/css-length.js";import{getNumberFormat}from"../../../internal/intl-cache.js";import{SeparatorDragController,separatorArrowDirection,separatorCoordinate}from"../../../internal/separator-drag.js";import{markVetoGuardWrite,VetoWriteGuard}from"../../../internal/veto-write-guard.js";import{requestThenCommit}from"../../../internal/request-commit.js";import{shadowFocusTarget}from"../../../internal/active-element.js";import{LYRA_DEFAULT_dockPanelCollapse,LYRA_DEFAULT_dockPanelExpand,LYRA_DEFAULT_dockPanelResize}from"../../../internal/default-strings/layout.generated.js";import{LYRA_DEFAULT_resizeValuePixels}from"../../../internal/default-strings/shared.generated.js";const KEYBOARD_STEP_PX=16;class LyraDockPanel extends LyraElement{constructor(){super(...arguments),this.placement="end",this._extent="280px",this.minExtent="160px",this.maxExtent="",this.collapsible=!1,this.toggleWriteGuard=new VetoWriteGuard,this._collapsed=!1,this.withoutResize=!1,this.drag=null,this.resizeWriteGuard=new VetoWriteGuard,this.resizeRequestSequence=0,this.dragController=new SeparatorDragController(this,event=>this.onPointerMove(event),event=>event.type==="pointerup"?this.onPointerUp(event):this.onPointerCancel(event)),this.contentId=nextId("dock-panel-content"),this.hasRail=!1,this.pendingRailFocus=!1,this.onRailSlotChange=()=>{const hasRail=this.railElements().length>0;hasRail!==this.hasRail&&(this.hasRail=hasRail,this.applyHostSize(),this.requestUpdate())},this.onPointerDown=e=>{if(!e.isPrimary||e.button!==0||this.withoutResize||this.collapsed||this.drag)return;const handle=e.currentTarget;if(!this.dragController.start(e,handle))return;const axis=this.axis,growSign=this.growSign,containerPx=this.containerPx(),startSizePx=this.currentSizePx();this.drag={pointerId:e.pointerId,startPos:separatorCoordinate(e,axis),startSizePx,axis,growSign,placement:this.placement,minExtent:this.minExtent,maxExtent:this.maxExtent,containerPx,bounds:this.resolveBoundsPx(containerPx),currentSizePx:startSizePx,expectedExtent:this.extent,finalExtent:this.extent,acceptedResize:!1}},this.onPointerMove=e=>{const drag=this.drag;if(!drag||e.pointerId!==drag.pointerId)return;if(this.withoutResize||this.collapsed||this.placement!==drag.placement||this.axis!==drag.axis||this.growSign!==drag.growSign||this.extent!==drag.expectedExtent||this.minExtent!==drag.minExtent||this.maxExtent!==drag.maxExtent){this.endDrag();return}const pos=separatorCoordinate(e,drag.axis),delta=drag.growSign*(pos-drag.startPos),proposal=this.resolveProposal(drag.startSizePx+delta,drag.bounds,drag.currentSizePx);if(!proposal)return;const extent=this.requestResize(proposal.bounds,proposal.nextExtent);!extent||this.drag!==drag||(drag.expectedExtent=extent,drag.finalExtent=extent,drag.currentSizePx=parseFloat(extent),drag.acceptedResize=!0,this.emitResize("lr-resize",extent),!(this.drag!==drag||this.extent!==extent||this.collapsed||this.withoutResize)&&this.emitResize("lr-resize-input",extent))},this.onPointerUp=e=>{const drag=this.drag;if(!drag||e.pointerId!==drag.pointerId)return;const shouldCommit=drag.acceptedResize&&this.dragSnapshotIsCurrent(drag),finalExtent=drag.finalExtent;this.endDrag(),shouldCommit&&this.emitResize("lr-resize-change",finalExtent)},this.onPointerCancel=e=>{!this.drag||e.pointerId!==this.drag.pointerId||this.endDrag()},this.onHandleKeyDown=e=>{if(this.withoutResize||this.collapsed||e.altKey||e.ctrlKey||e.metaKey||e.isComposing)return;const arrowDirection=separatorArrowDirection(e,this.axis,!1);let proposal;if(e.key==="Home"||e.key==="End"){e.preventDefault();const{minPx,maxPx}=this.resolveBoundsPx();proposal=this.resolveProposal(e.key==="Home"?minPx:maxPx)}else arrowDirection===1?(e.preventDefault(),proposal=this.resolveProposal(this.currentSizePx()+this.growSign*KEYBOARD_STEP_PX)):arrowDirection===-1&&(e.preventDefault(),proposal=this.resolveProposal(this.currentSizePx()-this.growSign*KEYBOARD_STEP_PX));if(!proposal)return;const extent=this.requestResize(proposal.bounds,proposal.nextExtent);extent&&(this.emitResize("lr-resize",extent),!(this.extent!==extent||this.collapsed||this.withoutResize)&&(this.emitResize("lr-resize-input",extent),!(this.extent!==extent||this.collapsed||this.withoutResize)&&this.emitResize("lr-resize-change",extent)))},this.dispatchingToggle=!1,this.toggleCollapsed=()=>{if(this.dispatchingToggle)return;const previous=this.collapsed,detail=()=>Object.freeze({expanded:previous});this.dispatchingToggle=!0;try{requestThenCommit({requestDetail:detail(),emitRequest:(proposal,init)=>this.emit("lr-toggle-request",proposal,init),guard:this.toggleWriteGuard,commit:()=>{this.collapsed===previous&&(this.collapsed=!previous,this.emit("lr-toggle",detail()))}})}finally{this.dispatchingToggle=!1}}}static{this.defaultStrings={...super.defaultStrings,dockPanelCollapse:LYRA_DEFAULT_dockPanelCollapse,dockPanelExpand:LYRA_DEFAULT_dockPanelExpand,dockPanelResize:LYRA_DEFAULT_dockPanelResize,resizeValuePixels:LYRA_DEFAULT_resizeValuePixels}}static{this.styles=[LyraElement.styles,styles]}get extent(){return this._extent}set extent(value){const old=this._extent;this._extent=value,markVetoGuardWrite(this.resizeWriteGuard),this.requestUpdate("extent",old)}get collapsed(){return this._collapsed}set collapsed(next){const old=this._collapsed;this._collapsed=next,markVetoGuardWrite(this.toggleWriteGuard),this.requestUpdate("collapsed",old)}connectedCallback(){super.connectedCallback(),this.renderBounds=void 0,this.renderSizePx=void 0,this.applyHostSize(),this.armContainerResizeObserver()}disconnectedCallback(){super.disconnectedCallback(),this.endDrag(),this.containerResizeObserver?.disconnect(),this.containerResizeObserver=void 0}adoptedCallback(){super.adoptedCallback(),this.renderBounds=void 0,this.renderSizePx=void 0,this.endDrag(),this.containerResizeObserver?.disconnect(),this.containerResizeObserver=void 0}armContainerResizeObserver(){const ResizeObserverCtor=this.ownerDocument.defaultView?.ResizeObserver,container=this.container;!container||!ResizeObserverCtor||(this.containerResizeObserver??=new ResizeObserverCtor(()=>{this.isConnected&&(this.drag&&!this.dragSnapshotIsCurrent(this.drag)&&this.endDrag(),this.reconcileLiveExtent(),this.requestUpdate())}),this.containerResizeObserver.observe(container),this.containerResizeObserver.observe(this))}get container(){let parent=flattenedParentElement(this);for(;parent?.localName==="slot";)parent=flattenedParentElement(parent);return parent}railElements(){return this.renderRoot.querySelector('slot[name="rail"]')?.assignedElements({flatten:!0})??[]}focusRail(){for(const item of this.railElements())if(!(!("focus"in item)||typeof item.focus!="function")&&(item.focus(),item.matches(":focus-within")))return!0;return!1}relocateFocus(collapsing=!1){const toggle=this.renderRoot.querySelector('[part="collapse-toggle"]');if(toggle){toggle.focus();return}if(collapsing&&this.hasRail){this.pendingRailFocus=!0;return}this.focusHost()}focusHost(){this.hasAttribute("tabindex")||(this.tabIndex=-1,this.addEventListener("blur",()=>this.removeAttribute("tabindex"),{once:!0})),this.focus()}willUpdate(changed){super.willUpdate(changed),this.hasUpdated&&(changed.has("collapsed")&&this.collapsed&&this.matches(":focus-within")||changed.has("withoutResize")&&this.withoutResize&&shadowFocusTarget(this)?.matches('[part="handle"]'))?this.relocateFocus(changed.has("collapsed")&&this.collapsed):this.hasUpdated&&changed.has("collapsed")&&!this.collapsed&&this.railElements().some(item=>item.matches(":focus-within"))&&this.relocateFocus(),changed.has("extent")||changed.has("minExtent")||changed.has("maxExtent")||changed.has("collapsed")||changed.has("placement")?(this.drag&&!this.dragSnapshotIsCurrent(this.drag)&&this.endDrag(),this.reconcileLiveExtent()):this.drag&&(changed.has("withoutResize")&&this.withoutResize||changed.has("collapsed")&&this.collapsed)&&this.endDrag()}updated(changed){super.updated(changed),this.pendingRailFocus&&(this.pendingRailFocus=!1,this.collapsed&&!this.focusRail()&&this.focusHost())}get axis(){return this.placement==="start"||this.placement==="end"?"inline":"block"}get growSign(){if(this.placement==="top")return 1;if(this.placement==="bottom")return-1;const rtl=isRtl(this);return this.placement==="start"?rtl?-1:1:rtl?1:-1}applyHostSize(bounds=this.resolveBoundsPx()){const value=this.collapsed?"var(--lr-dock-panel-collapsed-size, var(--_lr-dock-panel-collapsed-size))":this.extent;this.axis==="inline"?(this.style.inlineSize=value,this.style.blockSize="",this.style.minBlockSize="",this.style.maxBlockSize="",this.style.minInlineSize=this.collapsed?this.collapsedFloor():`${bounds.minPx}px`,this.style.maxInlineSize=this.collapsed?"":`${bounds.maxPx}px`):(this.style.blockSize=value,this.style.inlineSize="",this.style.minInlineSize="",this.style.maxInlineSize="",this.style.minBlockSize=this.collapsed?this.collapsedFloor():`${bounds.minPx}px`,this.style.maxBlockSize=this.collapsed?"":`${bounds.maxPx}px`)}collapsedFloor(){return this.hasRail?"max-content":""}containerPx(){const rect=this.container?.getBoundingClientRect(),ownerWindow=this.ownerDocument.defaultView;return this.axis==="inline"?rect?.width??ownerWindow?.innerWidth??0:rect?.height??ownerWindow?.innerHeight??0}resolveBoundsPx(containerSize=this.containerPx()){const containerPx=Math.max(0,containerSize),lengthContext={host:this,percentBase:containerPx,viewportBasis:this.ownerDocument.defaultView??void 0},authoredMax=Math.max(0,resolveCssLength(this.maxExtent,lengthContext)??containerPx),maxPx=Math.min(containerPx,authoredMax),authoredMin=Math.max(0,resolveCssLength(this.minExtent,lengthContext)??0);return{minPx:Math.min(authoredMin,maxPx),maxPx}}currentSizePx(){const rect=this.getBoundingClientRect();return this.axis==="inline"?rect.width:rect.height}resizeValueText(sizePx){return this.localize("resizeValuePixels",void 0,{value:getNumberFormat(this.effectiveLocale).format(Math.round(sizePx))})}reconcileLiveExtent(){const containerPx=this.containerPx(),bounds=this.resolveBoundsPx(containerPx);if(this.applyHostSize(bounds),this.renderBounds=bounds,this.collapsed)return;const authoredPx=resolveCssLength(this.extent,{host:this,percentBase:containerPx,viewportBasis:this.ownerDocument.defaultView??void 0}),renderedPx=this.currentSizePx();this.renderSizePx=renderedPx;const candidate=authoredPx??renderedPx;if(!Number.isFinite(candidate))return;const clamped=Math.min(Math.max(candidate,bounds.minPx),bounds.maxPx),renderedOutsideBounds=Number.isFinite(renderedPx)&&(renderedPx<bounds.minPx-.5||renderedPx>bounds.maxPx+.5);if(Math.abs(candidate-clamped)<=.5&&!renderedOutsideBounds)return;const nextExtent=`${Math.round(clamped)}px`;this.extent!==nextExtent&&(this.extent=nextExtent),this.applyHostSize(bounds),this.renderSizePx=this.currentSizePx()}resolveProposal(px,bounds=this.resolveBoundsPx(),currentSizePx=this.currentSizePx()){const clamped=Math.min(Math.max(px,bounds.minPx),bounds.maxPx),nextExtent=`${Math.round(clamped)}px`,currentExtent=`${Math.round(currentSizePx)}px`;if(nextExtent!==currentExtent)return{bounds,nextExtent}}applyProposal(bounds,nextExtent){this.extent=nextExtent,this.applyHostSize(bounds)}requestResize(bounds,extent){const requestSequence=++this.resizeRequestSequence,snapshot={drag:this.drag,extent:this.extent,placement:this.placement,collapsed:this.collapsed,withoutResize:this.withoutResize,minExtent:this.minExtent,maxExtent:this.maxExtent,growSign:this.growSign,containerPx:this.drag?.containerPx??this.containerPx()};let committed;return requestThenCommit({requestDetail:Object.freeze({extent}),emitRequest:(detail,init)=>this.emit("lr-resize-request",detail,init),guard:this.resizeWriteGuard,commit:()=>{const currentBounds=this.resolveBoundsPx(snapshot.containerPx);if(this.drag!==snapshot.drag||this.collapsed||this.collapsed!==snapshot.collapsed||this.resizeRequestSequence!==requestSequence||this.withoutResize||this.withoutResize!==snapshot.withoutResize||this.extent!==snapshot.extent||this.placement!==snapshot.placement||this.minExtent!==snapshot.minExtent||this.maxExtent!==snapshot.maxExtent||this.growSign!==snapshot.growSign||Math.abs(this.containerPx()-snapshot.containerPx)>.5||Math.abs(currentBounds.minPx-bounds.minPx)>.5||Math.abs(currentBounds.maxPx-bounds.maxPx)>.5){snapshot.drag&&this.drag===snapshot.drag&&this.endDrag();return}this.applyProposal(bounds,extent),committed=this.extent}}),committed}emitResize(type,extent){this.emit(type,Object.freeze({extent}))}dragSnapshotIsCurrent(drag){return!this.withoutResize&&!this.collapsed&&this.placement===drag.placement&&this.axis===drag.axis&&this.growSign===drag.growSign&&this.extent===drag.expectedExtent&&this.minExtent===drag.minExtent&&this.maxExtent===drag.maxExtent&&Math.abs(this.containerPx()-drag.containerPx)<=.5}endDrag(){const pointerId=this.drag?.pointerId;this.drag=null,pointerId!=null&&this.dragController.end(pointerId)}expand(){return this.collapsed&&this.toggleCollapsed(),!this.collapsed}collapse(){return this.collapsed||this.toggleCollapsed(),this.collapsed}toggle(){return this.toggleCollapsed(),!this.collapsed}get topBottomChevronDeg(){if(this.placement==="top")return this.collapsed?90:-90;if(this.placement==="bottom")return this.collapsed?-90:90}handleTemplate(){if(this.withoutResize||this.collapsed)return nothing;const{minPx,maxPx}=this.renderBounds??this.resolveBoundsPx(),nowPx=Math.min(Math.max(this.renderSizePx??this.currentSizePx(),minPx),maxPx);return html`<div
|
|
2
2
|
part="handle"
|
|
3
3
|
role="separator"
|
|
4
4
|
aria-label=${this.localize("dockPanelResize")}
|
|
@@ -18,15 +18,18 @@ import{__decorate}from"tslib";import{html,nothing}from"lit";import{property}from
|
|
|
18
18
|
aria-label=${this.collapsed?this.localize("dockPanelExpand"):this.localize("dockPanelCollapse")}
|
|
19
19
|
@click=${this.toggleCollapsed}
|
|
20
20
|
>
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
<slot name=${this.collapsed?"expand-icon":"collapse-icon"}
|
|
22
|
+
><span
|
|
23
|
+
style=${this.topBottomChevronDeg===void 0?"display:inline-flex":`display:inline-flex;transform:rotate(${this.topBottomChevronDeg}deg)`}
|
|
24
|
+
>${chevronIcon()}</span
|
|
25
|
+
></slot
|
|
24
26
|
>
|
|
25
27
|
</button>`:nothing}render(){return html`
|
|
26
|
-
<div part="base">
|
|
28
|
+
<div part="base" ?data-rail=${this.collapsed&&this.hasRail}>
|
|
27
29
|
<div part="content" id=${this.contentId} ?hidden=${this.collapsed}>
|
|
28
30
|
<slot></slot>
|
|
29
31
|
</div>
|
|
30
32
|
${this.handleTemplate()} ${this.collapseToggleTemplate()}
|
|
33
|
+
<div part="rail" ?hidden=${!this.collapsed}><slot name="rail" @slotchange=${this.onRailSlotChange}></slot></div>
|
|
31
34
|
</div>
|
|
32
35
|
`}}__decorate([property({reflect:!0})],LyraDockPanel.prototype,"placement",void 0),__decorate([property()],LyraDockPanel.prototype,"extent",null),__decorate([property({attribute:"min-extent"})],LyraDockPanel.prototype,"minExtent",void 0),__decorate([property({attribute:"max-extent"})],LyraDockPanel.prototype,"maxExtent",void 0),__decorate([property({type:Boolean,reflect:!0})],LyraDockPanel.prototype,"collapsible",void 0),__decorate([property({type:Boolean,reflect:!0})],LyraDockPanel.prototype,"collapsed",null),__decorate([property({type:Boolean,reflect:!0,attribute:"without-resize"})],LyraDockPanel.prototype,"withoutResize",void 0);export{LyraDockPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{iconHitTarget,focusRing}from"../../../internal/interactive-control.styles.js";import{css}from"lit";const styles=css` :host { display: block; box-sizing: border-box; --_lr-dock-panel-collapsed-size: var(--lr-icon-button-size); position: relative; } :host([placement="start"]), :host([placement="end"]) { block-size: 100%; } :host([placement="top"]), :host([placement="bottom"]) { inline-size: 100%; } :host([placement="start"][collapsed]), :host([placement="end"][collapsed]) { min-inline-size: var( --lr-dock-panel-collapsed-size, var(--_lr-dock-panel-collapsed-size) ); } :host([placement="top"][collapsed]), :host([placement="bottom"][collapsed]) { min-block-size: var( --lr-dock-panel-collapsed-size, var(--_lr-dock-panel-collapsed-size) ); } [part="base"] { position: relative; inline-size: 100%; block-size: 100%; background: var(--lr-color-surface); border: var(--lr-border-width-thin) solid var(--lr-color-border-subtle); overflow: hidden; } [part="content"] { inline-size: 100%; block-size: 100%; overflow: auto; } [part="content"][hidden] { display: none; } [part="handle"] { position: absolute; background: var(--lr-color-border); touch-action: none; transition: background var(--lr-transition-fast); } [part="handle"]:hover { background: var(--lr-dock-panel-handle-hover-color, var(--lr-color-brand)); } [part="handle"]:focus-visible { background: var(--lr-dock-panel-handle-hover-color, var(--lr-color-brand)); outline: var(--lr-focus-ring-width) solid var(--lr-focus-ring-color); outline-offset: calc(-1 * var(--lr-focus-ring-width)); } [part="handle"]:active { background: var( --lr-dock-panel-handle-active-color, color-mix( in oklab, var(--lr-dock-panel-handle-hover-color, var(--lr-color-brand)), var(--lr-color-mix-partner) var(--lr-color-mix-active) ) ); } [part="handle"]::before { content: ""; position: absolute;
|
|
1
|
+
import{iconHitTarget,focusRing}from"../../../internal/interactive-control.styles.js";import{css}from"lit";const styles=css` :host { display: block; box-sizing: border-box; --_lr-dock-panel-collapsed-size: var(--lr-icon-button-size); position: relative; } :host([placement="start"]), :host([placement="end"]) { block-size: 100%; } :host([placement="top"]), :host([placement="bottom"]) { inline-size: 100%; } :host([placement="start"][collapsed]), :host([placement="end"][collapsed]) { min-inline-size: var( --lr-dock-panel-collapsed-size, var(--_lr-dock-panel-collapsed-size) ); } :host([placement="top"][collapsed]), :host([placement="bottom"][collapsed]) { min-block-size: var( --lr-dock-panel-collapsed-size, var(--_lr-dock-panel-collapsed-size) ); } [part="base"] { position: relative; inline-size: 100%; block-size: 100%; background: var(--lr-color-surface); border: var(--lr-border-width-thin) solid var(--lr-color-border-subtle); overflow: hidden; } [part="content"] { inline-size: 100%; block-size: 100%; overflow: auto; } [part="content"][hidden] { display: none; } [part="handle"] { position: absolute; background: var(--lr-color-border); touch-action: none; transition: background var(--lr-transition-fast); } [part="handle"]:hover { background: var(--lr-dock-panel-handle-hover-color, var(--lr-color-brand)); } [part="handle"]:focus-visible { background: var(--lr-dock-panel-handle-hover-color, var(--lr-color-brand)); outline: var(--lr-focus-ring-width) solid var(--lr-focus-ring-color); outline-offset: calc(-1 * var(--lr-focus-ring-width)); } [part="handle"]:active { background: var( --lr-dock-panel-handle-active-color, color-mix( in oklab, var(--lr-dock-panel-handle-hover-color, var(--lr-color-brand)), var(--lr-color-mix-partner) var(--lr-color-mix-active) ) ); } [part="handle"]::before { content: ""; position: absolute; --_lr-dock-panel-hit-area: var(--lr-dock-panel-handle-hit-area, var(--lr-space-m)); inline-size: var(--_lr-dock-panel-hit-area); block-size: 100%; inset-block-start: 0; inset-inline-start: 0; } :host([placement="start"]) [part="handle"]::before { inset-inline-start: auto; inset-inline-end: 0; } :host([placement="top"]) [part="handle"]::before, :host([placement="bottom"]) [part="handle"]::before { inline-size: 100%; block-size: var(--_lr-dock-panel-hit-area); inset-inline-start: 0; inset-block-start: 0; } :host([placement="top"]) [part="handle"]::before { inset-block-start: auto; inset-block-end: 0; } @media (hover: none), (pointer: coarse) { [part="handle"]::before { --_lr-dock-panel-hit-area: max( var(--lr-icon-button-size), var(--lr-dock-panel-handle-hit-area, var(--lr-space-m)) ); } } :host([placement="start"]) [part="handle"] { inset-block: 0; inset-inline-end: 0; inline-size: var(--lr-size-3px); cursor: col-resize; } :host([placement="end"]) [part="handle"] { inset-block: 0; inset-inline-start: 0; inline-size: var(--lr-size-3px); cursor: col-resize; } :host([placement="top"]) [part="handle"] { inset-inline: 0; inset-block-end: 0; block-size: var(--lr-size-3px); cursor: row-resize; } :host([placement="bottom"]) [part="handle"] { inset-inline: 0; inset-block-start: 0; block-size: var(--lr-size-3px); cursor: row-resize; } [part="collapse-toggle"] { position: absolute; display: inline-flex; align-items: center; justify-content: center; inline-size: var(--lr-icon-button-size); block-size: var(--lr-icon-button-size); ${iconHitTarget} padding: 0; border: var(--lr-border-width-thin) solid var(--lr-color-border); border-radius: var(--lr-radius); background: var(--lr-color-surface); color: var(--lr-color-text); cursor: pointer; font-size: var(--lr-font-size-xs); line-height: var(--lr-line-height-none); transition: background var(--lr-transition-fast), color var(--lr-transition-fast); z-index: var(--lr-layer-content); } [part="collapse-toggle"]:hover { background: var( --lr-dock-panel-collapse-toggle-hover-bg, var(--lr-color-brand-quiet) ); color: var( --lr-dock-panel-collapse-toggle-hover-color, var(--lr-color-brand) ); } [part="collapse-toggle"]:active { background: color-mix( in oklab, var( --lr-dock-panel-collapse-toggle-hover-bg, var(--lr-color-brand-quiet) ), var(--lr-color-mix-partner) var(--lr-color-mix-active) ); color: var( --lr-dock-panel-collapse-toggle-hover-color, var(--lr-color-brand) ); } [part="collapse-toggle"]:focus-visible { ${focusRing} } :host([placement="start"]) [part="collapse-toggle"] { inset-inline-end: var(--lr-space-xs); inset-block-start: 50%; transform: translateY(-50%); } :host([placement="end"]) [part="collapse-toggle"] { inset-inline-start: var(--lr-space-xs); inset-block-start: 50%; transform: translateY(-50%); } :host([placement="top"]) [part="collapse-toggle"] { inset-block-end: var(--lr-space-xs); inset-inline-start: 50%; transform: translateX(-50%); } :host([placement="bottom"]) [part="collapse-toggle"] { inset-block-start: var(--lr-space-xs); inset-inline-start: 50%; transform: translateX(-50%); } :host(:dir(rtl)[placement="top"]) [part="collapse-toggle"], :host(:dir(rtl)[placement="bottom"]) [part="collapse-toggle"] { transform: translateX(50%); } :host([placement="start"]) [part="collapse-toggle"] span { transform: rotate(180deg); } :host([placement="start"][collapsed]) [part="collapse-toggle"] span { transform: rotate(0deg); } :host([placement="end"]) [part="collapse-toggle"] span { transform: rotate(0deg); } :host([placement="end"][collapsed]) [part="collapse-toggle"] span { transform: rotate(180deg); } :host(:dir(rtl)[placement="start"]) [part="collapse-toggle"] span { transform: rotate(0deg); } :host(:dir(rtl)[placement="start"][collapsed]) [part="collapse-toggle"] span { transform: rotate(180deg); } :host(:dir(rtl)[placement="end"]) [part="collapse-toggle"] span { transform: rotate(180deg); } :host(:dir(rtl)[placement="end"][collapsed]) [part="collapse-toggle"] span { transform: rotate(0deg); } [part="collapse-toggle"] ::slotted(*) { display: inline-flex; } [part="rail"] { display: contents; } [part="rail"][hidden] { display: none; } [part="base"]:where([data-rail]) { box-sizing: border-box; display: flex; flex-direction: column; align-items: center; gap: var(--lr-space-xs); padding: var(--lr-space-xs); } :host([placement="top"]) [part="base"]:where([data-rail]), :host([placement="bottom"]) [part="base"]:where([data-rail]) { flex-direction: row; } :host([collapsed]) [part="base"]:where([data-rail]) [part="collapse-toggle"] { position: static; flex: none; order: -1; transform: none; } @media (prefers-reduced-motion: reduce) { [part="collapse-toggle"], [part="handle"] { transition: none !important; } } `;export{styles};
|
|
@@ -210,8 +210,11 @@ loading:boolean;
|
|
|
210
210
|
* `[part="base"]` renders as a real `<a href=…>` instead of a `<span>`, and activation (click,
|
|
211
211
|
* or the parent's Enter/Space handling, which forwards through `click()` for a link item so the
|
|
212
212
|
* anchor's own native default action runs) navigates there in addition to firing the usual
|
|
213
|
-
* `select()`/`lr-select` contract.
|
|
214
|
-
*
|
|
213
|
+
* `select()`/`lr-select` contract. The anchor carries the row's accessible name as its own
|
|
214
|
+
* `aria-label` (a non-empty host `aria-label` wins, otherwise the visible label) and keeps it
|
|
215
|
+
* live when either changes, because its visible label sits behind the decorative label wrapper.
|
|
216
|
+
* An unsafe/unparseable `href` falls back to the plain `<span>`, matching `lr-button`'s
|
|
217
|
+
* identical fallback. Mirrors `wa-dropdown-item`'s link-item support. */
|
|
215
218
|
href?:string;
|
|
216
219
|
/** Native anchor `target`, used only while `href` resolves to a link. Setting this to `'_blank'`
|
|
217
220
|
* (or any other target) always contributes `noopener noreferrer` to the rendered anchor's `rel`
|
|
@@ -224,7 +227,7 @@ rel?:string;
|
|
|
224
227
|
/** Native anchor `download` attribute, used only while `href` resolves to a link. Narrows the
|
|
225
228
|
* safe-URL allowlist to `safeDownloadHref`'s, which drops `mailto:` — a mail handoff names no
|
|
226
229
|
* retrievable bytes, so it cannot be a download target. */
|
|
227
|
-
download?:string;private get resolvedRel();private get resolvedHref();private hasIconSlot;private hasDetailsSlot;private hasSuffixSlot;private detailsSlot?;private submenuAssigned;private submenuExpanded;private submenuKind;private slottedLabel;private submenuPanel;private submenuPanelAttached;private submenuPanelGeneration;private nativeStateObserver?;private readonly labelTextObserver;private labelObservationGeneration;private announcedNativeState;private owningMenu;private readonly ownedName;private writingComputedName;private panelName;
|
|
230
|
+
download?:string;private get resolvedRel();private get resolvedHref();private hasIconSlot;private hasDetailsSlot;private hasSuffixSlot;private detailsSlot?;private submenuAssigned;private submenuExpanded;private submenuKind;private slottedLabel;private submenuPanel;private submenuPanelAttached;private submenuPanelGeneration;private nativeStateObserver?;private readonly labelTextObserver;private labelObservationGeneration;private announcedNativeState;private owningMenu;private readonly ownedName;private writingComputedName;private panelName;private renderedLinkName;
|
|
228
231
|
/** Whether a nested `<lr-menu>` or direct mapped items are assigned to this item's `submenu`
|
|
229
232
|
* slot, making it a submenu parent. */
|
|
230
233
|
get hasSubmenu():boolean;
|
|
@@ -257,7 +260,7 @@ select():void;private proposeChecked;
|
|
|
257
260
|
openSubmenu(focus?:MenuFocusTarget):Promise<void>;
|
|
258
261
|
/** Closes this item's submenu (and, through it, any of its own descendants). A no-op without
|
|
259
262
|
* one. Focus is left alone — the caller that moved it knows where it belongs. */
|
|
260
|
-
closeSubmenu():Promise<void>;private onIconSlotChange;private onDetailsSlotChange;private syncDetailsSlot;private onSuffixSlotChange;private defaultLabelSlot;private isDefaultLabelBranch;private labelForwardingSlots;private isLabelSubtreeExcluded;private readSlottedLabel;private syncSlottedLabel;private onLabelSlotChange;private onForwardedLabelSlotChange;private onSubmenuSlotChange;private syncSubmenuSlot;private connectSubmenuPanel;private isCurrentSubmenuPanel;protected updated(changed:PropertyValues):void;protected firstUpdated(changed:PropertyValues):void;private onPanelStateChange;private applyComputedName;private applyPanelName;
|
|
263
|
+
closeSubmenu():Promise<void>;private onIconSlotChange;private onDetailsSlotChange;private syncDetailsSlot;private onSuffixSlotChange;private defaultLabelSlot;private isDefaultLabelBranch;private labelForwardingSlots;private isLabelSubtreeExcluded;private readSlottedLabel;private syncSlottedLabel;private get linkName();private onLabelSlotChange;private onForwardedLabelSlotChange;private onSubmenuSlotChange;private syncSubmenuSlot;private connectSubmenuPanel;private isCurrentSubmenuPanel;protected updated(changed:PropertyValues):void;protected firstUpdated(changed:PropertyValues):void;private onPanelStateChange;private applyComputedName;private applyPanelName;
|
|
261
264
|
/** Text label used by type-ahead and Shoelace-compatible integrations. Kept live by the label
|
|
262
265
|
* observer, so a read right after a label edit may lag it by one microtask. */
|
|
263
266
|
getTextLabel():string;render():TemplateResult;}declare global{interface HTMLElementTagNameMap{'lr-menu-item':LyraMenuItem;}}
|
|
@@ -12,7 +12,7 @@ import{__decorate}from"tslib";import{html,nothing,svg}from"lit";import{html as s
|
|
|
12
12
|
aria-hidden="true"
|
|
13
13
|
focusable="false"
|
|
14
14
|
><polyline points="5 12.5 10 17.5 19 6.5"></polyline></svg>
|
|
15
|
-
`}class LyraMenuItem extends LyraElement{static{this.knownUnobservedAttributes=["submenu-open"]}static{this.styles=[LyraElement.styles,sizes,styles]}get resolvedRel(){return resolveGuardedRel(this.rel,this.target)}get resolvedHref(){return(this.download!==void 0?safeDownloadHref(this.href):safeLinkHref(this.href))??void 0}get isLinkItem(){return this.resolvedHref!==void 0}get hasSubmenu(){return this.submenuAssigned}get submenuOpen(){return this.submenuExpanded}[menuItemOwner](owner,expectedOwner){owner===null&&expectedOwner&&this.owningMenu!==expectedOwner||(this.owningMenu=owner)}set submenuOpen(next){!!next!==this.submenuExpanded&&(next?this.openSubmenu("none"):this.closeSubmenu())}get interactionDisabled(){return this.disabled||this.loading}constructor(){super(),this.value="",this.size="m",this.disabled=!1,this.variant="default",this.type="normal",this.checked=!1,this.loading=!1,this.hasIconSlot=!1,this.hasDetailsSlot=!1,this.hasSuffixSlot=!1,this.submenuAssigned=!1,this.submenuExpanded=!1,this.slottedLabel="",this.submenuPanel=null,this.submenuPanelAttached=!1,this.submenuPanelGeneration=0,this.labelTextObserver=new AccessibleTextController(this,[],()=>this.syncSlottedLabel(),["data-hidden","label","slot"]),this.labelObservationGeneration=0,this.announcedNativeState="",this.owningMenu=null,this.ownedName={owns:!1,value:null},this.writingComputedName=!1,this.panelName={owns:!1,value:null},this.onNativeStateMutation=()=>{const signature=this.nativeStateSignature();signature!==this.announcedNativeState&&(this.announcedNativeState=signature,this.emitStateChange())},this.onIconSlotChange=()=>{this.hasIconSlot=Array.from(this.children).some(el=>el.getAttribute("slot")==="icon"||el.getAttribute("slot")==="prefix")},this.onDetailsSlotChange=e=>{this.syncDetailsSlot(e.target)},this.onSuffixSlotChange=()=>{this.hasSuffixSlot=Array.from(this.children).some(el=>el.getAttribute("slot")==="suffix")},this.onLabelSlotChange=event=>{this.labelTextObserver.bind(),this.syncSlottedLabel(event.target)},this.onForwardedLabelSlotChange=event=>{const slot=event.target;this.labelForwardingSlots().includes(slot)&&(this.labelTextObserver.bind(),this.syncSlottedLabel())},this.onSubmenuSlotChange=e=>{this.syncSubmenuSlot(e.target)},this.onPanelStateChange=open=>{this.submenuExpanded=open},this.addEventListener("mousedown",event=>{this.interactionDisabled&&event.preventDefault()})}connectedCallback(){super.connectedCallback();const initialLabel=this.readSlottedLabel(null,!1);initialLabel!==this.slottedLabel&&(this.slottedLabel=initialLabel),this.applyComputedName(),this.tabIndex!==0&&(this.tabIndex=-1),this.announcedNativeState=this.nativeStateSignature();const MutationObserverCtor=this.ownerDocument.defaultView?.MutationObserver;MutationObserverCtor&&(this.nativeStateObserver=new MutationObserverCtor(this.onNativeStateMutation),this.nativeStateObserver.observe(this,{attributes:!0,attributeFilter:["hidden","inert","aria-hidden"]})),this.addEventListener("slotchange",this.onForwardedLabelSlotChange);const labelGeneration=++this.labelObservationGeneration;this.updateComplete.then(()=>{if(!this.isConnected||labelGeneration!==this.labelObservationGeneration)return;this.labelTextObserver.bind(),this.syncSlottedLabel();const submenuSlot=this.renderRoot.querySelector('slot[name="submenu"]');submenuSlot&&this.syncSubmenuSlot(submenuSlot)})}attributeChangedCallback(name,oldValue,value){name==="aria-label"&&this.writingComputedName||super.attributeChangedCallback(name,oldValue,value)}disconnectedCallback(){super.disconnectedCallback(),this.submenuPanelGeneration+=1,this.submenuExpanded=!1,this.nativeStateObserver?.disconnect(),this.nativeStateObserver=void 0,this.labelObservationGeneration+=1,this.removeEventListener("slotchange",this.onForwardedLabelSlotChange),this.submenuPanel&&this.submenuPanelAttached&&(this.submenuPanel[submenuPanelController].detach(this),this.submenuPanelAttached=!1)}adoptedCallback(){super.adoptedCallback(),this.labelTextObserver.adopted()}nativeStateSignature(){return`${this.hidden}|${this.inert}|${this.getAttribute("aria-hidden")}`}emitStateChange(){this.emit("lr-menu-item-state-change",{disabled:this.interactionDisabled,hidden:!!this.hidden,inert:this.inert})}willUpdate(changed){super.willUpdate(changed);const isCheckbox=this.type==="checkbox"&&!this.submenuAssigned,isRadio=this.type==="radio"&&!this.submenuAssigned;this.setAttribute("role",isCheckbox?"menuitemcheckbox":isRadio?"menuitemradio":"menuitem"),isCheckbox||isRadio?this.setAttribute("aria-checked",this.checked?"true":"false"):this.removeAttribute("aria-checked"),this.submenuAssigned?(this.setAttribute("aria-haspopup","menu"),this.setAttribute("aria-expanded",this.submenuExpanded?"true":"false")):(this.removeAttribute("aria-haspopup"),this.removeAttribute("aria-expanded")),this.applyComputedName(),this.toggleAttribute("submenu-open",this.submenuExpanded),this.setAttribute("aria-disabled",String(this.interactionDisabled)),this.interactionDisabled&&(changed.has("disabled")||changed.has("loading"))&&(this.tabIndex=-1,activeElementIn(this.ownerDocument)===this&&this.blur()),(changed.has("disabled")||changed.has("loading"))&&this.emitStateChange()}click(){this.interactionDisabled||this.renderRoot.querySelector('[part~="base"]')?.click()}select(){if(!this.interactionDisabled){if(this.submenuPanel){this.openSubmenu("none");return}if(this.type==="checkbox"){const checked=!this.checked;this.proposeChecked(checked)&&(this.checked=checked)}else this.type==="radio"&&!this.checked&&this.proposeChecked(!0)&&(this.checked=!0,this.owningMenu?.uncheckRadioGroup(this,this.group));this.owningMenu?.activate(this)}}proposeChecked(checked){const value=this.value;return!this.emit("lr-menu-item-change-request",{value,checked},{cancelable:!0}).defaultPrevented}async openSubmenu(focus="first"){const panel=this.submenuPanel,generation=this.submenuPanelGeneration;if(!panel||this.interactionDisabled||!this.isCurrentSubmenuPanel(panel,generation))return;const controller=panel[submenuPanelController],shown=controller.show(focus);this.isCurrentSubmenuPanel(panel,generation)&&(this.submenuExpanded=controller.open,await shown,this.isCurrentSubmenuPanel(panel,generation)&&(panel.updateComplete&&await panel.updateComplete,this.isCurrentSubmenuPanel(panel,generation)&&(this.submenuExpanded=controller.open,await this.updateComplete)))}async closeSubmenu(){const panel=this.submenuPanel,generation=this.submenuPanelGeneration;if(!panel||!this.isCurrentSubmenuPanel(panel,generation))return;const controller=panel[submenuPanelController],hidden=controller.hide();this.isCurrentSubmenuPanel(panel,generation)&&(this.submenuExpanded=controller.open,await hidden,this.isCurrentSubmenuPanel(panel,generation)&&(panel.updateComplete&&await panel.updateComplete,this.isCurrentSubmenuPanel(panel,generation)&&(this.submenuExpanded=controller.open,await this.updateComplete)))}syncDetailsSlot(slot){const meaningful=node=>node.nodeType===Node.TEXT_NODE?(node.textContent??"").trim()!=="":node.nodeType!==Node.ELEMENT_NODE?!1:node instanceof HTMLSlotElement?node.assignedNodes({flatten:!0}).some(meaningful):!0;this.hasDetailsSlot=slot.assignedNodes({flatten:!0}).some(meaningful)}defaultLabelSlot(){return this.renderRoot?.querySelector("slot:not([name])")??null}isDefaultLabelBranch(node){let top=node;for(;top.parentNode&&top.parentNode!==this;)top=top.parentNode;return top.parentNode!==this?!1:top.nodeType!==1||(top.getAttribute("slot")??"")===""}labelForwardingSlots(){return Array.from(this.querySelectorAll("slot")).filter(slot=>this.isDefaultLabelBranch(slot))}isLabelSubtreeExcluded(element){return!(element.getRootNode()===this.renderRoot&&element.matches('[part~="label"][aria-hidden="true"][inert]:not([hidden])'))&&isAccessibilitySubtreeExcluded(element)}readSlottedLabel(slot=this.defaultLabelSlot(),requireRendered=!0){const nodes=slot?slot.assignedNodes({flatten:!0}):Array.from(this.childNodes).filter(node=>this.isDefaultLabelBranch(node));return composedAccessibilityText(nodes,{ancestorBoundary:this,isSubtreeExcluded:element=>this.isLabelSubtreeExcluded(element),requireRendered,ignoreInheritedVisibility:!0}).replace(/\s+/g," ").trim()}syncSlottedLabel(slot=this.defaultLabelSlot()){const next=this.readSlottedLabel(slot);next!==this.slottedLabel&&(this.slottedLabel=next),this.applyComputedName(),this.applyPanelName()}syncSubmenuSlot(submenuSlot){if(!submenuSlot.isConnected||submenuSlot.getRootNode()!==this.renderRoot)return;const assigned=submenuSlot.assignedElements({flatten:!0}),authoredPanel=assigned.find(element=>element.localName===tag("menu")),hasDirectItems=assigned.some(element=>element.localName===tag("menu-item")||element.localName===tag("dropdown-item")),kind=authoredPanel?"panel":hasDirectItems?"items":void 0;if(this.submenuKind=kind,this.submenuAssigned=kind!==void 0,kind==="items"){const generated=this.renderRoot.querySelector("[data-generated-submenu]");generated&&this.connectSubmenuPanel(generated);return}this.connectSubmenuPanel(authoredPanel??null)}connectSubmenuPanel(next){const samePanel=next===this.submenuPanel;if(samePanel&&(next===null||this.submenuPanelAttached))return;const previous=this.submenuPanel;if(++this.submenuPanelGeneration,previous&&this.submenuPanelAttached&&previous[submenuPanelController].detach(this),this.submenuPanelAttached=!1,samePanel||(this.submenuPanel=next,this.panelName={owns:!1,value:null}),!this.submenuPanel){this.submenuExpanded=!1;return}const controller=this.submenuPanel[submenuPanelController];controller.attach(this,this.onPanelStateChange),this.submenuPanelAttached=!0,this.submenuExpanded=controller.open,this.applyPanelName()}isCurrentSubmenuPanel(panel,generation){return this.isConnected&&this.submenuPanel===panel&&this.submenuPanelGeneration===generation}updated(changed){if(super.updated(changed),changed.has("submenuKind")&&this.submenuKind==="items"){const generated=this.renderRoot.querySelector("[data-generated-submenu]");this.connectSubmenuPanel(generated)}}firstUpdated(changed){super.firstUpdated(changed);const detailsSlot=this.detailsSlot;queueMicrotask(()=>{this.onIconSlotChange(),this.onSuffixSlotChange(),collectInitialSlotAssignment(detailsSlot,s=>this.syncDetailsSlot(s))})}applyComputedName(){this.writingComputedName=!0;try{syncOwnedAriaLabel(this,this.slottedLabel,this.ownedName,this.hasAttribute("aria-labelledby"))}finally{this.writingComputedName=!1}}applyPanelName(){const panel=this.submenuPanel;panel&&syncOwnedAriaLabel(panel,this.slottedLabel,this.panelName,panel.hasAttribute("label"))}getTextLabel(){return this.slottedLabel}get spinnerParts(){return"spinner spinner__base"}render(){const baseContent=html`
|
|
15
|
+
`}class LyraMenuItem extends LyraElement{static{this.knownUnobservedAttributes=["submenu-open"]}static{this.styles=[LyraElement.styles,sizes,styles]}get resolvedRel(){return resolveGuardedRel(this.rel,this.target)}get resolvedHref(){return(this.download!==void 0?safeDownloadHref(this.href):safeLinkHref(this.href))??void 0}get isLinkItem(){return this.resolvedHref!==void 0}get hasSubmenu(){return this.submenuAssigned}get submenuOpen(){return this.submenuExpanded}[menuItemOwner](owner,expectedOwner){owner===null&&expectedOwner&&this.owningMenu!==expectedOwner||(this.owningMenu=owner)}set submenuOpen(next){!!next!==this.submenuExpanded&&(next?this.openSubmenu("none"):this.closeSubmenu())}get interactionDisabled(){return this.disabled||this.loading}constructor(){super(),this.value="",this.size="m",this.disabled=!1,this.variant="default",this.type="normal",this.checked=!1,this.loading=!1,this.hasIconSlot=!1,this.hasDetailsSlot=!1,this.hasSuffixSlot=!1,this.submenuAssigned=!1,this.submenuExpanded=!1,this.slottedLabel="",this.submenuPanel=null,this.submenuPanelAttached=!1,this.submenuPanelGeneration=0,this.labelTextObserver=new AccessibleTextController(this,[],()=>this.syncSlottedLabel(),["data-hidden","label","slot"]),this.labelObservationGeneration=0,this.announcedNativeState="",this.owningMenu=null,this.ownedName={owns:!1,value:null},this.writingComputedName=!1,this.panelName={owns:!1,value:null},this.onNativeStateMutation=()=>{const signature=this.nativeStateSignature();signature!==this.announcedNativeState&&(this.announcedNativeState=signature,this.emitStateChange())},this.onIconSlotChange=()=>{this.hasIconSlot=Array.from(this.children).some(el=>el.getAttribute("slot")==="icon"||el.getAttribute("slot")==="prefix")},this.onDetailsSlotChange=e=>{this.syncDetailsSlot(e.target)},this.onSuffixSlotChange=()=>{this.hasSuffixSlot=Array.from(this.children).some(el=>el.getAttribute("slot")==="suffix")},this.onLabelSlotChange=event=>{this.labelTextObserver.bind(),this.syncSlottedLabel(event.target)},this.onForwardedLabelSlotChange=event=>{const slot=event.target;this.labelForwardingSlots().includes(slot)&&(this.labelTextObserver.bind(),this.syncSlottedLabel())},this.onSubmenuSlotChange=e=>{this.syncSubmenuSlot(e.target)},this.onPanelStateChange=open=>{this.submenuExpanded=open},this.addEventListener("mousedown",event=>{this.interactionDisabled&&event.preventDefault()})}connectedCallback(){super.connectedCallback();const initialLabel=this.readSlottedLabel(null,!1);initialLabel!==this.slottedLabel&&(this.slottedLabel=initialLabel),this.applyComputedName(),this.tabIndex!==0&&(this.tabIndex=-1),this.announcedNativeState=this.nativeStateSignature();const MutationObserverCtor=this.ownerDocument.defaultView?.MutationObserver;MutationObserverCtor&&(this.nativeStateObserver=new MutationObserverCtor(this.onNativeStateMutation),this.nativeStateObserver.observe(this,{attributes:!0,attributeFilter:["hidden","inert","aria-hidden"]})),this.addEventListener("slotchange",this.onForwardedLabelSlotChange);const labelGeneration=++this.labelObservationGeneration;this.updateComplete.then(()=>{if(!this.isConnected||labelGeneration!==this.labelObservationGeneration)return;this.labelTextObserver.bind(),this.syncSlottedLabel();const submenuSlot=this.renderRoot.querySelector('slot[name="submenu"]');submenuSlot&&this.syncSubmenuSlot(submenuSlot)})}attributeChangedCallback(name,oldValue,value){name==="aria-label"&&this.writingComputedName||super.attributeChangedCallback(name,oldValue,value)}disconnectedCallback(){super.disconnectedCallback(),this.submenuPanelGeneration+=1,this.submenuExpanded=!1,this.nativeStateObserver?.disconnect(),this.nativeStateObserver=void 0,this.labelObservationGeneration+=1,this.removeEventListener("slotchange",this.onForwardedLabelSlotChange),this.submenuPanel&&this.submenuPanelAttached&&(this.submenuPanel[submenuPanelController].detach(this),this.submenuPanelAttached=!1)}adoptedCallback(){super.adoptedCallback(),this.labelTextObserver.adopted()}nativeStateSignature(){return`${this.hidden}|${this.inert}|${this.getAttribute("aria-hidden")}`}emitStateChange(){this.emit("lr-menu-item-state-change",{disabled:this.interactionDisabled,hidden:!!this.hidden,inert:this.inert})}willUpdate(changed){super.willUpdate(changed);const isCheckbox=this.type==="checkbox"&&!this.submenuAssigned,isRadio=this.type==="radio"&&!this.submenuAssigned;this.setAttribute("role",isCheckbox?"menuitemcheckbox":isRadio?"menuitemradio":"menuitem"),isCheckbox||isRadio?this.setAttribute("aria-checked",this.checked?"true":"false"):this.removeAttribute("aria-checked"),this.submenuAssigned?(this.setAttribute("aria-haspopup","menu"),this.setAttribute("aria-expanded",this.submenuExpanded?"true":"false")):(this.removeAttribute("aria-haspopup"),this.removeAttribute("aria-expanded")),this.applyComputedName(),this.toggleAttribute("submenu-open",this.submenuExpanded),this.setAttribute("aria-disabled",String(this.interactionDisabled)),this.interactionDisabled&&(changed.has("disabled")||changed.has("loading"))&&(this.tabIndex=-1,activeElementIn(this.ownerDocument)===this&&this.blur()),(changed.has("disabled")||changed.has("loading"))&&this.emitStateChange()}click(){this.interactionDisabled||this.renderRoot.querySelector('[part~="base"]')?.click()}select(){if(!this.interactionDisabled){if(this.submenuPanel){this.openSubmenu("none");return}if(this.type==="checkbox"){const checked=!this.checked;this.proposeChecked(checked)&&(this.checked=checked)}else this.type==="radio"&&!this.checked&&this.proposeChecked(!0)&&(this.checked=!0,this.owningMenu?.uncheckRadioGroup(this,this.group));this.owningMenu?.activate(this)}}proposeChecked(checked){const value=this.value;return!this.emit("lr-menu-item-change-request",{value,checked},{cancelable:!0}).defaultPrevented}async openSubmenu(focus="first"){const panel=this.submenuPanel,generation=this.submenuPanelGeneration;if(!panel||this.interactionDisabled||!this.isCurrentSubmenuPanel(panel,generation))return;const controller=panel[submenuPanelController],shown=controller.show(focus);this.isCurrentSubmenuPanel(panel,generation)&&(this.submenuExpanded=controller.open,await shown,this.isCurrentSubmenuPanel(panel,generation)&&(panel.updateComplete&&await panel.updateComplete,this.isCurrentSubmenuPanel(panel,generation)&&(this.submenuExpanded=controller.open,await this.updateComplete)))}async closeSubmenu(){const panel=this.submenuPanel,generation=this.submenuPanelGeneration;if(!panel||!this.isCurrentSubmenuPanel(panel,generation))return;const controller=panel[submenuPanelController],hidden=controller.hide();this.isCurrentSubmenuPanel(panel,generation)&&(this.submenuExpanded=controller.open,await hidden,this.isCurrentSubmenuPanel(panel,generation)&&(panel.updateComplete&&await panel.updateComplete,this.isCurrentSubmenuPanel(panel,generation)&&(this.submenuExpanded=controller.open,await this.updateComplete)))}syncDetailsSlot(slot){const meaningful=node=>node.nodeType===Node.TEXT_NODE?(node.textContent??"").trim()!=="":node.nodeType!==Node.ELEMENT_NODE?!1:node instanceof HTMLSlotElement?node.assignedNodes({flatten:!0}).some(meaningful):!0;this.hasDetailsSlot=slot.assignedNodes({flatten:!0}).some(meaningful)}defaultLabelSlot(){return this.renderRoot?.querySelector("slot:not([name])")??null}isDefaultLabelBranch(node){let top=node;for(;top.parentNode&&top.parentNode!==this;)top=top.parentNode;return top.parentNode!==this?!1:top.nodeType!==1||(top.getAttribute("slot")??"")===""}labelForwardingSlots(){return Array.from(this.querySelectorAll("slot")).filter(slot=>this.isDefaultLabelBranch(slot))}isLabelSubtreeExcluded(element){return!(element.getRootNode()===this.renderRoot&&element.matches('[part~="label"][aria-hidden="true"][inert]:not([hidden])'))&&isAccessibilitySubtreeExcluded(element)}readSlottedLabel(slot=this.defaultLabelSlot(),requireRendered=!0){const nodes=slot?slot.assignedNodes({flatten:!0}):Array.from(this.childNodes).filter(node=>this.isDefaultLabelBranch(node));return composedAccessibilityText(nodes,{ancestorBoundary:this,isSubtreeExcluded:element=>this.isLabelSubtreeExcluded(element),requireRendered,ignoreInheritedVisibility:!0}).replace(/\s+/g," ").trim()}syncSlottedLabel(slot=this.defaultLabelSlot()){const next=this.readSlottedLabel(slot);next!==this.slottedLabel&&(this.slottedLabel=next),this.applyComputedName(),this.applyPanelName(),this.isLinkItem&&this.linkName!==this.renderedLinkName&&this.requestUpdate()}get linkName(){return this.getAttribute("aria-label")?.trim()||this.slottedLabel||void 0}syncSubmenuSlot(submenuSlot){if(!submenuSlot.isConnected||submenuSlot.getRootNode()!==this.renderRoot)return;const assigned=submenuSlot.assignedElements({flatten:!0}),authoredPanel=assigned.find(element=>element.localName===tag("menu")),hasDirectItems=assigned.some(element=>element.localName===tag("menu-item")||element.localName===tag("dropdown-item")),kind=authoredPanel?"panel":hasDirectItems?"items":void 0;if(this.submenuKind=kind,this.submenuAssigned=kind!==void 0,kind==="items"){const generated=this.renderRoot.querySelector("[data-generated-submenu]");generated&&this.connectSubmenuPanel(generated);return}this.connectSubmenuPanel(authoredPanel??null)}connectSubmenuPanel(next){const samePanel=next===this.submenuPanel;if(samePanel&&(next===null||this.submenuPanelAttached))return;const previous=this.submenuPanel;if(++this.submenuPanelGeneration,previous&&this.submenuPanelAttached&&previous[submenuPanelController].detach(this),this.submenuPanelAttached=!1,samePanel||(this.submenuPanel=next,this.panelName={owns:!1,value:null}),!this.submenuPanel){this.submenuExpanded=!1;return}const controller=this.submenuPanel[submenuPanelController];controller.attach(this,this.onPanelStateChange),this.submenuPanelAttached=!0,this.submenuExpanded=controller.open,this.applyPanelName()}isCurrentSubmenuPanel(panel,generation){return this.isConnected&&this.submenuPanel===panel&&this.submenuPanelGeneration===generation}updated(changed){if(super.updated(changed),changed.has("submenuKind")&&this.submenuKind==="items"){const generated=this.renderRoot.querySelector("[data-generated-submenu]");this.connectSubmenuPanel(generated)}}firstUpdated(changed){super.firstUpdated(changed);const detailsSlot=this.detailsSlot;queueMicrotask(()=>{this.onIconSlotChange(),this.onSuffixSlotChange(),collectInitialSlotAssignment(detailsSlot,s=>this.syncDetailsSlot(s))})}applyComputedName(){this.writingComputedName=!0;try{syncOwnedAriaLabel(this,this.slottedLabel,this.ownedName,this.hasAttribute("aria-labelledby"))}finally{this.writingComputedName=!1}}applyPanelName(){const panel=this.submenuPanel;panel&&syncOwnedAriaLabel(panel,this.slottedLabel,this.panelName,panel.hasAttribute("label"))}getTextLabel(){return this.slottedLabel}get spinnerParts(){return"spinner spinner__base"}render(){const baseContent=html`
|
|
16
16
|
<span part="icon" aria-hidden="true" inert ?hidden=${!this.hasIconSlot}>
|
|
17
17
|
<slot name="icon" @slotchange=${this.onIconSlotChange}></slot>
|
|
18
18
|
<span part="prefix"
|
|
@@ -45,12 +45,13 @@ import{__decorate}from"tslib";import{html,nothing,svg}from"lit";import{html as s
|
|
|
45
45
|
${this.submenuAssigned?html`<span part="submenu-icon" aria-hidden="true"
|
|
46
46
|
>${chevronIcon()}</span
|
|
47
47
|
>`:nothing}
|
|
48
|
-
`,href=this.resolvedHref,base=href!==void 0?html`<a
|
|
48
|
+
`,href=this.resolvedHref,linkName=href!==void 0?this.linkName:void 0;this.renderedLinkName=linkName;const base=href!==void 0?html`<a
|
|
49
49
|
part="base"
|
|
50
50
|
href=${href}
|
|
51
51
|
target=${this.target||nothing}
|
|
52
52
|
rel=${this.resolvedRel??nothing}
|
|
53
53
|
download=${this.download!==void 0?this.download??"":nothing}
|
|
54
|
+
aria-label=${linkName??nothing}
|
|
54
55
|
tabindex="-1"
|
|
55
56
|
@click=${()=>this.select()}
|
|
56
57
|
>
|