@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.
Files changed (156) hide show
  1. package/dist/chunks/lottie-e273b936.js +17032 -0
  2. package/dist/esm/components/animation-background/canvas-controller.js +121 -1
  3. package/dist/esm/components/animation-background/controls.js +180 -1
  4. package/dist/esm/components/animation-background/graphite-controller.js +196 -1
  5. package/dist/esm/components/animation-background/graphite-presets.js +42 -1
  6. package/dist/esm/components/animation-background/graphite-shader.js +111 -1
  7. package/dist/esm/components/animation-background/layers.js +369 -1
  8. package/dist/esm/components/animation-background/lumina-presets.js +53 -1
  9. package/dist/esm/components/animation-background/lumina-shaders.js +181 -1
  10. package/dist/esm/components/animation-background/lumina-utils.js +60 -1
  11. package/dist/esm/components/animation-background/particle-defaults.js +36 -1
  12. package/dist/esm/components/animation-background/renderers.js +167 -1
  13. package/dist/esm/components/animation-background/shader-controller.js +154 -1
  14. package/dist/esm/components/color-picker-utils.js +134 -1
  15. package/dist/esm/components/date-picker-utils.js +140 -1
  16. package/dist/esm/components/db-accordion.js +304 -1
  17. package/dist/esm/components/db-ad-banner.js +455 -1
  18. package/dist/esm/components/db-alert.js +149 -1
  19. package/dist/esm/components/db-animation-background.js +486 -1
  20. package/dist/esm/components/db-animation-text.js +601 -1
  21. package/dist/esm/components/db-app-badge.js +88 -1
  22. package/dist/esm/components/db-audio-player.js +752 -1
  23. package/dist/esm/components/db-avatar.js +188 -1
  24. package/dist/esm/components/db-backdrop.js +139 -1
  25. package/dist/esm/components/db-badge.js +91 -1
  26. package/dist/esm/components/db-banner.js +188 -1
  27. package/dist/esm/components/db-bottom-navigation.js +146 -1
  28. package/dist/esm/components/db-bottom-sheet.js +481 -1
  29. package/dist/esm/components/db-breadcrumbs.js +329 -1
  30. package/dist/esm/components/db-button.js +316 -1
  31. package/dist/esm/components/db-calendar.js +675 -1
  32. package/dist/esm/components/db-card.js +265 -1
  33. package/dist/esm/components/db-carousel.js +264 -1
  34. package/dist/esm/components/db-checkbox.js +202 -1
  35. package/dist/esm/components/db-chip.js +104 -1
  36. package/dist/esm/components/db-code-block.js +304 -1
  37. package/dist/esm/components/db-color-picker.js +746 -1
  38. package/dist/esm/components/db-confirm.js +191 -1
  39. package/dist/esm/components/db-container.js +39 -1
  40. package/dist/esm/components/db-context-menu.js +265 -1
  41. package/dist/esm/components/db-countdown.js +146 -1
  42. package/dist/esm/components/db-cursor-follower.js +173 -1
  43. package/dist/esm/components/db-date-picker.js +837 -1
  44. package/dist/esm/components/db-divider.js +66 -1
  45. package/dist/esm/components/db-drawer.js +245 -1
  46. package/dist/esm/components/db-dropdown.js +493 -1
  47. package/dist/esm/components/db-dropzone.js +266 -1
  48. package/dist/esm/components/db-empty-state.js +97 -1
  49. package/dist/esm/components/db-file-uploader.js +256 -1
  50. package/dist/esm/components/db-floating-action-button.js +139 -1
  51. package/dist/esm/components/db-footer.js +385 -1
  52. package/dist/esm/components/db-form.js +566 -1
  53. package/dist/esm/components/db-gantt.js +882 -1
  54. package/dist/esm/components/db-gradient.js +133 -1
  55. package/dist/esm/components/db-grid-background.js +909 -1
  56. package/dist/esm/components/db-grid.js +73 -1
  57. package/dist/esm/components/db-icons.js +82 -1
  58. package/dist/esm/components/db-image-list.js +214 -1
  59. package/dist/esm/components/db-image-placeholder.js +96 -1
  60. package/dist/esm/components/db-image.js +289 -1
  61. package/dist/esm/components/db-indicator.js +517 -1
  62. package/dist/esm/components/db-input.js +420 -1
  63. package/dist/esm/components/db-kanban.js +538 -1
  64. package/dist/esm/components/db-label.js +66 -1
  65. package/dist/esm/components/db-lightbox.js +372 -1
  66. package/dist/esm/components/db-list.js +340 -1
  67. package/dist/esm/components/db-logo-svg.js +72 -1
  68. package/dist/esm/components/db-logo.js +106 -1
  69. package/dist/esm/components/db-lottie.js +109 -1
  70. package/dist/esm/components/db-markdown-editor.js +458 -1
  71. package/dist/esm/components/db-marquee.js +402 -1
  72. package/dist/esm/components/db-masonry.js +94 -1
  73. package/dist/esm/components/db-menu-item.js +211 -1
  74. package/dist/esm/components/db-modal.js +522 -1
  75. package/dist/esm/components/db-navbar.js +680 -1
  76. package/dist/esm/components/db-onboarding-modal.js +322 -1
  77. package/dist/esm/components/db-page-header.js +312 -1
  78. package/dist/esm/components/db-pagination.js +271 -1
  79. package/dist/esm/components/db-popover.js +580 -1
  80. package/dist/esm/components/db-progress-step.js +166 -1
  81. package/dist/esm/components/db-progress.js +171 -1
  82. package/dist/esm/components/db-progressbar.js +72 -1
  83. package/dist/esm/components/db-radio.js +172 -1
  84. package/dist/esm/components/db-random-gradient.js +121 -1
  85. package/dist/esm/components/db-range-slider.js +811 -1
  86. package/dist/esm/components/db-rating.js +325 -1
  87. package/dist/esm/components/db-reorder.js +286 -1
  88. package/dist/esm/components/db-resizable-panels.js +282 -1
  89. package/dist/esm/components/db-scroll-area.js +126 -1
  90. package/dist/esm/components/db-search-bar.js +668 -1
  91. package/dist/esm/components/db-section-app-download.js +101 -1
  92. package/dist/esm/components/db-section-contact.js +102 -1
  93. package/dist/esm/components/db-section-cta.js +150 -1
  94. package/dist/esm/components/db-section-faq.js +120 -1
  95. package/dist/esm/components/db-section-feature-grid.js +137 -1
  96. package/dist/esm/components/db-section-feature.js +179 -1
  97. package/dist/esm/components/db-section-hero.js +243 -1
  98. package/dist/esm/components/db-section-logo-cloud.js +138 -1
  99. package/dist/esm/components/db-section-pricing.js +166 -1
  100. package/dist/esm/components/db-section-stats.js +129 -1
  101. package/dist/esm/components/db-section-testimonials.js +252 -1
  102. package/dist/esm/components/db-section.js +385 -1
  103. package/dist/esm/components/db-segment-control.js +231 -1
  104. package/dist/esm/components/db-select.js +571 -1
  105. package/dist/esm/components/db-share-icons.js +40 -1
  106. package/dist/esm/components/db-share.js +489 -1
  107. package/dist/esm/components/db-sidebar.js +1068 -1
  108. package/dist/esm/components/db-skeleton.js +94 -1
  109. package/dist/esm/components/db-spinner.js +102 -1
  110. package/dist/esm/components/db-split-view.js +297 -1
  111. package/dist/esm/components/db-stack.js +46 -1
  112. package/dist/esm/components/db-stat.js +218 -1
  113. package/dist/esm/components/db-stepper.js +398 -1
  114. package/dist/esm/components/db-table.js +412 -1
  115. package/dist/esm/components/db-tabs.js +335 -1
  116. package/dist/esm/components/db-testimonial.js +162 -1
  117. package/dist/esm/components/db-textarea.js +233 -1
  118. package/dist/esm/components/db-time-picker.js +523 -1
  119. package/dist/esm/components/db-timeline.js +174 -1
  120. package/dist/esm/components/db-toast.js +158 -1
  121. package/dist/esm/components/db-toggle.js +162 -1
  122. package/dist/esm/components/db-toolbar.js +94 -1
  123. package/dist/esm/components/db-tooltip.js +440 -1
  124. package/dist/esm/components/db-top-banner.js +121 -1
  125. package/dist/esm/components/db-tutorial.js +324 -1
  126. package/dist/esm/components/db-video-player.js +503 -1
  127. package/dist/esm/components/db-youtube-player.js +194 -1
  128. package/dist/esm/components/highlight-code.js +65 -1
  129. package/dist/esm/components/input-validation.js +50 -1
  130. package/dist/esm/components/marketing-block-host-utils.js +9 -1
  131. package/dist/esm/components/number-scrub.js +117 -1
  132. package/dist/esm/components/random-gradient-palettes.js +67 -1
  133. package/dist/esm/components/section-block-header-utils.js +48 -1
  134. package/dist/esm/helpers/confirm.js +52 -1
  135. package/dist/esm/helpers/toast.js +73 -1
  136. package/dist/esm/index.js +111 -1
  137. package/dist/esm/node_modules/prismjs/components/prism-bash.js +235 -1
  138. package/dist/esm/node_modules/prismjs/components/prism-clike.js +31 -1
  139. package/dist/esm/node_modules/prismjs/components/prism-css.js +64 -1
  140. package/dist/esm/node_modules/prismjs/components/prism-javascript.js +172 -1
  141. package/dist/esm/node_modules/prismjs/components/prism-json.js +27 -1
  142. package/dist/esm/node_modules/prismjs/components/prism-jsx.js +143 -1
  143. package/dist/esm/node_modules/prismjs/components/prism-markup.js +186 -1
  144. package/dist/esm/node_modules/prismjs/components/prism-scss.js +81 -1
  145. package/dist/esm/node_modules/prismjs/components/prism-tsx.js +15 -1
  146. package/dist/esm/node_modules/prismjs/components/prism-typescript.js +60 -1
  147. package/dist/index.cjs +55414 -1
  148. package/dist/index.css +1 -1
  149. package/dist/index.esm.js +38284 -1
  150. package/dist/react/chunks/lottie-72a4c6d4.js +17032 -0
  151. package/dist/react/index.cjs +56503 -1
  152. package/dist/react/index.d.ts +1 -1
  153. package/dist/react/index.esm.js +39373 -1
  154. package/package.json +1 -1
  155. package/dist/chunks/lottie-2d1f6278.js +0 -1
  156. package/dist/react/chunks/lottie-14e7addb.js +0 -1
