@8btc/mditor 0.0.18 → 0.0.19

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/index.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.18 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.19 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -25,7 +25,7 @@
25
25
  *
26
26
  */
27
27
  /*!
28
- * Vditor v0.0.18 - A markdown editor written in TypeScript.
28
+ * Vditor v0.0.19 - A markdown editor written in TypeScript.
29
29
  *
30
30
  * MIT License
31
31
  *
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.0.18 - A markdown editor written in TypeScript.
2
+ * Vditor v0.0.19 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -2866,7 +2866,7 @@ var Vditor = /** @class */ (function () {
2866
2866
  /* harmony export */ "H": () => (/* binding */ _VDITOR_VERSION),
2867
2867
  /* harmony export */ "g": () => (/* binding */ Constants)
2868
2868
  /* harmony export */ });
2869
- var _VDITOR_VERSION = "0.0.18";
2869
+ var _VDITOR_VERSION = "0.0.19";
2870
2870
 
2871
2871
  var Constants = /** @class */ (function () {
2872
2872
  function Constants() {
@@ -3168,7 +3168,7 @@ var Constants = /** @class */ (function () {
3168
3168
  "c#",
3169
3169
  "bat",
3170
3170
  ];
3171
- Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.18");
3171
+ Constants.CDN = "https://webcdn.wujieai.com/vditor@".concat("0.0.19");
3172
3172
  Constants.MARKDOWN_OPTIONS = {
3173
3173
  autoSpace: false,
3174
3174
  gfmAutoLink: true,
@@ -18323,7 +18323,7 @@ var wysiwyg_generator = (undefined && undefined.__generator) || function (thisAr
18323
18323
  var WYSIWYG = /** @class */ (function () {
18324
18324
  function WYSIWYG(vditor) {
18325
18325
  var _this = this;
18326
- var _a;
18326
+ var _a, _b, _c, _d, _e, _f;
18327
18327
  this.composingLock = false;
18328
18328
  this.commentIds = [];
18329
18329
  this.vditor = vditor;
@@ -18332,7 +18332,15 @@ var WYSIWYG = /** @class */ (function () {
18332
18332
  if ((_a = vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.enable) {
18333
18333
  divElement.classList.add("vditor--linenumber");
18334
18334
  }
18335
- divElement.innerHTML = "<pre class=\"vditor-reset\" placeholder=\"".concat(vditor.options.placeholder, "\"\n contenteditable=\"true\" spellcheck=\"false\"></pre>\n<div class=\"vditor-panel vditor-panel--none\"></div>\n<div class=\"vditor-selection-popover\">\n <div class=\"vditor-selection-popover__actions\">\n <button type=\"button\" data-action=\"ai\" aria-label=\"AI\u7F16\u8F91\" class=\"vditor-selection-popover__btn\">\u2728 AI\u7F16\u8F91</button>\n <button type=\"button\" data-action=\"cut\" aria-label=\"\u526A\u5207\" class=\"vditor-selection-popover__btn\">\u526A\u5207</button>\n <button type=\"button\" data-action=\"copy\" aria-label=\"\u590D\u5236\" class=\"vditor-selection-popover__btn\">\u590D\u5236</button>\n </div>\n <div class=\"vditor-selection-popover__input\">\n <textarea placeholder=\"\u8BF7\u8F93\u5165\u60A8\u60F3\u4FEE\u6539\u7684\u5185\u5BB9\"></textarea>\n <button class=\"vditor-selection-popover__send\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"lucide lucide-sparkles-icon lucide-sparkles\"><path d=\"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z\"/><path d=\"M20 2v4\"/><path d=\"M22 4h-4\"/><circle cx=\"4\" cy=\"20\" r=\"2\"/></svg>\n </button>\n </div>\n</div>");
18335
+ // 构建选择浮窗的操作按钮HTML
18336
+ var aiButtonHtml = ((_b = vditor.options.ai) === null || _b === void 0 ? void 0 : _b.enable)
18337
+ ? '<button type="button" data-action="ai" aria-label="AI编辑" class="vditor-selection-popover__btn">✨ AI编辑</button>'
18338
+ : '';
18339
+ // 构建AI输入区域HTML
18340
+ var aiInputHtml = ((_c = vditor.options.ai) === null || _c === void 0 ? void 0 : _c.enable)
18341
+ ? "<div class=\"vditor-selection-popover__input\">\n <textarea placeholder=\"\u8BF7\u8F93\u5165\u60A8\u60F3\u4FEE\u6539\u7684\u5185\u5BB9\"></textarea>\n <button class=\"vditor-selection-popover__send\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"lucide lucide-sparkles-icon lucide-sparkles\"><path d=\"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z\"/><path d=\"M20 2v4\"/><path d=\"M22 4h-4\"/><circle cx=\"4\" cy=\"20\" r=\"2\"/></svg>\n </button>\n </div>"
18342
+ : '';
18343
+ divElement.innerHTML = "<pre class=\"vditor-reset\" placeholder=\"".concat(vditor.options.placeholder, "\"\n contenteditable=\"true\" spellcheck=\"false\"></pre>\n<div class=\"vditor-panel vditor-panel--none\"></div>\n<div class=\"vditor-selection-popover\">\n <div class=\"vditor-selection-popover__actions\">\n ").concat(aiButtonHtml, "\n <button type=\"button\" data-action=\"cut\" aria-label=\"\u526A\u5207\" class=\"vditor-selection-popover__btn\">\u526A\u5207</button>\n <button type=\"button\" data-action=\"copy\" aria-label=\"\u590D\u5236\" class=\"vditor-selection-popover__btn\">\u590D\u5236</button>\n </div>\n ").concat(aiInputHtml, "\n</div>");
18336
18344
  this.element = divElement.firstElementChild;
18337
18345
  this.popover = divElement.firstElementChild
18338
18346
  .nextElementSibling;
@@ -18340,13 +18348,14 @@ var WYSIWYG = /** @class */ (function () {
18340
18348
  this.popoverInput = this.selectPopover.querySelector("textarea");
18341
18349
  this.popoverSendBtn = this.selectPopover.querySelector(".vditor-selection-popover__send");
18342
18350
  this.bindEvent(vditor);
18343
- // 绑定发送按钮事件
18344
- if (this.popoverSendBtn) {
18351
+ // 绑定发送按钮事件(仅在AI启用时)
18352
+ if (this.popoverSendBtn && ((_d = vditor.options.ai) === null || _d === void 0 ? void 0 : _d.enable)) {
18345
18353
  this.popoverSendBtn.setAttribute("disabled", "disabled");
18346
18354
  this.popoverSendBtn.onclick = function (event) {
18355
+ var _a;
18347
18356
  event.stopPropagation();
18348
- if (vditor.options.ai) {
18349
- vditor.options.ai({
18357
+ if ((_a = vditor.options.ai) === null || _a === void 0 ? void 0 : _a.callback) {
18358
+ vditor.options.ai.callback({
18350
18359
  value: _this.popoverInput.value,
18351
18360
  content: _this.selectionContent,
18352
18361
  lines: _this.selectionLines,
@@ -18354,30 +18363,30 @@ var WYSIWYG = /** @class */ (function () {
18354
18363
  }
18355
18364
  _this.hideSelectionPopover();
18356
18365
  };
18357
- // 阻止点击 popover 内任何区域时导致编辑器失去焦点
18358
- // 但不影响 textarea 获取焦点和按钮点击
18359
- this.selectPopover.addEventListener("mousedown", function (event) {
18360
- var target = event.target;
18361
- // 如果点击的是 textarea 或 button,允许默认行为
18362
- if (target.tagName === "TEXTAREA" ||
18363
- target.tagName === "BUTTON") {
18364
- return;
18366
+ }
18367
+ // 阻止点击 popover 内任何区域时导致编辑器失去焦点
18368
+ // 但不影响 textarea 获取焦点和按钮点击
18369
+ this.selectPopover.addEventListener("mousedown", function (event) {
18370
+ var target = event.target;
18371
+ // 如果点击的是 textarea button,允许默认行为
18372
+ if (target.tagName === "TEXTAREA" ||
18373
+ target.tagName === "BUTTON") {
18374
+ return;
18375
+ }
18376
+ // 其他情况阻止默认行为,防止编辑器失去焦点
18377
+ event.preventDefault();
18378
+ event.stopPropagation();
18379
+ });
18380
+ // 输入验证(仅在AI启用时)
18381
+ if (this.popoverInput && ((_e = vditor.options.ai) === null || _e === void 0 ? void 0 : _e.enable)) {
18382
+ this.popoverInput.addEventListener("input", function () {
18383
+ if (_this.popoverInput.value.trim().length > 0) {
18384
+ _this.popoverSendBtn.removeAttribute("disabled");
18385
+ }
18386
+ else {
18387
+ _this.popoverSendBtn.setAttribute("disabled", "disabled");
18365
18388
  }
18366
- // 其他情况阻止默认行为,防止编辑器失去焦点
18367
- event.preventDefault();
18368
- event.stopPropagation();
18369
18389
  });
18370
- // 输入验证
18371
- if (this.popoverInput) {
18372
- this.popoverInput.addEventListener("input", function () {
18373
- if (_this.popoverInput.value.trim().length > 0) {
18374
- _this.popoverSendBtn.removeAttribute("disabled");
18375
- }
18376
- else {
18377
- _this.popoverSendBtn.setAttribute("disabled", "disabled");
18378
- }
18379
- });
18380
- }
18381
18390
  }
18382
18391
  focusEvent(vditor, this.element);
18383
18392
  dblclickEvent(vditor, this.element);
@@ -18387,38 +18396,28 @@ var WYSIWYG = /** @class */ (function () {
18387
18396
  dropEvent(vditor, this.element);
18388
18397
  copyEvent(vditor, this.element, this.copy);
18389
18398
  cutEvent(vditor, this.element, this.copy);
18390
- // 选择浮窗按钮事件绑定
18391
- // const aiBtn = this.selectPopover.querySelector(
18392
- // '[data-action="ai"]'
18393
- // ) as HTMLButtonElement | null;
18394
- // if (aiBtn) {
18395
- // /**
18396
- // * AI编辑按钮占位事件
18397
- // * - 当前仅输出日志,不执行编辑逻辑
18398
- // */
18399
- // aiBtn.onclick = () => {
18400
- // console.log("[Selection AI Edit] clicked");
18401
- // };
18402
- // }
18403
- var copyBtn = this.selectPopover.querySelector('[data-action="copy"]');
18404
- if (copyBtn) {
18405
- /**
18406
- * 复制按钮点击处理
18407
- * - 优先使用 Clipboard API;降级为 execCommand('copy')
18408
- */
18409
- copyBtn.onclick = function () {
18410
- _this.copySelection(vditor);
18411
- };
18412
- }
18413
- var cutBtn = this.selectPopover.querySelector('[data-action="cut"]');
18414
- if (cutBtn) {
18415
- /**
18416
- * 剪切按钮点击处理
18417
- * - 将选区复制到剪贴板后删除,并接入撤销栈
18418
- */
18419
- cutBtn.onclick = function () {
18420
- _this.cutSelection(vditor);
18421
- };
18399
+ // 选择浮窗按钮事件绑定(仅在AI启用时)
18400
+ if ((_f = vditor.options.ai) === null || _f === void 0 ? void 0 : _f.enable) {
18401
+ var copyBtn = this.selectPopover.querySelector('[data-action="copy"]');
18402
+ if (copyBtn) {
18403
+ /**
18404
+ * 复制按钮点击处理
18405
+ * - 优先使用 Clipboard API;降级为 execCommand('copy')
18406
+ */
18407
+ copyBtn.onclick = function () {
18408
+ _this.copySelection(vditor);
18409
+ };
18410
+ }
18411
+ var cutBtn = this.selectPopover.querySelector('[data-action="cut"]');
18412
+ if (cutBtn) {
18413
+ /**
18414
+ * 剪切按钮点击处理
18415
+ * - 将选区复制到剪贴板后删除,并接入撤销栈
18416
+ */
18417
+ cutBtn.onclick = function () {
18418
+ _this.cutSelection(vditor);
18419
+ };
18420
+ }
18422
18421
  }
18423
18422
  // 评论按钮仅在启用时注册(避免选择浮窗结构变化导致报错)
18424
18423
  if (vditor.options.comment.enable) {
@@ -18562,8 +18561,14 @@ var WYSIWYG = /** @class */ (function () {
18562
18561
  /**
18563
18562
  * 显示选择浮窗(定位于选区右上)
18564
18563
  * - 当未选中文本或选区不在编辑器内时不显示
18564
+ * - 当AI功能未启用时不显示
18565
18565
  */
18566
18566
  WYSIWYG.prototype.showSelectionPopover = function () {
18567
+ var _a;
18568
+ // 如果AI功能未启用,不显示选择浮窗
18569
+ if (!((_a = this.vditor.options.ai) === null || _a === void 0 ? void 0 : _a.enable)) {
18570
+ return;
18571
+ }
18567
18572
  if (getSelection().rangeCount === 0) {
18568
18573
  return;
18569
18574
  }
@@ -19453,6 +19458,11 @@ var Vditor = /** @class */ (function (_super) {
19453
19458
  if (!Array.isArray(numbers)) {
19454
19459
  return;
19455
19460
  }
19461
+ // 当 highlightTimer 为 0 时,不处理高亮逻辑
19462
+ var highlightTimer = (_a = this.vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.highlightTimer;
19463
+ if (highlightTimer === 0) {
19464
+ return;
19465
+ }
19456
19466
  var valid = numbers
19457
19467
  .filter(function (n) { return typeof n === "number" && isFinite(n); })
19458
19468
  .map(function (n) { return String(Math.floor(n)); });
@@ -19467,7 +19477,7 @@ var Vditor = /** @class */ (function (_super) {
19467
19477
  if (nodeList.length === 0) {
19468
19478
  return;
19469
19479
  }
19470
- var duration = Math.max(0, Number((_a = this.vditor.options.lineNumber) === null || _a === void 0 ? void 0 : _a.highlightTimer) || 1500);
19480
+ var duration = Math.max(0, Number(highlightTimer) || 1500);
19471
19481
  var apply = function () {
19472
19482
  nodeList.forEach(function (el) {
19473
19483
  var old = lineHighlightTimers.get(el);