@empathyco/x-components 6.0.0-alpha.6 → 6.0.0-alpha.61
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 +531 -0
- package/core/index.js +9 -1
- package/core/index.js.map +1 -1
- package/design-system/deprecated-full-theme.css +2371 -2371
- package/docs/API-reference/api/x-adapter-platform.md +12 -0
- package/docs/API-reference/api/x-adapter-platform.nextqueriesrelatedpromptsschema.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformadapter.relatedprompts.md +1 -1
- package/docs/API-reference/api/x-adapter-platform.platformrelatedprompt.md +23 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedprompt.nextqueries.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedprompt.suggestiontext.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedprompt.tagging.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedprompt.type.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedpromptnextqueriestagging.md +22 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedpromptnextqueriestagging.toolingdisplay.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedpromptnextqueriestagging.toolingdisplayadd2cart.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedpromptnextqueriestagging.toolingdisplayclick.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedpromptsrequest.md +15 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedpromptsresponse.data.md +13 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedpromptsresponse.md +21 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedpromptsresponse.status.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedprompttagging.md +22 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedprompttagging.nextqueries.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedprompttagging.toolingdisplay.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformrelatedprompttagging.toolingdisplayclick.md +11 -0
- package/docs/API-reference/api/x-adapter-platform.platformsearchresponse.catalog.md +6 -0
- package/docs/API-reference/api/x-adapter-platform.platformsearchresponse.md +1 -1
- package/docs/API-reference/api/x-adapter-platform.relatedpromptschema.md +13 -0
- package/docs/API-reference/api/x-adapter-platform.relatedpromptsendpointadapter.md +13 -0
- package/docs/API-reference/api/x-adapter-platform.relatedpromptsrequestmapper.md +13 -0
- package/docs/API-reference/api/x-adapter-platform.relatedpromptsrequestschema.md +13 -0
- package/docs/API-reference/api/x-adapter-platform.relatedpromptsresponsemapper.md +13 -0
- package/docs/API-reference/api/x-adapter-platform.relatedpromptsresponseschema.md +13 -0
- package/docs/API-reference/api/x-components.animationprop.md +6 -1
- package/docs/API-reference/api/x-components.bannerslist.md +3 -3
- package/docs/API-reference/api/x-components.baseaddtocart.md +1 -0
- package/docs/API-reference/api/x-components.basedropdown.md +5 -5
- package/docs/API-reference/api/x-components.baseeventsmodal.md +2 -2
- package/docs/API-reference/api/x-components.basegrid.md +3 -3
- package/docs/API-reference/api/x-components.baseheadertogglepanel.md +5 -5
- package/docs/API-reference/api/x-components.baseidmodal.md +2 -2
- package/docs/API-reference/api/x-components.baseidtogglepanel.md +5 -5
- package/docs/API-reference/api/x-components.basemodal.md +10 -10
- package/docs/API-reference/api/x-components.baseresultimage.md +9 -9
- package/docs/API-reference/api/x-components.baseslider.md +70 -0
- package/docs/API-reference/api/x-components.basesuggestions.md +3 -3
- package/docs/API-reference/api/x-components.baseswitch.md +1 -1
- package/docs/API-reference/api/x-components.basetabspanel.md +8 -8
- package/docs/API-reference/api/x-components.baseteleport.md +21 -0
- package/docs/API-reference/api/x-components.basetogglepanel.md +3 -3
- package/docs/API-reference/api/x-components.basevariablecolumngrid.md +3 -3
- package/docs/API-reference/api/x-components.cancelfetchandsaverelatedprompts.md +13 -0
- package/docs/API-reference/api/x-components.configmutations.config.md +11 -0
- package/docs/API-reference/api/x-components.configmutations.md +29 -0
- package/docs/API-reference/api/x-components.configmutations.mergeconfig.md +24 -0
- package/docs/API-reference/api/x-components.configmutations.setconfig.md +24 -0
- package/docs/API-reference/api/x-components.createrelatedtagsquerygetter.md +26 -0
- package/docs/API-reference/api/x-components.createrelatedtagsquerygetteroptions.getrelatedtags.md +13 -0
- package/docs/API-reference/api/x-components.createrelatedtagsquerygetteroptions.md +20 -0
- package/docs/API-reference/api/x-components.createtrackrelatedprompttoolingdisplayclickwire.md +19 -0
- package/docs/API-reference/api/x-components.createtracktoolingadd2cartwire.md +19 -0
- package/docs/API-reference/api/x-components.createtracktoolingdisplaywire.md +19 -0
- package/docs/API-reference/api/{x-components.defaultpdpaddtocartservice._constructor_.md → x-components.defaultexternaltaggingservice._constructor_.md} +3 -3
- package/docs/API-reference/api/x-components.defaultexternaltaggingservice.add_to_cart_id_key.md +13 -0
- package/docs/API-reference/api/x-components.defaultexternaltaggingservice.instance.md +13 -0
- package/docs/API-reference/api/x-components.defaultexternaltaggingservice.localstorageservice.md +11 -0
- package/docs/API-reference/api/x-components.defaultexternaltaggingservice.md +43 -0
- package/docs/API-reference/api/{x-components.defaultpdpaddtocartservice.movetosessionstorage.md → x-components.defaultexternaltaggingservice.movetosessionstorage.md} +2 -2
- package/docs/API-reference/api/x-components.defaultexternaltaggingservice.result_clicked_id_key.md +13 -0
- package/docs/API-reference/api/x-components.defaultexternaltaggingservice.sessionstorageservice.md +11 -0
- package/docs/API-reference/api/x-components.defaultexternaltaggingservice.storagekey.md +11 -0
- package/docs/API-reference/api/x-components.defaultexternaltaggingservice.storagettlms.md +11 -0
- package/docs/API-reference/api/{x-components.defaultpdpaddtocartservice.store.md → x-components.defaultexternaltaggingservice.store.md} +2 -2
- package/docs/API-reference/api/x-components.defaultexternaltaggingservice.storeaddtocart.md +24 -0
- package/docs/API-reference/api/{x-components.defaultpdpaddtocartservice.storeresultclicked.md → x-components.defaultexternaltaggingservice.storeresultclicked.md} +3 -3
- package/docs/API-reference/api/{x-components.defaultpdpaddtocartservice.trackaddtocart.md → x-components.defaultexternaltaggingservice.trackaddtocart.md} +3 -3
- package/docs/API-reference/api/x-components.displayclickprovider.md +66 -0
- package/docs/API-reference/api/x-components.empathize.md +6 -6
- package/docs/API-reference/api/x-components.empathizemutations.md +1 -1
- package/docs/API-reference/api/x-components.externaltaggingservice.md +23 -0
- package/docs/API-reference/api/{x-components.pdpaddtocartservice.movetosessionstorage.md → x-components.externaltaggingservice.movetosessionstorage.md} +2 -2
- package/docs/API-reference/api/x-components.externaltaggingservice.storeaddtocart.md +24 -0
- package/docs/API-reference/api/{x-components.pdpaddtocartservice.storeresultclicked.md → x-components.externaltaggingservice.storeresultclicked.md} +3 -3
- package/docs/API-reference/api/{x-components.pdpaddtocartservice.trackaddtocart.md → x-components.externaltaggingservice.trackaddtocart.md} +3 -3
- package/docs/API-reference/api/x-components.facets.md +3 -3
- package/docs/API-reference/api/x-components.facetsmutations.md +1 -1
- package/docs/API-reference/api/x-components.featurelocation.md +1 -1
- package/docs/API-reference/api/x-components.fetchandsaverelatedprompts.md +13 -0
- package/docs/API-reference/api/x-components.fetchrelatedprompts.md +13 -0
- package/docs/API-reference/api/x-components.filterslist.md +3 -3
- package/docs/API-reference/api/x-components.globalxbus.md +14 -0
- package/docs/API-reference/api/x-components.hierarchicalfilter.md +9 -2
- package/docs/API-reference/api/x-components.historyqueriesmutations.md +1 -1
- package/docs/API-reference/api/x-components.historyqueriesstate.md +1 -1
- package/docs/API-reference/api/x-components.identifierresults.md +3 -3
- package/docs/API-reference/api/x-components.identifierresultsmutations.md +1 -1
- package/docs/API-reference/api/x-components.identifierresultsstate.md +1 -1
- package/docs/API-reference/api/x-components.installxoptions.domelement.md +1 -1
- package/docs/API-reference/api/x-components.installxoptions.installextraplugins.md +2 -2
- package/docs/API-reference/api/x-components.installxoptions.md +1 -1
- package/docs/API-reference/api/x-components.itemslist.md +3 -3
- package/docs/API-reference/api/x-components.mainmodal.md +2 -2
- package/docs/API-reference/api/x-components.md +39 -3
- package/docs/API-reference/api/x-components.mergeconfig.md +27 -0
- package/docs/API-reference/api/x-components.multicolumnmaxwidthlayout.md +5 -5
- package/docs/API-reference/api/x-components.myhistory.md +3 -3
- package/docs/API-reference/api/x-components.nextqueriesgroup.md +22 -0
- package/docs/API-reference/api/x-components.nextqueriesgroup.modelname.md +11 -0
- package/docs/API-reference/api/x-components.nextqueriesgroup.nextqueries.md +11 -0
- package/docs/API-reference/api/x-components.nextquerieslist.md +3 -3
- package/docs/API-reference/api/x-components.nextqueriesmutations.md +1 -1
- package/docs/API-reference/api/x-components.nextqueriesstate.md +1 -1
- package/docs/API-reference/api/x-components.pageselector.md +80 -0
- package/docs/API-reference/api/x-components.partialresultslist.md +3 -3
- package/docs/API-reference/api/x-components.popularsearchesmutations.md +1 -1
- package/docs/API-reference/api/x-components.promotedslist.md +3 -3
- package/docs/API-reference/api/x-components.queriespreviewmutations.md +1 -1
- package/docs/API-reference/api/x-components.queryfeature.md +1 -1
- package/docs/API-reference/api/x-components.querymutations.md +20 -0
- package/docs/API-reference/api/x-components.querymutations.setquery.md +24 -0
- package/docs/API-reference/api/x-components.querypreviewlist.md +3 -3
- package/docs/API-reference/api/x-components.querystate.md +20 -0
- package/docs/API-reference/api/x-components.querystate.query.md +13 -0
- package/docs/API-reference/api/x-components.querysuggestionsmutations.md +1 -1
- package/docs/API-reference/api/x-components.querysuggestionsstate.md +1 -1
- package/docs/API-reference/api/x-components.recommendations.md +3 -3
- package/docs/API-reference/api/x-components.recommendationsmutations.md +1 -1
- package/docs/API-reference/api/x-components.relatedprompt.md +33 -0
- package/docs/API-reference/api/x-components.relatedpromptsactioncontext.md +15 -0
- package/docs/API-reference/api/x-components.relatedpromptsactions.cancelfetchandsaverelatedprompts.md +17 -0
- package/docs/API-reference/api/x-components.relatedpromptsactions.fetchandsaverelatedprompts.md +24 -0
- package/docs/API-reference/api/x-components.relatedpromptsactions.fetchrelatedprompts.md +24 -0
- package/docs/API-reference/api/x-components.relatedpromptsactions.md +23 -0
- package/docs/API-reference/api/x-components.relatedpromptsactions.seturlparams.md +24 -0
- package/docs/API-reference/api/x-components.relatedpromptsgetters.md +21 -0
- package/docs/API-reference/api/x-components.relatedpromptsgetters.query.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsgetters.request.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptslist.md +72 -0
- package/docs/API-reference/api/x-components.relatedpromptsmutations.md +27 -0
- package/docs/API-reference/api/x-components.relatedpromptsmutations.resetrelatedpromptsstate.md +17 -0
- package/docs/API-reference/api/x-components.relatedpromptsmutations.resetselectedprompt.md +17 -0
- package/docs/API-reference/api/x-components.relatedpromptsmutations.setparams.md +24 -0
- package/docs/API-reference/api/x-components.relatedpromptsmutations.setrelatedpromptsproducts.md +24 -0
- package/docs/API-reference/api/x-components.relatedpromptsmutations.setrelatedpromptsrelatedtags.md +24 -0
- package/docs/API-reference/api/x-components.relatedpromptsmutations.setselectedprompt.md +24 -0
- package/docs/API-reference/api/x-components.relatedpromptsmutations.setselectedquery.md +24 -0
- package/docs/API-reference/api/x-components.relatedpromptsstate.md +25 -0
- package/docs/API-reference/api/x-components.relatedpromptsstate.params.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsstate.relatedprompts.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsstate.relatedtags.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsstate.selectedprompt.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsstate.selectedquery.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptstaglist.md +72 -0
- package/docs/API-reference/api/x-components.relatedpromptsxevents.md +25 -0
- package/docs/API-reference/api/x-components.relatedpromptsxevents.relatedpromptsrequestupdated.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsxevents.selectedrelatedpromptchanged.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsxevents.userclickedarelatedpromptadd2cart.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsxevents.userclickedarelatedpromptresult.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsxevents.userselectedarelatedprompt.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsxevents.userselectedarelatedpromptquery.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsxmodule.md +13 -0
- package/docs/API-reference/api/x-components.relatedpromptsxstoremodule.md +15 -0
- package/docs/API-reference/api/x-components.relatedtags.md +3 -3
- package/docs/API-reference/api/x-components.relatedtagsmutations.md +1 -1
- package/docs/API-reference/api/x-components.relatedtagsstate.md +1 -1
- package/docs/API-reference/api/x-components.resultfeature.md +1 -1
- package/docs/API-reference/api/x-components.resultslist.md +3 -3
- package/docs/API-reference/api/x-components.scrolltotop.md +5 -5
- package/docs/API-reference/api/x-components.searchboxmutations.md +1 -1
- package/docs/API-reference/api/x-components.searchboxstate.md +1 -1
- package/docs/API-reference/api/x-components.searchconfig.md +1 -0
- package/docs/API-reference/api/x-components.searchconfig.pagemode.md +11 -0
- package/docs/API-reference/api/x-components.searchinputplaceholder.md +3 -3
- package/docs/API-reference/api/x-components.searchmutations.md +2 -1
- package/docs/API-reference/api/x-components.searchmutations.setstats.md +24 -0
- package/docs/API-reference/api/x-components.searchstate.md +2 -1
- package/docs/API-reference/api/x-components.searchstate.stats.md +13 -0
- package/docs/API-reference/api/x-components.searchxevents.md +1 -0
- package/docs/API-reference/api/x-components.searchxevents.userselectedapage.md +13 -0
- package/docs/API-reference/api/x-components.selectedfilterslist.md +3 -3
- package/docs/API-reference/api/x-components.semanticqueriesgetters.md +1 -0
- package/docs/API-reference/api/x-components.semanticqueriesgetters.query.md +13 -0
- package/docs/API-reference/api/x-components.semanticqueriesmutations.md +2 -1
- package/docs/API-reference/api/x-components.semanticqueriesmutations.setsemanticqueriesrelatedtags.md +24 -0
- package/docs/API-reference/api/x-components.semanticqueriesstate.md +2 -1
- package/docs/API-reference/api/x-components.semanticqueriesstate.relatedtags.md +13 -0
- package/docs/API-reference/api/x-components.setconfig.md +27 -0
- package/docs/API-reference/api/x-components.setquery.md +25 -0
- package/docs/API-reference/api/x-components.seturlprompt.md +13 -0
- package/docs/API-reference/api/x-components.simplefilter.md +7 -0
- package/docs/API-reference/api/x-components.singlecolumnlayout.md +3 -3
- package/docs/API-reference/api/x-components.slidingpanel.md +13 -5
- package/docs/API-reference/api/x-components.snippetcallbacks.md +7 -0
- package/docs/API-reference/api/x-components.sortdropdown.md +1 -1
- package/docs/API-reference/api/x-components.tagging.md +6 -6
- package/docs/API-reference/api/x-components.taggingconfig.md +2 -2
- package/docs/API-reference/api/{x-components.taggingconfig.clickedresultstoragekey.md → x-components.taggingconfig.storagekey.md} +3 -3
- package/docs/API-reference/api/x-components.taggingconfig.storagettlms.md +13 -0
- package/docs/API-reference/api/x-components.taggingmutations.md +1 -1
- package/docs/API-reference/api/x-components.taggingxevents.md +1 -1
- package/docs/API-reference/api/x-components.taggingxevents.resulturltrackingenabled.md +1 -1
- package/docs/API-reference/api/x-components.trackrelatedprompttoolingdisplayclickwire.md +13 -0
- package/docs/API-reference/api/x-components.tracktoolingadd2cartwire.md +13 -0
- package/docs/API-reference/api/x-components.tracktoolingdisplayclickedwire.md +13 -0
- package/docs/API-reference/api/x-components.typing.md +13 -0
- package/docs/API-reference/api/x-components.typingoptions.md +22 -0
- package/docs/API-reference/api/x-components.typingoptions.speed.md +13 -0
- package/docs/API-reference/api/x-components.typingoptions.targetattr.md +18 -0
- package/docs/API-reference/api/x-components.typingoptions.text.md +13 -0
- package/docs/API-reference/api/x-components.urlmutations.md +2 -1
- package/docs/API-reference/api/x-components.urlmutations.setprompt.md +24 -0
- package/docs/API-reference/api/x-components.urlparams.md +1 -0
- package/docs/API-reference/api/x-components.urlparams.prompt.md +11 -0
- package/docs/API-reference/api/x-components.urlstate.md +1 -1
- package/docs/API-reference/api/x-components.usealiasapi.md +1 -0
- package/docs/API-reference/api/x-components.usealiasapi.pricestats.md +16 -0
- package/docs/API-reference/api/x-components.xeventstypes.md +3 -3
- package/docs/API-reference/api/x-components.xmodulestree.md +1 -0
- package/docs/API-reference/api/x-components.xmodulestree.relatedprompts.md +11 -0
- package/docs/API-reference/api/x-types.md +2 -0
- package/docs/API-reference/api/x-types.relatedprompt.md +4 -1
- package/docs/API-reference/api/x-types.relatedprompt.nextqueries.md +1 -1
- package/docs/API-reference/api/x-types.relatedprompt.relatedpromptnextqueries.md +13 -0
- package/docs/API-reference/api/x-types.relatedprompt.tagging.md +17 -0
- package/docs/API-reference/api/x-types.relatedprompt.toolingdisplaytagging.md +13 -0
- package/docs/API-reference/api/x-types.relatedpromptnextquery.md +23 -0
- package/docs/API-reference/api/x-types.relatedpromptnextquery.query.md +13 -0
- package/docs/API-reference/api/x-types.relatedpromptnextquery.toolingdisplayadd2carttagging.md +13 -0
- package/docs/API-reference/api/x-types.relatedpromptnextquery.toolingdisplayclicktagging.md +13 -0
- package/docs/API-reference/api/x-types.relatedpromptnextquery.toolingdisplaytagging.md +13 -0
- package/docs/API-reference/api/x-types.searchresponse.md +1 -0
- package/docs/API-reference/api/x-types.searchresponse.stats.md +11 -0
- package/docs/API-reference/api/x-types.stats.md +22 -0
- package/docs/API-reference/api/x-types.stats.price.md +14 -0
- package/docs/API-reference/components/common/result/x-components.base-result-image.md +2 -2
- package/docs/API-reference/components/common/x-components.base-slider.md +189 -0
- package/docs/API-reference/components/common/x-components.base-teleport.md +19 -0
- package/docs/API-reference/components/common/x-components.display-click-provider.md +17 -0
- package/docs/API-reference/components/common/x-components.items-list.md +1 -1
- package/docs/API-reference/components/common/x-components.page-selector.md +136 -0
- package/docs/API-reference/components/common/x-components.sliding-panel.md +7 -7
- package/docs/API-reference/components/facets/x-components.facets/facets.md +1 -1
- package/docs/API-reference/components/facets/x-components.lists/selected-filters-list.md +1 -1
- package/docs/API-reference/components/related-prompts/x-components.related-prompt.md +22 -0
- package/docs/API-reference/components/related-prompts/x-components.related-prompts-list.md +196 -0
- package/docs/API-reference/components/related-prompts/x-components.related-prompts-tag-list.md +32 -0
- package/docs/API-reference/components/search/x-components.results-list.md +1 -1
- package/docs/API-reference/components/tagging/x-components.tagging.md +15 -16
- package/js/components/animations/fade-and-slide.vue.js +1 -2
- package/js/components/animations/fade-and-slide.vue.js.map +1 -1
- package/js/components/base-dropdown.vue.js +1 -3
- package/js/components/base-dropdown.vue.js.map +1 -1
- package/js/components/base-dropdown.vue2.js +1 -7
- package/js/components/base-dropdown.vue2.js.map +1 -1
- package/js/components/base-event-button.vue.js +1 -2
- package/js/components/base-event-button.vue.js.map +1 -1
- package/js/components/base-grid.vue.js +11 -18
- package/js/components/base-grid.vue.js.map +1 -1
- package/js/components/base-grid.vue2.js.map +1 -1
- package/js/components/base-grid.vue3.js +1 -1
- package/js/components/base-keyboard-navigation.vue.js +1 -2
- package/js/components/base-keyboard-navigation.vue.js.map +1 -1
- package/js/components/base-rating.vue.js +1 -3
- package/js/components/base-rating.vue.js.map +1 -1
- package/js/components/base-slider.vue.js +65 -0
- package/js/components/base-slider.vue.js.map +1 -0
- package/js/components/base-slider.vue2.js +109 -0
- package/js/components/base-slider.vue2.js.map +1 -0
- package/js/components/base-slider.vue3.js +7 -0
- package/js/components/base-slider.vue3.js.map +1 -0
- package/js/components/base-switch.vue.js.map +1 -1
- package/js/components/base-switch.vue2.js +3 -7
- package/js/components/base-switch.vue2.js.map +1 -1
- package/js/components/base-teleport.vue.js +17 -0
- package/js/components/base-teleport.vue.js.map +1 -0
- package/js/components/base-teleport.vue2.js +14 -0
- package/js/components/base-teleport.vue2.js.map +1 -0
- package/js/components/base-teleport.vue3.js +7 -0
- package/js/components/base-teleport.vue3.js.map +1 -0
- package/js/components/base-variable-column-grid.vue.js +1 -2
- package/js/components/base-variable-column-grid.vue.js.map +1 -1
- package/js/components/column-picker/base-column-picker-dropdown.vue.js +1 -3
- package/js/components/column-picker/base-column-picker-dropdown.vue.js.map +1 -1
- package/js/components/column-picker/base-column-picker-list.vue.js +1 -3
- package/js/components/column-picker/base-column-picker-list.vue.js.map +1 -1
- package/js/components/display-click-provider.vue.js +74 -0
- package/js/components/display-click-provider.vue.js.map +1 -0
- package/js/components/display-click-provider.vue2.js +6 -0
- package/js/components/display-click-provider.vue2.js.map +1 -0
- package/js/components/filters/labels/base-rating-filter-label.vue.js +1 -3
- package/js/components/filters/labels/base-rating-filter-label.vue.js.map +1 -1
- package/js/components/icons/cross-tiny.vue.js +2 -2
- package/js/components/icons/plus.vue.js +2 -2
- package/js/components/items-list.vue.js +1 -2
- package/js/components/items-list.vue.js.map +1 -1
- package/js/components/items-list.vue2.js +2 -2
- package/js/components/items-list.vue2.js.map +1 -1
- package/js/components/layouts/fixed-header-and-asides-layout.vue.js +1 -7
- package/js/components/layouts/fixed-header-and-asides-layout.vue.js.map +1 -1
- package/js/components/layouts/multi-column-max-width-layout.vue.js +1 -9
- package/js/components/layouts/multi-column-max-width-layout.vue.js.map +1 -1
- package/js/components/layouts/single-column-layout.vue.js +1 -9
- package/js/components/layouts/single-column-layout.vue.js.map +1 -1
- package/js/components/modals/base-events-modal-close.vue.js +1 -2
- package/js/components/modals/base-events-modal-close.vue.js.map +1 -1
- package/js/components/modals/base-events-modal-open.vue.js +1 -2
- package/js/components/modals/base-events-modal-open.vue.js.map +1 -1
- package/js/components/modals/base-id-modal-close.vue.js +1 -2
- package/js/components/modals/base-id-modal-close.vue.js.map +1 -1
- package/js/components/modals/base-id-modal-open.vue.js +1 -2
- package/js/components/modals/base-id-modal-open.vue.js.map +1 -1
- package/js/components/modals/base-modal.vue.js +1 -2
- package/js/components/modals/base-modal.vue.js.map +1 -1
- package/js/components/modals/base-modal.vue2.js +13 -6
- package/js/components/modals/base-modal.vue2.js.map +1 -1
- package/js/components/page-loader-button.vue.js +8 -10
- package/js/components/page-loader-button.vue.js.map +1 -1
- package/js/components/page-loader-button.vue2.js.map +1 -1
- package/js/components/page-loader-button.vue3.js +7 -0
- package/js/components/page-loader-button.vue3.js.map +1 -0
- package/js/components/page-selector.vue.js +78 -0
- package/js/components/page-selector.vue.js.map +1 -0
- package/js/components/page-selector.vue2.js +128 -0
- package/js/components/page-selector.vue2.js.map +1 -0
- package/js/components/page-selector.vue3.js +7 -0
- package/js/components/page-selector.vue3.js.map +1 -0
- package/js/components/panels/base-header-toggle-panel.vue.js +1 -5
- package/js/components/panels/base-header-toggle-panel.vue.js.map +1 -1
- package/js/components/panels/base-id-toggle-panel-button.vue.js +1 -2
- package/js/components/panels/base-id-toggle-panel-button.vue.js.map +1 -1
- package/js/components/panels/base-id-toggle-panel.vue.js +1 -2
- package/js/components/panels/base-id-toggle-panel.vue.js.map +1 -1
- package/js/components/panels/base-tabs-panel.vue.js +1 -4
- package/js/components/panels/base-tabs-panel.vue.js.map +1 -1
- package/js/components/panels/base-toggle-panel.vue.js +1 -2
- package/js/components/panels/base-toggle-panel.vue.js.map +1 -1
- package/js/components/result/base-result-add-to-cart.vue.js +3 -3
- package/js/components/result/base-result-add-to-cart.vue.js.map +1 -1
- package/js/components/result/base-result-add-to-cart.vue2.js +19 -5
- package/js/components/result/base-result-add-to-cart.vue2.js.map +1 -1
- package/js/components/result/base-result-current-price.vue.js +1 -2
- package/js/components/result/base-result-current-price.vue.js.map +1 -1
- package/js/components/result/base-result-image.vue.js +39 -59
- package/js/components/result/base-result-image.vue.js.map +1 -1
- package/js/components/result/base-result-image.vue2.js +5 -5
- package/js/components/result/base-result-image.vue2.js.map +1 -1
- package/js/components/result/base-result-link.vue.js +1 -2
- package/js/components/result/base-result-link.vue.js.map +1 -1
- package/js/components/result/base-result-previous-price.vue.js +1 -2
- package/js/components/result/base-result-previous-price.vue.js.map +1 -1
- package/js/components/result/base-result-rating.vue.js +1 -4
- package/js/components/result/base-result-rating.vue.js.map +1 -1
- package/js/components/result/result-variant-selector.vue.js +1 -3
- package/js/components/result/result-variant-selector.vue.js.map +1 -1
- package/js/components/sliding-panel.vue.js +3 -6
- package/js/components/sliding-panel.vue.js.map +1 -1
- package/js/components/sliding-panel.vue2.js +2 -2
- package/js/components/sliding-panel.vue2.js.map +1 -1
- package/js/components/suggestions/base-suggestion.vue.js +1 -2
- package/js/components/suggestions/base-suggestion.vue.js.map +1 -1
- package/js/components/suggestions/base-suggestions.vue.js +1 -2
- package/js/components/suggestions/base-suggestions.vue.js.map +1 -1
- package/js/composables/use-alias-api.js +4 -1
- package/js/composables/use-alias-api.js.map +1 -1
- package/js/composables/use-getter.js +1 -1
- package/js/composables/use-state.js +1 -1
- package/js/directives/typing.js +58 -0
- package/js/directives/typing.js.map +1 -0
- package/js/index.js +21 -4
- package/js/index.js.map +1 -1
- package/js/types/animation-prop.js +5 -0
- package/js/types/animation-prop.js.map +1 -1
- package/js/x-installer/x-installer/x-installer.js +3 -3
- package/js/x-installer/x-installer/x-installer.js.map +1 -1
- package/js/x-modules/device/store/emitters.js +1 -0
- package/js/x-modules/device/store/emitters.js.map +1 -1
- package/js/x-modules/empathize/components/empathize.vue.js +1 -2
- package/js/x-modules/empathize/components/empathize.vue.js.map +1 -1
- package/js/x-modules/empathize/components/empathize.vue2.js +10 -3
- package/js/x-modules/empathize/components/empathize.vue2.js.map +1 -1
- package/js/x-modules/empathize/store/emitters.js +1 -0
- package/js/x-modules/empathize/store/emitters.js.map +1 -1
- package/js/x-modules/experience-controls/store/emitters.js +1 -0
- package/js/x-modules/experience-controls/store/emitters.js.map +1 -1
- package/js/x-modules/extra-params/components/extra-params.vue.js +1 -1
- package/js/x-modules/extra-params/components/extra-params.vue.js.map +1 -1
- package/js/x-modules/extra-params/store/emitters.js +1 -0
- package/js/x-modules/extra-params/store/emitters.js.map +1 -1
- package/js/x-modules/facets/components/facets/facets.vue.js +20 -33
- package/js/x-modules/facets/components/facets/facets.vue.js.map +1 -1
- package/js/x-modules/facets/components/facets/facets.vue2.js +2 -2
- package/js/x-modules/facets/components/facets/facets.vue2.js.map +1 -1
- package/js/x-modules/facets/components/filters/all-filter.vue.js +1 -2
- package/js/x-modules/facets/components/filters/all-filter.vue.js.map +1 -1
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue.js +1 -6
- package/js/x-modules/facets/components/filters/editable-number-range-filter.vue.js.map +1 -1
- package/js/x-modules/facets/components/filters/hierarchical-filter.vue.js +1 -3
- package/js/x-modules/facets/components/filters/hierarchical-filter.vue.js.map +1 -1
- package/js/x-modules/facets/components/filters/number-range-filter.vue.js +1 -3
- package/js/x-modules/facets/components/filters/number-range-filter.vue.js.map +1 -1
- package/js/x-modules/facets/components/filters/simple-filter.vue.js +1 -3
- package/js/x-modules/facets/components/filters/simple-filter.vue.js.map +1 -1
- package/js/x-modules/facets/components/lists/filters-list.vue.js +1 -2
- package/js/x-modules/facets/components/lists/filters-list.vue.js.map +1 -1
- package/js/x-modules/facets/components/lists/filters-search.vue.js +1 -3
- package/js/x-modules/facets/components/lists/filters-search.vue.js.map +1 -1
- package/js/x-modules/facets/components/lists/selected-filters-list.vue.js +11 -18
- package/js/x-modules/facets/components/lists/selected-filters-list.vue.js.map +1 -1
- package/js/x-modules/facets/components/lists/selected-filters-list.vue2.js +2 -2
- package/js/x-modules/facets/components/lists/selected-filters-list.vue2.js.map +1 -1
- package/js/x-modules/facets/components/lists/sliced-filters.vue.js +1 -4
- package/js/x-modules/facets/components/lists/sliced-filters.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/clear-history-queries.vue.js +1 -2
- package/js/x-modules/history-queries/components/clear-history-queries.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/history-queries.vue.js +1 -10
- package/js/x-modules/history-queries/components/history-queries.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/history-query.vue.js +1 -6
- package/js/x-modules/history-queries/components/history-query.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/my-history.vue.js +1 -4
- package/js/x-modules/history-queries/components/my-history.vue.js.map +1 -1
- package/js/x-modules/history-queries/components/remove-history-query.vue.js +1 -2
- package/js/x-modules/history-queries/components/remove-history-query.vue.js.map +1 -1
- package/js/x-modules/history-queries/store/emitters.js +1 -0
- package/js/x-modules/history-queries/store/emitters.js.map +1 -1
- package/js/x-modules/identifier-results/components/identifier-results.vue.js +1 -2
- package/js/x-modules/identifier-results/components/identifier-results.vue.js.map +1 -1
- package/js/x-modules/identifier-results/store/emitters.js +1 -0
- package/js/x-modules/identifier-results/store/emitters.js.map +1 -1
- package/js/x-modules/next-queries/components/next-queries.vue.js +1 -7
- package/js/x-modules/next-queries/components/next-queries.vue.js.map +1 -1
- package/js/x-modules/next-queries/components/next-query-preview.vue.js +1 -3
- package/js/x-modules/next-queries/components/next-query-preview.vue.js.map +1 -1
- package/js/x-modules/next-queries/components/next-query.vue.js +1 -4
- package/js/x-modules/next-queries/components/next-query.vue.js.map +1 -1
- package/js/x-modules/next-queries/store/emitters.js +1 -0
- package/js/x-modules/next-queries/store/emitters.js.map +1 -1
- package/js/x-modules/popular-searches/components/popular-search.vue.js +1 -4
- package/js/x-modules/popular-searches/components/popular-search.vue.js.map +1 -1
- package/js/x-modules/popular-searches/components/popular-searches.vue.js +1 -7
- package/js/x-modules/popular-searches/components/popular-searches.vue.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview-button.vue.js +1 -2
- package/js/x-modules/queries-preview/components/query-preview-button.vue.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview-button.vue2.js +8 -0
- package/js/x-modules/queries-preview/components/query-preview-button.vue2.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview-list.vue.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview-list.vue2.js +15 -2
- package/js/x-modules/queries-preview/components/query-preview-list.vue2.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview.vue.js +1 -2
- package/js/x-modules/queries-preview/components/query-preview.vue.js.map +1 -1
- package/js/x-modules/queries-preview/components/query-preview.vue2.js +9 -1
- package/js/x-modules/queries-preview/components/query-preview.vue2.js.map +1 -1
- package/js/x-modules/queries-preview/store/actions/fetch-and-save-query-preview.action.js +2 -1
- package/js/x-modules/queries-preview/store/actions/fetch-and-save-query-preview.action.js.map +1 -1
- package/js/x-modules/queries-preview/store/emitters.js +1 -0
- package/js/x-modules/queries-preview/store/emitters.js.map +1 -1
- package/js/x-modules/queries-preview/store/module.js +1 -1
- package/js/x-modules/queries-preview/store/module.js.map +1 -1
- package/js/x-modules/queries-preview/utils/get-hash-from-query-preview.js +6 -4
- package/js/x-modules/queries-preview/utils/get-hash-from-query-preview.js.map +1 -1
- package/js/x-modules/query-suggestions/components/query-suggestion.vue.js +1 -4
- package/js/x-modules/query-suggestions/components/query-suggestion.vue.js.map +1 -1
- package/js/x-modules/query-suggestions/components/query-suggestions.vue.js +1 -7
- package/js/x-modules/query-suggestions/components/query-suggestions.vue.js.map +1 -1
- package/js/x-modules/query-suggestions/store/emitters.js +1 -0
- package/js/x-modules/query-suggestions/store/emitters.js.map +1 -1
- package/js/x-modules/recommendations/components/recommendations.vue.js +1 -2
- package/js/x-modules/recommendations/components/recommendations.vue.js.map +1 -1
- package/js/x-modules/recommendations/store/emitters.js +1 -0
- package/js/x-modules/recommendations/store/emitters.js.map +1 -1
- package/js/x-modules/related-prompts/components/related-prompt.vue.js +27 -0
- package/js/x-modules/related-prompts/components/related-prompt.vue.js.map +1 -0
- package/js/x-modules/related-prompts/components/related-prompt.vue2.js +31 -0
- package/js/x-modules/related-prompts/components/related-prompt.vue2.js.map +1 -0
- package/js/x-modules/related-prompts/components/related-prompt.vue3.js +7 -0
- package/js/x-modules/related-prompts/components/related-prompt.vue3.js.map +1 -0
- package/js/x-modules/related-prompts/components/related-prompts-list.vue.js +154 -0
- package/js/x-modules/related-prompts/components/related-prompts-list.vue.js.map +1 -0
- package/js/x-modules/related-prompts/components/related-prompts-list.vue2.js +6 -0
- package/js/x-modules/related-prompts/components/related-prompts-list.vue2.js.map +1 -0
- package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue.js +101 -0
- package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue.js.map +1 -0
- package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue2.js +221 -0
- package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue2.js.map +1 -0
- package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue3.js +7 -0
- package/js/x-modules/related-prompts/components/related-prompts-tag-list.vue3.js.map +1 -0
- package/js/x-modules/related-prompts/store/actions/fetch-and-save-related-prompts.action.js +29 -0
- package/js/x-modules/related-prompts/store/actions/fetch-and-save-related-prompts.action.js.map +1 -0
- package/js/x-modules/related-prompts/store/actions/fetch-related-prompts.action.js +20 -0
- package/js/x-modules/related-prompts/store/actions/fetch-related-prompts.action.js.map +1 -0
- package/js/x-modules/related-prompts/store/actions/set-url-params.action.js +15 -0
- package/js/x-modules/related-prompts/store/actions/set-url-params.action.js.map +1 -0
- package/js/x-modules/related-prompts/store/emitters.js +16 -0
- package/js/x-modules/related-prompts/store/emitters.js.map +1 -0
- package/js/x-modules/related-prompts/store/getters/related-prompts-query.getter.js +18 -0
- package/js/x-modules/related-prompts/store/getters/related-prompts-query.getter.js.map +1 -0
- package/js/x-modules/related-prompts/store/getters/request.getter.js +17 -0
- package/js/x-modules/related-prompts/store/getters/request.getter.js.map +1 -0
- package/js/x-modules/related-prompts/store/module.js +64 -0
- package/js/x-modules/related-prompts/store/module.js.map +1 -0
- package/js/x-modules/related-prompts/wiring.js +82 -0
- package/js/x-modules/related-prompts/wiring.js.map +1 -0
- package/js/x-modules/related-prompts/x-module.js +21 -0
- package/js/x-modules/related-prompts/x-module.js.map +1 -0
- package/js/x-modules/related-tags/components/related-tag.vue.js +1 -2
- package/js/x-modules/related-tags/components/related-tag.vue.js.map +1 -1
- package/js/x-modules/related-tags/components/related-tags.vue.js +1 -4
- package/js/x-modules/related-tags/components/related-tags.vue.js.map +1 -1
- package/js/x-modules/related-tags/store/emitters.js +1 -0
- package/js/x-modules/related-tags/store/emitters.js.map +1 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue.js +1 -2
- package/js/x-modules/scroll/components/scroll-to-top.vue.js.map +1 -1
- package/js/x-modules/scroll/components/scroll-to-top.vue2.js +8 -0
- package/js/x-modules/scroll/components/scroll-to-top.vue2.js.map +1 -1
- package/js/x-modules/scroll/store/emitters.js +1 -0
- package/js/x-modules/scroll/store/emitters.js.map +1 -1
- package/js/x-modules/search/components/partial-results-list.vue.js +1 -2
- package/js/x-modules/search/components/partial-results-list.vue.js.map +1 -1
- package/js/x-modules/search/components/results-list.vue.js +2 -2
- package/js/x-modules/search/components/results-list.vue.js.map +1 -1
- package/js/x-modules/search/components/sort-dropdown.vue.js +1 -3
- package/js/x-modules/search/components/sort-dropdown.vue.js.map +1 -1
- package/js/x-modules/search/store/actions/fetch-and-save-search-response.action.js +10 -3
- package/js/x-modules/search/store/actions/fetch-and-save-search-response.action.js.map +1 -1
- package/js/x-modules/search/store/actions/save-search-response.action.js +3 -1
- package/js/x-modules/search/store/actions/save-search-response.action.js.map +1 -1
- package/js/x-modules/search/store/emitters.js +1 -0
- package/js/x-modules/search/store/emitters.js.map +1 -1
- package/js/x-modules/search/store/module.js +9 -3
- package/js/x-modules/search/store/module.js.map +1 -1
- package/js/x-modules/search/wiring.js +4 -0
- package/js/x-modules/search/wiring.js.map +1 -1
- package/js/x-modules/search-box/components/clear-search-input.vue.js +1 -2
- package/js/x-modules/search-box/components/clear-search-input.vue.js.map +1 -1
- package/js/x-modules/search-box/components/search-button.vue.js +1 -2
- package/js/x-modules/search-box/components/search-button.vue.js.map +1 -1
- package/js/x-modules/search-box/store/emitters.js +1 -0
- package/js/x-modules/search-box/store/emitters.js.map +1 -1
- package/js/x-modules/semantic-queries/components/semantic-queries.vue.js +1 -3
- package/js/x-modules/semantic-queries/components/semantic-queries.vue.js.map +1 -1
- package/js/x-modules/semantic-queries/components/semantic-query.vue.js +1 -4
- package/js/x-modules/semantic-queries/components/semantic-query.vue.js.map +1 -1
- package/js/x-modules/semantic-queries/store/getters/normalized-query.getter.js +1 -1
- package/js/x-modules/semantic-queries/store/getters/normalized-query.getter.js.map +1 -1
- package/js/x-modules/semantic-queries/store/getters/request.getter.js +5 -4
- package/js/x-modules/semantic-queries/store/getters/request.getter.js.map +1 -1
- package/js/x-modules/semantic-queries/store/getters/semanti-queries-query.getter.js +18 -0
- package/js/x-modules/semantic-queries/store/getters/semanti-queries-query.getter.js.map +1 -0
- package/js/x-modules/semantic-queries/store/module.js +8 -2
- package/js/x-modules/semantic-queries/store/module.js.map +1 -1
- package/js/x-modules/semantic-queries/wiring.js +5 -0
- package/js/x-modules/semantic-queries/wiring.js.map +1 -1
- package/js/x-modules/tagging/components/tagging.vue.js +8 -7
- package/js/x-modules/tagging/components/tagging.vue.js.map +1 -1
- package/js/x-modules/tagging/service/{pdp-add-to-cart.service.js → external-tagging.service.js} +56 -25
- package/js/x-modules/tagging/service/external-tagging.service.js.map +1 -0
- package/js/x-modules/tagging/store/emitters.js +1 -1
- package/js/x-modules/tagging/store/emitters.js.map +1 -1
- package/js/x-modules/tagging/store/module.js +7 -3
- package/js/x-modules/tagging/store/module.js.map +1 -1
- package/js/x-modules/tagging/wiring.js +110 -9
- package/js/x-modules/tagging/wiring.js.map +1 -1
- package/js/x-modules/url/components/url-handler.vue.js.map +1 -1
- package/js/x-modules/url/components/url-handler.vue2.js +4 -5
- package/js/x-modules/url/components/url-handler.vue2.js.map +1 -1
- package/js/x-modules/url/store/emitters.js +1 -0
- package/js/x-modules/url/store/emitters.js.map +1 -1
- package/js/x-modules/url/store/getters/url-params.getter.js +2 -3
- package/js/x-modules/url/store/getters/url-params.getter.js.map +1 -1
- package/js/x-modules/url/store/initial-state.js +2 -1
- package/js/x-modules/url/store/initial-state.js.map +1 -1
- package/js/x-modules/url/store/module.js +3 -0
- package/js/x-modules/url/store/module.js.map +1 -1
- package/js/x-modules/url/wiring.js +10 -1
- package/js/x-modules/url/wiring.js.map +1 -1
- package/package.json +50 -49
- package/related-prompts/index.d.ts +1 -0
- package/related-prompts/index.js +9 -0
- package/report/x-adapter-platform.api.json +895 -67
- package/report/x-components.api.json +16491 -17162
- package/report/x-components.api.md +847 -215
- package/report/x-types.api.json +320 -4
- package/tagging/index.js +2 -2
- package/types/adapter/mocked-responses.d.ts +3 -0
- package/types/adapter/mocked-responses.d.ts.map +1 -1
- package/types/components/base-dropdown.vue.d.ts +5 -5
- package/types/components/base-dropdown.vue.d.ts.map +1 -1
- package/types/components/base-grid.vue.d.ts +3 -3
- package/types/components/base-slider.vue.d.ts +74 -0
- package/types/components/base-slider.vue.d.ts.map +1 -0
- package/types/components/base-switch.vue.d.ts +2 -1
- package/types/components/base-switch.vue.d.ts.map +1 -1
- package/types/components/base-teleport.vue.d.ts +13 -0
- package/types/components/base-teleport.vue.d.ts.map +1 -0
- package/types/components/base-variable-column-grid.vue.d.ts +3 -3
- package/types/components/display-click-provider.vue.d.ts +61 -0
- package/types/components/display-click-provider.vue.d.ts.map +1 -0
- package/types/components/global-x-bus.vue.d.ts +14 -0
- package/types/components/global-x-bus.vue.d.ts.map +1 -1
- package/types/components/index.d.ts +4 -0
- package/types/components/index.d.ts.map +1 -1
- package/types/components/items-list.vue.d.ts +3 -3
- package/types/components/layouts/multi-column-max-width-layout.vue.d.ts +5 -5
- package/types/components/layouts/single-column-layout.vue.d.ts +3 -3
- package/types/components/modals/base-events-modal.vue.d.ts +2 -2
- package/types/components/modals/base-id-modal.vue.d.ts +2 -2
- package/types/components/modals/base-modal.vue.d.ts +10 -10
- package/types/components/modals/base-modal.vue.d.ts.map +1 -1
- package/types/components/modals/main-modal.vue.d.ts +2 -2
- package/types/components/page-selector.vue.d.ts +125 -0
- package/types/components/page-selector.vue.d.ts.map +1 -0
- package/types/components/panels/base-header-toggle-panel.vue.d.ts +5 -5
- package/types/components/panels/base-id-toggle-panel.vue.d.ts +5 -5
- package/types/components/panels/base-tabs-panel.vue.d.ts +8 -8
- package/types/components/panels/base-toggle-panel.vue.d.ts +3 -3
- package/types/components/result/base-result-add-to-cart.vue.d.ts +2 -0
- package/types/components/result/base-result-add-to-cart.vue.d.ts.map +1 -1
- package/types/components/result/base-result-image.vue.d.ts +10 -10
- package/types/components/result/base-result-image.vue.d.ts.map +1 -1
- package/types/components/sliding-panel.vue.d.ts +15 -5
- package/types/components/sliding-panel.vue.d.ts.map +1 -1
- package/types/components/snippet-callbacks.vue.d.ts +7 -0
- package/types/components/snippet-callbacks.vue.d.ts.map +1 -1
- package/types/components/suggestions/base-suggestions.vue.d.ts +3 -3
- package/types/composables/use-alias-api.d.ts +5 -0
- package/types/composables/use-alias-api.d.ts.map +1 -1
- package/types/composables/use-store.d.ts +2 -2
- package/types/composables/use-store.d.ts.map +1 -1
- package/types/directives/index.d.ts +1 -0
- package/types/directives/index.d.ts.map +1 -1
- package/types/directives/typing.d.ts +35 -0
- package/types/directives/typing.d.ts.map +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/store/index.d.ts +4 -1
- package/types/store/index.d.ts.map +1 -1
- package/types/tailwind/plugin-options.d.ts +1 -2
- package/types/tailwind/plugin-options.d.ts.map +1 -1
- package/types/types/animation-prop.d.ts +6 -2
- package/types/types/animation-prop.d.ts.map +1 -1
- package/types/types/origin.d.ts +3 -3
- package/types/types/origin.d.ts.map +1 -1
- package/types/types/page-mode.d.ts +2 -0
- package/types/types/page-mode.d.ts.map +1 -0
- package/types/types/url-params.d.ts +1 -0
- package/types/types/url-params.d.ts.map +1 -1
- package/types/views/home/types.d.ts +3 -0
- package/types/views/home/types.d.ts.map +1 -1
- package/types/wiring/events.types.d.ts +3 -1
- package/types/wiring/events.types.d.ts.map +1 -1
- package/types/x-installer/x-installer/types.d.ts +2 -2
- package/types/x-installer/x-installer/types.d.ts.map +1 -1
- package/types/x-installer/x-installer/x-installer.d.ts +4 -4
- package/types/x-installer/x-installer/x-installer.d.ts.map +1 -1
- package/types/x-modules/empathize/components/empathize.vue.d.ts +6 -6
- package/types/x-modules/empathize/components/empathize.vue.d.ts.map +1 -1
- package/types/x-modules/facets/components/facets/facets.vue.d.ts +3 -3
- package/types/x-modules/facets/components/filters/hierarchical-filter.vue.d.ts +9 -2
- package/types/x-modules/facets/components/filters/hierarchical-filter.vue.d.ts.map +1 -1
- package/types/x-modules/facets/components/filters/simple-filter.vue.d.ts +7 -0
- package/types/x-modules/facets/components/filters/simple-filter.vue.d.ts.map +1 -1
- package/types/x-modules/facets/components/lists/filters-list.vue.d.ts +3 -3
- package/types/x-modules/facets/components/lists/selected-filters-list.vue.d.ts +3 -3
- package/types/x-modules/history-queries/components/my-history.vue.d.ts +3 -3
- package/types/x-modules/identifier-results/components/identifier-results.vue.d.ts +3 -3
- package/types/x-modules/next-queries/components/next-queries-list.vue.d.ts +3 -3
- package/types/x-modules/next-queries/index.d.ts +1 -0
- package/types/x-modules/next-queries/index.d.ts.map +1 -1
- package/types/x-modules/queries-preview/components/query-preview-list.vue.d.ts +3 -3
- package/types/x-modules/queries-preview/components/query-preview-list.vue.d.ts.map +1 -1
- package/types/x-modules/queries-preview/components/query-preview.vue.d.ts.map +1 -1
- package/types/x-modules/queries-preview/store/actions/fetch-and-save-query-preview.action.d.ts.map +1 -1
- package/types/x-modules/queries-preview/store/module.d.ts.map +1 -1
- package/types/x-modules/queries-preview/utils/get-hash-from-query-preview.d.ts +4 -2
- package/types/x-modules/queries-preview/utils/get-hash-from-query-preview.d.ts.map +1 -1
- package/types/x-modules/recommendations/components/recommendations.vue.d.ts +3 -3
- package/types/x-modules/related-prompts/components/index.d.ts +4 -0
- package/types/x-modules/related-prompts/components/index.d.ts.map +1 -0
- package/types/x-modules/related-prompts/components/related-prompt.vue.d.ts +28 -0
- package/types/x-modules/related-prompts/components/related-prompt.vue.d.ts.map +1 -0
- package/types/x-modules/related-prompts/components/related-prompts-list.vue.d.ts +106 -0
- package/types/x-modules/related-prompts/components/related-prompts-list.vue.d.ts.map +1 -0
- package/types/x-modules/related-prompts/components/related-prompts-tag-list.vue.d.ts +131 -0
- package/types/x-modules/related-prompts/components/related-prompts-tag-list.vue.d.ts.map +1 -0
- package/types/x-modules/related-prompts/events.types.d.ts +41 -0
- package/types/x-modules/related-prompts/events.types.d.ts.map +1 -0
- package/types/x-modules/related-prompts/index.d.ts +6 -0
- package/types/x-modules/related-prompts/index.d.ts.map +1 -0
- package/types/x-modules/related-prompts/store/actions/fetch-and-save-related-prompts.action.d.ts +17 -0
- package/types/x-modules/related-prompts/store/actions/fetch-and-save-related-prompts.action.d.ts.map +1 -0
- package/types/x-modules/related-prompts/store/actions/fetch-related-prompts.action.d.ts +13 -0
- package/types/x-modules/related-prompts/store/actions/fetch-related-prompts.action.d.ts.map +1 -0
- package/types/x-modules/related-prompts/store/actions/set-url-params.action.d.ts +11 -0
- package/types/x-modules/related-prompts/store/actions/set-url-params.action.d.ts.map +1 -0
- package/types/x-modules/related-prompts/store/emitters.d.ts +10 -0
- package/types/x-modules/related-prompts/store/emitters.d.ts.map +1 -0
- package/types/x-modules/related-prompts/store/getters/index.d.ts +3 -0
- package/types/x-modules/related-prompts/store/getters/index.d.ts.map +1 -0
- package/types/x-modules/related-prompts/store/getters/related-prompts-query.getter.d.ts +13 -0
- package/types/x-modules/related-prompts/store/getters/related-prompts-query.getter.d.ts.map +1 -0
- package/types/x-modules/related-prompts/store/getters/request.getter.d.ts +14 -0
- package/types/x-modules/related-prompts/store/getters/request.getter.d.ts.map +1 -0
- package/types/x-modules/related-prompts/store/index.d.ts +6 -0
- package/types/x-modules/related-prompts/store/index.d.ts.map +1 -0
- package/types/x-modules/related-prompts/store/module.d.ts +8 -0
- package/types/x-modules/related-prompts/store/module.d.ts.map +1 -0
- package/types/x-modules/related-prompts/store/types.d.ts +125 -0
- package/types/x-modules/related-prompts/store/types.d.ts.map +1 -0
- package/types/x-modules/related-prompts/types.d.ts +10 -0
- package/types/x-modules/related-prompts/types.d.ts.map +1 -0
- package/types/x-modules/related-prompts/wiring.d.ts +42 -0
- package/types/x-modules/related-prompts/wiring.d.ts.map +1 -0
- package/types/x-modules/related-prompts/x-module.d.ts +16 -0
- package/types/x-modules/related-prompts/x-module.d.ts.map +1 -0
- package/types/x-modules/related-tags/components/related-tags.vue.d.ts +3 -3
- package/types/x-modules/scroll/components/scroll-to-top.vue.d.ts +5 -5
- package/types/x-modules/search/components/banners-list.vue.d.ts +3 -3
- package/types/x-modules/search/components/partial-results-list.vue.d.ts +3 -3
- package/types/x-modules/search/components/promoteds-list.vue.d.ts +3 -3
- package/types/x-modules/search/components/results-list.vue.d.ts +3 -3
- package/types/x-modules/search/components/sort-dropdown.vue.d.ts +1 -1
- package/types/x-modules/search/config.types.d.ts +2 -0
- package/types/x-modules/search/config.types.d.ts.map +1 -1
- package/types/x-modules/search/events.types.d.ts +4 -0
- package/types/x-modules/search/events.types.d.ts.map +1 -1
- package/types/x-modules/search/store/actions/fetch-and-save-search-response.action.d.ts.map +1 -1
- package/types/x-modules/search/store/actions/save-search-response.action.d.ts.map +1 -1
- package/types/x-modules/search/store/module.d.ts +2 -0
- package/types/x-modules/search/store/module.d.ts.map +1 -1
- package/types/x-modules/search/store/types.d.ts +9 -1
- package/types/x-modules/search/store/types.d.ts.map +1 -1
- package/types/x-modules/search/wiring.d.ts +4 -0
- package/types/x-modules/search/wiring.d.ts.map +1 -1
- package/types/x-modules/search-box/components/search-input-placeholder.vue.d.ts +3 -3
- package/types/x-modules/semantic-queries/store/getters/index.d.ts +1 -0
- package/types/x-modules/semantic-queries/store/getters/index.d.ts.map +1 -1
- package/types/x-modules/semantic-queries/store/getters/normalized-query.getter.d.ts +1 -1
- package/types/x-modules/semantic-queries/store/getters/request.getter.d.ts +2 -1
- package/types/x-modules/semantic-queries/store/getters/request.getter.d.ts.map +1 -1
- package/types/x-modules/semantic-queries/store/getters/semanti-queries-query.getter.d.ts +13 -0
- package/types/x-modules/semantic-queries/store/getters/semanti-queries-query.getter.d.ts.map +1 -0
- package/types/x-modules/semantic-queries/store/module.d.ts.map +1 -1
- package/types/x-modules/semantic-queries/store/types.d.ts +13 -1
- package/types/x-modules/semantic-queries/store/types.d.ts.map +1 -1
- package/types/x-modules/semantic-queries/wiring.d.ts +3 -0
- package/types/x-modules/semantic-queries/wiring.d.ts.map +1 -1
- package/types/x-modules/tagging/components/tagging.vue.d.ts +14 -12
- package/types/x-modules/tagging/components/tagging.vue.d.ts.map +1 -1
- package/types/x-modules/tagging/config.types.d.ts +3 -3
- package/types/x-modules/tagging/config.types.d.ts.map +1 -1
- package/types/x-modules/tagging/events.types.d.ts +2 -2
- package/types/x-modules/tagging/service/{pdp-add-to-cart.service.d.ts → external-tagging.service.d.ts} +31 -13
- package/types/x-modules/tagging/service/external-tagging.service.d.ts.map +1 -0
- package/types/x-modules/tagging/service/index.d.ts +1 -1
- package/types/x-modules/tagging/service/index.d.ts.map +1 -1
- package/types/x-modules/tagging/service/types.d.ts +13 -4
- package/types/x-modules/tagging/service/types.d.ts.map +1 -1
- package/types/x-modules/tagging/store/module.d.ts.map +1 -1
- package/types/x-modules/tagging/wiring.d.ts +54 -2
- package/types/x-modules/tagging/wiring.d.ts.map +1 -1
- package/types/x-modules/url/components/url-handler.vue.d.ts.map +1 -1
- package/types/x-modules/url/store/getters/url-params.getter.d.ts +2 -3
- package/types/x-modules/url/store/getters/url-params.getter.d.ts.map +1 -1
- package/types/x-modules/url/store/initial-state.d.ts.map +1 -1
- package/types/x-modules/url/store/module.d.ts.map +1 -1
- package/types/x-modules/url/store/types.d.ts +6 -0
- package/types/x-modules/url/store/types.d.ts.map +1 -1
- package/types/x-modules/url/wiring.d.ts +9 -0
- package/types/x-modules/url/wiring.d.ts.map +1 -1
- package/types/x-modules/x-modules.types.d.ts +2 -0
- package/types/x-modules/x-modules.types.d.ts.map +1 -1
- package/url/index.js +1 -1
- package/docs/API-reference/api/x-components.defaultpdpaddtocartservice.clickedresultstoragekey.md +0 -11
- package/docs/API-reference/api/x-components.defaultpdpaddtocartservice.clickedresultstoragettlms.md +0 -11
- package/docs/API-reference/api/x-components.defaultpdpaddtocartservice.instance.md +0 -13
- package/docs/API-reference/api/x-components.defaultpdpaddtocartservice.localstorageservice.md +0 -11
- package/docs/API-reference/api/x-components.defaultpdpaddtocartservice.md +0 -41
- package/docs/API-reference/api/x-components.defaultpdpaddtocartservice.result_clicked_id_key.md +0 -13
- package/docs/API-reference/api/x-components.defaultpdpaddtocartservice.sessionstorageservice.md +0 -11
- package/docs/API-reference/api/x-components.pdpaddtocartservice.md +0 -22
- package/docs/API-reference/api/x-components.taggingconfig.clickedresultstoragettlms.md +0 -13
- package/docs/API-reference/api/x-components.usestore.md +0 -19
- package/docs/assets/features/overview-my-history.svg +0 -279
- package/docs/assets/features/overview-product-results-card.svg +0 -128
- package/docs/assets/interface/build-search-ui.svg +0 -167
- package/docs/assets/interface/experience-search-intro.svg +0 -1
- package/docs/assets/interface/integration-guide.svg +0 -1
- package/docs/assets/interface/integration-video.png +0 -0
- package/docs/assets/interface/x-architecture.svg +0 -1
- package/docs/assets/interface/x-empathize.gif +0 -0
- package/docs/assets/interface/x-facets.gif +0 -0
- package/docs/assets/interface/x-facets.svg +0 -189
- package/docs/assets/interface/x-history-queries.gif +0 -0
- package/docs/assets/interface/x-id-results.gif +0 -0
- package/docs/assets/interface/x-next-queries.gif +0 -0
- package/docs/assets/interface/x-popular-searches.gif +0 -0
- package/docs/assets/interface/x-query-suggestions.gif +0 -0
- package/docs/assets/interface/x-recommendations.gif +0 -0
- package/docs/assets/interface/x-recommendations.svg +0 -472
- package/docs/assets/interface/x-related-tags.gif +0 -0
- package/docs/assets/interface/x-results-layout.svg +0 -259
- package/docs/assets/interface/x-search-box-elements.svg +0 -1
- package/docs/assets/interface/x-search-box.svg +0 -60
- package/docs/build-search-ui/README.md +0 -127
- package/docs/build-search-ui/sidebar.js +0 -7
- package/docs/build-search-ui/web-archetype-development-guide.md +0 -186
- package/docs/build-search-ui/web-archetype-integration-guide.md +0 -458
- package/docs/build-search-ui/web-how-to-use-x-components-guide.md +0 -200
- package/docs/build-search-ui/web-x-architecture.md +0 -83
- package/docs/build-search-ui/web-x-components-development-guide.md +0 -157
- package/docs/experience-search-and-discovery/README.md +0 -132
- package/docs/experience-search-and-discovery/empathize.md +0 -119
- package/docs/experience-search-and-discovery/facets-and-filters.md +0 -154
- package/docs/experience-search-and-discovery/history-queries.md +0 -70
- package/docs/experience-search-and-discovery/id-results.md +0 -49
- package/docs/experience-search-and-discovery/my-history.md +0 -60
- package/docs/experience-search-and-discovery/next-queries.md +0 -72
- package/docs/experience-search-and-discovery/popular-searches.md +0 -50
- package/docs/experience-search-and-discovery/product-results-ui.md +0 -82
- package/docs/experience-search-and-discovery/query-suggestions.md +0 -48
- package/docs/experience-search-and-discovery/recommendations.md +0 -134
- package/docs/experience-search-and-discovery/related-tags.md +0 -66
- package/docs/experience-search-and-discovery/search-box.md +0 -99
- package/docs/experience-search-and-discovery/serp-ui.md +0 -125
- package/docs/experience-search-and-discovery/sidebar.js +0 -17
- package/docs/experience-search-and-discovery/web-local-storage.md +0 -30
- package/docs/input-status-machine-state.png +0 -0
- package/js/composables/use-store.js +0 -15
- package/js/composables/use-store.js.map +0 -1
- package/js/utils/options-api.js +0 -4
- package/js/utils/options-api.js.map +0 -1
- package/js/x-modules/tagging/service/pdp-add-to-cart.service.js.map +0 -1
- package/types/utils/options-api.d.ts +0 -3
- package/types/utils/options-api.d.ts.map +0 -1
- package/types/x-modules/tagging/service/pdp-add-to-cart.service.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-dropdown.vue.js","sources":["../../../src/components/base-dropdown.vue"],"sourcesContent":["<template>\n <div\n ref=\"rootRef\"\n @keydown=\"updateSearchBuffer\"\n @keydown.down.prevent=\"highlightNextItem\"\n @keydown.up.prevent=\"highlightPreviousItem\"\n :class=\"dropdownCSSClasses\"\n class=\"x-dropdown\"\n >\n <button\n ref=\"toggleButtonRef\"\n @click=\"toggle\"\n @keydown.up.down.prevent.stop=\"open\"\n class=\"x-dropdown__toggle\"\n data-test=\"dropdown-toggle\"\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen.toString()\"\n :aria-controls=\"listId\"\n :aria-label=\"ariaLabel\"\n aria-autocomplete=\"none\"\n >\n <!--\n @slot Used to render the contents of the dropdown toggle button. If not provided, it uses\n the item slot as fallback.\n @binding {string|number|Identifiable} item - The item data to render.\n @binding {boolean} isOpen - True if the dropdown is opened, and false if it is closed.\n -->\n <slot v-if=\"hasToggleSlot\" :isOpen=\"isOpen\" :item=\"modelValue\" name=\"toggle\">\n {{ modelValue }}\n </slot>\n <slot v-else :item=\"modelValue\" name=\"item\">{{ modelValue }}</slot>\n </button>\n\n <component :is=\"animation\">\n <ul\n v-show=\"isOpen\"\n @keydown.end=\"highlightLastItem\"\n @keydown.esc=\"closeAndFocusToggleButton\"\n @keydown.home=\"highlightFirstItem\"\n :id=\"listId\"\n class=\"x-dropdown__items-list\"\n data-test=\"dropdown-list\"\n role=\"listbox\"\n tabindex=\"-1\"\n >\n <li v-for=\"(item, index) in items\" :key=\"item.id || item\" class=\"x-dropdown__list-item\">\n <button\n :ref=\"el => (itemsButtonRefs[index] = el)\"\n @click=\"emitSelectedItemChanged(item)\"\n :aria-selected=\"(item === modelValue).toString()\"\n :class=\"itemsCSSClasses[index]\"\n class=\"x-dropdown__item\"\n data-test=\"dropdown-item\"\n role=\"option\"\n >\n <!--\n @slot (required) Used to render each one of the items content, and as fallback\n for the toggle button content slot if it is not provided.\n @binding {string|number|Identifiable} item - Item to render\n @binding {boolean} isHighlighted - True when the item has the focus.\n @binding {boolean} isSelected - True when the item is selected.\n -->\n <slot\n :isHighlighted=\"index === highlightedItemIndex\"\n :isSelected=\"item === modelValue\"\n :item=\"item\"\n name=\"item\"\n >\n {{ item }}\n </slot>\n </button>\n </li>\n </ul>\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { Identifiable } from '@empathyco/x-types';\n import { computed, defineComponent, nextTick, onBeforeUnmount, PropType, ref, watch } from 'vue';\n import { AnimationProp } from '../types';\n import { debounceFunction, normalizeString, getTargetElement, isInRange } from '../utils';\n import { NoAnimation } from './animations';\n\n type DropdownItem = string | number | Identifiable;\n let dropdownCount = 0;\n\n /**\n * Dropdown component that mimics a Select element behavior, but with the option\n * to customize the toggle button and each item contents.\n */\n export default defineComponent({\n name: 'BaseDropdown',\n props: {\n /** List of items to display.*/\n items: {\n type: Array as PropType<DropdownItem[]>,\n required: true\n },\n /** The selected item. */\n modelValue: {\n type: null as unknown as PropType<DropdownItem | null>,\n validator: (v: any) =>\n typeof v === 'string' || typeof v === 'number' || typeof v === 'object' || v === null,\n required: true\n },\n /** Description of what the dropdown is used for. */\n ariaLabel: String,\n /**\n * Animation component to use for expanding the dropdown. This is a single element animation,\n * so only `<transition>` components are allowed.\n */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation\n },\n /** Time to wait without receiving any keystroke before resetting the items search query. */\n searchTimeoutMs: {\n type: Number,\n default: 1000\n }\n },\n emits: ['update:modelValue'],\n setup(props, { emit, slots }) {\n const rootRef = ref<HTMLElement>();\n /** The button that opens and closes the list of options. */\n const toggleButtonRef = ref<HTMLButtonElement>();\n /** Array containing the dropdown list buttons HTMLElements. */\n const itemsButtonRefs = ref<HTMLButtonElement[]>([]);\n\n /** Property to check whether the dropdown is expanded or closed. */\n const isOpen = ref(false);\n /** Index of the element that has the focus in the list. -1 means no element has focus. */\n const highlightedItemIndex = ref(-1);\n /** String to search for the first element that starts with it. */\n const searchBuffer = ref('');\n\n /** Resets the search buffer after a certain time has passed. */\n let restartResetSearchTimeout: () => void;\n /* Unique ID to identify the dropdown. */\n const listId = `x-dropdown-${dropdownCount++}`;\n\n /**\n * Dynamic CSS classes to add to the dropdown root element.\n *\n * @returns An object containing the CSS classes to add to the dropdown root element.\n */\n const dropdownCSSClasses = computed(() => ({ 'x-dropdown--is-open': isOpen }));\n\n /**\n * Dynamic CSS classes to add to each one of the items.\n *\n * @returns An object containing the CSS classes to add to each item.\n */\n const itemsCSSClasses = computed(() =>\n props.items.map((item, index) => ({\n 'x-dropdown__item--is-selected': props.modelValue === item,\n 'x-dropdown__item--is-highlighted': highlightedItemIndex.value === index\n }))\n );\n\n /* Opens the dropdown. */\n const open = () => (isOpen.value = true);\n /* Closes the dropdown. */\n const close = () => (isOpen.value = false);\n /* Toggles the dropdown. */\n const toggle = () => (isOpen.value = !isOpen.value);\n\n /**\n * Closes the modal and focuses the toggle button.\n */\n function closeAndFocusToggleButton() {\n close();\n toggleButtonRef.value?.focus();\n }\n\n /**\n * Emits the event that the selected item has changed.\n *\n * @param item - The new selected item.\n */\n function emitSelectedItemChanged(item: DropdownItem) {\n emit('update:modelValue', item);\n closeAndFocusToggleButton();\n }\n\n /**\n * Highlights the item after the one that is currently highlighted.\n */\n function highlightNextItem() {\n open();\n highlightedItemIndex.value = (highlightedItemIndex.value + 1) % props.items.length;\n }\n\n /**\n * Highlights the item before the one that is currently highlighted.\n */\n function highlightPreviousItem() {\n const currentIndex = highlightedItemIndex.value;\n open();\n highlightedItemIndex.value = currentIndex > 0 ? currentIndex - 1 : props.items.length - 1;\n }\n\n /**\n * Highlights the first of the provided items.\n */\n function highlightFirstItem() {\n highlightedItemIndex.value = 0;\n }\n\n /**\n * Highlights the last of the provided items.\n */\n function highlightLastItem() {\n highlightedItemIndex.value = props.items.length - 1;\n }\n\n /**\n * Updates the variable that is used to search in the filters.\n *\n * @param event - The event coming from the user typing.\n */\n function updateSearchBuffer(event: KeyboardEvent) {\n if (/^\\w$/.test(event.key)) {\n const key = event.key;\n searchBuffer.value += key;\n restartResetSearchTimeout();\n }\n }\n\n /**\n * Resets the search buffer.\n */\n function resetSearchBuffer() {\n searchBuffer.value = '';\n }\n\n /**\n * Closes the dropdown if the passed event has happened on an element out of the dropdown.\n *\n * @param event - The event to check if it has happened out of the dropdown component.\n */\n function closeIfEventIsOutOfDropdown(event: MouseEvent | TouchEvent | FocusEvent) {\n if (!rootRef.value?.contains(getTargetElement(event))) {\n close();\n }\n }\n\n /**\n * Adds listeners to the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function addDocumentCloseListeners() {\n document.addEventListener('mousedown', closeIfEventIsOutOfDropdown);\n document.addEventListener('touchstart', closeIfEventIsOutOfDropdown);\n document.addEventListener('focusin', closeIfEventIsOutOfDropdown);\n }\n\n /**\n * Removes the listeners of the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function removeDocumentCloseListeners() {\n document.removeEventListener('mousedown', closeIfEventIsOutOfDropdown);\n document.removeEventListener('touchstart', closeIfEventIsOutOfDropdown);\n document.removeEventListener('focusin', closeIfEventIsOutOfDropdown);\n }\n\n /**\n * Highlights the item that matches the search buffer. To do so it checks the list buttons\n * text content. It highlights items following this priority:\n * - If an element is already highlighted, it starts searching from that element.\n * - If no element is found starting from the previously highlighted, it returns the first one.\n * - If no element is found matching the search query it highlights the first element.\n *\n * @param search - The search string to find in the HTML.\n */\n watch(searchBuffer, search => {\n if (search) {\n const normalizedSearch = normalizeString(search);\n const matchingIndices = itemsButtonRefs?.value?.reduce<number[]>(\n (matchingIndices, button, index) => {\n const safeButtonWordCharacters = button.textContent!.replace(/[^\\w]/g, '');\n const normalizedButtonText = normalizeString(safeButtonWordCharacters);\n if (normalizedButtonText.startsWith(normalizedSearch)) {\n matchingIndices.push(index);\n }\n return matchingIndices;\n },\n []\n );\n highlightedItemIndex.value =\n // First matching item starting to search from the current highlighted element\n matchingIndices?.find(index => index >= highlightedItemIndex.value) ??\n // First matching item\n matchingIndices?.[0] ??\n // First item\n 0;\n }\n });\n\n /**\n * Updates the debounced function to reset the search.\n *\n * @param searchTimeoutMs - The new milliseconds that have to pass without typing before\n * resetting the search.\n */\n watch(\n () => props.searchTimeoutMs,\n searchTimeoutMs => {\n restartResetSearchTimeout = debounceFunction(resetSearchBuffer, searchTimeoutMs);\n },\n { immediate: true }\n );\n\n /**\n * Focuses the DOM element which matches the `highlightedItemIndex`.\n *\n * @param highlightedItemIndex - The index of the HTML element to focus.\n */\n watch(\n highlightedItemIndex,\n highlightedItemIndex => {\n nextTick(() => {\n if (itemsButtonRefs && isInRange(highlightedItemIndex, [0, props.items.length - 1])) {\n const newItem = itemsButtonRefs?.value?.[highlightedItemIndex];\n newItem?.focus();\n }\n });\n },\n { immediate: true }\n );\n\n /**\n * When the dropdown is open it sets the focused element to the one that is selected.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n highlightedItemIndex.value = isOpen\n ? props.modelValue === null\n ? 0\n : props.items.indexOf(props.modelValue)\n : -1;\n });\n\n /**\n * Adds and removes listeners to close the dropdown when it loses the focus.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n /*\n * Because there is an issue with Firefox in macOS and Safari that doesn't focus the target\n * element of the `mousedown` events, the `focusout` event `relatedTarget` property can't be\n * used to detect whether the user has blurred the dropdown. The hack here is to use\n * document listeners that have the side effect of losing the focus.\n */\n if (isOpen) {\n addDocumentCloseListeners();\n } else {\n removeDocumentCloseListeners();\n }\n });\n\n /**\n * If the dropdown is destroyed before removing the document listeners, it ensures that they\n * are removed too.\n */\n onBeforeUnmount(() => {\n removeDocumentCloseListeners();\n });\n\n return {\n hasToggleSlot: !!slots.toggle,\n closeAndFocusToggleButton,\n dropdownCSSClasses,\n emitSelectedItemChanged,\n highlightFirstItem,\n highlightLastItem,\n highlightNextItem,\n highlightPreviousItem,\n highlightedItemIndex,\n isOpen,\n itemsButtonRefs,\n itemsCSSClasses,\n listId,\n open,\n rootRef,\n toggle,\n toggleButtonRef,\n updateSearchBuffer\n };\n }\n });\n</script>\n\n<style lang=\"css\" scoped>\n .x-dropdown {\n position: relative;\n }\n\n .x-dropdown__items-list {\n z-index: 1;\n list-style: none;\n position: absolute;\n padding: 0;\n margin: 0;\n top: calc(100% + var(--x-size-gap-dropdown-default, 0));\n }\n</style>\n\n<docs lang=\"mdx\">\n## Example\n\nThe `Dropdown` component is a simple yet customizable select component. The component needs to work\nthe list of items available to select, which are passed using the `items` prop, and the selected\nitem, which is passed in using the `value` prop.\n\nThe supported items must be an array that can contain unique strings, unique numbers, or objects\nwith a unique `id` property.\n\nThe content of each item can be customized using the `item` slot, which apart from the data of the\nitem, it also receives via prop if the element is selected or highlighted.\n\nThere `toggle` slot can be used to customize the button that opens the dropdown. If this is not\nprovided, the `item` slot will be used for that.\n\n```vue\n<template>\n <BaseDropdown v-model=\"value\" :items=\"items\">\n <template #toggle=\"{ item, isOpen }\">{{ item }} {{ isOpen ? '🔼' : '🔽' }}️</template>\n\n <template #item=\"{ item, isSelected, isHighlighted }\">\n <span v-if=\"isHighlighted\">🟢</span>\n <span v-if=\"isSelected\">✅</span>\n <span>{{ item }}</span>\n </template>\n </BaseDropdown>\n</template>\n\n<script>\n import { BaseDropdown } from '@empathyco/x-components';\n\n export default {\n name: 'DropdownTest',\n components: {\n BaseDropdown\n },\n data() {\n return {\n items: ['a', 2, { id: '3' }],\n value: 'a'\n };\n }\n };\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_withKeys","_withModifiers","dropdownCSSClasses","_normalizeClass","_createElementVNode","listId","ariaLabel","hasToggleSlot","_createCommentVNode","isOpen","_createTextVNode","_toDisplayString","modelValue","_createBlock","_resolveDynamicComponent","_withCtx","_withDirectives","_Fragment","_renderList","itemsButtonRefs","itemsCSSClasses","_renderSlot"],"mappings":";;;;;AAAA,MAAA,UAAA,GAAA,CAAA,eAAA,EAAA,eAAA,EAAA,YAAA,CAAA,CAAA;;;SAEQ,WAAS,CAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,EAAA,KAAA,EAAA,QAAA,EAAA;SACZA,SAAO,EAAA,EAAAC,kBAAA;AAAA,IAAA,KAAA;AAAA,IAAA;AAAA,MAAA,GAAA,EAAA,SAAA;;kCAHZ,CAKyB,GAAA,IAAA,KAAA,IAAA,CAAA,kBAAA,IAAA,IAAA,CAAA,kBAAA,CAAA,GAAA,IAAA,CAAA,CAAA;AAAA,QAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAAC,QAAA,CAAAC,aAAA,CAAA,CAAA,GAAA,IAAA,KAAA,IAAA,CAAA,iBAAA,IAAA,IAAA,CAAA,iBAAA,CAAA,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CAAA,CAAA;AAAA,oBAAA,WAAA,EAAA,eAAA;AAEb,oBAAA,IAAA,EAAA,QAAA;AAAA,mBAOA,EAAA;AAAA,oBAAAK,kBAAA,CACkB,2aAA8B,CAAA;AAAA,oBAAAa,UAAA,CACnC,KAAE,MAAST,EAAAA,MAAAA,EAAAA;AAAAA,sBACrB,aAAU,EAAA,KAAA,KAAA,IAAA,CAAA,oBAAA;AAAA,sBAIN,UAAA,EAAA,IAAA,KAAA,IAAA,CAAA,UAAA;AAAA,sBAtEnB,IAAA;AAAA,qBAAA,EAAA,MAAA;;AAAA,wBAAAD,eAAA,CAAA,IAAA,CAAA;AAAA,wBAAA,CAAA;AAAA;AAAA,uBAAA;AAAA,qBAAA,EAAA,IAAA,CAAA;;;;;;AAoCsB,aAAA;AAAA,WAAA,EAAA,EAAA,EAAA,UAAA,CAAA,EAAA;;AApCtB,WAAA,CAAA;AAAA,SAAA,CAAA;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"base-dropdown.vue.js","sources":["../../../src/components/base-dropdown.vue"],"sourcesContent":["<template>\n <div\n ref=\"rootRef\"\n @keydown=\"updateSearchBuffer\"\n @keydown.down.prevent=\"highlightNextItem\"\n @keydown.up.prevent=\"highlightPreviousItem\"\n :class=\"dropdownCSSClasses\"\n class=\"x-dropdown\"\n >\n <button\n ref=\"toggleButtonRef\"\n @click=\"toggle\"\n @keydown.up.down.prevent.stop=\"open\"\n class=\"x-dropdown__toggle\"\n data-test=\"dropdown-toggle\"\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen.toString()\"\n :aria-controls=\"listId\"\n :aria-label=\"ariaLabel\"\n aria-autocomplete=\"none\"\n >\n <!--\n @slot Used to render the contents of the dropdown toggle button. If not provided, it uses\n the item slot as fallback.\n @binding {string|number|Identifiable} item - The item data to render.\n @binding {boolean} isOpen - True if the dropdown is opened, and false if it is closed.\n -->\n <slot v-if=\"hasToggleSlot\" :isOpen=\"isOpen\" :item=\"modelValue\" name=\"toggle\">\n {{ modelValue }}\n </slot>\n <slot v-else :item=\"modelValue\" name=\"item\">{{ modelValue }}</slot>\n </button>\n\n <component :is=\"animation\">\n <ul\n v-show=\"isOpen\"\n @keydown.end=\"highlightLastItem\"\n @keydown.esc=\"closeAndFocusToggleButton\"\n @keydown.home=\"highlightFirstItem\"\n :id=\"listId\"\n class=\"x-dropdown__items-list\"\n data-test=\"dropdown-list\"\n role=\"listbox\"\n tabindex=\"-1\"\n >\n <li v-for=\"(item, index) in items\" :key=\"item.id || item\" class=\"x-dropdown__list-item\">\n <button\n :ref=\"el => (itemsButtonRefs[index] = el)\"\n @click=\"emitSelectedItemChanged(item)\"\n :aria-selected=\"(item === modelValue).toString()\"\n :class=\"itemsCSSClasses[index]\"\n class=\"x-dropdown__item\"\n data-test=\"dropdown-item\"\n role=\"option\"\n >\n <!--\n @slot (required) Used to render each one of the items content, and as fallback\n for the toggle button content slot if it is not provided.\n @binding {string|number|Identifiable} item - Item to render\n @binding {boolean} isHighlighted - True when the item has the focus.\n @binding {boolean} isSelected - True when the item is selected.\n -->\n <slot\n :isHighlighted=\"index === highlightedItemIndex\"\n :isSelected=\"item === modelValue\"\n :item=\"item\"\n name=\"item\"\n >\n {{ item }}\n </slot>\n </button>\n </li>\n </ul>\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { Identifiable } from '@empathyco/x-types';\n import { computed, defineComponent, nextTick, onBeforeUnmount, PropType, ref, watch } from 'vue';\n import { AnimationProp } from '../types';\n import { debounceFunction, normalizeString, getTargetElement } from '../utils';\n import { NoAnimation } from './animations';\n\n type DropdownItem = string | number | Identifiable;\n let dropdownCount = 0;\n\n /**\n * Dropdown component that mimics a Select element behavior, but with the option\n * to customize the toggle button and each item contents.\n */\n export default defineComponent({\n name: 'BaseDropdown',\n props: {\n /** List of items to display.*/\n items: {\n type: Array as PropType<DropdownItem[]>,\n required: true\n },\n /** The selected item. */\n modelValue: {\n type: null as unknown as PropType<DropdownItem | null>,\n validator: (v: any) =>\n typeof v === 'string' || typeof v === 'number' || typeof v === 'object' || v === null,\n required: true\n },\n /** Description of what the dropdown is used for. */\n ariaLabel: String,\n /**\n * Animation component to use for expanding the dropdown. This is a single element animation,\n * so only `<transition>` components are allowed.\n */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation\n },\n /** Time to wait without receiving any keystroke before resetting the items search query. */\n searchTimeoutMs: {\n type: Number,\n default: 1000\n }\n },\n emits: ['update:modelValue'],\n setup(props, { emit, slots }) {\n const rootRef = ref<HTMLElement>();\n /** The button that opens and closes the list of options. */\n const toggleButtonRef = ref<HTMLButtonElement>();\n /** Array containing the dropdown list buttons HTMLElements. */\n const itemsButtonRefs = ref<HTMLButtonElement[]>([]);\n\n /** Property to check whether the dropdown is expanded or closed. */\n const isOpen = ref(false);\n /** Index of the element that has the focus in the list. -1 means no element has focus. */\n const highlightedItemIndex = ref(-1);\n /** String to search for the first element that starts with it. */\n const searchBuffer = ref('');\n\n /** Resets the search buffer after a certain time has passed. */\n let restartResetSearchTimeout: () => void;\n /* Unique ID to identify the dropdown. */\n const listId = `x-dropdown-${dropdownCount++}`;\n\n /**\n * Dynamic CSS classes to add to the dropdown root element.\n *\n * @returns An object containing the CSS classes to add to the dropdown root element.\n */\n const dropdownCSSClasses = computed(() => ({ 'x-dropdown--is-open': isOpen }));\n\n /**\n * Dynamic CSS classes to add to each one of the items.\n *\n * @returns An object containing the CSS classes to add to each item.\n */\n const itemsCSSClasses = computed(() =>\n props.items.map((item, index) => ({\n 'x-dropdown__item--is-selected': props.modelValue === item,\n 'x-dropdown__item--is-highlighted': highlightedItemIndex.value === index\n }))\n );\n\n /* Opens the dropdown. */\n const open = () => (isOpen.value = true);\n /* Closes the dropdown. */\n const close = () => (isOpen.value = false);\n /* Toggles the dropdown. */\n const toggle = () => (isOpen.value = !isOpen.value);\n\n /**\n * Closes the modal and focuses the toggle button.\n */\n function closeAndFocusToggleButton() {\n close();\n toggleButtonRef.value?.focus();\n }\n\n /**\n * Emits the event that the selected item has changed.\n *\n * @param item - The new selected item.\n */\n function emitSelectedItemChanged(item: DropdownItem) {\n emit('update:modelValue', item);\n closeAndFocusToggleButton();\n }\n\n /**\n * Highlights the item after the one that is currently highlighted.\n */\n function highlightNextItem() {\n open();\n highlightedItemIndex.value = (highlightedItemIndex.value + 1) % props.items.length;\n }\n\n /**\n * Highlights the item before the one that is currently highlighted.\n */\n function highlightPreviousItem() {\n const currentIndex = highlightedItemIndex.value;\n open();\n highlightedItemIndex.value = currentIndex > 0 ? currentIndex - 1 : props.items.length - 1;\n }\n\n /**\n * Highlights the first of the provided items.\n */\n function highlightFirstItem() {\n highlightedItemIndex.value = 0;\n }\n\n /**\n * Highlights the last of the provided items.\n */\n function highlightLastItem() {\n highlightedItemIndex.value = props.items.length - 1;\n }\n\n /**\n * Updates the variable that is used to search in the filters.\n *\n * @param event - The event coming from the user typing.\n */\n function updateSearchBuffer(event: KeyboardEvent) {\n if (/^\\w$/.test(event.key)) {\n const key = event.key;\n searchBuffer.value += key;\n restartResetSearchTimeout();\n }\n }\n\n /**\n * Resets the search buffer.\n */\n function resetSearchBuffer() {\n searchBuffer.value = '';\n }\n\n /**\n * Closes the dropdown if the passed event has happened on an element out of the dropdown.\n *\n * @param event - The event to check if it has happened out of the dropdown component.\n */\n function closeIfEventIsOutOfDropdown(event: MouseEvent | TouchEvent | FocusEvent) {\n if (!rootRef.value?.contains(getTargetElement(event))) {\n close();\n }\n }\n\n /**\n * Adds listeners to the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function addDocumentCloseListeners() {\n document.addEventListener('mousedown', closeIfEventIsOutOfDropdown);\n document.addEventListener('touchstart', closeIfEventIsOutOfDropdown);\n document.addEventListener('focusin', closeIfEventIsOutOfDropdown);\n }\n\n /**\n * Removes the listeners of the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function removeDocumentCloseListeners() {\n document.removeEventListener('mousedown', closeIfEventIsOutOfDropdown);\n document.removeEventListener('touchstart', closeIfEventIsOutOfDropdown);\n document.removeEventListener('focusin', closeIfEventIsOutOfDropdown);\n }\n\n /**\n * Highlights the item that matches the search buffer. To do so it checks the list buttons\n * text content. It highlights items following this priority:\n * - If an element is already highlighted, it starts searching from that element.\n * - If no element is found starting from the previously highlighted, it returns the first one.\n * - If no element is found matching the search query it highlights the first element.\n *\n * @param search - The search string to find in the HTML.\n */\n watch(searchBuffer, search => {\n if (search) {\n const normalizedSearch = normalizeString(search);\n const matchingIndices = itemsButtonRefs?.value?.reduce<number[]>(\n (matchingIndices, button, index) => {\n const safeButtonWordCharacters = button.textContent!.replace(/[^\\w]/g, '');\n const normalizedButtonText = normalizeString(safeButtonWordCharacters);\n if (normalizedButtonText.startsWith(normalizedSearch)) {\n matchingIndices.push(index);\n }\n return matchingIndices;\n },\n []\n );\n highlightedItemIndex.value =\n // First matching item starting to search from the current highlighted element\n matchingIndices?.find(index => index >= highlightedItemIndex.value) ??\n // First matching item\n matchingIndices?.[0] ??\n // First item\n 0;\n }\n });\n\n /**\n * Updates the debounced function to reset the search.\n *\n * @param searchTimeoutMs - The new milliseconds that have to pass without typing before\n * resetting the search.\n */\n watch(\n () => props.searchTimeoutMs,\n searchTimeoutMs => {\n restartResetSearchTimeout = debounceFunction(resetSearchBuffer, searchTimeoutMs);\n },\n { immediate: true }\n );\n\n /**\n * Focuses the DOM element which matches the `highlightedItemIndex`.\n *\n * @param highlightedItemIndex - The index of the HTML element to focus.\n */\n watch(\n highlightedItemIndex,\n highlightedItemIndex => {\n nextTick(() => itemsButtonRefs.value[highlightedItemIndex]?.focus());\n },\n { immediate: true }\n );\n\n /**\n * When the dropdown is open it sets the focused element to the one that is selected.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n highlightedItemIndex.value = isOpen\n ? props.modelValue === null\n ? 0\n : props.items.indexOf(props.modelValue)\n : -1;\n });\n\n /**\n * Adds and removes listeners to close the dropdown when it loses the focus.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n /*\n * Because there is an issue with Firefox in macOS and Safari that doesn't focus the target\n * element of the `mousedown` events, the `focusout` event `relatedTarget` property can't be\n * used to detect whether the user has blurred the dropdown. The hack here is to use\n * document listeners that have the side effect of losing the focus.\n */\n if (isOpen) {\n addDocumentCloseListeners();\n } else {\n removeDocumentCloseListeners();\n }\n });\n\n /**\n * If the dropdown is destroyed before removing the document listeners, it ensures that they\n * are removed too.\n */\n onBeforeUnmount(() => {\n removeDocumentCloseListeners();\n });\n\n return {\n hasToggleSlot: !!slots.toggle,\n closeAndFocusToggleButton,\n dropdownCSSClasses,\n emitSelectedItemChanged,\n highlightFirstItem,\n highlightLastItem,\n highlightNextItem,\n highlightPreviousItem,\n highlightedItemIndex,\n isOpen,\n itemsButtonRefs,\n itemsCSSClasses,\n listId,\n open,\n rootRef,\n toggle,\n toggleButtonRef,\n updateSearchBuffer\n };\n }\n });\n</script>\n\n<style lang=\"css\" scoped>\n .x-dropdown {\n position: relative;\n }\n\n .x-dropdown__items-list {\n z-index: 1;\n list-style: none;\n position: absolute;\n padding: 0;\n margin: 0;\n top: calc(100% + var(--x-size-gap-dropdown-default, 0));\n }\n</style>\n\n<docs lang=\"mdx\">\n## Example\n\nThe `Dropdown` component is a simple yet customizable select component. The component needs to work\nthe list of items available to select, which are passed using the `items` prop, and the selected\nitem, which is passed in using the `value` prop.\n\nThe supported items must be an array that can contain unique strings, unique numbers, or objects\nwith a unique `id` property.\n\nThe content of each item can be customized using the `item` slot, which apart from the data of the\nitem, it also receives via prop if the element is selected or highlighted.\n\nThere `toggle` slot can be used to customize the button that opens the dropdown. If this is not\nprovided, the `item` slot will be used for that.\n\n```vue\n<template>\n <BaseDropdown v-model=\"value\" :items=\"items\">\n <template #toggle=\"{ item, isOpen }\">{{ item }} {{ isOpen ? '🔼' : '🔽' }}️</template>\n\n <template #item=\"{ item, isSelected, isHighlighted }\">\n <span v-if=\"isHighlighted\">🟢</span>\n <span v-if=\"isSelected\">✅</span>\n <span>{{ item }}</span>\n </template>\n </BaseDropdown>\n</template>\n\n<script>\n import { BaseDropdown } from '@empathyco/x-components';\n\n export default {\n name: 'DropdownTest',\n components: {\n BaseDropdown\n },\n data() {\n return {\n items: ['a', 2, { id: '3' }],\n value: 'a'\n };\n }\n };\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_withKeys","_withModifiers","dropdownCSSClasses","_normalizeClass","_createElementVNode","listId","ariaLabel","_renderSlot","isOpen","_createTextVNode","_toDisplayString","modelValue","_createBlock","_resolveDynamicComponent","_withCtx","_withDirectives","_Fragment","_renderList","itemsButtonRefs","itemsCSSClasses"],"mappings":";;;;;AAAA,MAAA,UAAA,GAAA,CAAA,eAAA,EAAA,eAAA,EAAA,YAAA,CAAA,CAAA;;;SAEQ,WAAS,CAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,EAAA,KAAA,EAAA,QAAA,EAAA;SACZA,SAAO,EAAA,EAAAC,kBAAA;AAAA,IAAA,KAAA;AAAA,IAAA;AAAA,MAAA,GAAA,EAAA,SAAA;;kCAHZ,CAKyB,GAAA,IAAA,KAAA,IAAA,CAAA,kBAAA,IAAA,IAAA,CAAA,kBAAA,CAAA,GAAA,IAAA,CAAA,CAAA;AAAA,QAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAAC,QAAA,CAAAC,aAAA,CAAA,CAAA,GAAA,IAAA,KAAA,IAAA,CAAA,iBAAA,IAAA,IAAA,CAAA,iBAAA,CAAA,GAAA,IAAA,CAAA,EAAA,CAAA,SAAA,CAAA,CAAA,EAAA,CAAA,MAAA,CAAA,CAAA,CAAA;QACpB,MANL,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAMYC,2BACF,CAAY,GAAA,IAAA,KAAA,IAAA,CAAA,qBAAA,IAAA,IAAA,CAAA,qBAAA,CAAA,GAAA,IAAA,CAAA,EAAA,CAAA,SAAA,CAAA,CAAA,EAAA,CAA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BAAA,EAAA,MAAA;;AAAA,wBAAAD,eAAA,CAAA,IAAA,CAAA;AAAA,wBAAA,CAAA;AAAA;AAAA,uBAAA;AAAA,qBAAA,EAAA,IAAA,CAAA;;;;;;AAoCsB,aAAA;AAAA,WAAA,EAAA,EAAA,EAAA,UAAA,CAAA,EAAA;;AApCtB,WAAA,CAAA;AAAA,SAAA,CAAA;;;;;;;;;;;;;"}
|
|
@@ -3,7 +3,6 @@ import { AnimationProp } from '../types/animation-prop.js';
|
|
|
3
3
|
import { debounce } from '../utils/debounce.js';
|
|
4
4
|
import { getTargetElement } from '../utils/html.js';
|
|
5
5
|
import { normalizeString } from '../utils/normalize.js';
|
|
6
|
-
import { isInRange } from '../utils/number.js';
|
|
7
6
|
import '../utils/storage.js';
|
|
8
7
|
import './animations/animate-width.vue2.js';
|
|
9
8
|
import './animations/animate-width.vue3.js';
|
|
@@ -230,12 +229,7 @@ var _sfc_main = defineComponent({
|
|
|
230
229
|
* @param highlightedItemIndex - The index of the HTML element to focus.
|
|
231
230
|
*/
|
|
232
231
|
watch(highlightedItemIndex, highlightedItemIndex => {
|
|
233
|
-
nextTick(() =>
|
|
234
|
-
if (itemsButtonRefs && isInRange(highlightedItemIndex, [0, props.items.length - 1])) {
|
|
235
|
-
const newItem = itemsButtonRefs?.value?.[highlightedItemIndex];
|
|
236
|
-
newItem?.focus();
|
|
237
|
-
}
|
|
238
|
-
});
|
|
232
|
+
nextTick(() => itemsButtonRefs.value[highlightedItemIndex]?.focus());
|
|
239
233
|
}, { immediate: true });
|
|
240
234
|
/**
|
|
241
235
|
* When the dropdown is open it sets the focused element to the one that is selected.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-dropdown.vue2.js","sources":["../../../src/components/base-dropdown.vue"],"sourcesContent":["<template>\n <div\n ref=\"rootRef\"\n @keydown=\"updateSearchBuffer\"\n @keydown.down.prevent=\"highlightNextItem\"\n @keydown.up.prevent=\"highlightPreviousItem\"\n :class=\"dropdownCSSClasses\"\n class=\"x-dropdown\"\n >\n <button\n ref=\"toggleButtonRef\"\n @click=\"toggle\"\n @keydown.up.down.prevent.stop=\"open\"\n class=\"x-dropdown__toggle\"\n data-test=\"dropdown-toggle\"\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen.toString()\"\n :aria-controls=\"listId\"\n :aria-label=\"ariaLabel\"\n aria-autocomplete=\"none\"\n >\n <!--\n @slot Used to render the contents of the dropdown toggle button. If not provided, it uses\n the item slot as fallback.\n @binding {string|number|Identifiable} item - The item data to render.\n @binding {boolean} isOpen - True if the dropdown is opened, and false if it is closed.\n -->\n <slot v-if=\"hasToggleSlot\" :isOpen=\"isOpen\" :item=\"modelValue\" name=\"toggle\">\n {{ modelValue }}\n </slot>\n <slot v-else :item=\"modelValue\" name=\"item\">{{ modelValue }}</slot>\n </button>\n\n <component :is=\"animation\">\n <ul\n v-show=\"isOpen\"\n @keydown.end=\"highlightLastItem\"\n @keydown.esc=\"closeAndFocusToggleButton\"\n @keydown.home=\"highlightFirstItem\"\n :id=\"listId\"\n class=\"x-dropdown__items-list\"\n data-test=\"dropdown-list\"\n role=\"listbox\"\n tabindex=\"-1\"\n >\n <li v-for=\"(item, index) in items\" :key=\"item.id || item\" class=\"x-dropdown__list-item\">\n <button\n :ref=\"el => (itemsButtonRefs[index] = el)\"\n @click=\"emitSelectedItemChanged(item)\"\n :aria-selected=\"(item === modelValue).toString()\"\n :class=\"itemsCSSClasses[index]\"\n class=\"x-dropdown__item\"\n data-test=\"dropdown-item\"\n role=\"option\"\n >\n <!--\n @slot (required) Used to render each one of the items content, and as fallback\n for the toggle button content slot if it is not provided.\n @binding {string|number|Identifiable} item - Item to render\n @binding {boolean} isHighlighted - True when the item has the focus.\n @binding {boolean} isSelected - True when the item is selected.\n -->\n <slot\n :isHighlighted=\"index === highlightedItemIndex\"\n :isSelected=\"item === modelValue\"\n :item=\"item\"\n name=\"item\"\n >\n {{ item }}\n </slot>\n </button>\n </li>\n </ul>\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { Identifiable } from '@empathyco/x-types';\n import { computed, defineComponent, nextTick, onBeforeUnmount, PropType, ref, watch } from 'vue';\n import { AnimationProp } from '../types';\n import { debounceFunction, normalizeString, getTargetElement, isInRange } from '../utils';\n import { NoAnimation } from './animations';\n\n type DropdownItem = string | number | Identifiable;\n let dropdownCount = 0;\n\n /**\n * Dropdown component that mimics a Select element behavior, but with the option\n * to customize the toggle button and each item contents.\n */\n export default defineComponent({\n name: 'BaseDropdown',\n props: {\n /** List of items to display.*/\n items: {\n type: Array as PropType<DropdownItem[]>,\n required: true\n },\n /** The selected item. */\n modelValue: {\n type: null as unknown as PropType<DropdownItem | null>,\n validator: (v: any) =>\n typeof v === 'string' || typeof v === 'number' || typeof v === 'object' || v === null,\n required: true\n },\n /** Description of what the dropdown is used for. */\n ariaLabel: String,\n /**\n * Animation component to use for expanding the dropdown. This is a single element animation,\n * so only `<transition>` components are allowed.\n */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation\n },\n /** Time to wait without receiving any keystroke before resetting the items search query. */\n searchTimeoutMs: {\n type: Number,\n default: 1000\n }\n },\n emits: ['update:modelValue'],\n setup(props, { emit, slots }) {\n const rootRef = ref<HTMLElement>();\n /** The button that opens and closes the list of options. */\n const toggleButtonRef = ref<HTMLButtonElement>();\n /** Array containing the dropdown list buttons HTMLElements. */\n const itemsButtonRefs = ref<HTMLButtonElement[]>([]);\n\n /** Property to check whether the dropdown is expanded or closed. */\n const isOpen = ref(false);\n /** Index of the element that has the focus in the list. -1 means no element has focus. */\n const highlightedItemIndex = ref(-1);\n /** String to search for the first element that starts with it. */\n const searchBuffer = ref('');\n\n /** Resets the search buffer after a certain time has passed. */\n let restartResetSearchTimeout: () => void;\n /* Unique ID to identify the dropdown. */\n const listId = `x-dropdown-${dropdownCount++}`;\n\n /**\n * Dynamic CSS classes to add to the dropdown root element.\n *\n * @returns An object containing the CSS classes to add to the dropdown root element.\n */\n const dropdownCSSClasses = computed(() => ({ 'x-dropdown--is-open': isOpen }));\n\n /**\n * Dynamic CSS classes to add to each one of the items.\n *\n * @returns An object containing the CSS classes to add to each item.\n */\n const itemsCSSClasses = computed(() =>\n props.items.map((item, index) => ({\n 'x-dropdown__item--is-selected': props.modelValue === item,\n 'x-dropdown__item--is-highlighted': highlightedItemIndex.value === index\n }))\n );\n\n /* Opens the dropdown. */\n const open = () => (isOpen.value = true);\n /* Closes the dropdown. */\n const close = () => (isOpen.value = false);\n /* Toggles the dropdown. */\n const toggle = () => (isOpen.value = !isOpen.value);\n\n /**\n * Closes the modal and focuses the toggle button.\n */\n function closeAndFocusToggleButton() {\n close();\n toggleButtonRef.value?.focus();\n }\n\n /**\n * Emits the event that the selected item has changed.\n *\n * @param item - The new selected item.\n */\n function emitSelectedItemChanged(item: DropdownItem) {\n emit('update:modelValue', item);\n closeAndFocusToggleButton();\n }\n\n /**\n * Highlights the item after the one that is currently highlighted.\n */\n function highlightNextItem() {\n open();\n highlightedItemIndex.value = (highlightedItemIndex.value + 1) % props.items.length;\n }\n\n /**\n * Highlights the item before the one that is currently highlighted.\n */\n function highlightPreviousItem() {\n const currentIndex = highlightedItemIndex.value;\n open();\n highlightedItemIndex.value = currentIndex > 0 ? currentIndex - 1 : props.items.length - 1;\n }\n\n /**\n * Highlights the first of the provided items.\n */\n function highlightFirstItem() {\n highlightedItemIndex.value = 0;\n }\n\n /**\n * Highlights the last of the provided items.\n */\n function highlightLastItem() {\n highlightedItemIndex.value = props.items.length - 1;\n }\n\n /**\n * Updates the variable that is used to search in the filters.\n *\n * @param event - The event coming from the user typing.\n */\n function updateSearchBuffer(event: KeyboardEvent) {\n if (/^\\w$/.test(event.key)) {\n const key = event.key;\n searchBuffer.value += key;\n restartResetSearchTimeout();\n }\n }\n\n /**\n * Resets the search buffer.\n */\n function resetSearchBuffer() {\n searchBuffer.value = '';\n }\n\n /**\n * Closes the dropdown if the passed event has happened on an element out of the dropdown.\n *\n * @param event - The event to check if it has happened out of the dropdown component.\n */\n function closeIfEventIsOutOfDropdown(event: MouseEvent | TouchEvent | FocusEvent) {\n if (!rootRef.value?.contains(getTargetElement(event))) {\n close();\n }\n }\n\n /**\n * Adds listeners to the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function addDocumentCloseListeners() {\n document.addEventListener('mousedown', closeIfEventIsOutOfDropdown);\n document.addEventListener('touchstart', closeIfEventIsOutOfDropdown);\n document.addEventListener('focusin', closeIfEventIsOutOfDropdown);\n }\n\n /**\n * Removes the listeners of the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function removeDocumentCloseListeners() {\n document.removeEventListener('mousedown', closeIfEventIsOutOfDropdown);\n document.removeEventListener('touchstart', closeIfEventIsOutOfDropdown);\n document.removeEventListener('focusin', closeIfEventIsOutOfDropdown);\n }\n\n /**\n * Highlights the item that matches the search buffer. To do so it checks the list buttons\n * text content. It highlights items following this priority:\n * - If an element is already highlighted, it starts searching from that element.\n * - If no element is found starting from the previously highlighted, it returns the first one.\n * - If no element is found matching the search query it highlights the first element.\n *\n * @param search - The search string to find in the HTML.\n */\n watch(searchBuffer, search => {\n if (search) {\n const normalizedSearch = normalizeString(search);\n const matchingIndices = itemsButtonRefs?.value?.reduce<number[]>(\n (matchingIndices, button, index) => {\n const safeButtonWordCharacters = button.textContent!.replace(/[^\\w]/g, '');\n const normalizedButtonText = normalizeString(safeButtonWordCharacters);\n if (normalizedButtonText.startsWith(normalizedSearch)) {\n matchingIndices.push(index);\n }\n return matchingIndices;\n },\n []\n );\n highlightedItemIndex.value =\n // First matching item starting to search from the current highlighted element\n matchingIndices?.find(index => index >= highlightedItemIndex.value) ??\n // First matching item\n matchingIndices?.[0] ??\n // First item\n 0;\n }\n });\n\n /**\n * Updates the debounced function to reset the search.\n *\n * @param searchTimeoutMs - The new milliseconds that have to pass without typing before\n * resetting the search.\n */\n watch(\n () => props.searchTimeoutMs,\n searchTimeoutMs => {\n restartResetSearchTimeout = debounceFunction(resetSearchBuffer, searchTimeoutMs);\n },\n { immediate: true }\n );\n\n /**\n * Focuses the DOM element which matches the `highlightedItemIndex`.\n *\n * @param highlightedItemIndex - The index of the HTML element to focus.\n */\n watch(\n highlightedItemIndex,\n highlightedItemIndex => {\n nextTick(() => {\n if (itemsButtonRefs && isInRange(highlightedItemIndex, [0, props.items.length - 1])) {\n const newItem = itemsButtonRefs?.value?.[highlightedItemIndex];\n newItem?.focus();\n }\n });\n },\n { immediate: true }\n );\n\n /**\n * When the dropdown is open it sets the focused element to the one that is selected.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n highlightedItemIndex.value = isOpen\n ? props.modelValue === null\n ? 0\n : props.items.indexOf(props.modelValue)\n : -1;\n });\n\n /**\n * Adds and removes listeners to close the dropdown when it loses the focus.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n /*\n * Because there is an issue with Firefox in macOS and Safari that doesn't focus the target\n * element of the `mousedown` events, the `focusout` event `relatedTarget` property can't be\n * used to detect whether the user has blurred the dropdown. The hack here is to use\n * document listeners that have the side effect of losing the focus.\n */\n if (isOpen) {\n addDocumentCloseListeners();\n } else {\n removeDocumentCloseListeners();\n }\n });\n\n /**\n * If the dropdown is destroyed before removing the document listeners, it ensures that they\n * are removed too.\n */\n onBeforeUnmount(() => {\n removeDocumentCloseListeners();\n });\n\n return {\n hasToggleSlot: !!slots.toggle,\n closeAndFocusToggleButton,\n dropdownCSSClasses,\n emitSelectedItemChanged,\n highlightFirstItem,\n highlightLastItem,\n highlightNextItem,\n highlightPreviousItem,\n highlightedItemIndex,\n isOpen,\n itemsButtonRefs,\n itemsCSSClasses,\n listId,\n open,\n rootRef,\n toggle,\n toggleButtonRef,\n updateSearchBuffer\n };\n }\n });\n</script>\n\n<style lang=\"css\" scoped>\n .x-dropdown {\n position: relative;\n }\n\n .x-dropdown__items-list {\n z-index: 1;\n list-style: none;\n position: absolute;\n padding: 0;\n margin: 0;\n top: calc(100% + var(--x-size-gap-dropdown-default, 0));\n }\n</style>\n\n<docs lang=\"mdx\">\n## Example\n\nThe `Dropdown` component is a simple yet customizable select component. The component needs to work\nthe list of items available to select, which are passed using the `items` prop, and the selected\nitem, which is passed in using the `value` prop.\n\nThe supported items must be an array that can contain unique strings, unique numbers, or objects\nwith a unique `id` property.\n\nThe content of each item can be customized using the `item` slot, which apart from the data of the\nitem, it also receives via prop if the element is selected or highlighted.\n\nThere `toggle` slot can be used to customize the button that opens the dropdown. If this is not\nprovided, the `item` slot will be used for that.\n\n```vue\n<template>\n <BaseDropdown v-model=\"value\" :items=\"items\">\n <template #toggle=\"{ item, isOpen }\">{{ item }} {{ isOpen ? '🔼' : '🔽' }}️</template>\n\n <template #item=\"{ item, isSelected, isHighlighted }\">\n <span v-if=\"isHighlighted\">🟢</span>\n <span v-if=\"isSelected\">✅</span>\n <span>{{ item }}</span>\n </template>\n </BaseDropdown>\n</template>\n\n<script>\n import { BaseDropdown } from '@empathyco/x-components';\n\n export default {\n name: 'DropdownTest',\n components: {\n BaseDropdown\n },\n data() {\n return {\n items: ['a', 2, { id: '3' }],\n value: 'a'\n };\n }\n };\n</script>\n```\n</docs>\n"],"names":["NoAnimation","debounceFunction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsFE,IAAI,aAAY,GAAI,CAAC,CAAA;AAErB;;;AAGE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,cAAc;AACpB,IAAA,KAAK,EAAE;;AAEL,QAAA,KAAK,EAAE;AACL,YAAA,IAAI,EAAE,KAAiC;AACvC,YAAA,QAAQ,EAAE,IAAG;AACd,SAAA;;AAED,QAAA,UAAU,EAAE;AACV,YAAA,IAAI,EAAE,IAAgD;YACtD,SAAS,EAAE,CAAC,CAAM,KAChB,OAAO,CAAA,KAAM,QAAO,IAAK,OAAO,CAAA,KAAM,QAAO,IAAK,OAAO,CAAE,KAAI,YAAY,CAAE,KAAI,IAAI;AACvF,YAAA,QAAQ,EA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AAE,CAAA;AAClB,iBAAA;AACF,aAAC,CAAC,CAAA;AACJ,SAAC,EACD,EAAE,SAAS,EAAE,IAAK,EAAA,CACnB,CAAA;AAED;;;;AAIE;AACF,QAAA,KAAK,CAAC,MAAM,EAAE,MAAK,IAAK;YACtB,oBAAoB,CAAC,KAAI,GAAI,MAAK;AAChC,kBAAE,KAAK,CAAC,UAAS,KAAM,IAAG;AACxB,sBAAE,CAAA;sBACA,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAA;kBACtC,CAAC,CAAC,CAAA;AACR,SAAC,CAAC,CAAA;AAEF;;;;AAIE;AACF,QAAA,KAAK,CAAC,MAAM,EAAE,MAAK,IAAK;AACtB;;;;;AAKE;AACF,YAAA,IAAI,MAAM,EAAE;AACV,gBAAA,yBAAyB,EAAE,CAAA;AAC3B,aAAA;AAAK,iBAAA;AACL,gBAAA,4BAA4B,EAAE,CAAA;AAChC,aAAA;AACF,SAAC,CAAC,CAAA;AAEF;;;AAGE;QACF,eAAe,CAAC,MAAM;AACpB,YAAA,4BAA4B,EAAE,CAAA;AAChC,SAAC,CAAC,CAAA;QAEF,OAAO;AACL,YAAA,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM;YAC7B,yBAAyB;YACzB,kBAAkB;YAClB,uBAAuB;YACvB,kBAAkB;YAClB,iBAAiB;YACjB,iBAAiB;YACjB,qBAAqB;YACrB,oBAAoB;YACpB,MAAM;YACN,eAAe;YACf,eAAe;YACf,MAAM;YACN,IAAI;YACJ,OAAO;YACP,MAAM;YACN,eAAe;YACf,kBAAiB;SAClB,CAAA;KACH;AACD,CAAA,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"base-dropdown.vue2.js","sources":["../../../src/components/base-dropdown.vue"],"sourcesContent":["<template>\n <div\n ref=\"rootRef\"\n @keydown=\"updateSearchBuffer\"\n @keydown.down.prevent=\"highlightNextItem\"\n @keydown.up.prevent=\"highlightPreviousItem\"\n :class=\"dropdownCSSClasses\"\n class=\"x-dropdown\"\n >\n <button\n ref=\"toggleButtonRef\"\n @click=\"toggle\"\n @keydown.up.down.prevent.stop=\"open\"\n class=\"x-dropdown__toggle\"\n data-test=\"dropdown-toggle\"\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n :aria-expanded=\"isOpen.toString()\"\n :aria-controls=\"listId\"\n :aria-label=\"ariaLabel\"\n aria-autocomplete=\"none\"\n >\n <!--\n @slot Used to render the contents of the dropdown toggle button. If not provided, it uses\n the item slot as fallback.\n @binding {string|number|Identifiable} item - The item data to render.\n @binding {boolean} isOpen - True if the dropdown is opened, and false if it is closed.\n -->\n <slot v-if=\"hasToggleSlot\" :isOpen=\"isOpen\" :item=\"modelValue\" name=\"toggle\">\n {{ modelValue }}\n </slot>\n <slot v-else :item=\"modelValue\" name=\"item\">{{ modelValue }}</slot>\n </button>\n\n <component :is=\"animation\">\n <ul\n v-show=\"isOpen\"\n @keydown.end=\"highlightLastItem\"\n @keydown.esc=\"closeAndFocusToggleButton\"\n @keydown.home=\"highlightFirstItem\"\n :id=\"listId\"\n class=\"x-dropdown__items-list\"\n data-test=\"dropdown-list\"\n role=\"listbox\"\n tabindex=\"-1\"\n >\n <li v-for=\"(item, index) in items\" :key=\"item.id || item\" class=\"x-dropdown__list-item\">\n <button\n :ref=\"el => (itemsButtonRefs[index] = el)\"\n @click=\"emitSelectedItemChanged(item)\"\n :aria-selected=\"(item === modelValue).toString()\"\n :class=\"itemsCSSClasses[index]\"\n class=\"x-dropdown__item\"\n data-test=\"dropdown-item\"\n role=\"option\"\n >\n <!--\n @slot (required) Used to render each one of the items content, and as fallback\n for the toggle button content slot if it is not provided.\n @binding {string|number|Identifiable} item - Item to render\n @binding {boolean} isHighlighted - True when the item has the focus.\n @binding {boolean} isSelected - True when the item is selected.\n -->\n <slot\n :isHighlighted=\"index === highlightedItemIndex\"\n :isSelected=\"item === modelValue\"\n :item=\"item\"\n name=\"item\"\n >\n {{ item }}\n </slot>\n </button>\n </li>\n </ul>\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\n import { Identifiable } from '@empathyco/x-types';\n import { computed, defineComponent, nextTick, onBeforeUnmount, PropType, ref, watch } from 'vue';\n import { AnimationProp } from '../types';\n import { debounceFunction, normalizeString, getTargetElement } from '../utils';\n import { NoAnimation } from './animations';\n\n type DropdownItem = string | number | Identifiable;\n let dropdownCount = 0;\n\n /**\n * Dropdown component that mimics a Select element behavior, but with the option\n * to customize the toggle button and each item contents.\n */\n export default defineComponent({\n name: 'BaseDropdown',\n props: {\n /** List of items to display.*/\n items: {\n type: Array as PropType<DropdownItem[]>,\n required: true\n },\n /** The selected item. */\n modelValue: {\n type: null as unknown as PropType<DropdownItem | null>,\n validator: (v: any) =>\n typeof v === 'string' || typeof v === 'number' || typeof v === 'object' || v === null,\n required: true\n },\n /** Description of what the dropdown is used for. */\n ariaLabel: String,\n /**\n * Animation component to use for expanding the dropdown. This is a single element animation,\n * so only `<transition>` components are allowed.\n */\n animation: {\n type: AnimationProp,\n default: () => NoAnimation\n },\n /** Time to wait without receiving any keystroke before resetting the items search query. */\n searchTimeoutMs: {\n type: Number,\n default: 1000\n }\n },\n emits: ['update:modelValue'],\n setup(props, { emit, slots }) {\n const rootRef = ref<HTMLElement>();\n /** The button that opens and closes the list of options. */\n const toggleButtonRef = ref<HTMLButtonElement>();\n /** Array containing the dropdown list buttons HTMLElements. */\n const itemsButtonRefs = ref<HTMLButtonElement[]>([]);\n\n /** Property to check whether the dropdown is expanded or closed. */\n const isOpen = ref(false);\n /** Index of the element that has the focus in the list. -1 means no element has focus. */\n const highlightedItemIndex = ref(-1);\n /** String to search for the first element that starts with it. */\n const searchBuffer = ref('');\n\n /** Resets the search buffer after a certain time has passed. */\n let restartResetSearchTimeout: () => void;\n /* Unique ID to identify the dropdown. */\n const listId = `x-dropdown-${dropdownCount++}`;\n\n /**\n * Dynamic CSS classes to add to the dropdown root element.\n *\n * @returns An object containing the CSS classes to add to the dropdown root element.\n */\n const dropdownCSSClasses = computed(() => ({ 'x-dropdown--is-open': isOpen }));\n\n /**\n * Dynamic CSS classes to add to each one of the items.\n *\n * @returns An object containing the CSS classes to add to each item.\n */\n const itemsCSSClasses = computed(() =>\n props.items.map((item, index) => ({\n 'x-dropdown__item--is-selected': props.modelValue === item,\n 'x-dropdown__item--is-highlighted': highlightedItemIndex.value === index\n }))\n );\n\n /* Opens the dropdown. */\n const open = () => (isOpen.value = true);\n /* Closes the dropdown. */\n const close = () => (isOpen.value = false);\n /* Toggles the dropdown. */\n const toggle = () => (isOpen.value = !isOpen.value);\n\n /**\n * Closes the modal and focuses the toggle button.\n */\n function closeAndFocusToggleButton() {\n close();\n toggleButtonRef.value?.focus();\n }\n\n /**\n * Emits the event that the selected item has changed.\n *\n * @param item - The new selected item.\n */\n function emitSelectedItemChanged(item: DropdownItem) {\n emit('update:modelValue', item);\n closeAndFocusToggleButton();\n }\n\n /**\n * Highlights the item after the one that is currently highlighted.\n */\n function highlightNextItem() {\n open();\n highlightedItemIndex.value = (highlightedItemIndex.value + 1) % props.items.length;\n }\n\n /**\n * Highlights the item before the one that is currently highlighted.\n */\n function highlightPreviousItem() {\n const currentIndex = highlightedItemIndex.value;\n open();\n highlightedItemIndex.value = currentIndex > 0 ? currentIndex - 1 : props.items.length - 1;\n }\n\n /**\n * Highlights the first of the provided items.\n */\n function highlightFirstItem() {\n highlightedItemIndex.value = 0;\n }\n\n /**\n * Highlights the last of the provided items.\n */\n function highlightLastItem() {\n highlightedItemIndex.value = props.items.length - 1;\n }\n\n /**\n * Updates the variable that is used to search in the filters.\n *\n * @param event - The event coming from the user typing.\n */\n function updateSearchBuffer(event: KeyboardEvent) {\n if (/^\\w$/.test(event.key)) {\n const key = event.key;\n searchBuffer.value += key;\n restartResetSearchTimeout();\n }\n }\n\n /**\n * Resets the search buffer.\n */\n function resetSearchBuffer() {\n searchBuffer.value = '';\n }\n\n /**\n * Closes the dropdown if the passed event has happened on an element out of the dropdown.\n *\n * @param event - The event to check if it has happened out of the dropdown component.\n */\n function closeIfEventIsOutOfDropdown(event: MouseEvent | TouchEvent | FocusEvent) {\n if (!rootRef.value?.contains(getTargetElement(event))) {\n close();\n }\n }\n\n /**\n * Adds listeners to the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function addDocumentCloseListeners() {\n document.addEventListener('mousedown', closeIfEventIsOutOfDropdown);\n document.addEventListener('touchstart', closeIfEventIsOutOfDropdown);\n document.addEventListener('focusin', closeIfEventIsOutOfDropdown);\n }\n\n /**\n * Removes the listeners of the document element to detect if the focus has moved out from the\n * dropdown.\n */\n function removeDocumentCloseListeners() {\n document.removeEventListener('mousedown', closeIfEventIsOutOfDropdown);\n document.removeEventListener('touchstart', closeIfEventIsOutOfDropdown);\n document.removeEventListener('focusin', closeIfEventIsOutOfDropdown);\n }\n\n /**\n * Highlights the item that matches the search buffer. To do so it checks the list buttons\n * text content. It highlights items following this priority:\n * - If an element is already highlighted, it starts searching from that element.\n * - If no element is found starting from the previously highlighted, it returns the first one.\n * - If no element is found matching the search query it highlights the first element.\n *\n * @param search - The search string to find in the HTML.\n */\n watch(searchBuffer, search => {\n if (search) {\n const normalizedSearch = normalizeString(search);\n const matchingIndices = itemsButtonRefs?.value?.reduce<number[]>(\n (matchingIndices, button, index) => {\n const safeButtonWordCharacters = button.textContent!.replace(/[^\\w]/g, '');\n const normalizedButtonText = normalizeString(safeButtonWordCharacters);\n if (normalizedButtonText.startsWith(normalizedSearch)) {\n matchingIndices.push(index);\n }\n return matchingIndices;\n },\n []\n );\n highlightedItemIndex.value =\n // First matching item starting to search from the current highlighted element\n matchingIndices?.find(index => index >= highlightedItemIndex.value) ??\n // First matching item\n matchingIndices?.[0] ??\n // First item\n 0;\n }\n });\n\n /**\n * Updates the debounced function to reset the search.\n *\n * @param searchTimeoutMs - The new milliseconds that have to pass without typing before\n * resetting the search.\n */\n watch(\n () => props.searchTimeoutMs,\n searchTimeoutMs => {\n restartResetSearchTimeout = debounceFunction(resetSearchBuffer, searchTimeoutMs);\n },\n { immediate: true }\n );\n\n /**\n * Focuses the DOM element which matches the `highlightedItemIndex`.\n *\n * @param highlightedItemIndex - The index of the HTML element to focus.\n */\n watch(\n highlightedItemIndex,\n highlightedItemIndex => {\n nextTick(() => itemsButtonRefs.value[highlightedItemIndex]?.focus());\n },\n { immediate: true }\n );\n\n /**\n * When the dropdown is open it sets the focused element to the one that is selected.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n highlightedItemIndex.value = isOpen\n ? props.modelValue === null\n ? 0\n : props.items.indexOf(props.modelValue)\n : -1;\n });\n\n /**\n * Adds and removes listeners to close the dropdown when it loses the focus.\n *\n * @param isOpen - True if the dropdown is open, false otherwise.\n */\n watch(isOpen, isOpen => {\n /*\n * Because there is an issue with Firefox in macOS and Safari that doesn't focus the target\n * element of the `mousedown` events, the `focusout` event `relatedTarget` property can't be\n * used to detect whether the user has blurred the dropdown. The hack here is to use\n * document listeners that have the side effect of losing the focus.\n */\n if (isOpen) {\n addDocumentCloseListeners();\n } else {\n removeDocumentCloseListeners();\n }\n });\n\n /**\n * If the dropdown is destroyed before removing the document listeners, it ensures that they\n * are removed too.\n */\n onBeforeUnmount(() => {\n removeDocumentCloseListeners();\n });\n\n return {\n hasToggleSlot: !!slots.toggle,\n closeAndFocusToggleButton,\n dropdownCSSClasses,\n emitSelectedItemChanged,\n highlightFirstItem,\n highlightLastItem,\n highlightNextItem,\n highlightPreviousItem,\n highlightedItemIndex,\n isOpen,\n itemsButtonRefs,\n itemsCSSClasses,\n listId,\n open,\n rootRef,\n toggle,\n toggleButtonRef,\n updateSearchBuffer\n };\n }\n });\n</script>\n\n<style lang=\"css\" scoped>\n .x-dropdown {\n position: relative;\n }\n\n .x-dropdown__items-list {\n z-index: 1;\n list-style: none;\n position: absolute;\n padding: 0;\n margin: 0;\n top: calc(100% + var(--x-size-gap-dropdown-default, 0));\n }\n</style>\n\n<docs lang=\"mdx\">\n## Example\n\nThe `Dropdown` component is a simple yet customizable select component. The component needs to work\nthe list of items available to select, which are passed using the `items` prop, and the selected\nitem, which is passed in using the `value` prop.\n\nThe supported items must be an array that can contain unique strings, unique numbers, or objects\nwith a unique `id` property.\n\nThe content of each item can be customized using the `item` slot, which apart from the data of the\nitem, it also receives via prop if the element is selected or highlighted.\n\nThere `toggle` slot can be used to customize the button that opens the dropdown. If this is not\nprovided, the `item` slot will be used for that.\n\n```vue\n<template>\n <BaseDropdown v-model=\"value\" :items=\"items\">\n <template #toggle=\"{ item, isOpen }\">{{ item }} {{ isOpen ? '🔼' : '🔽' }}️</template>\n\n <template #item=\"{ item, isSelected, isHighlighted }\">\n <span v-if=\"isHighlighted\">🟢</span>\n <span v-if=\"isSelected\">✅</span>\n <span>{{ item }}</span>\n </template>\n </BaseDropdown>\n</template>\n\n<script>\n import { BaseDropdown } from '@empathyco/x-components';\n\n export default {\n name: 'DropdownTest',\n components: {\n BaseDropdown\n },\n data() {\n return {\n items: ['a', 2, { id: '3' }],\n value: 'a'\n };\n }\n };\n</script>\n```\n</docs>\n"],"names":["NoAnimation","debounceFunction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsFE,IAAI,aAAY,GAAI,CAAC,CAAA;AAErB;;;AAGE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,cAAc;AACpB,IAAA,KAAK,EAAE;;AAEL,QAAA,KAAK,EAAE;AACL,YAAA,IAAI,EAAE,KAAiC;AACvC,YAAA,QAAQ,EAAE,IAAG;AACd,SAAA;;AAED,QAAA,UAAU,EAAE;AACV,YAAA,IAAI,EAAE,IAAgD;YACtD,SAAS,EAAE,CAAC,CAAM,KAChB,OAAO,CAAA,KAAM,QAAO,IAAK,OAAO,CAAA,KAAM,QAAO,IAAK,OAAO,CAAE,KAAI,YAAY,CAAE,KAAI,IAAI;AACvF,YAAA,QAAQ,EAAE,IAAG;AACd,SAAA;;AAED,QAAA,SAAS,EAAE,MAAM;AACjB;;;AAGE;AACF,QAAA,SAA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C,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAA;kBACtC,CAAC,CAAC,CAAA;AACR,SAAC,CAAC,CAAA;AAEF;;;;AAIE;AACF,QAAA,KAAK,CAAC,MAAM,EAAE,MAAK,IAAK;AACtB;;;;;AAKE;AACF,YAAA,IAAI,MAAM,EAAE;AACV,gBAAA,yBAAyB,EAAE,CAAA;AAC3B,aAAA;AAAK,iBAAA;AACL,gBAAA,4BAA4B,EAAE,CAAA;AAChC,aAAA;AACF,SAAC,CAAC,CAAA;AAEF;;;AAGE;QACF,eAAe,CAAC,MAAM;AACpB,YAAA,4BAA4B,EAAE,CAAA;AAChC,SAAC,CAAC,CAAA;QAEF,OAAO;AACL,YAAA,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM;YAC7B,yBAAyB;YACzB,kBAAkB;YAClB,uBAAuB;YACvB,kBAAkB;YAClB,iBAAiB;YACjB,iBAAiB;YACjB,qBAAqB;YACrB,oBAAoB;YACpB,MAAM;YACN,eAAe;YACf,eAAe;YACf,MAAM;YACN,IAAI;YACJ,OAAO;YACP,MAAM;YACN,eAAe;YACf,kBAAiB;SAClB,CAAA;KACH;AACD,CAAA,CAAC;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _sfc_main from './base-event-button.vue2.js';
|
|
2
|
-
import { openBlock, createElementBlock,
|
|
2
|
+
import { openBlock, createElementBlock, renderSlot } from 'vue';
|
|
3
3
|
import _export_sfc from '../_virtual/_plugin-vue_export-helper.js';
|
|
4
4
|
|
|
5
5
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
@@ -11,7 +11,6 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
11
11
|
"data-test": "event-button"
|
|
12
12
|
},
|
|
13
13
|
[
|
|
14
|
-
createCommentVNode(" @slot (Required) Button content with a text, an icon or both "),
|
|
15
14
|
renderSlot(_ctx.$slots, "default")
|
|
16
15
|
],
|
|
17
16
|
512
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-event-button.vue.js","sources":["../../../src/components/base-event-button.vue"],"sourcesContent":["<template>\n <button ref=\"rootRef\" @click=\"emitEvents\" data-test=\"event-button\">\n <!-- @slot (Required) Button content with a text, an icon or both -->\n <slot />\n </button>\n</template>\n\n<script lang=\"ts\">\n import { defineComponent, PropType, ref } from 'vue';\n import { use$x } from '../composables/use-$x';\n import { XEvent, XEventsTypes } from '../wiring/events.types';\n import { WireMetadata } from '../wiring/index';\n\n /**\n * Component to be reused that renders a `<button>` with the logic of emitting events to the bus\n * on click. The events are passed as an object to prop {@link XEvent}.\n * The keys are the event name and the values are the payload of each event. All events are\n * emitted with its respective payload. If any event doesn't need payload a `undefined` must be\n * passed as value.\n *\n * @public\n */\n export default defineComponent({\n name: 'BaseEventButton',\n props: {\n /** An object where the keys are the {@link XEvent} and the values are the payload. */\n events: {\n type: Object as PropType<Partial<XEventsTypes>>,\n required: true\n },\n /**\n * The metadata property for the request on each query preview.\n *\n * @public\n */\n metadata: {\n type: Object as PropType<Omit<WireMetadata, 'moduleName'>>\n }\n },\n setup(props) {\n const $x = use$x();\n\n const rootRef = ref<HTMLButtonElement>();\n\n /**\n * Emits `events` prop to the X bus with the payload given by it.\n */\n function emitEvents() {\n Object.entries(props.events).forEach(([event, payload]) =>\n $x.emit(event as XEvent, payload, { target: rootRef.value, ...props.metadata })\n );\n }\n\n return {\n emitEvents,\n rootRef\n };\n }\n });\n</script>\n\n<docs lang=\"mdx\">\n## Examples\n\n### Basic example\n\nThe event prop is required. It will render a <button></button> that emits the event passed as prop\nwith the value as payload on click:\n\n```vue\n<BaseEventButton :events=\"{ myEvent: payload }\" />\n```\n\nIf the event doesn't need payload then `undefined` must be passed:\n\n```vue\n<BaseEventButton :events=\"{ myEvent: undefined }\" />\n```\n\nIt can emit multiple events at the same time:\n\n```vue\n<BaseEventButton :events=\"{ myFirstEvent: payload1, mySecondEvent: payload2 }\" />\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock"
|
|
1
|
+
{"version":3,"file":"base-event-button.vue.js","sources":["../../../src/components/base-event-button.vue"],"sourcesContent":["<template>\n <button ref=\"rootRef\" @click=\"emitEvents\" data-test=\"event-button\">\n <!-- @slot (Required) Button content with a text, an icon or both -->\n <slot />\n </button>\n</template>\n\n<script lang=\"ts\">\n import { defineComponent, PropType, ref } from 'vue';\n import { use$x } from '../composables/use-$x';\n import { XEvent, XEventsTypes } from '../wiring/events.types';\n import { WireMetadata } from '../wiring/index';\n\n /**\n * Component to be reused that renders a `<button>` with the logic of emitting events to the bus\n * on click. The events are passed as an object to prop {@link XEvent}.\n * The keys are the event name and the values are the payload of each event. All events are\n * emitted with its respective payload. If any event doesn't need payload a `undefined` must be\n * passed as value.\n *\n * @public\n */\n export default defineComponent({\n name: 'BaseEventButton',\n props: {\n /** An object where the keys are the {@link XEvent} and the values are the payload. */\n events: {\n type: Object as PropType<Partial<XEventsTypes>>,\n required: true\n },\n /**\n * The metadata property for the request on each query preview.\n *\n * @public\n */\n metadata: {\n type: Object as PropType<Omit<WireMetadata, 'moduleName'>>\n }\n },\n setup(props) {\n const $x = use$x();\n\n const rootRef = ref<HTMLButtonElement>();\n\n /**\n * Emits `events` prop to the X bus with the payload given by it.\n */\n function emitEvents() {\n Object.entries(props.events).forEach(([event, payload]) =>\n $x.emit(event as XEvent, payload, { target: rootRef.value, ...props.metadata })\n );\n }\n\n return {\n emitEvents,\n rootRef\n };\n }\n });\n</script>\n\n<docs lang=\"mdx\">\n## Examples\n\n### Basic example\n\nThe event prop is required. It will render a <button></button> that emits the event passed as prop\nwith the value as payload on click:\n\n```vue\n<BaseEventButton :events=\"{ myEvent: payload }\" />\n```\n\nIf the event doesn't need payload then `undefined` must be passed:\n\n```vue\n<BaseEventButton :events=\"{ myEvent: undefined }\" />\n```\n\nIt can emit multiple events at the same time:\n\n```vue\n<BaseEventButton :events=\"{ myFirstEvent: payload1, mySecondEvent: payload2 }\" />\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock"],"mappings":";;;;SACc,WAAS,CAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,EAAA,KAAA,EAAA,QAAA,EAAA;SAAEA,SAAK,EAAA,EAAAC,kBAAA;AAAA,IAAA,QAAA;AAAA,IAAE;AAAA,MAAY,GAAA,EAAA,SAAA;AAAA,MAAA,OAAA,EAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAA,IAAA,CAAA,UAAA,IAAA,IAAA,CAAA,UAAA,CAAA,GAAA,IAAA,CAAA,CAAA;MAExC,WAAQ,EAAA,cAAA;AAAA,KAAA;;;;;;;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _sfc_main from './base-grid.vue2.js';
|
|
2
|
-
import { openBlock, createBlock, resolveDynamicComponent, normalizeStyle, normalizeClass, withCtx, createElementBlock, Fragment, renderList,
|
|
2
|
+
import { openBlock, createBlock, resolveDynamicComponent, normalizeStyle, normalizeClass, withCtx, createElementBlock, Fragment, renderList, renderSlot, createTextVNode, toDisplayString } from 'vue';
|
|
3
3
|
import './base-grid.vue3.js';
|
|
4
4
|
import _export_sfc from '../_virtual/_plugin-vue_export-helper.js';
|
|
5
5
|
|
|
@@ -23,26 +23,19 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
23
23
|
class: normalizeClass([cssClass, "x-base-grid__item"])
|
|
24
24
|
},
|
|
25
25
|
[
|
|
26
|
-
createCommentVNode("\n @slot Customized item rendering. Specifying a slot with the item's modelName will result in\n the item using that slot composition to render.\n @binding {item} item - Item to render\n "),
|
|
27
26
|
_ctx.slots[slotName] ? renderSlot(_ctx.$slots, slotName, {
|
|
28
27
|
key: 0,
|
|
29
28
|
item
|
|
30
|
-
}, void 0, true) : (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
41
|
-
], true)
|
|
42
|
-
],
|
|
43
|
-
2112
|
|
44
|
-
/* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
|
|
45
|
-
))
|
|
29
|
+
}, void 0, true) : renderSlot(_ctx.$slots, "default", {
|
|
30
|
+
key: 1,
|
|
31
|
+
item
|
|
32
|
+
}, () => [
|
|
33
|
+
createTextVNode(
|
|
34
|
+
toDisplayString(item.name || item.modelName || item.id || item),
|
|
35
|
+
1
|
|
36
|
+
/* TEXT */
|
|
37
|
+
)
|
|
38
|
+
], true)
|
|
46
39
|
],
|
|
47
40
|
2
|
|
48
41
|
/* CLASS */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-grid.vue.js","sources":["../../../src/components/base-grid.vue"],"sourcesContent":["<template>\n <component\n :is=\"animation\"\n ref=\"gridEl\"\n :style=\"style\"\n class=\"x-base-grid\"\n :class=\"cssClasses\"\n tag=\"ul\"\n data-test=\"grid\"\n >\n <li\n v-for=\"{ item, cssClass, slotName } in gridItems\"\n :key=\"item.id\"\n :class=\"cssClass\"\n class=\"x-base-grid__item\"\n >\n <!--\n @slot Customized item rendering. Specifying a slot with the item's modelName will result in\n the item using that slot composition to render.\n @binding {item} item - Item to render\n -->\n <slot v-if=\"slots[slotName]\" :name=\"slotName\" :item=\"item\" />\n <!--\n @slot (required) Default item rendering. This slot will be used by default for rendering\n the item without an specific slot implementation.\n @binding {item} item - Item to render\n -->\n <slot v-else :item=\"item\">{{ item.name || item.modelName || item.id || item }}</slot>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\n import {\n computed,\n defineComponent,\n inject,\n onBeforeUnmount,\n onMounted,\n PropType,\n Ref,\n ref,\n watch\n } from 'vue';\n import {\n MaybeComputedElementRef,\n useResizeObserver,\n UseResizeObserverReturn\n } from '@vueuse/core';\n import { toKebabCase } from '../utils/string';\n import { ListItem, VueCSSClasses } from '../utils/types';\n import { AnimationProp } from '../types/animation-prop';\n import { useXBus } from '../composables/use-x-bus';\n import { LIST_ITEMS_KEY } from './decorators/injection.consts';\n\n /**\n * The type returned by the gridItems function. Basically it's a list of items with its CSS\n * classes and a slotName.\n */\n interface GridItem {\n slotName: string;\n item: ListItem;\n cssClass: VueCSSClasses;\n }\n\n /**\n * Grid component that is able to render different items based on their modelName value. In order\n * to achieve this, it exposes a scopedSlot for each different modelName. In case the items used\n * do not have modelName property, the default slot is used instead. It has a required property:\n * the `items` to render; and an optional one: the number `columns` the grid is divided in. If the\n * number of columns is not specified, the grid automatically fills the rows with as many columns\n * as it can fit.\n *\n * @public\n */\n export default defineComponent({\n name: 'BaseGrid',\n props: {\n /** Animation component that will be used to animate the base grid. */\n animation: {\n type: AnimationProp,\n default: 'ul'\n },\n /**\n * Number of columns the grid is divided into. By default, its value is 0, setting the grid\n * columns mode to auto-fill.\n */\n columns: {\n type: Number,\n default: 0\n },\n /**\n * The list of items to be rendered.\n *\n * @remarks The items must have an ID property.\n */\n items: {\n type: Array as PropType<ListItem[]>\n }\n },\n setup(props, { slots }) {\n type ElementRef = {\n $el: HTMLElement;\n };\n\n const xBus = useXBus();\n\n /** It injects {@link ListItem} provided by an ancestor. */\n const injectedListItems = inject<Ref<ListItem[]>>(LIST_ITEMS_KEY as string);\n const gridEl = ref<ElementRef | HTMLElement>();\n let renderedColumnsNumber = ref(0);\n\n /**\n * Emits the {@link XEventsTypes.RenderedColumnsNumberChanged}\n * event whenever the number of columns rendered inside the grid changes.\n */\n watch(\n renderedColumnsNumber,\n () => xBus.emit('RenderedColumnsNumberChanged', renderedColumnsNumber.value),\n { immediate: false }\n );\n\n /**\n * It returns the items passed as props or the injected ones.\n *\n * @returns List of grid items.\n */\n const computedItems = computed<ListItem[] | void>(() => {\n return (\n props.items ??\n injectedListItems?.value ??\n //TODO: add here logger\n //eslint-disable-next-line no-console\n console.warn('It is necessary to pass a prop or inject the list of filters')\n );\n });\n\n /**\n * CSS class based on the column property value so items inside the grid can fill different\n * amount of columns or rows based on how many columns the grid is divided into.\n *\n * @returns CSS class with the column property value.\n */\n const cssClasses = computed(() => `x-base-grid--cols-${props.columns || 'auto'}`);\n\n /**\n * CSSStyleDeclaration object specifying the number of columns the grid is divided into based on\n * the column property value.\n *\n * @returns A CSSStyleDeclaration to use as the style attribute.\n */\n const style = computed<Partial<CSSStyleDeclaration>>(() => ({\n gridTemplateColumns: props.columns\n ? `repeat(${props.columns}, minmax(0, 1fr))`\n : 'repeat(auto-fill, minmax(var(--x-size-min-width-grid-item, 150px), 1fr))'\n }));\n\n /**\n * Maps the item to an object containing: the `item`, its `CSS class` and its slot name.\n *\n * @returns An array of objects containing the item and its CSS class.\n */\n const gridItems = computed<GridItem[]>(() =>\n (computedItems.value as ListItem[]).map(item => {\n const slotName = toKebabCase(item.modelName);\n return {\n slotName,\n item,\n cssClass: `x-base-grid__${slotName}`\n };\n })\n );\n\n /**\n * Checks if a given value is an `ElementRef` object.\n *\n * @param value - The value to check.\n * @returns `true` if the value is an `ElementRef` object, `false` otherwise.\n */\n const isElementRef = (value: any): value is ElementRef => {\n return value && value.$el instanceof HTMLElement;\n };\n\n /** Updates the number of columns rendered inside the grid. */\n function updateRenderedColumnsNumber() {\n const { gridTemplateColumns } = getComputedStyle(\n isElementRef(gridEl.value) ? gridEl.value.$el : (gridEl.value as Element)\n );\n renderedColumnsNumber.value = gridTemplateColumns.split(' ').length;\n }\n\n /** Initialises the rendered columns number and sets a ResizeObserver to keep it updated. */\n let resizeObserver: UseResizeObserverReturn;\n onMounted(() => {\n resizeObserver = useResizeObserver(\n gridEl as MaybeComputedElementRef,\n updateRenderedColumnsNumber\n );\n });\n onBeforeUnmount(() => resizeObserver?.stop());\n\n return {\n gridItems,\n cssClasses,\n style,\n gridEl,\n slots\n };\n }\n });\n</script>\n\n<style lang=\"css\" scoped>\n .x-base-grid {\n display: grid;\n grid-auto-flow: dense;\n list-style: none;\n align-items: stretch;\n }\n\n .x-base-grid__banner,\n .x-base-grid__next-queries-group {\n grid-column-start: 1;\n grid-column-end: -1;\n }\n\n .x-base-grid__item {\n display: flex;\n flex-flow: column nowrap;\n }\n\n .x-base-grid__item > * {\n flex-grow: 1;\n }\n\n .x-base-grid--cols-auto .x-base-grid__item {\n min-width: var(--x-size-min-width-grid-item);\n }\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a list of elements in different slots depending on their modelName. In order\nto achieve this, it exposes a scopedSlot for each different modelName. In case the items used do not\nhave modelName property, the default slot is used instead. It has a required property, the `items`\nto render, and an optional one, the number of `columns` the grid is divided in. If the number of\ncolumns is not specified, the grid automatically fills the rows with as many columns as it can fit.\n\n### Basic example\n\nIt renders a list of items using the default slot:\n\n```vue\n<template>\n <BaseGrid :items=\"items\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </BaseGrid>\n</template>\n```\n\n### Configuring the number of columns\n\nIt renders a grid with 12 columns instead of 6, which is the default value:\n\n```vue\n<template>\n <BaseGrid :items=\"items\" :columns=\"12\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </BaseGrid>\n</template>\n```\n\n### Rendering usage\n\nConfiguring the number of columns.\n\nIt renders a list of items using the different scopedSlots created by the item's modelName. For\nexample, if you want to use this component as the search grid, you pass the search results (results,\nbanners, promoted, next queries...etc) as items. Each of these results have a different modelName\nand are rendered in different slots.\n\n```vue\n<template>\n <BaseGrid :animation=\"animation\" :items=\"items\">\n <template #banner=\"{ item }\">\n <span class=\"banner\">\n {{ `${item.title} banner` }}\n </span>\n </template>\n <template #next-queries=\"{ item }\">\n <span>\n {{ `${item.totalResults} next queries` }}\n </span>\n </template>\n <template #promoted=\"{ item }\">\n <span class=\"promoted\">\n {{ `${item.title} promoted` }}\n </span>\n </template>\n <template #result=\"{ item }\">\n <BaseResultLink :result=\"item\">\n {{ item.name }}\n </BaseResultLink>\n </template>\n </BaseGrid>\n</template>\n```\n\n### Customizing the items width\n\nThe `--x-size-min-width-grid-item` variable can be used to customize the min width of the grid\nitems.\n\n```vue\n<template>\n <BaseGrid :items=\"items\" style=\"--x-size-min-width-grid-item: 150px\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </BaseGrid>\n</template>\n```\n</docs>\n"],"names":["_openBlock","_createBlock","_resolveDynamicComponent","_normalizeStyle","_normalizeClass","_createElementBlock","_Fragment","_renderList","slots","_renderSlot","_createCommentVNode"],"mappings":";;;;;SAGQ,WAAQ,CAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,EAAA,KAAA,EAAA,QAAA,EAAA;AACN,EAAA,OAAAA,SAAA,EAAO,EAAAC,WAAA,CAAAC,uBAAA,CAAA,IAAA,CAAA,SAAA,CAAA,EAAA;AAAA,IACb,GAAK,EAAA,QAAA;AAAA,IAEL,OAAIC,cAAI,CAAA,IAAA,CAAA,KAAA,CAAA;AAAA,IACR,KAAgB,EAAAC,cAAA,CAAA,CAAA,aAAA,EAAA,IAAA,CAAA,UAAA,CAAA,CAAA;AAAA,IAAA,GAAA,EAAA,IAAA;AARpB,IAAA,WAAA,EAAA,MAAA;AAAA,GAAA,EAAA;;iBAYY,IAAO,CAAA,EAAAC,kBAAA;AAAA,QAAAC,QAAA;AAAA,QAAA,IAAA;AAAA,QAAAC,UAAA,CAAA,IAAA,CAAA,SAAA,EAAA,CAAA,EAAA,IAAA,EAAA,QAAA,EAAA,QAAA,EAAA,KAAA;iBACPP,SAbZ,EAAA,EAAAK,kBAAA;AAAA,YAcY,IAAA;AAAA,YAAA;AAAA,cAAA,GAAA,EAAA,IAAA,CAAA,EAAA;AAEN,cAAA,KAAA,EAAAD,cAAA,CAAA,CAAA,QAAA,EAAA,mBAAA,CAAA,CAAA;AAAA,aAAA;AAKYI,YAAAA;AAAAA,cAAAA,kBAAAA,CAAiD,2NAAjB,CAAA;AAAA,cAAA,IAAA,CArBlD,KAqB+D,CAAA,QAAA,CAAA,GAAAC,UAAA,CAAA,IAAA,CAAA,MAAA,EAAA,QAAA,EAAA;AAAA,gBAAA,GAAA,EAAA,CAAA;;AACzD,eAAA,EAAA,KAAA,CAAA,EAAA,IAAA,CAAA,IAAAT,SAAA,EAKqF,EAAAK,kBAAA;AAAA,gBAAAC,QAAA;AAAA,gBAAjE,OAAI,CAA6D,EAAA;AAAA,gBAAA;AAAA,kBAAAI,kBAAA,CA3B3F,0NA2BiF,CAAA;AAAA,kBAAAD,UAAA,CAAA,IAAA,CAAA,MAAA,EAAA,SAAA,EAAA,EAAA,IAAA,EAAA,EAAA,MAAA;;;;;;;;;;;;;;;AA3BjF,SAAA,CAAA;AAAA,QAAA,GAAA;AAAA;AAAA,OAAA;AAAA,KAAA,CAAA;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"base-grid.vue.js","sources":["../../../src/components/base-grid.vue"],"sourcesContent":["<template>\n <component\n :is=\"animation\"\n ref=\"gridEl\"\n :style=\"style\"\n class=\"x-base-grid\"\n :class=\"cssClasses\"\n tag=\"ul\"\n data-test=\"grid\"\n >\n <li\n v-for=\"{ item, cssClass, slotName } in gridItems\"\n :key=\"item.id\"\n :class=\"cssClass\"\n class=\"x-base-grid__item\"\n >\n <!--\n @slot Customized item rendering. Specifying a slot with the item's modelName will result in\n the item using that slot composition to render.\n @binding {item} item - Item to render\n -->\n <slot v-if=\"slots[slotName]\" :name=\"slotName\" :item=\"item\" />\n <!--\n @slot (required) Default item rendering. This slot will be used by default for rendering\n the item without an specific slot implementation.\n @binding {item} item - Item to render\n -->\n <slot v-else :item=\"item\">{{ item.name || item.modelName || item.id || item }}</slot>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\n import {\n computed,\n defineComponent,\n inject,\n onBeforeUnmount,\n onMounted,\n PropType,\n Ref,\n ref,\n watch\n } from 'vue';\n import {\n MaybeComputedElementRef,\n useResizeObserver,\n UseResizeObserverReturn\n } from '@vueuse/core';\n import { toKebabCase } from '../utils/string';\n import { ListItem, VueCSSClasses } from '../utils/types';\n import { AnimationProp } from '../types/animation-prop';\n import { useXBus } from '../composables/use-x-bus';\n import { LIST_ITEMS_KEY } from './decorators/injection.consts';\n\n /**\n * The type returned by the gridItems function. Basically it's a list of items with its CSS\n * classes and a slotName.\n */\n interface GridItem {\n slotName: string;\n item: ListItem;\n cssClass: VueCSSClasses;\n }\n\n /**\n * Grid component that is able to render different items based on their modelName value. In order\n * to achieve this, it exposes a scopedSlot for each different modelName. In case the items used\n * do not have modelName property, the default slot is used instead. It has a required property:\n * the `items` to render; and an optional one: the number `columns` the grid is divided in. If the\n * number of columns is not specified, the grid automatically fills the rows with as many columns\n * as it can fit.\n *\n * @public\n */\n export default defineComponent({\n name: 'BaseGrid',\n props: {\n /** Animation component that will be used to animate the base grid. */\n animation: {\n type: AnimationProp,\n default: 'ul'\n },\n /**\n * Number of columns the grid is divided into. By default, its value is 0, setting the grid\n * columns mode to auto-fill.\n */\n columns: {\n type: Number,\n default: 0\n },\n /**\n * The list of items to be rendered.\n *\n * @remarks The items must have an ID property.\n */\n items: {\n type: Array as PropType<ListItem[]>\n }\n },\n setup(props, { slots }) {\n type ElementRef = {\n $el: HTMLElement;\n };\n\n const xBus = useXBus();\n\n /** It injects {@link ListItem} provided by an ancestor. */\n const injectedListItems = inject<Ref<ListItem[]>>(LIST_ITEMS_KEY as string);\n const gridEl = ref<ElementRef | HTMLElement>();\n let renderedColumnsNumber = ref(0);\n\n /**\n * Emits the {@link XEventsTypes.RenderedColumnsNumberChanged}\n * event whenever the number of columns rendered inside the grid changes.\n */\n watch(\n renderedColumnsNumber,\n () => xBus.emit('RenderedColumnsNumberChanged', renderedColumnsNumber.value),\n { immediate: false }\n );\n\n /**\n * It returns the items passed as props or the injected ones.\n *\n * @returns List of grid items.\n */\n const computedItems = computed<ListItem[] | void>(() => {\n return (\n props.items ??\n injectedListItems?.value ??\n //TODO: add here logger\n //eslint-disable-next-line no-console\n console.warn('It is necessary to pass a prop or inject the list of filters')\n );\n });\n\n /**\n * CSS class based on the column property value so items inside the grid can fill different\n * amount of columns or rows based on how many columns the grid is divided into.\n *\n * @returns CSS class with the column property value.\n */\n const cssClasses = computed(() => `x-base-grid--cols-${props.columns || 'auto'}`);\n\n /**\n * CSSStyleDeclaration object specifying the number of columns the grid is divided into based on\n * the column property value.\n *\n * @returns A CSSStyleDeclaration to use as the style attribute.\n */\n const style = computed<Partial<CSSStyleDeclaration>>(() => ({\n gridTemplateColumns: props.columns\n ? `repeat(${props.columns}, minmax(0, 1fr))`\n : 'repeat(auto-fill, minmax(var(--x-size-min-width-grid-item, 150px), 1fr))'\n }));\n\n /**\n * Maps the item to an object containing: the `item`, its `CSS class` and its slot name.\n *\n * @returns An array of objects containing the item and its CSS class.\n */\n const gridItems = computed<GridItem[]>(() =>\n (computedItems.value as ListItem[]).map(item => {\n const slotName = toKebabCase(item.modelName);\n return {\n slotName,\n item,\n cssClass: `x-base-grid__${slotName}`\n };\n })\n );\n\n /**\n * Checks if a given value is an `ElementRef` object.\n *\n * @param value - The value to check.\n * @returns `true` if the value is an `ElementRef` object, `false` otherwise.\n */\n const isElementRef = (value: any): value is ElementRef => {\n return value && value.$el instanceof HTMLElement;\n };\n\n /** Updates the number of columns rendered inside the grid. */\n function updateRenderedColumnsNumber() {\n const { gridTemplateColumns } = getComputedStyle(\n isElementRef(gridEl.value) ? gridEl.value.$el : (gridEl.value as Element)\n );\n renderedColumnsNumber.value = gridTemplateColumns.split(' ').length;\n }\n\n /** Initialises the rendered columns number and sets a ResizeObserver to keep it updated. */\n let resizeObserver: UseResizeObserverReturn;\n onMounted(() => {\n resizeObserver = useResizeObserver(\n gridEl as MaybeComputedElementRef,\n updateRenderedColumnsNumber\n );\n });\n onBeforeUnmount(() => resizeObserver?.stop());\n\n return {\n gridItems,\n cssClasses,\n style,\n gridEl,\n slots\n };\n }\n });\n</script>\n\n<style lang=\"css\" scoped>\n .x-base-grid {\n display: grid;\n grid-auto-flow: dense;\n list-style: none;\n align-items: stretch;\n }\n\n .x-base-grid__banner,\n .x-base-grid__next-queries-group,\n .x-base-grid__related-prompts-group {\n grid-column-start: 1;\n grid-column-end: -1;\n }\n\n .x-base-grid__item {\n display: flex;\n flex-flow: column nowrap;\n }\n\n .x-base-grid__item > * {\n flex-grow: 1;\n }\n\n .x-base-grid--cols-auto .x-base-grid__item {\n min-width: var(--x-size-min-width-grid-item);\n }\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a list of elements in different slots depending on their modelName. In order\nto achieve this, it exposes a scopedSlot for each different modelName. In case the items used do not\nhave modelName property, the default slot is used instead. It has a required property, the `items`\nto render, and an optional one, the number of `columns` the grid is divided in. If the number of\ncolumns is not specified, the grid automatically fills the rows with as many columns as it can fit.\n\n### Basic example\n\nIt renders a list of items using the default slot:\n\n```vue\n<template>\n <BaseGrid :items=\"items\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </BaseGrid>\n</template>\n```\n\n### Configuring the number of columns\n\nIt renders a grid with 12 columns instead of 6, which is the default value:\n\n```vue\n<template>\n <BaseGrid :items=\"items\" :columns=\"12\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </BaseGrid>\n</template>\n```\n\n### Rendering usage\n\nConfiguring the number of columns.\n\nIt renders a list of items using the different scopedSlots created by the item's modelName. For\nexample, if you want to use this component as the search grid, you pass the search results (results,\nbanners, promoted, next queries...etc) as items. Each of these results have a different modelName\nand are rendered in different slots.\n\n```vue\n<template>\n <BaseGrid :animation=\"animation\" :items=\"items\">\n <template #banner=\"{ item }\">\n <span class=\"banner\">\n {{ `${item.title} banner` }}\n </span>\n </template>\n <template #next-queries=\"{ item }\">\n <span>\n {{ `${item.totalResults} next queries` }}\n </span>\n </template>\n <template #promoted=\"{ item }\">\n <span class=\"promoted\">\n {{ `${item.title} promoted` }}\n </span>\n </template>\n <template #result=\"{ item }\">\n <BaseResultLink :result=\"item\">\n {{ item.name }}\n </BaseResultLink>\n </template>\n </BaseGrid>\n</template>\n```\n\n### Customizing the items width\n\nThe `--x-size-min-width-grid-item` variable can be used to customize the min width of the grid\nitems.\n\n```vue\n<template>\n <BaseGrid :items=\"items\" style=\"--x-size-min-width-grid-item: 150px\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </BaseGrid>\n</template>\n```\n</docs>\n"],"names":["_openBlock","_createBlock","_resolveDynamicComponent","_normalizeStyle","_normalizeClass","_createElementBlock","_Fragment","_renderList","slots","_renderSlot"],"mappings":";;;;;SAGQ,WAAQ,CAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,EAAA,KAAA,EAAA,QAAA,EAAA;AACN,EAAA,OAAAA,SAAA,EAAO,EAAAC,WAAA,CAAAC,uBAAA,CAAA,IAAA,CAAA,SAAA,CAAA,EAAA;AAAA,IACb,GAAK,EAAA,QAAA;AAAA,IAEL,OAAIC,cAAI,CAAA,IAAA,CAAA,KAAA,CAAA;AAAA,IACR,KAAgB,EAAAC,cAAA,CAAA,CAAA,aAAA,EAAA,IAAA,CAAA,UAAA,CAAA,CAAA;AAAA,IAAA,GAAA,EAAA,IAAA;AARpB,IAAA,WAAA,EAAA,MAAA;AAAA,GAAA,EAAA;;iBAYY,IAAO,CAAA,EAAAC,kBAAA;AAAA,QAAAC,QAAA;AAAA,QAAA,IAAA;AAAA,QAAAC,UAAA,CAAA,IAAA,CAAA,SAAA,EAAA,CAAA,EAAA,IAAA,EAAA,QAAA,EAAA,QAAA,EAAA,KAAA;iBACPP,SAbZ,EAAA,EAAAK,kBAAA;AAAA,YAcY,IAAA;AAAA,YAAA;AAAA,cAAA,GAAA,EAAA,IAAA,CAAA,EAAA;qBAOMG,cAAc,CAAA,CAAA,QAAA,EAAA,mBAAA,CAAA,CAAA;AAAA,aAAA;;mBArBhC,KAqB+D,CAAA,QAAA,CAAA,GAAAC,UAAA,CAAA,IAAA,CAAA,MAAA,EAAA,QAAA,EAAA;AAAA,gBAAA,GAAA,EAAA,CAAA;AAMzD,gBAAA,IAAA;AAAA,eAAA,EA3BN,KA2B8B,CAAA,EAAA,IAAA,CAAA,GAAAA,UAAA,CAAA,IAAA,CAAA,MAAA,EAAA,SAAA,EAAA;AAAA,gBAA6D,GAAA,EAAA,CAAA;AAAA,gBA3B3F,IAAA;AAAA,eAAA,EAAA,MAAA;;;;;;;;;;;AAAA,SAAA,CAAA;AAAA,QAAA,GAAA;AAAA;AAAA,OAAA;AAAA,KAAA,CAAA;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-grid.vue2.js","sources":["../../../src/components/base-grid.vue"],"sourcesContent":["<template>\n <component\n :is=\"animation\"\n ref=\"gridEl\"\n :style=\"style\"\n class=\"x-base-grid\"\n :class=\"cssClasses\"\n tag=\"ul\"\n data-test=\"grid\"\n >\n <li\n v-for=\"{ item, cssClass, slotName } in gridItems\"\n :key=\"item.id\"\n :class=\"cssClass\"\n class=\"x-base-grid__item\"\n >\n <!--\n @slot Customized item rendering. Specifying a slot with the item's modelName will result in\n the item using that slot composition to render.\n @binding {item} item - Item to render\n -->\n <slot v-if=\"slots[slotName]\" :name=\"slotName\" :item=\"item\" />\n <!--\n @slot (required) Default item rendering. This slot will be used by default for rendering\n the item without an specific slot implementation.\n @binding {item} item - Item to render\n -->\n <slot v-else :item=\"item\">{{ item.name || item.modelName || item.id || item }}</slot>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\n import {\n computed,\n defineComponent,\n inject,\n onBeforeUnmount,\n onMounted,\n PropType,\n Ref,\n ref,\n watch\n } from 'vue';\n import {\n MaybeComputedElementRef,\n useResizeObserver,\n UseResizeObserverReturn\n } from '@vueuse/core';\n import { toKebabCase } from '../utils/string';\n import { ListItem, VueCSSClasses } from '../utils/types';\n import { AnimationProp } from '../types/animation-prop';\n import { useXBus } from '../composables/use-x-bus';\n import { LIST_ITEMS_KEY } from './decorators/injection.consts';\n\n /**\n * The type returned by the gridItems function. Basically it's a list of items with its CSS\n * classes and a slotName.\n */\n interface GridItem {\n slotName: string;\n item: ListItem;\n cssClass: VueCSSClasses;\n }\n\n /**\n * Grid component that is able to render different items based on their modelName value. In order\n * to achieve this, it exposes a scopedSlot for each different modelName. In case the items used\n * do not have modelName property, the default slot is used instead. It has a required property:\n * the `items` to render; and an optional one: the number `columns` the grid is divided in. If the\n * number of columns is not specified, the grid automatically fills the rows with as many columns\n * as it can fit.\n *\n * @public\n */\n export default defineComponent({\n name: 'BaseGrid',\n props: {\n /** Animation component that will be used to animate the base grid. */\n animation: {\n type: AnimationProp,\n default: 'ul'\n },\n /**\n * Number of columns the grid is divided into. By default, its value is 0, setting the grid\n * columns mode to auto-fill.\n */\n columns: {\n type: Number,\n default: 0\n },\n /**\n * The list of items to be rendered.\n *\n * @remarks The items must have an ID property.\n */\n items: {\n type: Array as PropType<ListItem[]>\n }\n },\n setup(props, { slots }) {\n type ElementRef = {\n $el: HTMLElement;\n };\n\n const xBus = useXBus();\n\n /** It injects {@link ListItem} provided by an ancestor. */\n const injectedListItems = inject<Ref<ListItem[]>>(LIST_ITEMS_KEY as string);\n const gridEl = ref<ElementRef | HTMLElement>();\n let renderedColumnsNumber = ref(0);\n\n /**\n * Emits the {@link XEventsTypes.RenderedColumnsNumberChanged}\n * event whenever the number of columns rendered inside the grid changes.\n */\n watch(\n renderedColumnsNumber,\n () => xBus.emit('RenderedColumnsNumberChanged', renderedColumnsNumber.value),\n { immediate: false }\n );\n\n /**\n * It returns the items passed as props or the injected ones.\n *\n * @returns List of grid items.\n */\n const computedItems = computed<ListItem[] | void>(() => {\n return (\n props.items ??\n injectedListItems?.value ??\n //TODO: add here logger\n //eslint-disable-next-line no-console\n console.warn('It is necessary to pass a prop or inject the list of filters')\n );\n });\n\n /**\n * CSS class based on the column property value so items inside the grid can fill different\n * amount of columns or rows based on how many columns the grid is divided into.\n *\n * @returns CSS class with the column property value.\n */\n const cssClasses = computed(() => `x-base-grid--cols-${props.columns || 'auto'}`);\n\n /**\n * CSSStyleDeclaration object specifying the number of columns the grid is divided into based on\n * the column property value.\n *\n * @returns A CSSStyleDeclaration to use as the style attribute.\n */\n const style = computed<Partial<CSSStyleDeclaration>>(() => ({\n gridTemplateColumns: props.columns\n ? `repeat(${props.columns}, minmax(0, 1fr))`\n : 'repeat(auto-fill, minmax(var(--x-size-min-width-grid-item, 150px), 1fr))'\n }));\n\n /**\n * Maps the item to an object containing: the `item`, its `CSS class` and its slot name.\n *\n * @returns An array of objects containing the item and its CSS class.\n */\n const gridItems = computed<GridItem[]>(() =>\n (computedItems.value as ListItem[]).map(item => {\n const slotName = toKebabCase(item.modelName);\n return {\n slotName,\n item,\n cssClass: `x-base-grid__${slotName}`\n };\n })\n );\n\n /**\n * Checks if a given value is an `ElementRef` object.\n *\n * @param value - The value to check.\n * @returns `true` if the value is an `ElementRef` object, `false` otherwise.\n */\n const isElementRef = (value: any): value is ElementRef => {\n return value && value.$el instanceof HTMLElement;\n };\n\n /** Updates the number of columns rendered inside the grid. */\n function updateRenderedColumnsNumber() {\n const { gridTemplateColumns } = getComputedStyle(\n isElementRef(gridEl.value) ? gridEl.value.$el : (gridEl.value as Element)\n );\n renderedColumnsNumber.value = gridTemplateColumns.split(' ').length;\n }\n\n /** Initialises the rendered columns number and sets a ResizeObserver to keep it updated. */\n let resizeObserver: UseResizeObserverReturn;\n onMounted(() => {\n resizeObserver = useResizeObserver(\n gridEl as MaybeComputedElementRef,\n updateRenderedColumnsNumber\n );\n });\n onBeforeUnmount(() => resizeObserver?.stop());\n\n return {\n gridItems,\n cssClasses,\n style,\n gridEl,\n slots\n };\n }\n });\n</script>\n\n<style lang=\"css\" scoped>\n .x-base-grid {\n display: grid;\n grid-auto-flow: dense;\n list-style: none;\n align-items: stretch;\n }\n\n .x-base-grid__banner,\n .x-base-grid__next-queries-group {\n grid-column-start: 1;\n grid-column-end: -1;\n }\n\n .x-base-grid__item {\n display: flex;\n flex-flow: column nowrap;\n }\n\n .x-base-grid__item > * {\n flex-grow: 1;\n }\n\n .x-base-grid--cols-auto .x-base-grid__item {\n min-width: var(--x-size-min-width-grid-item);\n }\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a list of elements in different slots depending on their modelName. In order\nto achieve this, it exposes a scopedSlot for each different modelName. In case the items used do not\nhave modelName property, the default slot is used instead. It has a required property, the `items`\nto render, and an optional one, the number of `columns` the grid is divided in. If the number of\ncolumns is not specified, the grid automatically fills the rows with as many columns as it can fit.\n\n### Basic example\n\nIt renders a list of items using the default slot:\n\n```vue\n<template>\n <BaseGrid :items=\"items\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </BaseGrid>\n</template>\n```\n\n### Configuring the number of columns\n\nIt renders a grid with 12 columns instead of 6, which is the default value:\n\n```vue\n<template>\n <BaseGrid :items=\"items\" :columns=\"12\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </BaseGrid>\n</template>\n```\n\n### Rendering usage\n\nConfiguring the number of columns.\n\nIt renders a list of items using the different scopedSlots created by the item's modelName. For\nexample, if you want to use this component as the search grid, you pass the search results (results,\nbanners, promoted, next queries...etc) as items. Each of these results have a different modelName\nand are rendered in different slots.\n\n```vue\n<template>\n <BaseGrid :animation=\"animation\" :items=\"items\">\n <template #banner=\"{ item }\">\n <span class=\"banner\">\n {{ `${item.title} banner` }}\n </span>\n </template>\n <template #next-queries=\"{ item }\">\n <span>\n {{ `${item.totalResults} next queries` }}\n </span>\n </template>\n <template #promoted=\"{ item }\">\n <span class=\"promoted\">\n {{ `${item.title} promoted` }}\n </span>\n </template>\n <template #result=\"{ item }\">\n <BaseResultLink :result=\"item\">\n {{ item.name }}\n </BaseResultLink>\n </template>\n </BaseGrid>\n</template>\n```\n\n### Customizing the items width\n\nThe `--x-size-min-width-grid-item` variable can be used to customize the min width of the grid\nitems.\n\n```vue\n<template>\n <BaseGrid :items=\"items\" style=\"--x-size-min-width-grid-item: 150px\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </B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YACV,KAAK;YACL,MAAM;YACN,KAAI;SACL,CAAA;KACH;AACD,CAAA,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"base-grid.vue2.js","sources":["../../../src/components/base-grid.vue"],"sourcesContent":["<template>\n <component\n :is=\"animation\"\n ref=\"gridEl\"\n :style=\"style\"\n class=\"x-base-grid\"\n :class=\"cssClasses\"\n tag=\"ul\"\n data-test=\"grid\"\n >\n <li\n v-for=\"{ item, cssClass, slotName } in gridItems\"\n :key=\"item.id\"\n :class=\"cssClass\"\n class=\"x-base-grid__item\"\n >\n <!--\n @slot Customized item rendering. Specifying a slot with the item's modelName will result in\n the item using that slot composition to render.\n @binding {item} item - Item to render\n -->\n <slot v-if=\"slots[slotName]\" :name=\"slotName\" :item=\"item\" />\n <!--\n @slot (required) Default item rendering. This slot will be used by default for rendering\n the item without an specific slot implementation.\n @binding {item} item - Item to render\n -->\n <slot v-else :item=\"item\">{{ item.name || item.modelName || item.id || item }}</slot>\n </li>\n </component>\n</template>\n\n<script lang=\"ts\">\n import {\n computed,\n defineComponent,\n inject,\n onBeforeUnmount,\n onMounted,\n PropType,\n Ref,\n ref,\n watch\n } from 'vue';\n import {\n MaybeComputedElementRef,\n useResizeObserver,\n UseResizeObserverReturn\n } from '@vueuse/core';\n import { toKebabCase } from '../utils/string';\n import { ListItem, VueCSSClasses } from '../utils/types';\n import { AnimationProp } from '../types/animation-prop';\n import { useXBus } from '../composables/use-x-bus';\n import { LIST_ITEMS_KEY } from './decorators/injection.consts';\n\n /**\n * The type returned by the gridItems function. Basically it's a list of items with its CSS\n * classes and a slotName.\n */\n interface GridItem {\n slotName: string;\n item: ListItem;\n cssClass: VueCSSClasses;\n }\n\n /**\n * Grid component that is able to render different items based on their modelName value. In order\n * to achieve this, it exposes a scopedSlot for each different modelName. In case the items used\n * do not have modelName property, the default slot is used instead. It has a required property:\n * the `items` to render; and an optional one: the number `columns` the grid is divided in. If the\n * number of columns is not specified, the grid automatically fills the rows with as many columns\n * as it can fit.\n *\n * @public\n */\n export default defineComponent({\n name: 'BaseGrid',\n props: {\n /** Animation component that will be used to animate the base grid. */\n animation: {\n type: AnimationProp,\n default: 'ul'\n },\n /**\n * Number of columns the grid is divided into. By default, its value is 0, setting the grid\n * columns mode to auto-fill.\n */\n columns: {\n type: Number,\n default: 0\n },\n /**\n * The list of items to be rendered.\n *\n * @remarks The items must have an ID property.\n */\n items: {\n type: Array as PropType<ListItem[]>\n }\n },\n setup(props, { slots }) {\n type ElementRef = {\n $el: HTMLElement;\n };\n\n const xBus = useXBus();\n\n /** It injects {@link ListItem} provided by an ancestor. */\n const injectedListItems = inject<Ref<ListItem[]>>(LIST_ITEMS_KEY as string);\n const gridEl = ref<ElementRef | HTMLElement>();\n let renderedColumnsNumber = ref(0);\n\n /**\n * Emits the {@link XEventsTypes.RenderedColumnsNumberChanged}\n * event whenever the number of columns rendered inside the grid changes.\n */\n watch(\n renderedColumnsNumber,\n () => xBus.emit('RenderedColumnsNumberChanged', renderedColumnsNumber.value),\n { immediate: false }\n );\n\n /**\n * It returns the items passed as props or the injected ones.\n *\n * @returns List of grid items.\n */\n const computedItems = computed<ListItem[] | void>(() => {\n return (\n props.items ??\n injectedListItems?.value ??\n //TODO: add here logger\n //eslint-disable-next-line no-console\n console.warn('It is necessary to pass a prop or inject the list of filters')\n );\n });\n\n /**\n * CSS class based on the column property value so items inside the grid can fill different\n * amount of columns or rows based on how many columns the grid is divided into.\n *\n * @returns CSS class with the column property value.\n */\n const cssClasses = computed(() => `x-base-grid--cols-${props.columns || 'auto'}`);\n\n /**\n * CSSStyleDeclaration object specifying the number of columns the grid is divided into based on\n * the column property value.\n *\n * @returns A CSSStyleDeclaration to use as the style attribute.\n */\n const style = computed<Partial<CSSStyleDeclaration>>(() => ({\n gridTemplateColumns: props.columns\n ? `repeat(${props.columns}, minmax(0, 1fr))`\n : 'repeat(auto-fill, minmax(var(--x-size-min-width-grid-item, 150px), 1fr))'\n }));\n\n /**\n * Maps the item to an object containing: the `item`, its `CSS class` and its slot name.\n *\n * @returns An array of objects containing the item and its CSS class.\n */\n const gridItems = computed<GridItem[]>(() =>\n (computedItems.value as ListItem[]).map(item => {\n const slotName = toKebabCase(item.modelName);\n return {\n slotName,\n item,\n cssClass: `x-base-grid__${slotName}`\n };\n })\n );\n\n /**\n * Checks if a given value is an `ElementRef` object.\n *\n * @param value - The value to check.\n * @returns `true` if the value is an `ElementRef` object, `false` otherwise.\n */\n const isElementRef = (value: any): value is ElementRef => {\n return value && value.$el instanceof HTMLElement;\n };\n\n /** Updates the number of columns rendered inside the grid. */\n function updateRenderedColumnsNumber() {\n const { gridTemplateColumns } = getComputedStyle(\n isElementRef(gridEl.value) ? gridEl.value.$el : (gridEl.value as Element)\n );\n renderedColumnsNumber.value = gridTemplateColumns.split(' ').length;\n }\n\n /** Initialises the rendered columns number and sets a ResizeObserver to keep it updated. */\n let resizeObserver: UseResizeObserverReturn;\n onMounted(() => {\n resizeObserver = useResizeObserver(\n gridEl as MaybeComputedElementRef,\n updateRenderedColumnsNumber\n );\n });\n onBeforeUnmount(() => resizeObserver?.stop());\n\n return {\n gridItems,\n cssClasses,\n style,\n gridEl,\n slots\n };\n }\n });\n</script>\n\n<style lang=\"css\" scoped>\n .x-base-grid {\n display: grid;\n grid-auto-flow: dense;\n list-style: none;\n align-items: stretch;\n }\n\n .x-base-grid__banner,\n .x-base-grid__next-queries-group,\n .x-base-grid__related-prompts-group {\n grid-column-start: 1;\n grid-column-end: -1;\n }\n\n .x-base-grid__item {\n display: flex;\n flex-flow: column nowrap;\n }\n\n .x-base-grid__item > * {\n flex-grow: 1;\n }\n\n .x-base-grid--cols-auto .x-base-grid__item {\n min-width: var(--x-size-min-width-grid-item);\n }\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component renders a list of elements in different slots depending on their modelName. In order\nto achieve this, it exposes a scopedSlot for each different modelName. In case the items used do not\nhave modelName property, the default slot is used instead. It has a required property, the `items`\nto render, and an optional one, the number of `columns` the grid is divided in. If the number of\ncolumns is not specified, the grid automatically fills the rows with as many columns as it can fit.\n\n### Basic example\n\nIt renders a list of items using the default slot:\n\n```vue\n<template>\n <BaseGrid :items=\"items\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </BaseGrid>\n</template>\n```\n\n### Configuring the number of columns\n\nIt renders a grid with 12 columns instead of 6, which is the default value:\n\n```vue\n<template>\n <BaseGrid :items=\"items\" :columns=\"12\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </BaseGrid>\n</template>\n```\n\n### Rendering usage\n\nConfiguring the number of columns.\n\nIt renders a list of items using the different scopedSlots created by the item's modelName. For\nexample, if you want to use this component as the search grid, you pass the search results (results,\nbanners, promoted, next queries...etc) as items. Each of these results have a different modelName\nand are rendered in different slots.\n\n```vue\n<template>\n <BaseGrid :animation=\"animation\" :items=\"items\">\n <template #banner=\"{ item }\">\n <span class=\"banner\">\n {{ `${item.title} banner` }}\n </span>\n </template>\n <template #next-queries=\"{ item }\">\n <span>\n {{ `${item.totalResults} next queries` }}\n </span>\n </template>\n <template #promoted=\"{ item }\">\n <span class=\"promoted\">\n {{ `${item.title} promoted` }}\n </span>\n </template>\n <template #result=\"{ item }\">\n <BaseResultLink :result=\"item\">\n {{ item.name }}\n </BaseResultLink>\n </template>\n </BaseGrid>\n</template>\n```\n\n### Customizing the items width\n\nThe `--x-size-min-width-grid-item` variable can be used to customize the min width of the grid\nitems.\n\n```vue\n<template>\n <BaseGrid :items=\"items\" style=\"--x-size-min-width-grid-item: 150px\">\n <template #default=\"{ item }\">\n {{ `Default slot content: ${item.id}` }}\n </template>\n </BaseGrid>\n</template>\n```\n</docs>\n"],"names":[],"mappings":";;;;;;;AAiEE;;;;;;;;;AASE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,UAAU;AAChB,IAAA,KAAK,EAAE;;AAEL,QAAA,SAAS,EAAE;AACT,YAAA,IAAI,EAAE,aAAa;AACnB,YA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dense;list-style:none}.x-base-grid__banner[data-v-070eaadb],.x-base-grid__next-queries-group[data-v-070eaadb]{grid-column-end:-1;grid-column-start:1}.x-base-grid__item[data-v-070eaadb]{display:flex;flex-flow:column nowrap}.x-base-grid__item[data-v-070eaadb]>*{flex-grow:1}.x-base-grid--cols-auto .x-base-grid__item[data-v-070eaadb]{min-width:var(--x-size-min-width-grid-item)}";
|
|
3
|
+
var css = ".x-base-grid[data-v-070eaadb]{align-items:stretch;display:grid;grid-auto-flow:dense;list-style:none}.x-base-grid__banner[data-v-070eaadb],.x-base-grid__next-queries-group[data-v-070eaadb],.x-base-grid__related-prompts-group[data-v-070eaadb]{grid-column-end:-1;grid-column-start:1}.x-base-grid__item[data-v-070eaadb]{display:flex;flex-flow:column nowrap}.x-base-grid__item[data-v-070eaadb]>*{flex-grow:1}.x-base-grid--cols-auto .x-base-grid__item[data-v-070eaadb]{min-width:var(--x-size-min-width-grid-item)}";
|
|
4
4
|
injectCss(css);
|
|
5
5
|
|
|
6
6
|
export { css, css as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _sfc_main from './base-keyboard-navigation.vue2.js';
|
|
2
|
-
import { openBlock, createElementBlock, withKeys, withModifiers,
|
|
2
|
+
import { openBlock, createElementBlock, withKeys, withModifiers, renderSlot } from 'vue';
|
|
3
3
|
import _export_sfc from '../_virtual/_plugin-vue_export-helper.js';
|
|
4
4
|
|
|
5
5
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
@@ -12,7 +12,6 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
12
12
|
"data-test": "keyboard-navigation"
|
|
13
13
|
},
|
|
14
14
|
[
|
|
15
|
-
createCommentVNode(" @slot (Required) Container content "),
|
|
16
15
|
renderSlot(_ctx.$slots, "default")
|
|
17
16
|
],
|
|
18
17
|
544
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-keyboard-navigation.vue.js","sources":["../../../src/components/base-keyboard-navigation.vue"],"sourcesContent":["<template>\n <div\n ref=\"el\"\n @keydown.up.down.right.left.prevent=\"focusNextNavigableElement\"\n class=\"x-keyboard-navigation\"\n data-test=\"keyboard-navigation\"\n >\n <!-- @slot (Required) Container content -->\n <slot />\n </div>\n</template>\n\n<script lang=\"ts\">\n import { PropType, computed, defineComponent, onMounted, ref } from 'vue';\n // eslint-disable-next-line max-len\n import { DirectionalFocusNavigationService } from '../services/directional-focus-navigation.service';\n import { SpatialNavigation } from '../services/services.types';\n import { ArrowKey, EventsForDirectionLimit, TakeNavigationControl } from '../utils/types';\n import { XEventsOf } from '../wiring/events.types';\n import { WireMetadata } from '../wiring/wiring.types';\n import { useXBus } from '../composables';\n\n /**\n * Base component to handle keyboard navigation for elements inside it. It has a required slot to\n * include the navigable elements.\n *\n * @remarks\n * The component can be customized through props: an array of navigationHijacker objects, which\n * contains: the xEvent to listen to, the moduleName in charge of emitting the event and to which\n * direction it should react to; to take control of the navigation and eventsForDirectionLimit, to\n * emit an xEvent when reaching the navigation limit in any direction.\n *\n * @public\n */\n export default defineComponent({\n name: 'BaseKeyboardNavigation',\n props: {\n /**\n * An array of {@link TakeNavigationControl} objects defining when to\n * take control of the keyboard navigation.\n */\n navigationHijacker: {\n type: Array as PropType<TakeNavigationControl[]>,\n default: () => [\n { xEvent: 'UserPressedArrowKey', moduleName: 'searchBox', direction: 'ArrowDown' }\n ]\n },\n /**\n * An {@link EventsForDirectionLimit} to emit when the user is already at the furthest element\n * in a direction and tries to keep going on the same direction.\n */\n eventsForDirectionLimit: {\n type: Object as PropType<Partial<EventsForDirectionLimit>>,\n default: () => ({ ArrowUp: 'UserReachedEmpathizeTop' })\n }\n },\n setup: function (props) {\n const el = ref<HTMLElement>();\n const xBus = useXBus();\n\n /**\n * The {@link SpatialNavigation} service to use.\n */\n let navigationService!: SpatialNavigation;\n\n /**\n * The element to focus.\n */\n let elementToFocus: HTMLElement | undefined;\n\n /**\n * Get the navigation hijacker events.\n *\n * @remarks\n * If the same {@link XEvent} is defined multiple times it is only inserted once.\n *\n * @returns The events to hijack the navigation.\n */\n const navigationHijackerEvents = computed((): XEventsOf<ArrowKey>[] => {\n const eventsSet = props.navigationHijacker.map(({ xEvent }) => xEvent);\n return Array.from(new Set(eventsSet));\n });\n\n onMounted(() => {\n // TODO Replace this with injection\n navigationService = new DirectionalFocusNavigationService(el.value!);\n });\n\n /**\n * Checks if the component has to take control of the keyboard navigation.\n *\n * @param eventPayload - The {@link ArrowKey}.\n * @param metadata - The {@link WireMetadata}.\n *\n * @returns Whether the component needs to take control of the keyboard navigation or not.\n * @internal\n */\n function hasToTakeNavigationControl(eventPayload: ArrowKey, metadata: WireMetadata): boolean {\n return props.navigationHijacker.some(\n ({ moduleName, direction }) =>\n moduleName === metadata.moduleName && direction === eventPayload\n );\n }\n\n /**\n * Focus the next navigable element returned by the navigation service.\n *\n * @param direction - The navigation direction.\n * @internal\n */\n function focusNextNavigableElement(direction: ArrowKey | KeyboardEvent): void {\n const dir = typeof direction === 'object' ? (direction.key as ArrowKey) : direction;\n const nextElementToFocus = navigationService?.navigateTo(dir);\n\n if (elementToFocus !== nextElementToFocus) {\n elementToFocus = nextElementToFocus;\n elementToFocus.focus();\n } else {\n emitDirectionalLimitReached(dir);\n elementToFocus = undefined;\n }\n }\n\n /**\n * Emit the {@link XEvent} associated to the navigation's direction when reaching its limit.\n *\n * @param direction - The navigation direction.\n * @internal\n */\n function emitDirectionalLimitReached(direction: ArrowKey): void {\n const xEvent = props.eventsForDirectionLimit?.[direction];\n if (xEvent) {\n xBus.emit(xEvent, undefined, { target: elementToFocus });\n }\n }\n\n /**\n * Trigger navigation if this component is in control of it.\n *\n * @param eventPayload - The {@link @empathyco/x-bus#SubjectPayload.eventPayload}.\n * @param metadata - The {@link @empathyco/x-bus#SubjectPayload.metadata}.\n * @public\n */\n navigationHijackerEvents.value.forEach(event => {\n xBus.on(event, true).subscribe(({ eventPayload, metadata }) => {\n if (hasToTakeNavigationControl(eventPayload, metadata)) {\n focusNextNavigableElement(eventPayload);\n }\n });\n });\n\n return { el, focusNextNavigableElement };\n }\n });\n</script>\n\n<docs lang=\"mdx\">\n## Events\n\nAn event that the component will emit:\n\n- [`UserReachedEmpathizeTop`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n the event emitted by default when the container reaches its top navigation, but more events can be\n emitted for each direction using the `eventsForDirectionLimit` prop.\n\n## Examples\n\nThis component has a slot to inject other components inside it. The component expects a required\nprop, navigationHijacker, which is an array of objects containing: the xEvent to listen to, the\nmoduleName in charge of emitting the event and to which direction it should react to; to take\ncontrol of the navigation. It has another prop, optional in this case, to emit an xEvent when\nreaching the navigation limit in any direction.\n\n### Basic Usage\n\n```vue\n<KeyboardNavigation>\n <QuerySuggestions/>\n</KeyboardNavigation>\n```\n\n### Defining multiple conditions to take navigation's control\n\n```vue\n<KeyboardNavigation\n :navigationHijacker=\"[\n {\n xEvent: 'UserPressedArrowKey',\n moduleName: 'searchBox',\n direction: 'ArrowDown'\n },\n {\n xEvent: 'UserPressedArrowKey',\n moduleName: 'facets',\n direction: 'ArrowRight'\n }\n ]\"\n>\n <QuerySuggestions/>\n</KeyboardNavigation>\n```\n\n### Defining events to emit when reaching a navigation limit\n\n```vue\n<KeyboardNavigation\n :navigationHijacker=\"[\n {\n xEvent: 'UserPressedArrowKey',\n moduleName: 'searchBox',\n direction: 'ArrowDown'\n }\n ]\"\n :eventsForDirectionLimit=\"{\n ArrowUp: 'UserReachedEmpathizeTop'\n }\"\n>\n <QuerySuggestions/>\n</KeyboardNavigation>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_withKeys","_withModifiers"
|
|
1
|
+
{"version":3,"file":"base-keyboard-navigation.vue.js","sources":["../../../src/components/base-keyboard-navigation.vue"],"sourcesContent":["<template>\n <div\n ref=\"el\"\n @keydown.up.down.right.left.prevent=\"focusNextNavigableElement\"\n class=\"x-keyboard-navigation\"\n data-test=\"keyboard-navigation\"\n >\n <!-- @slot (Required) Container content -->\n <slot />\n </div>\n</template>\n\n<script lang=\"ts\">\n import { PropType, computed, defineComponent, onMounted, ref } from 'vue';\n // eslint-disable-next-line max-len\n import { DirectionalFocusNavigationService } from '../services/directional-focus-navigation.service';\n import { SpatialNavigation } from '../services/services.types';\n import { ArrowKey, EventsForDirectionLimit, TakeNavigationControl } from '../utils/types';\n import { XEventsOf } from '../wiring/events.types';\n import { WireMetadata } from '../wiring/wiring.types';\n import { useXBus } from '../composables';\n\n /**\n * Base component to handle keyboard navigation for elements inside it. It has a required slot to\n * include the navigable elements.\n *\n * @remarks\n * The component can be customized through props: an array of navigationHijacker objects, which\n * contains: the xEvent to listen to, the moduleName in charge of emitting the event and to which\n * direction it should react to; to take control of the navigation and eventsForDirectionLimit, to\n * emit an xEvent when reaching the navigation limit in any direction.\n *\n * @public\n */\n export default defineComponent({\n name: 'BaseKeyboardNavigation',\n props: {\n /**\n * An array of {@link TakeNavigationControl} objects defining when to\n * take control of the keyboard navigation.\n */\n navigationHijacker: {\n type: Array as PropType<TakeNavigationControl[]>,\n default: () => [\n { xEvent: 'UserPressedArrowKey', moduleName: 'searchBox', direction: 'ArrowDown' }\n ]\n },\n /**\n * An {@link EventsForDirectionLimit} to emit when the user is already at the furthest element\n * in a direction and tries to keep going on the same direction.\n */\n eventsForDirectionLimit: {\n type: Object as PropType<Partial<EventsForDirectionLimit>>,\n default: () => ({ ArrowUp: 'UserReachedEmpathizeTop' })\n }\n },\n setup: function (props) {\n const el = ref<HTMLElement>();\n const xBus = useXBus();\n\n /**\n * The {@link SpatialNavigation} service to use.\n */\n let navigationService!: SpatialNavigation;\n\n /**\n * The element to focus.\n */\n let elementToFocus: HTMLElement | undefined;\n\n /**\n * Get the navigation hijacker events.\n *\n * @remarks\n * If the same {@link XEvent} is defined multiple times it is only inserted once.\n *\n * @returns The events to hijack the navigation.\n */\n const navigationHijackerEvents = computed((): XEventsOf<ArrowKey>[] => {\n const eventsSet = props.navigationHijacker.map(({ xEvent }) => xEvent);\n return Array.from(new Set(eventsSet));\n });\n\n onMounted(() => {\n // TODO Replace this with injection\n navigationService = new DirectionalFocusNavigationService(el.value!);\n });\n\n /**\n * Checks if the component has to take control of the keyboard navigation.\n *\n * @param eventPayload - The {@link ArrowKey}.\n * @param metadata - The {@link WireMetadata}.\n *\n * @returns Whether the component needs to take control of the keyboard navigation or not.\n * @internal\n */\n function hasToTakeNavigationControl(eventPayload: ArrowKey, metadata: WireMetadata): boolean {\n return props.navigationHijacker.some(\n ({ moduleName, direction }) =>\n moduleName === metadata.moduleName && direction === eventPayload\n );\n }\n\n /**\n * Focus the next navigable element returned by the navigation service.\n *\n * @param direction - The navigation direction.\n * @internal\n */\n function focusNextNavigableElement(direction: ArrowKey | KeyboardEvent): void {\n const dir = typeof direction === 'object' ? (direction.key as ArrowKey) : direction;\n const nextElementToFocus = navigationService?.navigateTo(dir);\n\n if (elementToFocus !== nextElementToFocus) {\n elementToFocus = nextElementToFocus;\n elementToFocus.focus();\n } else {\n emitDirectionalLimitReached(dir);\n elementToFocus = undefined;\n }\n }\n\n /**\n * Emit the {@link XEvent} associated to the navigation's direction when reaching its limit.\n *\n * @param direction - The navigation direction.\n * @internal\n */\n function emitDirectionalLimitReached(direction: ArrowKey): void {\n const xEvent = props.eventsForDirectionLimit?.[direction];\n if (xEvent) {\n xBus.emit(xEvent, undefined, { target: elementToFocus });\n }\n }\n\n /**\n * Trigger navigation if this component is in control of it.\n *\n * @param eventPayload - The {@link @empathyco/x-bus#SubjectPayload.eventPayload}.\n * @param metadata - The {@link @empathyco/x-bus#SubjectPayload.metadata}.\n * @public\n */\n navigationHijackerEvents.value.forEach(event => {\n xBus.on(event, true).subscribe(({ eventPayload, metadata }) => {\n if (hasToTakeNavigationControl(eventPayload, metadata)) {\n focusNextNavigableElement(eventPayload);\n }\n });\n });\n\n return { el, focusNextNavigableElement };\n }\n });\n</script>\n\n<docs lang=\"mdx\">\n## Events\n\nAn event that the component will emit:\n\n- [`UserReachedEmpathizeTop`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts):\n the event emitted by default when the container reaches its top navigation, but more events can be\n emitted for each direction using the `eventsForDirectionLimit` prop.\n\n## Examples\n\nThis component has a slot to inject other components inside it. The component expects a required\nprop, navigationHijacker, which is an array of objects containing: the xEvent to listen to, the\nmoduleName in charge of emitting the event and to which direction it should react to; to take\ncontrol of the navigation. It has another prop, optional in this case, to emit an xEvent when\nreaching the navigation limit in any direction.\n\n### Basic Usage\n\n```vue\n<KeyboardNavigation>\n <QuerySuggestions/>\n</KeyboardNavigation>\n```\n\n### Defining multiple conditions to take navigation's control\n\n```vue\n<KeyboardNavigation\n :navigationHijacker=\"[\n {\n xEvent: 'UserPressedArrowKey',\n moduleName: 'searchBox',\n direction: 'ArrowDown'\n },\n {\n xEvent: 'UserPressedArrowKey',\n moduleName: 'facets',\n direction: 'ArrowRight'\n }\n ]\"\n>\n <QuerySuggestions/>\n</KeyboardNavigation>\n```\n\n### Defining events to emit when reaching a navigation limit\n\n```vue\n<KeyboardNavigation\n :navigationHijacker=\"[\n {\n xEvent: 'UserPressedArrowKey',\n moduleName: 'searchBox',\n direction: 'ArrowDown'\n }\n ]\"\n :eventsForDirectionLimit=\"{\n ArrowUp: 'UserReachedEmpathizeTop'\n }\"\n>\n <QuerySuggestions/>\n</KeyboardNavigation>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_withKeys","_withModifiers"],"mappings":";;;;SAEQ,WAAI,CAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,EAAA,KAAA,EAAA,QAAA,EAAA;SACPA,SAAO,EAAA,EAAAC,kBAAA;AAAA,IAHZ,KAAA;AAAA,IAAA;AAAA,MAII,GAAK,EAAA,IAAA;AAAA,MACL,SAAA,EAAS,OAAC,CAAqB,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAAC,QAAA,CAAAC,aAAA,CAAA,CAAA,GAAA,IAAA,KAAA,IAAA,CAAA,yBAAA,IAAA,IAAA,CAAA,yBAAA,CAAA,GAAA,IAAA,CAAA,EAAA,CAAA,SAAA,CAAA,CAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,OAAA,EAAA,MAAA,CAAA,CAAA,CAAA;AAAA,MAAA,KAAA,EAAA,uBAAA;MAG/B,WAAQ,EAAA,qBAAA;AAAA,KAAA;;;;;;;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _sfc_main from './base-rating.vue2.js';
|
|
2
|
-
import { resolveComponent, openBlock, createElementBlock, createElementVNode,
|
|
2
|
+
import { resolveComponent, openBlock, createElementBlock, createElementVNode, Fragment, renderList, renderSlot, createBlock, normalizeStyle } from 'vue';
|
|
3
3
|
import './base-rating.vue3.js';
|
|
4
4
|
import _export_sfc from '../_virtual/_plugin-vue_export-helper.js';
|
|
5
5
|
|
|
@@ -17,7 +17,6 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
17
17
|
"data-test": "rating"
|
|
18
18
|
}, [
|
|
19
19
|
createElementVNode("div", _hoisted_2, [
|
|
20
|
-
createCommentVNode("\n @slot The content to render as empty icon\n "),
|
|
21
20
|
(openBlock(true), createElementBlock(
|
|
22
21
|
Fragment,
|
|
23
22
|
null,
|
|
@@ -41,7 +40,6 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
41
40
|
"data-test": "rating-filled"
|
|
42
41
|
},
|
|
43
42
|
[
|
|
44
|
-
createCommentVNode("\n @slot The content to render as filled icon\n "),
|
|
45
43
|
(openBlock(true), createElementBlock(
|
|
46
44
|
Fragment,
|
|
47
45
|
null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-rating.vue.js","sources":["../../../src/components/base-rating.vue"],"sourcesContent":["<template>\n <span class=\"x-rating\" role=\"img\" :aria-label=\"ariaLabel\" data-test=\"rating\">\n <div class=\"x-rating--empty\" data-test=\"rating-empty\">\n <!--\n @slot The content to render as empty icon\n -->\n <slot v-for=\"i in max\" name=\"empty-icon\">\n <DefaultIcon :key=\"i\" class=\"x-rating__default-icon x-rating__default-icon--empty\" />\n </slot>\n </div>\n <div\n class=\"x-rating--filled\"\n :style=\"{ width: calculateFilledWrapperWidth }\"\n data-test=\"rating-filled\"\n >\n <!--\n @slot The content to render as filled icon\n -->\n <slot v-for=\"i in max\" name=\"filled-icon\">\n <DefaultIcon :key=\"i\" class=\"x-rating__default-icon x-rating__default-icon--filled\" />\n </slot>\n </div>\n </span>\n</template>\n\n<script lang=\"ts\">\n import { computed, defineComponent } from 'vue';\n import StarIcon from './icons/star.vue';\n\n /**\n * Rating component. This component renders a set of elements filled based on the value passed as\n * prop.\n *\n * @public\n */\n export default defineComponent({\n name: 'BaseRating',\n components: {\n DefaultIcon: StarIcon\n },\n props: {\n /**\n * Numeric value used to calculates the width of the filled elements.\n *\n * @public\n */\n value: {\n type: Number,\n required: true\n },\n /**\n * Maximum number of elements to paint.\n *\n * @public\n */\n max: {\n type: Number,\n default: 5\n }\n },\n setup(props) {\n /**\n * Calculates the width of the filled elements wrapper.\n *\n * @returns The % of the wrapper width.\n *\n * @internal\n */\n const calculateFilledWrapperWidth = computed(() => {\n return props.value < 0 ? '0%' : `${(props.value * 100) / props.max}%`;\n });\n\n /**\n * Creates the aria label for accessibility purpose.\n *\n * @returns The aria label.\n *\n * @internal\n */\n const ariaLabel = computed(() => {\n return `${props.value}/${props.max}`;\n });\n\n return {\n calculateFilledWrapperWidth,\n ariaLabel\n };\n }\n });\n</script>\n\n<style lang=\"css\" scoped>\n .x-rating {\n position: relative;\n display: inline-block;\n max-width: fit-content;\n }\n\n .x-rating--empty {\n overflow: hidden;\n display: flex;\n flex-flow: row nowrap;\n white-space: nowrap;\n }\n\n .x-rating--filled {\n display: flex;\n flex-flow: row nowrap;\n white-space: nowrap;\n position: absolute;\n overflow: hidden;\n top: 0;\n left: 0;\n height: 100%;\n }\n\n .x-rating__default-icon {\n fill: currentColor;\n stroke: currentColor;\n }\n\n .x-rating__default-icon--empty {\n fill: none;\n }\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component receives a `value` as prop and renders a set of elements, which will be filled based\non this value.\n\n### Basic usage\n\n```vue\n<BaseRating :value=\"5.23\" />\n```\n\n### Customizing its contents\n\n```vue\n<BaseRating :value=\"7.15\" :max=\"10\">\n <template #filled-icon>\n <TestIcon/>\n </template>\n <template #empty-icon>\n <TestIcon/>\n </template>\n</BaseRating>\n```\n</docs>\n"],"names":["_resolveComponent","_openBlock","_createElementBlock","
|
|
1
|
+
{"version":3,"file":"base-rating.vue.js","sources":["../../../src/components/base-rating.vue"],"sourcesContent":["<template>\n <span class=\"x-rating\" role=\"img\" :aria-label=\"ariaLabel\" data-test=\"rating\">\n <div class=\"x-rating--empty\" data-test=\"rating-empty\">\n <!--\n @slot The content to render as empty icon\n -->\n <slot v-for=\"i in max\" name=\"empty-icon\">\n <DefaultIcon :key=\"i\" class=\"x-rating__default-icon x-rating__default-icon--empty\" />\n </slot>\n </div>\n <div\n class=\"x-rating--filled\"\n :style=\"{ width: calculateFilledWrapperWidth }\"\n data-test=\"rating-filled\"\n >\n <!--\n @slot The content to render as filled icon\n -->\n <slot v-for=\"i in max\" name=\"filled-icon\">\n <DefaultIcon :key=\"i\" class=\"x-rating__default-icon x-rating__default-icon--filled\" />\n </slot>\n </div>\n </span>\n</template>\n\n<script lang=\"ts\">\n import { computed, defineComponent } from 'vue';\n import StarIcon from './icons/star.vue';\n\n /**\n * Rating component. This component renders a set of elements filled based on the value passed as\n * prop.\n *\n * @public\n */\n export default defineComponent({\n name: 'BaseRating',\n components: {\n DefaultIcon: StarIcon\n },\n props: {\n /**\n * Numeric value used to calculates the width of the filled elements.\n *\n * @public\n */\n value: {\n type: Number,\n required: true\n },\n /**\n * Maximum number of elements to paint.\n *\n * @public\n */\n max: {\n type: Number,\n default: 5\n }\n },\n setup(props) {\n /**\n * Calculates the width of the filled elements wrapper.\n *\n * @returns The % of the wrapper width.\n *\n * @internal\n */\n const calculateFilledWrapperWidth = computed(() => {\n return props.value < 0 ? '0%' : `${(props.value * 100) / props.max}%`;\n });\n\n /**\n * Creates the aria label for accessibility purpose.\n *\n * @returns The aria label.\n *\n * @internal\n */\n const ariaLabel = computed(() => {\n return `${props.value}/${props.max}`;\n });\n\n return {\n calculateFilledWrapperWidth,\n ariaLabel\n };\n }\n });\n</script>\n\n<style lang=\"css\" scoped>\n .x-rating {\n position: relative;\n display: inline-block;\n max-width: fit-content;\n }\n\n .x-rating--empty {\n overflow: hidden;\n display: flex;\n flex-flow: row nowrap;\n white-space: nowrap;\n }\n\n .x-rating--filled {\n display: flex;\n flex-flow: row nowrap;\n white-space: nowrap;\n position: absolute;\n overflow: hidden;\n top: 0;\n left: 0;\n height: 100%;\n }\n\n .x-rating__default-icon {\n fill: currentColor;\n stroke: currentColor;\n }\n\n .x-rating__default-icon--empty {\n fill: none;\n }\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\nThis component receives a `value` as prop and renders a set of elements, which will be filled based\non this value.\n\n### Basic usage\n\n```vue\n<BaseRating :value=\"5.23\" />\n```\n\n### Customizing its contents\n\n```vue\n<BaseRating :value=\"7.15\" :max=\"10\">\n <template #filled-icon>\n <TestIcon/>\n </template>\n <template #empty-icon>\n <TestIcon/>\n </template>\n</BaseRating>\n```\n</docs>\n"],"names":["_resolveComponent","_openBlock","_createElementBlock","_Fragment","_renderList","_renderSlot","_createBlock","_normalizeStyle"],"mappings":";;;;;AAES,MAAA,UAAA,GAAM,CAAiB,YAAA,CAAA,CAAA;MAAC,UAAU,GAAA;AAAA,EAAA,KAAA,EAAA,iBAAA;;;;iCADzCA,gBAqBO,CAAA,aAAA,CAAA,CAAA;SArBqBC,SAAK,EAAA,EAAAC,kBAAA,CAAA,MAAA,EAAA;AAAA,IAAE,KAAA,EAAA,UAAA;AAAA,IAAuB,IAAA,EAAA,KAAA;AAAA,IAAA,YAAA,EAAA,IAAA,CAAA,SAAA;AACxD,IAAA,WAAA,EAAA,QAAA;AAAA,GAAA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