@designbasekorea/ui-wc 0.5.6 → 0.6.1
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-35a9b0f5.js +1 -0
- package/dist/esm/components/animation-background/canvas-controller.js +1 -121
- package/dist/esm/components/animation-background/controls.js +1 -180
- package/dist/esm/components/animation-background/graphite-controller.js +1 -196
- package/dist/esm/components/animation-background/graphite-presets.js +1 -42
- package/dist/esm/components/animation-background/graphite-shader.js +1 -111
- package/dist/esm/components/animation-background/layers.js +1 -369
- package/dist/esm/components/animation-background/lumina-presets.js +1 -53
- package/dist/esm/components/animation-background/lumina-shaders.js +1 -181
- package/dist/esm/components/animation-background/lumina-utils.js +1 -60
- package/dist/esm/components/animation-background/particle-defaults.js +1 -36
- package/dist/esm/components/animation-background/renderers.js +1 -167
- package/dist/esm/components/animation-background/shader-controller.js +1 -154
- package/dist/esm/components/color-picker-utils.js +1 -134
- package/dist/esm/components/date-picker-utils.js +1 -140
- package/dist/esm/components/db-accordion.js +1 -304
- package/dist/esm/components/db-ad-banner.js +1 -455
- package/dist/esm/components/db-ai-chat-list.d.ts +43 -0
- package/dist/esm/components/db-ai-chat-list.js +1 -0
- package/dist/esm/components/db-ai-chat.d.ts +159 -0
- package/dist/esm/components/db-ai-chat.js +1 -0
- package/dist/esm/components/db-alert.js +1 -149
- package/dist/esm/components/db-animation-background.js +1 -486
- package/dist/esm/components/db-animation-text.js +1 -601
- package/dist/esm/components/db-app-badge.js +1 -88
- package/dist/esm/components/db-audio-player.js +1 -752
- package/dist/esm/components/db-avatar.js +1 -188
- package/dist/esm/components/db-backdrop.js +1 -139
- package/dist/esm/components/db-badge.js +1 -91
- package/dist/esm/components/db-banner.js +1 -188
- package/dist/esm/components/db-bottom-navigation.js +1 -146
- package/dist/esm/components/db-bottom-sheet.js +1 -481
- package/dist/esm/components/db-breadcrumbs.js +1 -329
- package/dist/esm/components/db-button.js +1 -316
- package/dist/esm/components/db-calendar.js +1 -675
- package/dist/esm/components/db-card.js +1 -265
- package/dist/esm/components/db-carousel.js +1 -264
- package/dist/esm/components/db-chat-composer.d.ts +134 -0
- package/dist/esm/components/db-chat-composer.js +1 -0
- package/dist/esm/components/db-chat-list.d.ts +47 -0
- package/dist/esm/components/db-chat-list.js +1 -0
- package/dist/esm/components/db-chat-message.d.ts +39 -0
- package/dist/esm/components/db-chat-message.js +1 -0
- package/dist/esm/components/db-chat-orb.d.ts +99 -0
- package/dist/esm/components/db-chat-orb.js +1 -0
- package/dist/esm/components/db-chat-room.d.ts +71 -0
- package/dist/esm/components/db-chat-room.js +1 -0
- package/dist/esm/components/db-chat-suggestions.d.ts +44 -0
- package/dist/esm/components/db-chat-suggestions.js +1 -0
- package/dist/esm/components/db-chat-typing.d.ts +22 -0
- package/dist/esm/components/db-chat-typing.js +1 -0
- package/dist/esm/components/db-chat-welcome.d.ts +32 -0
- package/dist/esm/components/db-chat-welcome.js +1 -0
- package/dist/esm/components/db-chat-widget.d.ts +146 -0
- package/dist/esm/components/db-chat-widget.js +1 -0
- package/dist/esm/components/db-checkbox.js +1 -202
- package/dist/esm/components/db-chip.js +1 -104
- package/dist/esm/components/db-code-block.js +1 -304
- package/dist/esm/components/db-color-picker.js +1 -746
- package/dist/esm/components/db-confirm.js +1 -191
- package/dist/esm/components/db-container.js +1 -39
- package/dist/esm/components/db-context-menu.js +1 -265
- package/dist/esm/components/db-countdown.js +1 -146
- package/dist/esm/components/db-cursor-follower.js +1 -173
- package/dist/esm/components/db-date-picker.js +1 -837
- package/dist/esm/components/db-divider.js +1 -66
- package/dist/esm/components/db-download-progress.d.ts +89 -0
- package/dist/esm/components/db-download-progress.js +1 -0
- package/dist/esm/components/db-drawer.js +1 -245
- package/dist/esm/components/db-dropdown.js +1 -493
- package/dist/esm/components/db-dropzone.js +1 -266
- package/dist/esm/components/db-email-verify.d.ts +64 -0
- package/dist/esm/components/db-email-verify.js +1 -0
- package/dist/esm/components/db-empty-state.js +1 -97
- package/dist/esm/components/db-file-uploader.js +1 -256
- package/dist/esm/components/db-floating-action-button.js +1 -139
- package/dist/esm/components/db-footer.js +1 -385
- package/dist/esm/components/db-form.js +1 -566
- package/dist/esm/components/db-gantt.js +1 -882
- package/dist/esm/components/db-gradient.js +1 -133
- package/dist/esm/components/db-grid-background.js +1 -909
- package/dist/esm/components/db-grid.js +1 -73
- package/dist/esm/components/db-icons.d.ts +3 -0
- package/dist/esm/components/db-icons.js +1 -82
- package/dist/esm/components/db-image-list.js +1 -214
- package/dist/esm/components/db-image-placeholder.js +1 -96
- package/dist/esm/components/db-image.js +1 -289
- package/dist/esm/components/db-indicator.js +1 -517
- package/dist/esm/components/db-input.js +1 -420
- package/dist/esm/components/db-kanban.js +1 -538
- package/dist/esm/components/db-label.js +1 -66
- package/dist/esm/components/db-lightbox.js +1 -372
- package/dist/esm/components/db-list.js +1 -340
- package/dist/esm/components/db-logo-svg.js +1 -72
- package/dist/esm/components/db-logo.js +1 -106
- package/dist/esm/components/db-lottie.js +1 -109
- package/dist/esm/components/db-markdown-editor.js +1 -458
- package/dist/esm/components/db-marquee.js +1 -402
- package/dist/esm/components/db-masonry.js +1 -94
- package/dist/esm/components/db-menu-item.js +1 -211
- package/dist/esm/components/db-modal.js +1 -522
- package/dist/esm/components/db-navbar.js +1 -680
- package/dist/esm/components/db-onboarding-modal.js +1 -322
- package/dist/esm/components/db-otp-input.d.ts +53 -0
- package/dist/esm/components/db-otp-input.js +1 -0
- package/dist/esm/components/db-page-header.js +1 -312
- package/dist/esm/components/db-pagination.js +1 -271
- package/dist/esm/components/db-phone-verify.d.ts +63 -0
- package/dist/esm/components/db-phone-verify.js +1 -0
- package/dist/esm/components/db-popover.js +1 -580
- package/dist/esm/components/db-progress-step.js +1 -166
- package/dist/esm/components/db-progress.js +1 -171
- package/dist/esm/components/db-progressbar.js +1 -72
- package/dist/esm/components/db-radio.js +1 -172
- package/dist/esm/components/db-random-gradient.js +1 -121
- package/dist/esm/components/db-range-slider.js +1 -811
- package/dist/esm/components/db-rating.js +1 -325
- package/dist/esm/components/db-reorder.js +1 -286
- package/dist/esm/components/db-resizable-panels.js +1 -282
- package/dist/esm/components/db-scroll-area.js +1 -126
- package/dist/esm/components/db-search-bar.js +1 -668
- package/dist/esm/components/db-section-app-download.js +1 -101
- package/dist/esm/components/db-section-contact.js +1 -102
- package/dist/esm/components/db-section-cta.js +1 -150
- package/dist/esm/components/db-section-faq.js +1 -120
- package/dist/esm/components/db-section-feature-grid.js +1 -137
- package/dist/esm/components/db-section-feature.js +1 -179
- package/dist/esm/components/db-section-hero.js +1 -243
- package/dist/esm/components/db-section-logo-cloud.js +1 -138
- package/dist/esm/components/db-section-pricing.js +1 -166
- package/dist/esm/components/db-section-stats.js +1 -129
- package/dist/esm/components/db-section-testimonials.js +1 -252
- package/dist/esm/components/db-section.js +1 -385
- package/dist/esm/components/db-segment-control.js +1 -231
- package/dist/esm/components/db-select.js +1 -571
- package/dist/esm/components/db-share-icons.js +1 -40
- package/dist/esm/components/db-share.js +1 -489
- package/dist/esm/components/db-sidebar.d.ts +20 -0
- package/dist/esm/components/db-sidebar.js +1 -1068
- package/dist/esm/components/db-skeleton.js +1 -94
- package/dist/esm/components/db-spinner.js +1 -102
- package/dist/esm/components/db-split-view.js +1 -297
- package/dist/esm/components/db-stack.js +1 -46
- package/dist/esm/components/db-stat.js +1 -218
- package/dist/esm/components/db-stepper.js +1 -398
- package/dist/esm/components/db-table.js +1 -412
- package/dist/esm/components/db-tabs.js +1 -335
- package/dist/esm/components/db-testimonial.d.ts +2 -0
- package/dist/esm/components/db-testimonial.js +1 -162
- package/dist/esm/components/db-textarea.js +1 -233
- package/dist/esm/components/db-time-picker.js +1 -523
- package/dist/esm/components/db-timeline.js +1 -174
- package/dist/esm/components/db-toast.js +1 -158
- package/dist/esm/components/db-toggle.js +1 -162
- package/dist/esm/components/db-toolbar.js +1 -94
- package/dist/esm/components/db-tooltip.js +1 -440
- package/dist/esm/components/db-top-banner.js +1 -121
- package/dist/esm/components/db-tutorial.js +1 -324
- package/dist/esm/components/db-two-factor.d.ts +71 -0
- package/dist/esm/components/db-two-factor.js +1 -0
- package/dist/esm/components/db-video-player.js +1 -503
- package/dist/esm/components/db-youtube-player.js +1 -194
- package/dist/esm/components/highlight-code.js +1 -65
- package/dist/esm/components/input-validation.js +1 -50
- package/dist/esm/components/marketing-block-host-utils.js +1 -9
- package/dist/esm/components/number-scrub.js +1 -117
- package/dist/esm/components/random-gradient-palettes.js +1 -67
- package/dist/esm/components/section-block-header-utils.js +1 -48
- package/dist/esm/helpers/confirm.js +1 -52
- package/dist/esm/helpers/toast.js +1 -73
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +1 -111
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +1 -235
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +1 -31
- package/dist/esm/node_modules/prismjs/components/prism-css.js +1 -64
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +1 -172
- package/dist/esm/node_modules/prismjs/components/prism-json.js +1 -27
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +1 -143
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +1 -186
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +1 -81
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +1 -15
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +1 -60
- package/dist/index.cjs +1 -55414
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1125 -2
- package/dist/index.esm.js +1 -38284
- package/dist/react/chunks/lottie-14e7addb.js +1 -0
- package/dist/react/index.cjs +1 -56503
- package/dist/react/index.d.ts +1637 -21
- package/dist/react/index.esm.js +1 -39373
- package/package.json +2 -2
- package/dist/chunks/lottie-e273b936.js +0 -17032
- package/dist/react/chunks/lottie-72a4c6d4.js +0 -17032
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./db-button.js";import"./db-input.js";import"./db-otp-input.js";import"./db-select.js";const t=[{value:"skt",label:"SKT"},{value:"kt",label:"KT"},{value:"lgu",label:"LG U+"},{value:"mvno",label:"알뜰폰"}],e=["s","m","l"];function el(t,e){const i=document.createElement(t);return e&&(i.className=e),i}function formatPhone(t){const e=t.replace(/\D/g,"").slice(0,11);return e.length<=3?e:e.length<=7?`${e.slice(0,3)}-${e.slice(3)}`:`${e.slice(0,3)}-${e.slice(3,7)}-${e.slice(7)}`}class DbPhoneVerify extends HTMLElement{constructor(){super(...arguments),this.built=!1,this.timerId=null,this.remaining=0}static get observedAttributes(){return["carrier","phone","code","step","size","disabled","error","error-message","carrier-options","countdown","title","description","send-label","resend-label","verify-label","code-length","manual","sending","verifying","auto-submit"]}get size(){return function pick(t,e,i){return t.includes(e)?e:i}(e,this.getAttribute("size"),"m")}set size(t){this.setAttribute("size",t)}get step(){const t=this.getAttribute("step");return"code"===t||"verified"===t?t:"phone"}set step(t){this.setAttribute("step",t)}get phone(){return(this.getAttribute("phone")||"").replace(/\D/g,"")}set phone(t){this.setAttribute("phone",formatPhone(t))}get carrier(){return this.getAttribute("carrier")||"skt"}set carrier(t){this.setAttribute("carrier",t)}get code(){return this.getAttribute("code")||""}set code(t){this.setAttribute("code",t)}get countdown(){const t=Number(this.getAttribute("countdown")||180);return Number.isFinite(t)&&t>0?t:180}set countdown(t){this.setAttribute("countdown",String(t))}connectedCallback(){this.build(),this.sync(),"code"===this.step&&this.startTimer(this.countdown)}disconnectedCallback(){this.clearTimer()}attributeChangedCallback(t,e,i){this.built&&(this.sync(),"step"===t&&e!==i&&("code"===this.step?this.startTimer(this.countdown):this.clearTimer()))}startCodeStep(){"code"===this.step?this.startTimer(this.countdown):this.step="code",requestAnimationFrame(()=>this.otpInput?.focus?.())}restartCountdown(){"code"===this.step&&this.startTimer(this.countdown)}markVerified(){this.step="verified",this.clearTimer()}clearTimer(){this.timerId&&clearInterval(this.timerId),this.timerId=null,this.remaining=0}startTimer(t){this.clearTimer(),this.remaining=t,this.renderTimer(),this.timerId=setInterval(()=>{this.remaining-=1,this.renderTimer(),this.remaining<=0&&(this.clearTimer(),this.resendBtn.disabled=!1,this.dispatchEvent(new CustomEvent("db-countdown-complete",{bubbles:!0,composed:!0})))},1e3)}renderTimer(){const t=Math.max(0,Math.floor(this.remaining/60)),e=Math.max(0,this.remaining%60);this.timerEl.textContent=`${String(t).padStart(2,"0")}:${String(e).padStart(2,"0")}`,this.timerEl.setAttribute("aria-label",`남은 시간 ${t}분 ${e}초`),this.resendBtn.disabled=this.remaining>0||this.hasAttribute("disabled")}build(){if(this.built)return;this.built=!0;const t="designbase-wc-phone-verify";this.replaceChildren();const e=el("div",`${t}__header`),i=el("h3",`${t}__title`);i.dataset.role="title";const s=el("p",`${t}__description`);s.dataset.role="description",e.append(i,s);const r=el("div",`${t}__field`);this.carrierSelect=document.createElement("db-select"),this.carrierSelect.setAttribute("label","통신사"),this.carrierSelect.setAttribute("full-width",""),this.carrierSelect.setAttribute("placeholder","통신사 선택"),this.carrierSelect.addEventListener("db-change",t=>{t.stopPropagation();const e=t.detail?.value??this.carrierSelect.value;this.carrier=String(e||""),this.dispatchEvent(new CustomEvent("db-carrier-change",{detail:{carrier:this.carrier},bubbles:!0,composed:!0}))}),r.append(this.carrierSelect);const n=el("div",`${t}__phone-row`);this.phoneInput=document.createElement("db-input"),this.phoneInput.setAttribute("type","tel"),this.phoneInput.setAttribute("label","휴대폰 번호"),this.phoneInput.setAttribute("placeholder","010-0000-0000"),this.phoneInput.setAttribute("full-width",""),this.phoneInput.setAttribute("start-icon","user"),this.phoneInput.addEventListener("db-input",t=>{t.stopPropagation();const e=formatPhone(String(t.detail?.value??this.phoneInput.value??""));this.phoneInput.value=e,this.setAttribute("phone",e),this.dispatchEvent(new CustomEvent("db-phone-change",{detail:{phone:e.replace(/\D/g,""),formatted:e},bubbles:!0,composed:!0}))}),this.sendBtn=document.createElement("db-button"),this.sendBtn.setAttribute("variant","primary"),this.sendBtn.addEventListener("db-click",t=>{t.stopPropagation(),this.isPhoneValid()&&(this.dispatchEvent(new CustomEvent("db-send-code",{detail:{carrier:this.carrier,phone:this.phone},bubbles:!0,composed:!0})),this.hasAttribute("manual")||this.startCodeStep())}),n.append(this.phoneInput,this.sendBtn),this.codeBlock=el("div",`${t}__code`);const o=el("div",`${t}__code-head`),h=el("span",`${t}__code-label`);h.textContent="인증번호",this.timerEl=el("span",`${t}__timer`),o.append(h,this.timerEl),this.otpInput=document.createElement("db-otp-input"),this.otpInput.addEventListener("db-change",t=>{t.stopPropagation();const e=String(t.detail?.value||"");this.setAttribute("code",e),this.dispatchEvent(new CustomEvent("db-code-change",{detail:{code:e},bubbles:!0,composed:!0}))}),this.otpInput.addEventListener("db-complete",t=>{t.stopPropagation();const e=String(t.detail?.value||"");this.dispatchEvent(new CustomEvent("db-code-complete",{detail:{code:e,carrier:this.carrier,phone:this.phone},bubbles:!0,composed:!0})),this.hasAttribute("auto-submit")&&this.requestVerify()});const a=el("div",`${t}__code-actions`);this.resendBtn=el("button",`${t}__resend`),this.resendBtn.type="button",this.resendBtn.addEventListener("click",()=>{this.resendBtn.disabled||(this.dispatchEvent(new CustomEvent("db-resend",{detail:{carrier:this.carrier,phone:this.phone},bubbles:!0,composed:!0})),this.hasAttribute("manual")||this.startTimer(this.countdown))}),this.verifyBtn=document.createElement("db-button"),this.verifyBtn.setAttribute("variant","primary"),this.verifyBtn.setAttribute("full-width",""),this.verifyBtn.addEventListener("db-click",t=>{t.stopPropagation(),this.requestVerify()}),a.append(this.resendBtn,this.verifyBtn),this.codeBlock.append(o,this.otpInput,a),this.errorEl=el("p",`${t}__error`),this.errorEl.hidden=!0;const d=el("div",`${t}__verified`);d.dataset.role="verified",d.innerHTML=`<span class="${t}__verified-badge">인증 완료</span><p class="${t}__verified-text">휴대폰 번호 인증이 완료되었습니다.</p>`,this.append(e,r,n,this.codeBlock,this.errorEl,d)}sync(){const e="designbase-wc-phone-verify",i=this.size,s=this.step,r=this.hasAttribute("disabled"),n=function parseCarriers(e){if(!e)return t;try{const i=JSON.parse(e);return Array.isArray(i)&&i.length?i:t}catch{return t}}(this.getAttribute("carrier-options")),o=this.getAttribute("code-length")||"6";this.className=[e,`${e}--${i}`,`${e}--step-${s}`,r&&`${e}--disabled`,this.hasAttribute("error")&&`${e}--error`].filter(Boolean).join(" ");const h=this.querySelector('[data-role="title"]'),a=this.querySelector('[data-role="description"]');h.textContent=this.getAttribute("title")||"휴대폰 인증",a.textContent=this.getAttribute("description")||"본인 명의의 휴대폰 번호를 입력하고 인증번호를 받아 주세요.",this.carrierSelect.setAttribute("options",JSON.stringify(n)),this.carrierSelect.setAttribute("value",this.carrier),this.carrierSelect.setAttribute("size",i),this.carrierSelect.toggleAttribute("disabled",r||"verified"===s);const d=this.getAttribute("phone")||"";this.phoneInput.value=d,this.phoneInput.setAttribute("size",i),this.phoneInput.toggleAttribute("disabled",r||"phone"!==s),this.phoneInput.toggleAttribute("error",this.hasAttribute("error")&&"phone"===s),this.sendBtn.setAttribute("size",i),this.sendBtn.textContent=this.getAttribute("send-label")||"인증번호 받기",this.sendBtn.toggleAttribute("disabled",r||"phone"!==s||!this.isPhoneValid()),this.sendBtn.toggleAttribute("loading",this.hasAttribute("sending")),this.otpInput.setAttribute("length",o),this.otpInput.setAttribute("size",i),this.otpInput.setAttribute("value",this.getAttribute("code")||""),this.otpInput.toggleAttribute("disabled",r||"code"!==s),this.otpInput.toggleAttribute("error",this.hasAttribute("error")&&"code"===s),this.resendBtn.textContent=this.getAttribute("resend-label")||"재전송",this.verifyBtn.setAttribute("size",i),this.verifyBtn.textContent=this.getAttribute("verify-label")||"인증하기",this.verifyBtn.toggleAttribute("disabled",r||(this.getAttribute("code")||"").length<Number(o)),this.verifyBtn.toggleAttribute("loading",this.hasAttribute("verifying")),this.codeBlock.hidden="phone"===s;this.querySelector('[data-role="verified"]').hidden="verified"!==s;const l=this.getAttribute("error-message")||"";this.errorEl.textContent=l,this.errorEl.hidden=!this.hasAttribute("error")||!l}isPhoneValid(){return/^01[016789]\d{7,8}$/.test(this.phone)&&Boolean(this.carrier)}requestVerify(){const t=(this.code||this.otpInput.value).replace(/\D/g,""),e=Number(this.getAttribute("code-length")||6);"code"!==this.step||t.length!==e||this.hasAttribute("disabled")||this.dispatchEvent(new CustomEvent("db-verify",{detail:{carrier:this.carrier,phone:this.phone,code:t},bubbles:!0,composed:!0}))}}customElements.get("db-phone-verify")||customElements.define("db-phone-verify",DbPhoneVerify);export{DbPhoneVerify};
|
|
@@ -1,580 +1 @@
|
|
|
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 };
|
|
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};
|