@designbasekorea/ui-wc 0.5.3 → 0.5.6
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/dist/chunks/lottie-e273b936.js +17032 -0
- package/dist/esm/components/animation-background/canvas-controller.js +121 -1
- package/dist/esm/components/animation-background/controls.js +180 -1
- package/dist/esm/components/animation-background/graphite-controller.js +196 -1
- package/dist/esm/components/animation-background/graphite-presets.js +42 -1
- package/dist/esm/components/animation-background/graphite-shader.js +111 -1
- package/dist/esm/components/animation-background/layers.js +369 -1
- package/dist/esm/components/animation-background/lumina-presets.js +53 -1
- package/dist/esm/components/animation-background/lumina-shaders.js +181 -1
- package/dist/esm/components/animation-background/lumina-utils.js +60 -1
- package/dist/esm/components/animation-background/particle-defaults.js +36 -1
- package/dist/esm/components/animation-background/renderers.js +167 -1
- package/dist/esm/components/animation-background/shader-controller.js +154 -1
- package/dist/esm/components/color-picker-utils.js +134 -1
- package/dist/esm/components/date-picker-utils.js +140 -1
- package/dist/esm/components/db-accordion.js +304 -1
- package/dist/esm/components/db-ad-banner.js +455 -1
- package/dist/esm/components/db-alert.js +149 -1
- package/dist/esm/components/db-animation-background.js +486 -1
- package/dist/esm/components/db-animation-text.js +601 -1
- package/dist/esm/components/db-app-badge.js +88 -1
- package/dist/esm/components/db-audio-player.js +752 -1
- package/dist/esm/components/db-avatar.js +188 -1
- package/dist/esm/components/db-backdrop.js +139 -1
- package/dist/esm/components/db-badge.js +91 -1
- package/dist/esm/components/db-banner.js +188 -1
- package/dist/esm/components/db-bottom-navigation.js +146 -1
- package/dist/esm/components/db-bottom-sheet.js +481 -1
- package/dist/esm/components/db-breadcrumbs.js +329 -1
- package/dist/esm/components/db-button.js +316 -1
- package/dist/esm/components/db-calendar.js +675 -1
- package/dist/esm/components/db-card.js +265 -1
- package/dist/esm/components/db-carousel.js +264 -1
- package/dist/esm/components/db-checkbox.js +202 -1
- package/dist/esm/components/db-chip.js +104 -1
- package/dist/esm/components/db-code-block.js +304 -1
- package/dist/esm/components/db-color-picker.js +746 -1
- package/dist/esm/components/db-confirm.js +191 -1
- package/dist/esm/components/db-container.js +39 -1
- package/dist/esm/components/db-context-menu.js +265 -1
- package/dist/esm/components/db-countdown.js +146 -1
- package/dist/esm/components/db-cursor-follower.js +173 -1
- package/dist/esm/components/db-date-picker.js +837 -1
- package/dist/esm/components/db-divider.js +66 -1
- package/dist/esm/components/db-drawer.js +245 -1
- package/dist/esm/components/db-dropdown.js +493 -1
- package/dist/esm/components/db-dropzone.js +266 -1
- package/dist/esm/components/db-empty-state.js +97 -1
- package/dist/esm/components/db-file-uploader.js +256 -1
- package/dist/esm/components/db-floating-action-button.js +139 -1
- package/dist/esm/components/db-footer.js +385 -1
- package/dist/esm/components/db-form.js +566 -1
- package/dist/esm/components/db-gantt.js +882 -1
- package/dist/esm/components/db-gradient.js +133 -1
- package/dist/esm/components/db-grid-background.js +909 -1
- package/dist/esm/components/db-grid.js +73 -1
- package/dist/esm/components/db-icons.js +82 -1
- package/dist/esm/components/db-image-list.js +214 -1
- package/dist/esm/components/db-image-placeholder.js +96 -1
- package/dist/esm/components/db-image.js +289 -1
- package/dist/esm/components/db-indicator.js +517 -1
- package/dist/esm/components/db-input.js +420 -1
- package/dist/esm/components/db-kanban.js +538 -1
- package/dist/esm/components/db-label.js +66 -1
- package/dist/esm/components/db-lightbox.js +372 -1
- package/dist/esm/components/db-list.js +340 -1
- package/dist/esm/components/db-logo-svg.js +72 -1
- package/dist/esm/components/db-logo.js +106 -1
- package/dist/esm/components/db-lottie.js +109 -1
- package/dist/esm/components/db-markdown-editor.js +458 -1
- package/dist/esm/components/db-marquee.js +402 -1
- package/dist/esm/components/db-masonry.js +94 -1
- package/dist/esm/components/db-menu-item.js +211 -1
- package/dist/esm/components/db-modal.js +522 -1
- package/dist/esm/components/db-navbar.js +680 -1
- package/dist/esm/components/db-onboarding-modal.js +322 -1
- package/dist/esm/components/db-page-header.js +312 -1
- package/dist/esm/components/db-pagination.js +271 -1
- package/dist/esm/components/db-popover.js +580 -1
- package/dist/esm/components/db-progress-step.js +166 -1
- package/dist/esm/components/db-progress.js +171 -1
- package/dist/esm/components/db-progressbar.js +72 -1
- package/dist/esm/components/db-radio.js +172 -1
- package/dist/esm/components/db-random-gradient.js +121 -1
- package/dist/esm/components/db-range-slider.js +811 -1
- package/dist/esm/components/db-rating.js +325 -1
- package/dist/esm/components/db-reorder.js +286 -1
- package/dist/esm/components/db-resizable-panels.js +282 -1
- package/dist/esm/components/db-scroll-area.js +126 -1
- package/dist/esm/components/db-search-bar.js +668 -1
- package/dist/esm/components/db-section-app-download.js +101 -1
- package/dist/esm/components/db-section-contact.js +102 -1
- package/dist/esm/components/db-section-cta.js +150 -1
- package/dist/esm/components/db-section-faq.js +120 -1
- package/dist/esm/components/db-section-feature-grid.js +137 -1
- package/dist/esm/components/db-section-feature.js +179 -1
- package/dist/esm/components/db-section-hero.js +243 -1
- package/dist/esm/components/db-section-logo-cloud.js +138 -1
- package/dist/esm/components/db-section-pricing.js +166 -1
- package/dist/esm/components/db-section-stats.js +129 -1
- package/dist/esm/components/db-section-testimonials.js +252 -1
- package/dist/esm/components/db-section.js +385 -1
- package/dist/esm/components/db-segment-control.js +231 -1
- package/dist/esm/components/db-select.js +571 -1
- package/dist/esm/components/db-share-icons.js +40 -1
- package/dist/esm/components/db-share.js +489 -1
- package/dist/esm/components/db-sidebar.js +1068 -1
- package/dist/esm/components/db-skeleton.js +94 -1
- package/dist/esm/components/db-spinner.js +102 -1
- package/dist/esm/components/db-split-view.js +297 -1
- package/dist/esm/components/db-stack.js +46 -1
- package/dist/esm/components/db-stat.js +218 -1
- package/dist/esm/components/db-stepper.js +398 -1
- package/dist/esm/components/db-table.js +412 -1
- package/dist/esm/components/db-tabs.js +335 -1
- package/dist/esm/components/db-testimonial.js +162 -1
- package/dist/esm/components/db-textarea.js +233 -1
- package/dist/esm/components/db-time-picker.js +523 -1
- package/dist/esm/components/db-timeline.js +174 -1
- package/dist/esm/components/db-toast.js +158 -1
- package/dist/esm/components/db-toggle.js +162 -1
- package/dist/esm/components/db-toolbar.js +94 -1
- package/dist/esm/components/db-tooltip.js +440 -1
- package/dist/esm/components/db-top-banner.js +121 -1
- package/dist/esm/components/db-tutorial.js +324 -1
- package/dist/esm/components/db-video-player.js +503 -1
- package/dist/esm/components/db-youtube-player.js +194 -1
- package/dist/esm/components/highlight-code.js +65 -1
- package/dist/esm/components/input-validation.js +50 -1
- package/dist/esm/components/marketing-block-host-utils.js +9 -1
- package/dist/esm/components/number-scrub.js +117 -1
- package/dist/esm/components/random-gradient-palettes.js +67 -1
- package/dist/esm/components/section-block-header-utils.js +48 -1
- package/dist/esm/helpers/confirm.js +52 -1
- package/dist/esm/helpers/toast.js +73 -1
- package/dist/esm/index.js +111 -1
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +235 -1
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +31 -1
- package/dist/esm/node_modules/prismjs/components/prism-css.js +64 -1
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +172 -1
- package/dist/esm/node_modules/prismjs/components/prism-json.js +27 -1
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +143 -1
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +186 -1
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +81 -1
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +15 -1
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +60 -1
- package/dist/index.cjs +55414 -1
- package/dist/index.css +1 -1
- package/dist/index.esm.js +38284 -1
- package/dist/react/chunks/lottie-72a4c6d4.js +17032 -0
- package/dist/react/index.cjs +56503 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.esm.js +39373 -1
- package/package.json +1 -1
- package/dist/chunks/lottie-2d1f6278.js +0 -1
- package/dist/react/chunks/lottie-14e7addb.js +0 -1
|
@@ -1 +1,580 @@
|
|
|
1
|
-
const e=["top","bottom","left","right","top-start","top-end","bottom-start","bottom-end","left-start","left-end","right-start","right-end"],t=["click","hover","focus","manual"];class DbPopover extends HTMLElement{constructor(){super(...arguments),this.onDocMouseDown=null,this.onDocKeyDown=null,this.onExternalTriggerClick=null,this.handleTriggerClick=e=>{"click"===this.resolvedTrigger()&&(e.preventDefault(),e.stopPropagation(),this.setOpen(!this.isOpen()))},this.handleTriggerMouseEnter=()=>{"hover"===this.resolvedTrigger()&&this.scheduleOpen()},this.handleTriggerMouseLeave=()=>{"hover"===this.resolvedTrigger()&&this.scheduleClose()},this.handleTriggerFocus=()=>{"focus"===this.resolvedTrigger()&&this.scheduleOpen()},this.handleTriggerBlur=()=>{"focus"===this.resolvedTrigger()&&this.scheduleClose()},this.handleReposition=()=>{this.isOpen()&&(this.repositionRaf&&cancelAnimationFrame(this.repositionRaf),this.repositionRaf=requestAnimationFrame(()=>{this.positionPanel(),this.repositionRaf=void 0}))}}static get observedAttributes(){return["open","placement","position","title","content","size","variant","trigger","delay","hide-delay","always-show","disabled","max-width","show-arrow","close-on-outside-click","close-on-escape","trigger-id"]}get open(){return this.hasAttribute("open")&&"false"!==this.getAttribute("open")}set open(e){e?this.setAttribute("open",""):this.removeAttribute("open")}connectedCallback(){this.classList.add("designbase-wc-popover-host"),this.hasAttribute("placement")||this.hasAttribute("position")||this.setAttribute("placement","top"),this.render(),this.childObserver=new MutationObserver(()=>this.render()),this.childObserver.observe(this,{childList:!0}),this.bindExternalTrigger(),this.attachGlobalListeners(),this.syncOpenFromAttributes()}disconnectedCallback(){this.childObserver?.disconnect(),this.clearTimers(),this.repositionRaf&&cancelAnimationFrame(this.repositionRaf),this.unbindExternalTrigger(),this.detachGlobalListeners(),this.removePanel()}attributeChangedCallback(e){this.isConnected&&("trigger-id"===e&&(this.unbindExternalTrigger(),this.bindExternalTrigger()),"open"!==e&&"always-show"!==e&&"disabled"!==e?("content"===e&&this.bodyEl&&(this.bodyEl.textContent=this.getAttribute("content")||""),this.isOpen()&&(this.updatePanelMetadata(),requestAnimationFrame(()=>this.positionPanel()))):this.syncOpenFromAttributes())}resolvedPlacement(){const t=this.getAttribute("position")||this.getAttribute("placement")||"top";return e.includes(t)?t:"top"}resolvedTrigger(){const e=this.getAttribute("trigger")||"click";return t.includes(e)?e:"click"}isControlled(){return this.hasAttribute("open")}isOpen(){return!this.hasAttribute("disabled")&&(!!this.hasAttribute("always-show")||(this.isControlled()?"false"!==this.getAttribute("open"):this.panel?.classList.contains("designbase-wc-popover--visible")??!1))}setOpen(e){this.hasAttribute("disabled")||this.hasAttribute("always-show")||(this.isControlled()?e?this.setAttribute("open",""):this.removeAttribute("open"):e?this.showPanel():this.hidePanel(),this.dispatchEvent(new CustomEvent("db-open-change",{bubbles:!0,composed:!0,detail:{open:e}})),e||this.dispatchEvent(new CustomEvent("db-close",{bubbles:!0,composed:!0})))}syncOpenFromAttributes(){this.hasAttribute("always-show")?this.showPanel():this.isControlled()&&("false"!==this.getAttribute("open")?this.showPanel():this.hidePanel())}clearTimers(){this.showTimer&&clearTimeout(this.showTimer),this.hideTimer&&clearTimeout(this.hideTimer),this.showTimer=void 0,this.hideTimer=void 0}groupOf(e){return e.startsWith("top")?"top":e.startsWith("bottom")?"bottom":e.startsWith("left")?"left":"right"}collectTriggerChildren(){const isInternalNode=e=>e.hasAttribute("data-wc-internal")||e===this.triggerWrap,e=Array.from(this.children).filter(e=>!isInternalNode(e));return e.length>0?e:Array.from(this.triggerWrap?.children||[])}ensureTriggerWrap(){this.triggerWrap||(this.triggerWrap=document.createElement("span"),this.triggerWrap.className="designbase-wc-popover__trigger",this.triggerWrap.setAttribute("data-wc-internal",""),this.triggerWrap.tabIndex=0,this.triggerWrap.addEventListener("click",this.handleTriggerClick),this.triggerWrap.addEventListener("mouseenter",this.handleTriggerMouseEnter),this.triggerWrap.addEventListener("mouseleave",this.handleTriggerMouseLeave),this.triggerWrap.addEventListener("focus",this.handleTriggerFocus),this.triggerWrap.addEventListener("blur",this.handleTriggerBlur))}mountTriggerChildren(e){this.triggerWrap&&e.forEach(e=>{e.parentElement!==this.triggerWrap&&this.triggerWrap.append(e)})}collectBodyChildren(){return Array.from(this.querySelectorAll('[slot="content"]'))}bindExternalTrigger(){const e=this.getAttribute("trigger-id");e&&(this.triggerEl=document.getElementById(e),this.triggerEl&&(this.onExternalTriggerClick=()=>{"click"===this.resolvedTrigger()&&this.setOpen(!this.isOpen())},this.triggerEl.addEventListener("click",this.onExternalTriggerClick)))}unbindExternalTrigger(){this.triggerEl&&this.onExternalTriggerClick&&this.triggerEl.removeEventListener("click",this.onExternalTriggerClick),this.triggerEl=null,this.onExternalTriggerClick=null}attachGlobalListeners(){this.onDocMouseDown=e=>{if(!this.isOpen()||"false"===this.getAttribute("close-on-outside-click"))return;const t=e.target;this.panel?.contains(t)||this.triggerWrap?.contains(t)||this.triggerEl?.contains(t)||this.setOpen(!1)},this.onDocKeyDown=e=>{"Escape"===e.key&&this.isOpen()&&"false"!==this.getAttribute("close-on-escape")&&this.setOpen(!1)},document.addEventListener("mousedown",this.onDocMouseDown),document.addEventListener("keydown",this.onDocKeyDown)}detachGlobalListeners(){this.onDocMouseDown&&document.removeEventListener("mousedown",this.onDocMouseDown),this.onDocKeyDown&&document.removeEventListener("keydown",this.onDocKeyDown),this.onDocMouseDown=null,this.onDocKeyDown=null}scheduleOpen(){this.clearTimers();const e="hover"===this.resolvedTrigger()?Math.max(0,Number(this.getAttribute("delay")||0)):0;this.showTimer=setTimeout(()=>this.showPanel(),e)}scheduleClose(){this.clearTimers();const e="hover"===this.resolvedTrigger()?Math.max(0,Number(this.getAttribute("hide-delay")||80)):0;this.hideTimer=setTimeout(()=>this.setOpen(!1),e)}getTriggerRect(){const e=this.triggerEl||this.triggerWrap;return e?.getBoundingClientRect()}flipPlacementIfNeeded(e,t,i){const s=window.innerHeight,r=window.innerWidth,o=this.groupOf(e),n=t.top-i.height-8>=8,a=t.bottom+8+i.height<=s-8,h=t.left-i.width-8>=8,l=t.right+8+i.width<=r-8;return"top"===o&&!n&&a?e.replace(/^top/,"bottom"):"bottom"===o&&!a&&n?e.replace(/^bottom/,"top"):"left"===o&&!h&&l?e.replace(/^left/,"right"):"right"===o&&!l&&h?e.replace(/^right/,"left"):e}applyCoords(e,t,i){let s=0,r=0,o=0,n=0;const a=i.height,h=i.width,l=16;switch(e){case"top":s=t.top-i.height-8,r=t.left+t.width/2-i.width/2,o=a-5,n=h/2-5;break;case"top-start":s=t.top-i.height-8,r=t.left,o=a-5,n=11;break;case"top-end":s=t.top-i.height-8,r=t.right-i.width,o=a-5,n=h-l-5;break;case"bottom":s=t.bottom+8,r=t.left+t.width/2-i.width/2,o=-5,n=h/2-5;break;case"bottom-start":s=t.bottom+8,r=t.left,o=-5,n=11;break;case"bottom-end":s=t.bottom+8,r=t.right-i.width,o=-5,n=h-l-5;break;case"left":s=t.top+t.height/2-i.height/2,r=t.left-i.width-8,o=a/2-5,n=h-5;break;case"left-start":s=t.top,r=t.left-i.width-8,o=11,n=h-5;break;case"left-end":s=t.bottom-i.height,r=t.left-i.width-8,o=a-l-5,n=h-5;break;case"right":s=t.top+t.height/2-i.height/2,r=t.right+8,o=a/2-5,n=-5;break;case"right-start":s=t.top,r=t.right+8,o=11,n=-5;break;case"right-end":s=t.bottom-i.height,r=t.right+8,o=a-l-5,n=-5}const d=window.innerWidth,c=window.innerHeight;return r<8&&(r=8),r+i.width>d-8&&(r=d-i.width-8),s<8&&(s=8),s+i.height>c-8&&(s=c-i.height-8),{top:s,left:r,aTop:o,aLeft:n,placement:e}}positionPanel(){if(!this.panel)return;const t=this.getTriggerRect();if(!t)return;const i=Number(this.getAttribute("max-width")||300);this.panel.style.maxWidth=`${i}px`,this.panel.offsetHeight;const s=this.panel.getBoundingClientRect(),r=this.resolvedPlacement(),o=this.flipPlacementIfNeeded(r,t,s),{top:n,left:a,aTop:h,aLeft:l}=this.applyCoords(o,t,s);this.panel.style.top=`${n}px`,this.panel.style.left=`${a}px`,this.panel.dataset.placementGroup=this.groupOf(o),e.forEach(e=>{this.panel.classList.toggle(`designbase-wc-popover--${e}`,e===o)}),this.arrowEl&&(this.arrowEl.className=`designbase-wc-popover__arrow designbase-wc-popover__arrow--${o}`,this.arrowEl.style.top=`${h}px`,this.arrowEl.style.left=`${l}px`)}revealPanel(){this.panel&&(this.panel.classList.remove("designbase-wc-popover--visible"),this.positionPanel(),this.panel.offsetHeight,this.positionPanel(),this.panel.classList.add("designbase-wc-popover--visible"))}updatePanelMetadata(){if(!this.panel)return;const e=this.getAttribute("size")||"m",t=this.getAttribute("variant")||"default",i=this.resolvedPlacement();this.panel.className=["designbase-wc-popover",`designbase-wc-popover--${e}`,`designbase-wc-popover--${t}`,`designbase-wc-popover--${i}`,this.isOpen()?"designbase-wc-popover--visible":"",this.hasAttribute("disabled")?"designbase-wc-popover--disabled":""].filter(Boolean).join(" ")}ensurePanel(){if(this.panel)return;const e=document.createElement("div");e.className="designbase-wc-popover",e.setAttribute("data-wc-internal",""),e.setAttribute("role","dialog"),e.setAttribute("aria-modal","false"),e.style.position="fixed",e.style.zIndex="9999";const t=document.createElement("div");t.className="designbase-wc-popover__content";const i=document.createElement("div");i.className="designbase-wc-popover__header";const s=document.createElement("h3");s.className="designbase-wc-popover__title";const r=document.createElement("db-button");r.className="designbase-wc-popover__close-button",r.setAttribute("variant","ghost"),r.setAttribute("size","s"),r.setAttribute("icon-only",""),r.setAttribute("start-icon","close"),r.setAttribute("aria-label","팝오버 닫기"),r.addEventListener("db-click",e=>{e.stopPropagation(),this.setOpen(!1)}),i.append(s,r),this.bodyEl=document.createElement("div"),this.bodyEl.className="designbase-wc-popover__body",t.append(i,this.bodyEl),e.append(t),"false"!==this.getAttribute("show-arrow")&&(this.arrowEl=document.createElement("div"),this.arrowEl.className=`designbase-wc-popover__arrow designbase-wc-popover__arrow--${this.resolvedPlacement()}`,e.append(this.arrowEl)),this.panel=e,this.panel.querySelector(".designbase-wc-popover__title").textContent=this.getAttribute("title")||"",this.panel.querySelector(".designbase-wc-popover__title").hidden=!this.getAttribute("title"),document.body.append(e),e.addEventListener("mouseenter",()=>{"hover"===this.resolvedTrigger()&&this.clearTimers()}),e.addEventListener("mouseleave",()=>{"hover"===this.resolvedTrigger()&&this.scheduleClose()})}showPanel(){if(this.hasAttribute("disabled"))return;this.ensurePanel(),this.updatePanelMetadata();const e=this.collectBodyChildren();e.length>0?this.bodyEl.replaceChildren(...e.map(e=>e.cloneNode(!0))):this.bodyEl.textContent=this.getAttribute("content")||"";const t=this.panel.querySelector(".designbase-wc-popover__title");t.textContent=this.getAttribute("title")||"",t.hidden=!this.getAttribute("title"),requestAnimationFrame(()=>{this.revealPanel(),window.addEventListener("scroll",this.handleReposition,!0),window.addEventListener("resize",this.handleReposition)})}hidePanel(){this.panel?.classList.remove("designbase-wc-popover--visible"),window.removeEventListener("scroll",this.handleReposition,!0),window.removeEventListener("resize",this.handleReposition),this.hasAttribute("always-show")||this.removePanel()}removePanel(){this.panel?.remove(),this.panel=void 0,this.bodyEl=void 0,this.arrowEl=void 0}render(){this.ensureTriggerWrap();const e=this.collectTriggerChildren();this.mountTriggerChildren(e);const t=Boolean(this.getAttribute("trigger-id"));this.triggerWrap&&(e.length>0||!t?this.triggerWrap.parentElement!==this&&this.append(this.triggerWrap):this.triggerWrap.parentElement===this&&this.triggerWrap.remove()),this.hasAttribute("always-show")&&this.showPanel()}}customElements.get("db-popover")||customElements.define("db-popover",DbPopover);export{DbPopover};
|
|
1
|
+
const PLACEMENTS = [
|
|
2
|
+
'top',
|
|
3
|
+
'bottom',
|
|
4
|
+
'left',
|
|
5
|
+
'right',
|
|
6
|
+
'top-start',
|
|
7
|
+
'top-end',
|
|
8
|
+
'bottom-start',
|
|
9
|
+
'bottom-end',
|
|
10
|
+
'left-start',
|
|
11
|
+
'left-end',
|
|
12
|
+
'right-start',
|
|
13
|
+
'right-end',
|
|
14
|
+
];
|
|
15
|
+
const TRIGGERS = ['click', 'hover', 'focus', 'manual'];
|
|
16
|
+
const GAP = 8;
|
|
17
|
+
class DbPopover extends HTMLElement {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.onDocMouseDown = null;
|
|
21
|
+
this.onDocKeyDown = null;
|
|
22
|
+
this.onExternalTriggerClick = null;
|
|
23
|
+
this.handleTriggerClick = (event) => {
|
|
24
|
+
if (this.resolvedTrigger() !== 'click')
|
|
25
|
+
return;
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
event.stopPropagation();
|
|
28
|
+
this.setOpen(!this.isOpen());
|
|
29
|
+
};
|
|
30
|
+
this.handleTriggerMouseEnter = () => {
|
|
31
|
+
if (this.resolvedTrigger() === 'hover')
|
|
32
|
+
this.scheduleOpen();
|
|
33
|
+
};
|
|
34
|
+
this.handleTriggerMouseLeave = () => {
|
|
35
|
+
if (this.resolvedTrigger() === 'hover')
|
|
36
|
+
this.scheduleClose();
|
|
37
|
+
};
|
|
38
|
+
this.handleTriggerFocus = () => {
|
|
39
|
+
if (this.resolvedTrigger() === 'focus')
|
|
40
|
+
this.scheduleOpen();
|
|
41
|
+
};
|
|
42
|
+
this.handleTriggerBlur = () => {
|
|
43
|
+
if (this.resolvedTrigger() === 'focus')
|
|
44
|
+
this.scheduleClose();
|
|
45
|
+
};
|
|
46
|
+
this.handleReposition = () => {
|
|
47
|
+
if (!this.isOpen())
|
|
48
|
+
return;
|
|
49
|
+
if (this.repositionRaf)
|
|
50
|
+
cancelAnimationFrame(this.repositionRaf);
|
|
51
|
+
this.repositionRaf = requestAnimationFrame(() => {
|
|
52
|
+
this.positionPanel();
|
|
53
|
+
this.repositionRaf = undefined;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
static get observedAttributes() {
|
|
58
|
+
return [
|
|
59
|
+
'open',
|
|
60
|
+
'placement',
|
|
61
|
+
'position',
|
|
62
|
+
'title',
|
|
63
|
+
'content',
|
|
64
|
+
'size',
|
|
65
|
+
'variant',
|
|
66
|
+
'trigger',
|
|
67
|
+
'delay',
|
|
68
|
+
'hide-delay',
|
|
69
|
+
'always-show',
|
|
70
|
+
'disabled',
|
|
71
|
+
'max-width',
|
|
72
|
+
'show-arrow',
|
|
73
|
+
'close-on-outside-click',
|
|
74
|
+
'close-on-escape',
|
|
75
|
+
'trigger-id',
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
get open() {
|
|
79
|
+
return this.hasAttribute('open') && this.getAttribute('open') !== 'false';
|
|
80
|
+
}
|
|
81
|
+
set open(value) {
|
|
82
|
+
if (value)
|
|
83
|
+
this.setAttribute('open', '');
|
|
84
|
+
else
|
|
85
|
+
this.removeAttribute('open');
|
|
86
|
+
}
|
|
87
|
+
connectedCallback() {
|
|
88
|
+
this.classList.add('designbase-wc-popover-host');
|
|
89
|
+
if (!this.hasAttribute('placement') && !this.hasAttribute('position')) {
|
|
90
|
+
this.setAttribute('placement', 'top');
|
|
91
|
+
}
|
|
92
|
+
this.render();
|
|
93
|
+
this.childObserver = new MutationObserver(() => this.render());
|
|
94
|
+
this.childObserver.observe(this, { childList: true });
|
|
95
|
+
this.bindExternalTrigger();
|
|
96
|
+
this.attachGlobalListeners();
|
|
97
|
+
this.syncOpenFromAttributes();
|
|
98
|
+
}
|
|
99
|
+
disconnectedCallback() {
|
|
100
|
+
this.childObserver?.disconnect();
|
|
101
|
+
this.clearTimers();
|
|
102
|
+
if (this.repositionRaf)
|
|
103
|
+
cancelAnimationFrame(this.repositionRaf);
|
|
104
|
+
this.unbindExternalTrigger();
|
|
105
|
+
this.detachGlobalListeners();
|
|
106
|
+
this.removePanel();
|
|
107
|
+
}
|
|
108
|
+
attributeChangedCallback(name) {
|
|
109
|
+
if (!this.isConnected)
|
|
110
|
+
return;
|
|
111
|
+
if (name === 'trigger-id') {
|
|
112
|
+
this.unbindExternalTrigger();
|
|
113
|
+
this.bindExternalTrigger();
|
|
114
|
+
}
|
|
115
|
+
if (name === 'open' || name === 'always-show' || name === 'disabled') {
|
|
116
|
+
this.syncOpenFromAttributes();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (name === 'content' && this.bodyEl) {
|
|
120
|
+
this.bodyEl.textContent = this.getAttribute('content') || '';
|
|
121
|
+
}
|
|
122
|
+
if (this.isOpen()) {
|
|
123
|
+
this.updatePanelMetadata();
|
|
124
|
+
requestAnimationFrame(() => this.positionPanel());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
resolvedPlacement() {
|
|
128
|
+
const value = this.getAttribute('position') || this.getAttribute('placement') || 'top';
|
|
129
|
+
return PLACEMENTS.includes(value) ? value : 'top';
|
|
130
|
+
}
|
|
131
|
+
resolvedTrigger() {
|
|
132
|
+
const value = this.getAttribute('trigger') || 'click';
|
|
133
|
+
return TRIGGERS.includes(value) ? value : 'click';
|
|
134
|
+
}
|
|
135
|
+
isControlled() {
|
|
136
|
+
return this.hasAttribute('open');
|
|
137
|
+
}
|
|
138
|
+
isOpen() {
|
|
139
|
+
if (this.hasAttribute('disabled'))
|
|
140
|
+
return false;
|
|
141
|
+
if (this.hasAttribute('always-show'))
|
|
142
|
+
return true;
|
|
143
|
+
if (this.isControlled()) {
|
|
144
|
+
return this.getAttribute('open') !== 'false';
|
|
145
|
+
}
|
|
146
|
+
return this.panel?.classList.contains('designbase-wc-popover--visible') ?? false;
|
|
147
|
+
}
|
|
148
|
+
setOpen(next) {
|
|
149
|
+
if (this.hasAttribute('disabled') || this.hasAttribute('always-show'))
|
|
150
|
+
return;
|
|
151
|
+
if (this.isControlled()) {
|
|
152
|
+
if (next)
|
|
153
|
+
this.setAttribute('open', '');
|
|
154
|
+
else
|
|
155
|
+
this.removeAttribute('open');
|
|
156
|
+
}
|
|
157
|
+
else if (next) {
|
|
158
|
+
this.showPanel();
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
this.hidePanel();
|
|
162
|
+
}
|
|
163
|
+
this.dispatchEvent(new CustomEvent('db-open-change', {
|
|
164
|
+
bubbles: true,
|
|
165
|
+
composed: true,
|
|
166
|
+
detail: { open: next },
|
|
167
|
+
}));
|
|
168
|
+
if (!next) {
|
|
169
|
+
this.dispatchEvent(new CustomEvent('db-close', { bubbles: true, composed: true }));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
syncOpenFromAttributes() {
|
|
173
|
+
if (this.hasAttribute('always-show')) {
|
|
174
|
+
this.showPanel();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (this.isControlled()) {
|
|
178
|
+
if (this.getAttribute('open') !== 'false')
|
|
179
|
+
this.showPanel();
|
|
180
|
+
else
|
|
181
|
+
this.hidePanel();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
clearTimers() {
|
|
185
|
+
if (this.showTimer)
|
|
186
|
+
clearTimeout(this.showTimer);
|
|
187
|
+
if (this.hideTimer)
|
|
188
|
+
clearTimeout(this.hideTimer);
|
|
189
|
+
this.showTimer = undefined;
|
|
190
|
+
this.hideTimer = undefined;
|
|
191
|
+
}
|
|
192
|
+
groupOf(position) {
|
|
193
|
+
if (position.startsWith('top'))
|
|
194
|
+
return 'top';
|
|
195
|
+
if (position.startsWith('bottom'))
|
|
196
|
+
return 'bottom';
|
|
197
|
+
if (position.startsWith('left'))
|
|
198
|
+
return 'left';
|
|
199
|
+
return 'right';
|
|
200
|
+
}
|
|
201
|
+
collectTriggerChildren() {
|
|
202
|
+
const isInternalNode = (child) => child.hasAttribute('data-wc-internal') || child === this.triggerWrap;
|
|
203
|
+
const fromHost = Array.from(this.children).filter((child) => !isInternalNode(child));
|
|
204
|
+
if (fromHost.length > 0)
|
|
205
|
+
return fromHost;
|
|
206
|
+
return Array.from(this.triggerWrap?.children || []);
|
|
207
|
+
}
|
|
208
|
+
ensureTriggerWrap() {
|
|
209
|
+
if (!this.triggerWrap) {
|
|
210
|
+
this.triggerWrap = document.createElement('span');
|
|
211
|
+
this.triggerWrap.className = 'designbase-wc-popover__trigger';
|
|
212
|
+
this.triggerWrap.setAttribute('data-wc-internal', '');
|
|
213
|
+
this.triggerWrap.tabIndex = 0;
|
|
214
|
+
this.triggerWrap.addEventListener('click', this.handleTriggerClick);
|
|
215
|
+
this.triggerWrap.addEventListener('mouseenter', this.handleTriggerMouseEnter);
|
|
216
|
+
this.triggerWrap.addEventListener('mouseleave', this.handleTriggerMouseLeave);
|
|
217
|
+
this.triggerWrap.addEventListener('focus', this.handleTriggerFocus);
|
|
218
|
+
this.triggerWrap.addEventListener('blur', this.handleTriggerBlur);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
mountTriggerChildren(children) {
|
|
222
|
+
if (!this.triggerWrap)
|
|
223
|
+
return;
|
|
224
|
+
children.forEach((child) => {
|
|
225
|
+
if (child.parentElement !== this.triggerWrap) {
|
|
226
|
+
this.triggerWrap.append(child);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
collectBodyChildren() {
|
|
231
|
+
return Array.from(this.querySelectorAll('[slot="content"]'));
|
|
232
|
+
}
|
|
233
|
+
bindExternalTrigger() {
|
|
234
|
+
const triggerId = this.getAttribute('trigger-id');
|
|
235
|
+
if (!triggerId)
|
|
236
|
+
return;
|
|
237
|
+
this.triggerEl = document.getElementById(triggerId);
|
|
238
|
+
if (!this.triggerEl)
|
|
239
|
+
return;
|
|
240
|
+
this.onExternalTriggerClick = () => {
|
|
241
|
+
if (this.resolvedTrigger() !== 'click')
|
|
242
|
+
return;
|
|
243
|
+
this.setOpen(!this.isOpen());
|
|
244
|
+
};
|
|
245
|
+
this.triggerEl.addEventListener('click', this.onExternalTriggerClick);
|
|
246
|
+
}
|
|
247
|
+
unbindExternalTrigger() {
|
|
248
|
+
if (this.triggerEl && this.onExternalTriggerClick) {
|
|
249
|
+
this.triggerEl.removeEventListener('click', this.onExternalTriggerClick);
|
|
250
|
+
}
|
|
251
|
+
this.triggerEl = null;
|
|
252
|
+
this.onExternalTriggerClick = null;
|
|
253
|
+
}
|
|
254
|
+
attachGlobalListeners() {
|
|
255
|
+
this.onDocMouseDown = (event) => {
|
|
256
|
+
if (!this.isOpen() || this.getAttribute('close-on-outside-click') === 'false')
|
|
257
|
+
return;
|
|
258
|
+
const target = event.target;
|
|
259
|
+
if (this.panel?.contains(target))
|
|
260
|
+
return;
|
|
261
|
+
if (this.triggerWrap?.contains(target))
|
|
262
|
+
return;
|
|
263
|
+
if (this.triggerEl?.contains(target))
|
|
264
|
+
return;
|
|
265
|
+
this.setOpen(false);
|
|
266
|
+
};
|
|
267
|
+
this.onDocKeyDown = (event) => {
|
|
268
|
+
if (event.key === 'Escape' && this.isOpen() && this.getAttribute('close-on-escape') !== 'false') {
|
|
269
|
+
this.setOpen(false);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
document.addEventListener('mousedown', this.onDocMouseDown);
|
|
273
|
+
document.addEventListener('keydown', this.onDocKeyDown);
|
|
274
|
+
}
|
|
275
|
+
detachGlobalListeners() {
|
|
276
|
+
if (this.onDocMouseDown)
|
|
277
|
+
document.removeEventListener('mousedown', this.onDocMouseDown);
|
|
278
|
+
if (this.onDocKeyDown)
|
|
279
|
+
document.removeEventListener('keydown', this.onDocKeyDown);
|
|
280
|
+
this.onDocMouseDown = null;
|
|
281
|
+
this.onDocKeyDown = null;
|
|
282
|
+
}
|
|
283
|
+
scheduleOpen() {
|
|
284
|
+
this.clearTimers();
|
|
285
|
+
const trigger = this.resolvedTrigger();
|
|
286
|
+
const delay = trigger === 'hover' ? Math.max(0, Number(this.getAttribute('delay') || 0)) : 0;
|
|
287
|
+
this.showTimer = setTimeout(() => this.showPanel(), delay);
|
|
288
|
+
}
|
|
289
|
+
scheduleClose() {
|
|
290
|
+
this.clearTimers();
|
|
291
|
+
const trigger = this.resolvedTrigger();
|
|
292
|
+
const hideDelay = trigger === 'hover' ? Math.max(0, Number(this.getAttribute('hide-delay') || 80)) : 0;
|
|
293
|
+
this.hideTimer = setTimeout(() => this.setOpen(false), hideDelay);
|
|
294
|
+
}
|
|
295
|
+
getTriggerRect() {
|
|
296
|
+
const target = this.triggerEl || this.triggerWrap;
|
|
297
|
+
return target?.getBoundingClientRect();
|
|
298
|
+
}
|
|
299
|
+
flipPlacementIfNeeded(placement, tRect, pRect) {
|
|
300
|
+
const margin = 8;
|
|
301
|
+
const vh = window.innerHeight;
|
|
302
|
+
const vw = window.innerWidth;
|
|
303
|
+
const group = this.groupOf(placement);
|
|
304
|
+
const fitsTop = tRect.top - pRect.height - GAP >= margin;
|
|
305
|
+
const fitsBottom = tRect.bottom + GAP + pRect.height <= vh - margin;
|
|
306
|
+
const fitsLeft = tRect.left - pRect.width - GAP >= margin;
|
|
307
|
+
const fitsRight = tRect.right + GAP + pRect.width <= vw - margin;
|
|
308
|
+
if (group === 'top' && !fitsTop && fitsBottom) {
|
|
309
|
+
return placement.replace(/^top/, 'bottom');
|
|
310
|
+
}
|
|
311
|
+
if (group === 'bottom' && !fitsBottom && fitsTop) {
|
|
312
|
+
return placement.replace(/^bottom/, 'top');
|
|
313
|
+
}
|
|
314
|
+
if (group === 'left' && !fitsLeft && fitsRight) {
|
|
315
|
+
return placement.replace(/^left/, 'right');
|
|
316
|
+
}
|
|
317
|
+
if (group === 'right' && !fitsRight && fitsLeft) {
|
|
318
|
+
return placement.replace(/^right/, 'left');
|
|
319
|
+
}
|
|
320
|
+
return placement;
|
|
321
|
+
}
|
|
322
|
+
applyCoords(placement, tRect, pRect) {
|
|
323
|
+
let top = 0;
|
|
324
|
+
let left = 0;
|
|
325
|
+
let aTop = 0;
|
|
326
|
+
let aLeft = 0;
|
|
327
|
+
// 회전한 정사각형 화살표(10px)의 중심을 패널 가장자리에 맞춤 (half = 5)
|
|
328
|
+
const H = pRect.height;
|
|
329
|
+
const W = pRect.width;
|
|
330
|
+
const EDGE = 16; // start/end 앵커 중심 위치
|
|
331
|
+
const HALF = 5;
|
|
332
|
+
switch (placement) {
|
|
333
|
+
case 'top':
|
|
334
|
+
top = tRect.top - pRect.height - GAP;
|
|
335
|
+
left = tRect.left + tRect.width / 2 - pRect.width / 2;
|
|
336
|
+
aTop = H - HALF;
|
|
337
|
+
aLeft = W / 2 - HALF;
|
|
338
|
+
break;
|
|
339
|
+
case 'top-start':
|
|
340
|
+
top = tRect.top - pRect.height - GAP;
|
|
341
|
+
left = tRect.left;
|
|
342
|
+
aTop = H - HALF;
|
|
343
|
+
aLeft = EDGE - HALF;
|
|
344
|
+
break;
|
|
345
|
+
case 'top-end':
|
|
346
|
+
top = tRect.top - pRect.height - GAP;
|
|
347
|
+
left = tRect.right - pRect.width;
|
|
348
|
+
aTop = H - HALF;
|
|
349
|
+
aLeft = W - EDGE - HALF;
|
|
350
|
+
break;
|
|
351
|
+
case 'bottom':
|
|
352
|
+
top = tRect.bottom + GAP;
|
|
353
|
+
left = tRect.left + tRect.width / 2 - pRect.width / 2;
|
|
354
|
+
aTop = -HALF;
|
|
355
|
+
aLeft = W / 2 - HALF;
|
|
356
|
+
break;
|
|
357
|
+
case 'bottom-start':
|
|
358
|
+
top = tRect.bottom + GAP;
|
|
359
|
+
left = tRect.left;
|
|
360
|
+
aTop = -HALF;
|
|
361
|
+
aLeft = EDGE - HALF;
|
|
362
|
+
break;
|
|
363
|
+
case 'bottom-end':
|
|
364
|
+
top = tRect.bottom + GAP;
|
|
365
|
+
left = tRect.right - pRect.width;
|
|
366
|
+
aTop = -HALF;
|
|
367
|
+
aLeft = W - EDGE - HALF;
|
|
368
|
+
break;
|
|
369
|
+
case 'left':
|
|
370
|
+
top = tRect.top + tRect.height / 2 - pRect.height / 2;
|
|
371
|
+
left = tRect.left - pRect.width - GAP;
|
|
372
|
+
aTop = H / 2 - HALF;
|
|
373
|
+
aLeft = W - HALF;
|
|
374
|
+
break;
|
|
375
|
+
case 'left-start':
|
|
376
|
+
top = tRect.top;
|
|
377
|
+
left = tRect.left - pRect.width - GAP;
|
|
378
|
+
aTop = EDGE - HALF;
|
|
379
|
+
aLeft = W - HALF;
|
|
380
|
+
break;
|
|
381
|
+
case 'left-end':
|
|
382
|
+
top = tRect.bottom - pRect.height;
|
|
383
|
+
left = tRect.left - pRect.width - GAP;
|
|
384
|
+
aTop = H - EDGE - HALF;
|
|
385
|
+
aLeft = W - HALF;
|
|
386
|
+
break;
|
|
387
|
+
case 'right':
|
|
388
|
+
top = tRect.top + tRect.height / 2 - pRect.height / 2;
|
|
389
|
+
left = tRect.right + GAP;
|
|
390
|
+
aTop = H / 2 - HALF;
|
|
391
|
+
aLeft = -HALF;
|
|
392
|
+
break;
|
|
393
|
+
case 'right-start':
|
|
394
|
+
top = tRect.top;
|
|
395
|
+
left = tRect.right + GAP;
|
|
396
|
+
aTop = EDGE - HALF;
|
|
397
|
+
aLeft = -HALF;
|
|
398
|
+
break;
|
|
399
|
+
case 'right-end':
|
|
400
|
+
top = tRect.bottom - pRect.height;
|
|
401
|
+
left = tRect.right + GAP;
|
|
402
|
+
aTop = H - EDGE - HALF;
|
|
403
|
+
aLeft = -HALF;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
const vw = window.innerWidth;
|
|
407
|
+
const vh = window.innerHeight;
|
|
408
|
+
if (left < 8)
|
|
409
|
+
left = 8;
|
|
410
|
+
if (left + pRect.width > vw - 8)
|
|
411
|
+
left = vw - pRect.width - 8;
|
|
412
|
+
if (top < 8)
|
|
413
|
+
top = 8;
|
|
414
|
+
if (top + pRect.height > vh - 8)
|
|
415
|
+
top = vh - pRect.height - 8;
|
|
416
|
+
return { top, left, aTop, aLeft, placement };
|
|
417
|
+
}
|
|
418
|
+
positionPanel() {
|
|
419
|
+
if (!this.panel)
|
|
420
|
+
return;
|
|
421
|
+
const tRect = this.getTriggerRect();
|
|
422
|
+
if (!tRect)
|
|
423
|
+
return;
|
|
424
|
+
// maxWidth를 측정 전에 적용해야 패널 폭이 확정되어 위치가 어긋나지 않음
|
|
425
|
+
const maxWidth = Number(this.getAttribute('max-width') || 300);
|
|
426
|
+
this.panel.style.maxWidth = `${maxWidth}px`;
|
|
427
|
+
// 레이아웃 확정 후 측정 (첫 페인트 높이 0 방지)
|
|
428
|
+
void this.panel.offsetHeight;
|
|
429
|
+
const pRect = this.panel.getBoundingClientRect();
|
|
430
|
+
const preferred = this.resolvedPlacement();
|
|
431
|
+
const placement = this.flipPlacementIfNeeded(preferred, tRect, pRect);
|
|
432
|
+
const { top, left, aTop, aLeft } = this.applyCoords(placement, tRect, pRect);
|
|
433
|
+
this.panel.style.top = `${top}px`;
|
|
434
|
+
this.panel.style.left = `${left}px`;
|
|
435
|
+
this.panel.dataset.placementGroup = this.groupOf(placement);
|
|
436
|
+
PLACEMENTS.forEach((name) => {
|
|
437
|
+
this.panel.classList.toggle(`designbase-wc-popover--${name}`, name === placement);
|
|
438
|
+
});
|
|
439
|
+
if (this.arrowEl) {
|
|
440
|
+
this.arrowEl.className = `designbase-wc-popover__arrow designbase-wc-popover__arrow--${placement}`;
|
|
441
|
+
this.arrowEl.style.top = `${aTop}px`;
|
|
442
|
+
this.arrowEl.style.left = `${aLeft}px`;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
revealPanel() {
|
|
446
|
+
if (!this.panel)
|
|
447
|
+
return;
|
|
448
|
+
this.panel.classList.remove('designbase-wc-popover--visible');
|
|
449
|
+
this.positionPanel();
|
|
450
|
+
void this.panel.offsetHeight;
|
|
451
|
+
this.positionPanel();
|
|
452
|
+
this.panel.classList.add('designbase-wc-popover--visible');
|
|
453
|
+
}
|
|
454
|
+
updatePanelMetadata() {
|
|
455
|
+
if (!this.panel)
|
|
456
|
+
return;
|
|
457
|
+
const size = this.getAttribute('size') || 'm';
|
|
458
|
+
const variant = this.getAttribute('variant') || 'default';
|
|
459
|
+
const placement = this.resolvedPlacement();
|
|
460
|
+
this.panel.className = [
|
|
461
|
+
'designbase-wc-popover',
|
|
462
|
+
`designbase-wc-popover--${size}`,
|
|
463
|
+
`designbase-wc-popover--${variant}`,
|
|
464
|
+
`designbase-wc-popover--${placement}`,
|
|
465
|
+
this.isOpen() ? 'designbase-wc-popover--visible' : '',
|
|
466
|
+
this.hasAttribute('disabled') ? 'designbase-wc-popover--disabled' : '',
|
|
467
|
+
]
|
|
468
|
+
.filter(Boolean)
|
|
469
|
+
.join(' ');
|
|
470
|
+
}
|
|
471
|
+
ensurePanel() {
|
|
472
|
+
if (this.panel)
|
|
473
|
+
return;
|
|
474
|
+
const panel = document.createElement('div');
|
|
475
|
+
panel.className = 'designbase-wc-popover';
|
|
476
|
+
panel.setAttribute('data-wc-internal', '');
|
|
477
|
+
panel.setAttribute('role', 'dialog');
|
|
478
|
+
panel.setAttribute('aria-modal', 'false');
|
|
479
|
+
panel.style.position = 'fixed';
|
|
480
|
+
panel.style.zIndex = '9999';
|
|
481
|
+
const inner = document.createElement('div');
|
|
482
|
+
inner.className = 'designbase-wc-popover__content';
|
|
483
|
+
const header = document.createElement('div');
|
|
484
|
+
header.className = 'designbase-wc-popover__header';
|
|
485
|
+
const title = document.createElement('h3');
|
|
486
|
+
title.className = 'designbase-wc-popover__title';
|
|
487
|
+
const close = document.createElement('db-button');
|
|
488
|
+
close.className = 'designbase-wc-popover__close-button';
|
|
489
|
+
close.setAttribute('variant', 'ghost');
|
|
490
|
+
close.setAttribute('size', 's');
|
|
491
|
+
close.setAttribute('icon-only', '');
|
|
492
|
+
close.setAttribute('start-icon', 'close');
|
|
493
|
+
close.setAttribute('aria-label', '팝오버 닫기');
|
|
494
|
+
close.addEventListener('db-click', (event) => {
|
|
495
|
+
event.stopPropagation();
|
|
496
|
+
this.setOpen(false);
|
|
497
|
+
});
|
|
498
|
+
header.append(title, close);
|
|
499
|
+
this.bodyEl = document.createElement('div');
|
|
500
|
+
this.bodyEl.className = 'designbase-wc-popover__body';
|
|
501
|
+
inner.append(header, this.bodyEl);
|
|
502
|
+
panel.append(inner);
|
|
503
|
+
if (this.getAttribute('show-arrow') !== 'false') {
|
|
504
|
+
this.arrowEl = document.createElement('div');
|
|
505
|
+
this.arrowEl.className = `designbase-wc-popover__arrow designbase-wc-popover__arrow--${this.resolvedPlacement()}`;
|
|
506
|
+
panel.append(this.arrowEl);
|
|
507
|
+
}
|
|
508
|
+
this.panel = panel;
|
|
509
|
+
this.panel.querySelector('.designbase-wc-popover__title').textContent = this.getAttribute('title') || '';
|
|
510
|
+
this.panel.querySelector('.designbase-wc-popover__title').hidden = !this.getAttribute('title');
|
|
511
|
+
document.body.append(panel);
|
|
512
|
+
panel.addEventListener('mouseenter', () => {
|
|
513
|
+
if (this.resolvedTrigger() === 'hover')
|
|
514
|
+
this.clearTimers();
|
|
515
|
+
});
|
|
516
|
+
panel.addEventListener('mouseleave', () => {
|
|
517
|
+
if (this.resolvedTrigger() === 'hover')
|
|
518
|
+
this.scheduleClose();
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
showPanel() {
|
|
522
|
+
if (this.hasAttribute('disabled'))
|
|
523
|
+
return;
|
|
524
|
+
this.ensurePanel();
|
|
525
|
+
this.updatePanelMetadata();
|
|
526
|
+
const slotContent = this.collectBodyChildren();
|
|
527
|
+
if (slotContent.length > 0) {
|
|
528
|
+
this.bodyEl.replaceChildren(...slotContent.map((node) => node.cloneNode(true)));
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
this.bodyEl.textContent = this.getAttribute('content') || '';
|
|
532
|
+
}
|
|
533
|
+
const titleEl = this.panel.querySelector('.designbase-wc-popover__title');
|
|
534
|
+
titleEl.textContent = this.getAttribute('title') || '';
|
|
535
|
+
titleEl.hidden = !this.getAttribute('title');
|
|
536
|
+
requestAnimationFrame(() => {
|
|
537
|
+
this.revealPanel();
|
|
538
|
+
window.addEventListener('scroll', this.handleReposition, true);
|
|
539
|
+
window.addEventListener('resize', this.handleReposition);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
hidePanel() {
|
|
543
|
+
this.panel?.classList.remove('designbase-wc-popover--visible');
|
|
544
|
+
window.removeEventListener('scroll', this.handleReposition, true);
|
|
545
|
+
window.removeEventListener('resize', this.handleReposition);
|
|
546
|
+
if (!this.hasAttribute('always-show')) {
|
|
547
|
+
this.removePanel();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
removePanel() {
|
|
551
|
+
this.panel?.remove();
|
|
552
|
+
this.panel = undefined;
|
|
553
|
+
this.bodyEl = undefined;
|
|
554
|
+
this.arrowEl = undefined;
|
|
555
|
+
}
|
|
556
|
+
render() {
|
|
557
|
+
this.ensureTriggerWrap();
|
|
558
|
+
const triggerChildren = this.collectTriggerChildren();
|
|
559
|
+
this.mountTriggerChildren(triggerChildren);
|
|
560
|
+
const hasExternalTrigger = Boolean(this.getAttribute('trigger-id'));
|
|
561
|
+
if (this.triggerWrap) {
|
|
562
|
+
if (triggerChildren.length > 0 || !hasExternalTrigger) {
|
|
563
|
+
if (this.triggerWrap.parentElement !== this) {
|
|
564
|
+
this.append(this.triggerWrap);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
else if (this.triggerWrap.parentElement === this) {
|
|
568
|
+
this.triggerWrap.remove();
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (this.hasAttribute('always-show')) {
|
|
572
|
+
this.showPanel();
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (!customElements.get('db-popover')) {
|
|
577
|
+
customElements.define('db-popover', DbPopover);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
export { DbPopover };
|