@8btc/mditor 0.0.12 → 0.0.14

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.
@@ -69,7 +69,7 @@ class WYSIWYG {
69
69
  <div class="vditor-panel vditor-panel--none"></div>
70
70
  <div class="vditor-selection-popover">
71
71
  <div class="vditor-selection-popover__actions">
72
- <button type="button" data-action="ai" aria-label="AI编辑" class="vditor-selection-popover__btn" disabled>✨ AI编辑</button>
72
+ <button type="button" data-action="ai" aria-label="AI编辑" class="vditor-selection-popover__btn">✨ AI编辑</button>
73
73
  <button type="button" data-action="cut" aria-label="剪切" class="vditor-selection-popover__btn">剪切</button>
74
74
  <button type="button" data-action="copy" aria-label="复制" class="vditor-selection-popover__btn">复制</button>
75
75
  </div>
@@ -109,12 +109,18 @@ class WYSIWYG {
109
109
  }
110
110
  this.hideSelectionPopover();
111
111
  };
112
- // 阻止点击输入区域时清除选区
113
- this.selectPopover
114
- .querySelector(".vditor-selection-popover__input")
115
- ?.addEventListener("mousedown", (event) => {
116
- event.stopPropagation();
117
- });
112
+ // 阻止点击 popover 内任何区域时导致编辑器失去焦点
113
+ // 但不影响 textarea 获取焦点和按钮点击
114
+ this.selectPopover.addEventListener("mousedown", (event) => {
115
+ const target = event.target as HTMLElement;
116
+ // 如果点击的是 textarea 或 button,允许默认行为
117
+ if (target.tagName === "TEXTAREA" || target.tagName === "BUTTON") {
118
+ return;
119
+ }
120
+ // 其他情况阻止默认行为,防止编辑器失去焦点
121
+ event.preventDefault();
122
+ event.stopPropagation();
123
+ });
118
124
 
119
125
  // 输入验证
120
126
  if (this.popoverInput) {
@@ -141,18 +147,18 @@ class WYSIWYG {
141
147
  cutEvent(vditor, this.element, this.copy);
142
148
 
143
149
  // 选择浮窗按钮事件绑定
144
- const aiBtn = this.selectPopover.querySelector(
145
- '[data-action="ai"]'
146
- ) as HTMLButtonElement | null;
147
- if (aiBtn) {
148
- /**
149
- * AI编辑按钮占位事件
150
- * - 当前仅输出日志,不执行编辑逻辑
151
- */
152
- aiBtn.onclick = () => {
153
- console.log("[Selection AI Edit] clicked");
154
- };
155
- }
150
+ // const aiBtn = this.selectPopover.querySelector(
151
+ // '[data-action="ai"]'
152
+ // ) as HTMLButtonElement | null;
153
+ // if (aiBtn) {
154
+ // /**
155
+ // * AI编辑按钮占位事件
156
+ // * - 当前仅输出日志,不执行编辑逻辑
157
+ // */
158
+ // aiBtn.onclick = () => {
159
+ // console.log("[Selection AI Edit] clicked");
160
+ // };
161
+ // }
156
162
  const copyBtn = this.selectPopover.querySelector(
157
163
  '[data-action="copy"]'
158
164
  ) as HTMLButtonElement | null;
@@ -224,8 +230,8 @@ class WYSIWYG {
224
230
  item.getAttribute("data-block") === "0" &&
225
231
  index === contents.childNodes.length - 1 &&
226
232
  rangeClone.endOffset <
227
- rangeClone.endContainer.textContent
228
- .length
233
+ rangeClone.endContainer.textContent
234
+ .length
229
235
  ) {
230
236
  item.innerHTML = `<span class="vditor-comment" data-cmtids="${id}">${item.innerHTML}</span>`;
231
237
  blockEndElement = item;