@@ -1 +1,458 @@
1
- import{createDbIcon as t}from"./db-icons.js";const e="designbase-wc-markdown-editor";class DbMarkdownEditor extends HTMLElement{constructor(){super(...arguments),this.built=!1,this.internalValue="",this.currentMode="preview",this.isFocused=!1,this.wordCount=0,this.lineCount=0,this.lastSaved=null,this.isSaving=!1,this.handleKeyDown=t=>{if(this.getBool("disabled")||this.getBool("readonly"))return;const{ctrlKey:e,shiftKey:i,key:s}=t;e&&"b"===s?(t.preventDefault(),this.insertText("**","**","**")):e&&"i"===s?(t.preventDefault(),this.insertText("*","*","*")):e&&"k"===s?(t.preventDefault(),this.insertText("[","](",")")):e&&"`"===s?(t.preventDefault(),this.insertText("`","`","`")):e&&i&&"S"===s?(t.preventDefault(),this.insertText("~~","~~","~~")):"Tab"===s&&(t.preventDefault(),this.insertText(" ","",""))}}static get observedAttributes(){return["size","variant","mode","theme","value","placeholder","min-height","max-height","auto-height","readonly","disabled","show-toolbar","show-status","show-word-count","show-line-count","auto-save","auto-save-interval","file-upload"]}connectedCallback(){this.built||(this.built=!0,this.build()),this.syncFromAttributes(),this.renderMode(),this.updateCounts(),this.updateStatus(),this.setupAutoSave()}disconnectedCallback(){this.autoSaveTimer&&window.clearInterval(this.autoSaveTimer)}attributeChangedCallback(t){if(this.built){if("value"===t&&this.textareaEl)return this.internalValue=this.getAttribute("value")||"",this.textareaEl.value=this.internalValue,this.updatePreview(),this.updateCodeView(),void this.updateCounts();if("mode"===t)return this.currentMode=this.getAttribute("mode")||"preview",void this.renderMode();"auto-save"!==t&&"auto-save-interval"!==t||this.setupAutoSave(),this.updateRootClasses()}}get value(){return this.internalValue}set value(t){this.internalValue=t,this.setAttribute("value",t),this.textareaEl&&(this.textareaEl.value=t),this.updatePreview(),this.updateCodeView(),this.updateCounts()}getBool(t,e=!1){if(!this.hasAttribute(t))return e;const i=this.getAttribute(t);return""===i||"true"===i}syncFromAttributes(){if(this.internalValue=this.getAttribute("value")||"",this.currentMode=this.getAttribute("mode")||"preview",this.textareaEl){this.textareaEl.value=this.internalValue,this.textareaEl.placeholder=this.getAttribute("placeholder")||"마크다운을 입력하세요...",this.textareaEl.readOnly=this.getBool("readonly"),this.textareaEl.disabled=this.getBool("disabled");const t=Number(this.getAttribute("min-height")||200),e=Number(this.getAttribute("max-height")||600),i=this.getBool("auto-height");this.textareaEl.style.minHeight=i?"auto":`${t}px`,this.textareaEl.style.maxHeight=i?"none":`${e}px`}this.updateRootClasses(),this.updatePreview(),this.updateCodeView()}updateRootClasses(){const t=this.getAttribute("size")||"m",i=this.getAttribute("variant")||"default",s=this.getAttribute("theme")||"light";this.className=[e,`${e}--size-${t}`,`${e}--variant-${i}`,`${e}--mode-${this.currentMode}`,`${e}--theme-${s}`,this.isFocused&&`${e}--focused`,this.getBool("disabled")&&`${e}--disabled`,this.getBool("readonly")&&`${e}--readonly`].filter(Boolean).join(" ")}markdownToHtml(t){return t.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*)\*\*/gim,"<strong>$1</strong>").replace(/\*(.*)\*/gim,"<em>$1</em>").replace(/~~(.*)~~/gim,"<del>$1</del>").replace(/`(.*)`/gim,"<code>$1</code>").replace(/\[([^\]]+)\]\(([^)]+)\)/gim,'<a href="$2">$1</a>').replace(/!\[([^\]]*)\]\(([^)]+)\)/gim,'<img alt="$1" src="$2" />').replace(/^> (.*$)/gim,"<blockquote>$1</blockquote>").replace(/^- (.*$)/gim,"<ul><li>$1</li></ul>").replace(/^(\d+)\. (.*$)/gim,"<ol><li>$2</li></ol>").replace(/\n/gim,"<br />")}updatePreview(){this.previewEl&&(this.previewEl.innerHTML=this.markdownToHtml(this.internalValue))}updateCodeView(){if(this.codeViewEl){const t=this.codeViewEl.querySelector("code");t&&(t.textContent=this.internalValue)}}updateCounts(){this.wordCount=this.internalValue.trim()?this.internalValue.trim().split(/\s+/).length:0,this.lineCount=this.internalValue?this.internalValue.split("\n").length:0,this.wordCountEl&&(this.wordCountEl.textContent=`단어: ${this.wordCount}`),this.lineCountEl&&(this.lineCountEl.textContent=`라인: ${this.lineCount}`)}updateStatus(){if(!this.statusEl)return;const t=this.getBool("show-status",!0);this.statusEl.hidden=!t,this.wordCountEl&&(this.wordCountEl.hidden=!this.getBool("show-word-count",!0)),this.lineCountEl&&(this.lineCountEl.hidden=!this.getBool("show-line-count",!0)),this.lastSavedEl&&(this.lastSavedEl.hidden=!this.lastSaved,this.lastSaved&&(this.lastSavedEl.textContent=`저장됨: ${this.lastSaved.toLocaleTimeString()}`)),this.savingEl&&(this.savingEl.hidden=!this.isSaving)}emitChange(){this.dispatchEvent(new CustomEvent("db-change",{detail:{value:this.internalValue},bubbles:!0,composed:!0}))}insertText(t,e="",i=""){if(!this.textareaEl||this.getBool("disabled")||this.getBool("readonly"))return;const{selectionStart:s,selectionEnd:a}=this.textareaEl,l=this.internalValue.substring(s,a),n=e+(l||t)+i,o=this.internalValue.substring(0,s)+n+this.internalValue.substring(a);this.internalValue=o,this.textareaEl.value=o,this.emitChange(),this.updatePreview(),this.updateCodeView(),this.updateCounts();const r=s+e.length+(l?l.length:t.length);window.setTimeout(()=>{this.textareaEl&&(this.textareaEl.setSelectionRange(r,r),this.textareaEl.focus())},0)}getDefaultToolbarActions(){return[{id:"bold",label:"B",tooltip:"굵게 (Ctrl+B)",shortcut:"Ctrl+B",action:()=>this.insertText("**","**","**")},{id:"italic",label:"I",tooltip:"기울임 (Ctrl+I)",shortcut:"Ctrl+I",action:()=>this.insertText("*","*","*")},{id:"strikethrough",label:"S",tooltip:"취소선 (Ctrl+Shift+S)",shortcut:"Ctrl+Shift+S",action:()=>this.insertText("~~","~~","~~")},{id:"separator1",label:"|",separator:!0,action:()=>{}},{id:"heading1",label:"H1",tooltip:"제목 1",action:()=>this.insertText("# ","","")},{id:"heading2",label:"H2",tooltip:"제목 2",action:()=>this.insertText("## ","","")},{id:"heading3",label:"H3",tooltip:"제목 3",action:()=>this.insertText("### ","","")},{id:"separator2",label:"|",separator:!0,action:()=>{}},{id:"link",label:"",icon:"share-alt",tooltip:"링크 (Ctrl+K)",shortcut:"Ctrl+K",action:()=>this.insertText("[","](",")")},{id:"image",label:"",icon:"video",tooltip:"이미지",action:()=>this.insertText("![","](",")")},{id:"code",label:"",icon:"code",tooltip:"인라인 코드 (Ctrl+`)",shortcut:"Ctrl+`",action:()=>this.insertText("`","`","`")},{id:"codeBlock",label:"```",tooltip:"코드 블록",action:()=>this.insertText("\n```\n","","\n```\n")},{id:"separator3",label:"|",separator:!0,action:()=>{}},{id:"list",label:"•",tooltip:"순서 없는 목록",action:()=>this.insertText("- ","","")},{id:"orderedList",label:"1.",tooltip:"순서 있는 목록",action:()=>this.insertText("1. ","","")},{id:"quote",label:'"',tooltip:"인용구",action:()=>this.insertText("> ","","")},{id:"separator4",label:"|",separator:!0,action:()=>{}},{id:"table",label:"⊞",tooltip:"테이블",action:()=>this.insertText("\n| 헤더1 | 헤더2 | 헤더3 |\n|-------|-------|-------|\n| 셀1 | 셀2 | 셀3 |\n","","")},{id:"horizontalRule",label:"—",tooltip:"수평선",action:()=>this.insertText("\n---\n","","")}]}renderToolbar(){if(!this.toolbarEl)return;const i=this.getBool("show-toolbar",!0);this.toolbarEl.hidden=!i,this.toolbarEl.replaceChildren();const s=document.createElement("div");s.className=`${e}__mode-buttons`;[{mode:"edit",icon:"write",title:"편집 모드"},{mode:"preview",icon:"show",title:"미리보기 모드"},{mode:"split",icon:"hide",title:"분할 모드"},{mode:"code",icon:"code",title:"코드 보기"}].forEach(({mode:i,icon:a,title:l})=>{const n=document.createElement("button");n.type="button",n.className=`${e}__mode-button${this.currentMode===i?` ${e}__mode-button--active`:""}`,n.title=l,n.append(t(a,16)),n.addEventListener("click",()=>{this.currentMode=i,this.updateRootClasses(),this.renderMode(),this.renderToolbar()}),s.append(n)}),this.toolbarEl.append(s);const a=document.createElement("div");if(a.className=`${e}__toolbar-separator`,this.toolbarEl.append(a),"code"!==this.currentMode&&(this.getDefaultToolbarActions().forEach(i=>{const s=document.createElement("button");if(s.type="button",s.className=`${e}__toolbar-item`,s.disabled=this.getBool("disabled"),i.tooltip&&(s.title=i.tooltip),i.icon)s.append(t(i.icon,16));else if("bold"===i.id){const t=document.createElement("strong");t.textContent=i.label,s.append(t)}else if("italic"===i.id){const t=document.createElement("em");t.textContent=i.label,s.append(t)}else if("strikethrough"===i.id){const t=document.createElement("span");t.style.textDecoration="line-through",t.textContent=i.label,s.append(t)}else s.textContent=i.label;if(i.shortcut){const t=document.createElement("span");t.className=`${e}__toolbar-shortcut`,t.textContent=i.shortcut,s.append(t)}s.addEventListener("click",i.action),this.toolbarEl?.append(s)}),this.getBool("file-upload"))){const i=document.createElement("label");i.className=`${e}__file-upload`;const s=document.createElement("input");s.type="file",s.accept="image/*",s.hidden=!0,s.addEventListener("change",async()=>{const t=s.files?.[0];if(!t)return;const e=new CustomEvent("db-file-upload",{detail:{file:t},bubbles:!0,composed:!0,cancelable:!0});if(this.dispatchEvent(e),!e.defaultPrevented){const e=URL.createObjectURL(t);this.insertText(`![${t.name}](${e})`)}s.value=""}),i.append(s,t("upload",16)),this.toolbarEl.append(i)}}renderMode(){if(!this.editPanelEl||!this.previewPanelEl||!this.codePanelEl)return;const t="edit"===this.currentMode||"split"===this.currentMode,e="preview"===this.currentMode||"split"===this.currentMode,i="code"===this.currentMode;this.editPanelEl.hidden=!t,this.previewPanelEl.hidden=!e,this.codePanelEl.hidden=!i,this.updateRootClasses(),this.renderToolbar()}setupAutoSave(){if(this.autoSaveTimer&&window.clearInterval(this.autoSaveTimer),!this.getBool("auto-save"))return;const t=Number(this.getAttribute("auto-save-interval")||3e4);this.autoSaveTimer=window.setInterval(()=>{const t=this.getAttribute("value")||"";this.internalValue&&this.internalValue!==t&&(this.isSaving=!0,this.updateStatus(),this.dispatchEvent(new CustomEvent("db-save",{detail:{value:this.internalValue},bubbles:!0,composed:!0})),this.isSaving=!1,this.lastSaved=new Date,this.updateStatus())},t)}build(){this.toolbarEl=document.createElement("div"),this.toolbarEl.className=`${e}__toolbar`,this.contentEl=document.createElement("div"),this.contentEl.className=`${e}__content`,this.editPanelEl=document.createElement("div"),this.editPanelEl.className=`${e}__edit-panel`,this.textareaEl=document.createElement("textarea"),this.textareaEl.className=`${e}__textarea`,this.textareaEl.addEventListener("input",()=>{this.internalValue=this.textareaEl?.value||"",this.emitChange(),this.updatePreview(),this.updateCodeView(),this.updateCounts()}),this.textareaEl.addEventListener("focus",()=>{this.isFocused=!0,this.updateRootClasses(),this.dispatchEvent(new CustomEvent("db-focus",{bubbles:!0,composed:!0}))}),this.textareaEl.addEventListener("blur",()=>{this.isFocused=!1,this.updateRootClasses(),this.dispatchEvent(new CustomEvent("db-blur",{bubbles:!0,composed:!0}))}),this.textareaEl.addEventListener("keydown",this.handleKeyDown),this.editPanelEl.append(this.textareaEl),this.previewPanelEl=document.createElement("div"),this.previewPanelEl.className=`${e}__preview-panel`,this.previewEl=document.createElement("div"),this.previewEl.className=`${e}__preview`,this.previewPanelEl.append(this.previewEl),this.codePanelEl=document.createElement("div"),this.codePanelEl.className=`${e}__code-panel`,this.codeViewEl=document.createElement("pre"),this.codeViewEl.className=`${e}__code-view`;const t=document.createElement("code");this.codeViewEl.append(t),this.codePanelEl.append(this.codeViewEl),this.contentEl.append(this.editPanelEl,this.previewPanelEl,this.codePanelEl),this.statusEl=document.createElement("div"),this.statusEl.className=`${e}__status`,this.wordCountEl=document.createElement("span"),this.wordCountEl.className=`${e}__word-count`,this.lineCountEl=document.createElement("span"),this.lineCountEl.className=`${e}__line-count`,this.lastSavedEl=document.createElement("span"),this.lastSavedEl.className=`${e}__last-saved`,this.savingEl=document.createElement("span"),this.savingEl.className=`${e}__saving`,this.savingEl.textContent="저장 중...",this.statusEl.append(this.wordCountEl,this.lineCountEl,this.lastSavedEl,this.savingEl),this.append(this.toolbarEl,this.contentEl,this.statusEl)}}customElements.get("db-markdown-editor")||customElements.define("db-markdown-editor",DbMarkdownEditor);export{DbMarkdownEditor};
1
+ import { createDbIcon } from './db-icons.js';
2
+
3
+ const CLASS = 'designbase-wc-markdown-editor';
4
+ class DbMarkdownEditor extends HTMLElement {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.built = false;
8
+ this.internalValue = '';
9
+ this.currentMode = 'preview';
10
+ this.isFocused = false;
11
+ this.wordCount = 0;
12
+ this.lineCount = 0;
13
+ this.lastSaved = null;
14
+ this.isSaving = false;
15
+ this.handleKeyDown = (event) => {
16
+ if (this.getBool('disabled') || this.getBool('readonly'))
17
+ return;
18
+ const { ctrlKey, shiftKey, key } = event;
19
+ if (ctrlKey && key === 'b') {
20
+ event.preventDefault();
21
+ this.insertText('**', '**', '**');
22
+ }
23
+ else if (ctrlKey && key === 'i') {
24
+ event.preventDefault();
25
+ this.insertText('*', '*', '*');
26
+ }
27
+ else if (ctrlKey && key === 'k') {
28
+ event.preventDefault();
29
+ this.insertText('[', '](', ')');
30
+ }
31
+ else if (ctrlKey && key === '`') {
32
+ event.preventDefault();
33
+ this.insertText('`', '`', '`');
34
+ }
35
+ else if (ctrlKey && shiftKey && key === 'S') {
36
+ event.preventDefault();
37
+ this.insertText('~~', '~~', '~~');
38
+ }
39
+ else if (key === 'Tab') {
40
+ event.preventDefault();
41
+ this.insertText(' ', '', '');
42
+ }
43
+ };
44
+ }
45
+ static get observedAttributes() {
46
+ return [
47
+ 'size',
48
+ 'variant',
49
+ 'mode',
50
+ 'theme',
51
+ 'value',
52
+ 'placeholder',
53
+ 'min-height',
54
+ 'max-height',
55
+ 'auto-height',
56
+ 'readonly',
57
+ 'disabled',
58
+ 'show-toolbar',
59
+ 'show-status',
60
+ 'show-word-count',
61
+ 'show-line-count',
62
+ 'auto-save',
63
+ 'auto-save-interval',
64
+ 'file-upload',
65
+ ];
66
+ }
67
+ connectedCallback() {
68
+ if (!this.built) {
69
+ this.built = true;
70
+ this.build();
71
+ }
72
+ this.syncFromAttributes();
73
+ this.renderMode();
74
+ this.updateCounts();
75
+ this.updateStatus();
76
+ this.setupAutoSave();
77
+ }
78
+ disconnectedCallback() {
79
+ if (this.autoSaveTimer)
80
+ window.clearInterval(this.autoSaveTimer);
81
+ }
82
+ attributeChangedCallback(name) {
83
+ if (!this.built)
84
+ return;
85
+ if (name === 'value' && this.textareaEl) {
86
+ this.internalValue = this.getAttribute('value') || '';
87
+ this.textareaEl.value = this.internalValue;
88
+ this.updatePreview();
89
+ this.updateCodeView();
90
+ this.updateCounts();
91
+ return;
92
+ }
93
+ if (name === 'mode') {
94
+ this.currentMode = this.getAttribute('mode') || 'preview';
95
+ this.renderMode();
96
+ return;
97
+ }
98
+ if (name === 'auto-save' || name === 'auto-save-interval') {
99
+ this.setupAutoSave();
100
+ }
101
+ this.updateRootClasses();
102
+ }
103
+ get value() {
104
+ return this.internalValue;
105
+ }
106
+ set value(next) {
107
+ this.internalValue = next;
108
+ this.setAttribute('value', next);
109
+ if (this.textareaEl)
110
+ this.textareaEl.value = next;
111
+ this.updatePreview();
112
+ this.updateCodeView();
113
+ this.updateCounts();
114
+ }
115
+ getBool(name, fallback = false) {
116
+ if (!this.hasAttribute(name))
117
+ return fallback;
118
+ const value = this.getAttribute(name);
119
+ return value === '' || value === 'true';
120
+ }
121
+ syncFromAttributes() {
122
+ this.internalValue = this.getAttribute('value') || '';
123
+ this.currentMode = this.getAttribute('mode') || 'preview';
124
+ if (this.textareaEl) {
125
+ this.textareaEl.value = this.internalValue;
126
+ this.textareaEl.placeholder = this.getAttribute('placeholder') || '마크다운을 입력하세요...';
127
+ this.textareaEl.readOnly = this.getBool('readonly');
128
+ this.textareaEl.disabled = this.getBool('disabled');
129
+ const minHeight = Number(this.getAttribute('min-height') || 200);
130
+ const maxHeight = Number(this.getAttribute('max-height') || 600);
131
+ const autoHeight = this.getBool('auto-height');
132
+ this.textareaEl.style.minHeight = autoHeight ? 'auto' : `${minHeight}px`;
133
+ this.textareaEl.style.maxHeight = autoHeight ? 'none' : `${maxHeight}px`;
134
+ }
135
+ this.updateRootClasses();
136
+ this.updatePreview();
137
+ this.updateCodeView();
138
+ }
139
+ updateRootClasses() {
140
+ const size = this.getAttribute('size') || 'm';
141
+ const variant = this.getAttribute('variant') || 'default';
142
+ const theme = this.getAttribute('theme') || 'light';
143
+ this.className = [
144
+ CLASS,
145
+ `${CLASS}--size-${size}`,
146
+ `${CLASS}--variant-${variant}`,
147
+ `${CLASS}--mode-${this.currentMode}`,
148
+ `${CLASS}--theme-${theme}`,
149
+ this.isFocused && `${CLASS}--focused`,
150
+ this.getBool('disabled') && `${CLASS}--disabled`,
151
+ this.getBool('readonly') && `${CLASS}--readonly`,
152
+ ]
153
+ .filter(Boolean)
154
+ .join(' ');
155
+ }
156
+ markdownToHtml(markdown) {
157
+ return markdown
158
+ .replace(/^### (.*$)/gim, '<h3>$1</h3>')
159
+ .replace(/^## (.*$)/gim, '<h2>$1</h2>')
160
+ .replace(/^# (.*$)/gim, '<h1>$1</h1>')
161
+ .replace(/\*\*(.*)\*\*/gim, '<strong>$1</strong>')
162
+ .replace(/\*(.*)\*/gim, '<em>$1</em>')
163
+ .replace(/~~(.*)~~/gim, '<del>$1</del>')
164
+ .replace(/`(.*)`/gim, '<code>$1</code>')
165
+ .replace(/\[([^\]]+)\]\(([^)]+)\)/gim, '<a href="$2">$1</a>')
166
+ .replace(/!\[([^\]]*)\]\(([^)]+)\)/gim, '<img alt="$1" src="$2" />')
167
+ .replace(/^> (.*$)/gim, '<blockquote>$1</blockquote>')
168
+ .replace(/^- (.*$)/gim, '<ul><li>$1</li></ul>')
169
+ .replace(/^(\d+)\. (.*$)/gim, '<ol><li>$2</li></ol>')
170
+ .replace(/\n/gim, '<br />');
171
+ }
172
+ updatePreview() {
173
+ if (this.previewEl) {
174
+ this.previewEl.innerHTML = this.markdownToHtml(this.internalValue);
175
+ }
176
+ }
177
+ updateCodeView() {
178
+ if (this.codeViewEl) {
179
+ const code = this.codeViewEl.querySelector('code');
180
+ if (code)
181
+ code.textContent = this.internalValue;
182
+ }
183
+ }
184
+ updateCounts() {
185
+ this.wordCount = this.internalValue.trim() ? this.internalValue.trim().split(/\s+/).length : 0;
186
+ this.lineCount = this.internalValue ? this.internalValue.split('\n').length : 0;
187
+ if (this.wordCountEl)
188
+ this.wordCountEl.textContent = `단어: ${this.wordCount}`;
189
+ if (this.lineCountEl)
190
+ this.lineCountEl.textContent = `라인: ${this.lineCount}`;
191
+ }
192
+ updateStatus() {
193
+ if (!this.statusEl)
194
+ return;
195
+ const showStatus = this.getBool('show-status', true);
196
+ this.statusEl.hidden = !showStatus;
197
+ if (this.wordCountEl)
198
+ this.wordCountEl.hidden = !this.getBool('show-word-count', true);
199
+ if (this.lineCountEl)
200
+ this.lineCountEl.hidden = !this.getBool('show-line-count', true);
201
+ if (this.lastSavedEl) {
202
+ this.lastSavedEl.hidden = !this.lastSaved;
203
+ if (this.lastSaved)
204
+ this.lastSavedEl.textContent = `저장됨: ${this.lastSaved.toLocaleTimeString()}`;
205
+ }
206
+ if (this.savingEl)
207
+ this.savingEl.hidden = !this.isSaving;
208
+ }
209
+ emitChange() {
210
+ this.dispatchEvent(new CustomEvent('db-change', {
211
+ detail: { value: this.internalValue },
212
+ bubbles: true,
213
+ composed: true,
214
+ }));
215
+ }
216
+ insertText(text, before = '', after = '') {
217
+ if (!this.textareaEl || this.getBool('disabled') || this.getBool('readonly'))
218
+ return;
219
+ const { selectionStart, selectionEnd } = this.textareaEl;
220
+ const selectedText = this.internalValue.substring(selectionStart, selectionEnd);
221
+ const newText = before + (selectedText || text) + after;
222
+ const newValue = this.internalValue.substring(0, selectionStart) + newText + this.internalValue.substring(selectionEnd);
223
+ this.internalValue = newValue;
224
+ this.textareaEl.value = newValue;
225
+ this.emitChange();
226
+ this.updatePreview();
227
+ this.updateCodeView();
228
+ this.updateCounts();
229
+ const newCursorPos = selectionStart + before.length + (selectedText ? selectedText.length : text.length);
230
+ window.setTimeout(() => {
231
+ if (!this.textareaEl)
232
+ return;
233
+ this.textareaEl.setSelectionRange(newCursorPos, newCursorPos);
234
+ this.textareaEl.focus();
235
+ }, 0);
236
+ }
237
+ getDefaultToolbarActions() {
238
+ return [
239
+ { id: 'bold', label: 'B', tooltip: '굵게 (Ctrl+B)', shortcut: 'Ctrl+B', action: () => this.insertText('**', '**', '**') },
240
+ { id: 'italic', label: 'I', tooltip: '기울임 (Ctrl+I)', shortcut: 'Ctrl+I', action: () => this.insertText('*', '*', '*') },
241
+ { id: 'strikethrough', label: 'S', tooltip: '취소선 (Ctrl+Shift+S)', shortcut: 'Ctrl+Shift+S', action: () => this.insertText('~~', '~~', '~~') },
242
+ { id: 'separator1', label: '|', separator: true, action: () => { } },
243
+ { id: 'heading1', label: 'H1', tooltip: '제목 1', action: () => this.insertText('# ', '', '') },
244
+ { id: 'heading2', label: 'H2', tooltip: '제목 2', action: () => this.insertText('## ', '', '') },
245
+ { id: 'heading3', label: 'H3', tooltip: '제목 3', action: () => this.insertText('### ', '', '') },
246
+ { id: 'separator2', label: '|', separator: true, action: () => { } },
247
+ { id: 'link', label: '', icon: 'share-alt', tooltip: '링크 (Ctrl+K)', shortcut: 'Ctrl+K', action: () => this.insertText('[', '](', ')') },
248
+ { id: 'image', label: '', icon: 'video', tooltip: '이미지', action: () => this.insertText('![', '](', ')') },
249
+ { id: 'code', label: '', icon: 'code', tooltip: '인라인 코드 (Ctrl+`)', shortcut: 'Ctrl+`', action: () => this.insertText('`', '`', '`') },
250
+ { id: 'codeBlock', label: '```', tooltip: '코드 블록', action: () => this.insertText('\n```\n', '', '\n```\n') },
251
+ { id: 'separator3', label: '|', separator: true, action: () => { } },
252
+ { id: 'list', label: '•', tooltip: '순서 없는 목록', action: () => this.insertText('- ', '', '') },
253
+ { id: 'orderedList', label: '1.', tooltip: '순서 있는 목록', action: () => this.insertText('1. ', '', '') },
254
+ { id: 'quote', label: '"', tooltip: '인용구', action: () => this.insertText('> ', '', '') },
255
+ { id: 'separator4', label: '|', separator: true, action: () => { } },
256
+ {
257
+ id: 'table',
258
+ label: '⊞',
259
+ tooltip: '테이블',
260
+ action: () => this.insertText('\n| 헤더1 | 헤더2 | 헤더3 |\n|-------|-------|-------|\n| 셀1 | 셀2 | 셀3 |\n', '', ''),
261
+ },
262
+ { id: 'horizontalRule', label: '—', tooltip: '수평선', action: () => this.insertText('\n---\n', '', '') },
263
+ ];
264
+ }
265
+ renderToolbar() {
266
+ if (!this.toolbarEl)
267
+ return;
268
+ const showToolbar = this.getBool('show-toolbar', true);
269
+ this.toolbarEl.hidden = !showToolbar;
270
+ this.toolbarEl.replaceChildren();
271
+ const modeButtons = document.createElement('div');
272
+ modeButtons.className = `${CLASS}__mode-buttons`;
273
+ const modes = [
274
+ { mode: 'edit', icon: 'write', title: '편집 모드' },
275
+ { mode: 'preview', icon: 'show', title: '미리보기 모드' },
276
+ { mode: 'split', icon: 'hide', title: '분할 모드' },
277
+ { mode: 'code', icon: 'code', title: '코드 보기' },
278
+ ];
279
+ modes.forEach(({ mode, icon, title }) => {
280
+ const button = document.createElement('button');
281
+ button.type = 'button';
282
+ button.className = `${CLASS}__mode-button${this.currentMode === mode ? ` ${CLASS}__mode-button--active` : ''}`;
283
+ button.title = title;
284
+ button.append(createDbIcon(icon, 16));
285
+ button.addEventListener('click', () => {
286
+ this.currentMode = mode;
287
+ this.updateRootClasses();
288
+ this.renderMode();
289
+ this.renderToolbar();
290
+ });
291
+ modeButtons.append(button);
292
+ });
293
+ this.toolbarEl.append(modeButtons);
294
+ const separator = document.createElement('div');
295
+ separator.className = `${CLASS}__toolbar-separator`;
296
+ this.toolbarEl.append(separator);
297
+ if (this.currentMode !== 'code') {
298
+ this.getDefaultToolbarActions().forEach((item) => {
299
+ const button = document.createElement('button');
300
+ button.type = 'button';
301
+ button.className = `${CLASS}__toolbar-item`;
302
+ button.disabled = this.getBool('disabled');
303
+ if (item.tooltip)
304
+ button.title = item.tooltip;
305
+ if (item.icon) {
306
+ button.append(createDbIcon(item.icon, 16));
307
+ }
308
+ else if (item.id === 'bold') {
309
+ const strong = document.createElement('strong');
310
+ strong.textContent = item.label;
311
+ button.append(strong);
312
+ }
313
+ else if (item.id === 'italic') {
314
+ const em = document.createElement('em');
315
+ em.textContent = item.label;
316
+ button.append(em);
317
+ }
318
+ else if (item.id === 'strikethrough') {
319
+ const span = document.createElement('span');
320
+ span.style.textDecoration = 'line-through';
321
+ span.textContent = item.label;
322
+ button.append(span);
323
+ }
324
+ else {
325
+ button.textContent = item.label;
326
+ }
327
+ if (item.shortcut) {
328
+ const shortcut = document.createElement('span');
329
+ shortcut.className = `${CLASS}__toolbar-shortcut`;
330
+ shortcut.textContent = item.shortcut;
331
+ button.append(shortcut);
332
+ }
333
+ button.addEventListener('click', item.action);
334
+ this.toolbarEl?.append(button);
335
+ });
336
+ if (this.getBool('file-upload')) {
337
+ const label = document.createElement('label');
338
+ label.className = `${CLASS}__file-upload`;
339
+ const input = document.createElement('input');
340
+ input.type = 'file';
341
+ input.accept = 'image/*';
342
+ input.hidden = true;
343
+ input.addEventListener('change', async () => {
344
+ const file = input.files?.[0];
345
+ if (!file)
346
+ return;
347
+ const event = new CustomEvent('db-file-upload', {
348
+ detail: { file },
349
+ bubbles: true,
350
+ composed: true,
351
+ cancelable: true,
352
+ });
353
+ this.dispatchEvent(event);
354
+ if (!event.defaultPrevented) {
355
+ const url = URL.createObjectURL(file);
356
+ this.insertText(`![${file.name}](${url})`);
357
+ }
358
+ input.value = '';
359
+ });
360
+ label.append(input, createDbIcon('upload', 16));
361
+ this.toolbarEl.append(label);
362
+ }
363
+ }
364
+ }
365
+ renderMode() {
366
+ if (!this.editPanelEl || !this.previewPanelEl || !this.codePanelEl)
367
+ return;
368
+ const showEdit = this.currentMode === 'edit' || this.currentMode === 'split';
369
+ const showPreview = this.currentMode === 'preview' || this.currentMode === 'split';
370
+ const showCode = this.currentMode === 'code';
371
+ this.editPanelEl.hidden = !showEdit;
372
+ this.previewPanelEl.hidden = !showPreview;
373
+ this.codePanelEl.hidden = !showCode;
374
+ this.updateRootClasses();
375
+ this.renderToolbar();
376
+ }
377
+ setupAutoSave() {
378
+ if (this.autoSaveTimer)
379
+ window.clearInterval(this.autoSaveTimer);
380
+ if (!this.getBool('auto-save'))
381
+ return;
382
+ const interval = Number(this.getAttribute('auto-save-interval') || 30000);
383
+ this.autoSaveTimer = window.setInterval(() => {
384
+ const initial = this.getAttribute('value') || '';
385
+ if (this.internalValue && this.internalValue !== initial) {
386
+ this.isSaving = true;
387
+ this.updateStatus();
388
+ this.dispatchEvent(new CustomEvent('db-save', {
389
+ detail: { value: this.internalValue },
390
+ bubbles: true,
391
+ composed: true,
392
+ }));
393
+ this.isSaving = false;
394
+ this.lastSaved = new Date();
395
+ this.updateStatus();
396
+ }
397
+ }, interval);
398
+ }
399
+ build() {
400
+ this.toolbarEl = document.createElement('div');
401
+ this.toolbarEl.className = `${CLASS}__toolbar`;
402
+ this.contentEl = document.createElement('div');
403
+ this.contentEl.className = `${CLASS}__content`;
404
+ this.editPanelEl = document.createElement('div');
405
+ this.editPanelEl.className = `${CLASS}__edit-panel`;
406
+ this.textareaEl = document.createElement('textarea');
407
+ this.textareaEl.className = `${CLASS}__textarea`;
408
+ this.textareaEl.addEventListener('input', () => {
409
+ this.internalValue = this.textareaEl?.value || '';
410
+ this.emitChange();
411
+ this.updatePreview();
412
+ this.updateCodeView();
413
+ this.updateCounts();
414
+ });
415
+ this.textareaEl.addEventListener('focus', () => {
416
+ this.isFocused = true;
417
+ this.updateRootClasses();
418
+ this.dispatchEvent(new CustomEvent('db-focus', { bubbles: true, composed: true }));
419
+ });
420
+ this.textareaEl.addEventListener('blur', () => {
421
+ this.isFocused = false;
422
+ this.updateRootClasses();
423
+ this.dispatchEvent(new CustomEvent('db-blur', { bubbles: true, composed: true }));
424
+ });
425
+ this.textareaEl.addEventListener('keydown', this.handleKeyDown);
426
+ this.editPanelEl.append(this.textareaEl);
427
+ this.previewPanelEl = document.createElement('div');
428
+ this.previewPanelEl.className = `${CLASS}__preview-panel`;
429
+ this.previewEl = document.createElement('div');
430
+ this.previewEl.className = `${CLASS}__preview`;
431
+ this.previewPanelEl.append(this.previewEl);
432
+ this.codePanelEl = document.createElement('div');
433
+ this.codePanelEl.className = `${CLASS}__code-panel`;
434
+ this.codeViewEl = document.createElement('pre');
435
+ this.codeViewEl.className = `${CLASS}__code-view`;
436
+ const code = document.createElement('code');
437
+ this.codeViewEl.append(code);
438
+ this.codePanelEl.append(this.codeViewEl);
439
+ this.contentEl.append(this.editPanelEl, this.previewPanelEl, this.codePanelEl);
440
+ this.statusEl = document.createElement('div');
441
+ this.statusEl.className = `${CLASS}__status`;
442
+ this.wordCountEl = document.createElement('span');
443
+ this.wordCountEl.className = `${CLASS}__word-count`;
444
+ this.lineCountEl = document.createElement('span');
445
+ this.lineCountEl.className = `${CLASS}__line-count`;
446
+ this.lastSavedEl = document.createElement('span');
447
+ this.lastSavedEl.className = `${CLASS}__last-saved`;
448
+ this.savingEl = document.createElement('span');
449
+ this.savingEl.className = `${CLASS}__saving`;
450
+ this.savingEl.textContent = '저장 중...';
451
+ this.statusEl.append(this.wordCountEl, this.lineCountEl, this.lastSavedEl, this.savingEl);
452
+ this.append(this.toolbarEl, this.contentEl, this.statusEl);
453
+ }
454
+ }
455
+ if (!customElements.get('db-markdown-editor'))
456
+ customElements.define('db-markdown-editor', DbMarkdownEditor);
457
+
458
+ export { DbMarkdownEditor };