10 lines
17 KiB
JavaScript
Raw Permalink Normal View History

/*!
* This source file is part of the Swift.org open source project
*
* Copyright (c) 2021 Apple Inc. and the Swift project authors
* Licensed under Apache License v2.0 with Runtime Library Exception
*
* See https://swift.org/LICENSE.txt for license information
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
"use strict";(self["webpackChunkswift_docc_render"]=self["webpackChunkswift_docc_render"]||[]).push([[842],{5590:function(t,e,n){n.d(e,{Z:function(){return m}});var s=function(){var t=this,e=t._self._c;return e("PortalSource",{attrs:{to:"modal-destination",disabled:!t.isVisible}},[e("div",{directives:[{name:"show",rawName:"v-show",value:t.isVisible,expression:"isVisible"}],staticClass:"generic-modal",class:[t.stateClasses,t.themeClass],style:t.modalColors,attrs:{role:"dialog"}},[e("div",{staticClass:"backdrop",on:{click:t.onClickOutside}}),e("div",{ref:"container",staticClass:"container",style:{width:t.width}},[t.showClose?e("button",{ref:"close",staticClass:"close",attrs:{"aria-label":t.$t("verbs.close")},on:{click:function(e){return e.preventDefault(),t.closeModal.apply(null,arguments)}}},[e("CloseIcon")],1):t._e(),e("div",{ref:"content",staticClass:"modal-content"},[t._t("default")],2)])])])},r=[],o=n(9652),i=n(114),a=n(1147),l=n(2433),c=n(1970);const u={light:"light",dark:"dark",dynamic:"dynamic",code:"code"};var h={name:"GenericModal",model:{prop:"visible",event:"update:visible"},components:{CloseIcon:c.Z,PortalSource:l.h_},props:{visible:{type:Boolean,default:!1},isFullscreen:{type:Boolean,default:!1},theme:{type:String,validator:t=>Object.keys(u).includes(t),default:u.light},codeBackgroundColorOverride:{type:String,default:""},backdropBackgroundColorOverride:{type:String,default:""},width:{type:String,default:null},showClose:{type:Boolean,default:!0}},data(){return{lastFocusItem:null,prefersDarkStyle:!1,focusTrapInstance:null}},computed:{isVisible:{get:({visible:t})=>t,set(t){this.$emit("update:visible",t)}},modalColors(){return{"--code-background":this.codeBackgroundColorOverride,"--backdrop-background":this.backdropBackgroundColorOverride}},themeClass({theme:t,prefersDarkStyle:e,isThemeDynamic:n}){let s={};return n&&(s={"theme-light":!e,"theme-dark":e}),[`theme-${t}`,s]},stateClasses:({isFullscreen:t,isVisible:e,showClose:n})=>({"modal-fullscreen":t,"modal-standard":!t,"modal-open":e,"modal-with-close":n}),isThemeDynamic:({theme:t})=>t===u.dynamic||t===u.code},watch:{isVisible(t){t?this.onShow():this.onHide()}},mounted(){if(this.focusTrapInstance=new i.Z,document.addEventListener("keydown",this.onKeydown),this.isThemeDynamic){const t=window.matchMedia("(prefers-color-scheme: dark)");t.addListener(this.onColorSchemePreferenceChange),this.$once("hook:beforeDestroy",(()=>{t.removeListener(this.onColorSchemePreferenceChange)})),this.onColorSchemePreferenceChange(t)}},beforeDestroy(){this.isVisible&&o.Z.unlockScroll(this.$refs.container),document.removeEventListener("keydown",this.onKeydown),this.focusTrapInstance.destroy()},methods:{async onShow(){await this.$nextTick(),o.Z.lockScroll(this.$refs.container),await this.focusCloseButton(),this.focusTrapInstance.updateFocusContainer(this.$refs.container),this.focusTrapInstance.start(),a.Z.hide(this.$refs.container)},onHide(){o.Z.unlockScroll(this.$refs.container),this.focusTrapInstance.stop(),this.lastFocusItem&&(this.lastFocusItem.focus({preventScroll:!0}),this.lastFocusItem=null),this.$emit("close"),a.Z.show(this.$refs.container)},closeModal(){this.isVisible=!1},selectContent(){window.getSelection().selectAllChildren(this.$refs.content)},onClickOutside(){this.closeModal()},onKeydown(t){const{metaKey:e=!1,ctrlKey:n=!1,key:s}=t;this.isVisible&&("a"===s&&(e||n)&&(t.preventDefault(),this.selectContent()),"Escape"===s&&(t.preventDefault(),this.closeModal()))},onColorSchemePreferenceChange({matches:t}){this.prefersDarkStyle=t},async focusCloseButton(){this.lastFocusItem=document.activeElement,await this.$nextTick(),this.$refs.close&&this.$refs.close.focus(),this.$emit("open")}}},d=h,f=n(1001),p=(0,f.Z)(d,s,r,!1,null,"795f7b59",null),m=p.exports},5151:function(t,e,n){n.d(e,{Z:function(){return u}});var s=function(){var t=this,e=t._self._c;return e("SVGIcon",{staticClass:"inline-chevron-down-icon",attrs:{viewBox:"0 0 14 14",themeId:"inline-chevron-down"}},[e("path",{attrs:{d:"M12.634 2.964l0.76 0.649-6.343 7.426-6.445-7.423 0.755-0.655 5.683 6.545 5.59-6.542z"}})])},r=[],o=n