aden-editor-vue 0.1.2 → 0.1.4

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.cjs CHANGED
@@ -6595,6 +6595,42 @@ function renderTextChildren(block) {
6595
6595
  return frag;
6596
6596
  }
6597
6597
  init_src();
6598
+ var toastEl = null;
6599
+ var hideTimer = null;
6600
+ var toastUsers = 0;
6601
+ function retainToast() {
6602
+ toastUsers += 1;
6603
+ }
6604
+ function releaseToast() {
6605
+ toastUsers = Math.max(0, toastUsers - 1);
6606
+ if (toastUsers === 0) destroyToast();
6607
+ }
6608
+ function showToast(message, duration = 2600) {
6609
+ if (typeof document === "undefined") return;
6610
+ if (!toastEl || !document.body.contains(toastEl)) {
6611
+ toastEl = document.createElement("div");
6612
+ toastEl.className = "aden-toast";
6613
+ toastEl.setAttribute("role", "status");
6614
+ toastEl.setAttribute("aria-live", "polite");
6615
+ document.body.appendChild(toastEl);
6616
+ }
6617
+ toastEl.textContent = message;
6618
+ void toastEl.offsetWidth;
6619
+ toastEl.classList.add("show");
6620
+ if (hideTimer !== null) window.clearTimeout(hideTimer);
6621
+ hideTimer = window.setTimeout(() => {
6622
+ toastEl == null ? void 0 : toastEl.classList.remove("show");
6623
+ hideTimer = null;
6624
+ }, duration);
6625
+ }
6626
+ function destroyToast() {
6627
+ if (hideTimer !== null) {
6628
+ window.clearTimeout(hideTimer);
6629
+ hideTimer = null;
6630
+ }
6631
+ toastEl == null ? void 0 : toastEl.remove();
6632
+ toastEl = null;
6633
+ }
6598
6634
  function escapeText(s) {
6599
6635
  return s.replace(/[<>&"]/g, (c) => ({ "<": "&lt;", ">": "&gt;", "&": "&amp;", '"': "&quot;" })[c]);
6600
6636
  }
@@ -6657,7 +6693,10 @@ function renderImage(block, handlers) {
6657
6693
  img.style.width = "auto";
6658
6694
  img.style.maxWidth = "100%";
6659
6695
  }
6660
- img.addEventListener("error", () => wrap.classList.add("is-broken"));
6696
+ img.addEventListener("error", () => {
6697
+ wrap.classList.add("is-broken");
6698
+ showToast("\u56FE\u7247\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u56FE\u7247\u5730\u5740\u6216\u914D\u7F6E uploadImage \u4E0A\u4F20\u5230\u53EF\u8BBF\u95EE\u7684\u5B58\u50A8\u670D\u52A1", 5200);
6699
+ });
6661
6700
  if (handlers.isSelected(block.id)) wrap.classList.add("is-selected");
6662
6701
  wrap.appendChild(img);
6663
6702
  return wrap;
@@ -7310,42 +7349,6 @@ function injectAttachmentStyles() {
7310
7349
  injected7 = true;
7311
7350
  }
7312
7351
  init_src();
7313
- var toastEl = null;
7314
- var hideTimer = null;
7315
- var toastUsers = 0;
7316
- function retainToast() {
7317
- toastUsers += 1;
7318
- }
7319
- function releaseToast() {
7320
- toastUsers = Math.max(0, toastUsers - 1);
7321
- if (toastUsers === 0) destroyToast();
7322
- }
7323
- function showToast(message, duration = 2600) {
7324
- if (typeof document === "undefined") return;
7325
- if (!toastEl || !document.body.contains(toastEl)) {
7326
- toastEl = document.createElement("div");
7327
- toastEl.className = "aden-toast";
7328
- toastEl.setAttribute("role", "status");
7329
- toastEl.setAttribute("aria-live", "polite");
7330
- document.body.appendChild(toastEl);
7331
- }
7332
- toastEl.textContent = message;
7333
- void toastEl.offsetWidth;
7334
- toastEl.classList.add("show");
7335
- if (hideTimer !== null) window.clearTimeout(hideTimer);
7336
- hideTimer = window.setTimeout(() => {
7337
- toastEl == null ? void 0 : toastEl.classList.remove("show");
7338
- hideTimer = null;
7339
- }, duration);
7340
- }
7341
- function destroyToast() {
7342
- if (hideTimer !== null) {
7343
- window.clearTimeout(hideTimer);
7344
- hideTimer = null;
7345
- }
7346
- toastEl == null ? void 0 : toastEl.remove();
7347
- toastEl = null;
7348
- }
7349
7352
  var DEFAULT_ACCEPT = [
7350
7353
  "image/png",
7351
7354
  "image/jpeg",
@@ -7439,7 +7442,9 @@ var ImageController = class {
7439
7442
  try {
7440
7443
  const rawUrl = await uploader(file);
7441
7444
  const url = this.opts.upload ? sanitizePersistentMediaUrl(rawUrl) : sanitizeUrl(rawUrl, "media");
7442
- if (!url) throw new Error("\u4E0A\u4F20\u63A5\u53E3\u672A\u8FD4\u56DE\u6709\u6548\u7684\u53EF\u8BBF\u95EE\u56FE\u7247\u5730\u5740");
7445
+ if (!url) {
7446
+ throw new Error(this.opts.upload ? "\u4E0A\u4F20\u63A5\u53E3\u672A\u8FD4\u56DE\u53EF\u6301\u4E45\u8BBF\u95EE\u7684\u56FE\u7247 URL\uFF0C\u8BF7\u68C0\u67E5\u63A5\u53E3\u54CD\u5E94\u548C\u56FE\u7247\u5730\u5740" : "\u672C\u5730\u56FE\u7247\u8BFB\u53D6\u5931\u8D25");
7447
+ }
7443
7448
  resolveImageUpload(this.opts.editor, uploadId, { src: url });
7444
7449
  this.pending.delete(uploadId);
7445
7450
  this.uploadToBlock.delete(uploadId);
@@ -7454,9 +7459,11 @@ var ImageController = class {
7454
7459
  return;
7455
7460
  }
7456
7461
  const msg = (e == null ? void 0 : e.message) || "\u672A\u77E5\u9519\u8BEF";
7462
+ const userMessage = this.opts.upload ? `\u56FE\u7247\u4E0A\u4F20\u5931\u8D25\uFF1A${msg}\u3002\u8BF7\u68C0\u67E5 uploadImage \u63A5\u53E3\u5730\u5740\u3001\u9274\u6743\u548C\u670D\u52A1\u7AEF\u54CD\u5E94` : `\u56FE\u7247\u5904\u7406\u5931\u8D25\uFF1A${msg}\u3002\u8BF7\u914D\u7F6E uploadImage \u56FE\u7247\u4E0A\u4F20\u63A5\u53E3\u540E\u91CD\u8BD5`;
7463
+ showToast(userMessage, 6500);
7457
7464
  const blockId = this.uploadToBlock.get(uploadId);
7458
7465
  const blockStillExists = !!blockId && this.opts.editor.getDoc().blocks.some((block) => block.id === blockId);
7459
- resolveImageUpload(this.opts.editor, uploadId, { error: msg });
7466
+ resolveImageUpload(this.opts.editor, uploadId, { error: userMessage });
7460
7467
  if (!blockStillExists) {
7461
7468
  this.pending.delete(uploadId);
7462
7469
  this.uploadToBlock.delete(uploadId);
@@ -9378,7 +9385,7 @@ var WebAdapter = class {
9378
9385
  }
9379
9386
  if (images.length) {
9380
9387
  e.preventDefault();
9381
- const existingImageIds = new Set(
9388
+ const existingImageIds2 = new Set(
9382
9389
  this.editor.getDoc().blocks.filter((block) => block.type === "image").map((block) => block.id)
9383
9390
  );
9384
9391
  if (pasteHtml2) {
@@ -9387,7 +9394,7 @@ var WebAdapter = class {
9387
9394
  this.runCommand((cmd) => cmd.pastePlainText(this.editor, pasteText));
9388
9395
  }
9389
9396
  const pastedImages = this.editor.getDoc().blocks.filter(
9390
- (block) => block.type === "image" && !existingImageIds.has(block.id)
9397
+ (block) => block.type === "image" && !existingImageIds2.has(block.id)
9391
9398
  );
9392
9399
  images.forEach((file, index) => {
9393
9400
  const target = pastedImages[index];
@@ -9396,10 +9403,25 @@ var WebAdapter = class {
9396
9403
  });
9397
9404
  return;
9398
9405
  }
9406
+ const clipboardContainsImageMarkup = /<img\b|v:imagedata|w:drawing/i.test(pasteHtml2);
9407
+ const existingImageIds = new Set(
9408
+ this.editor.getDoc().blocks.filter((block) => block.type === "image").map((block) => block.id)
9409
+ );
9399
9410
  e.preventDefault();
9400
9411
  this.runCommand((cmd) => {
9401
9412
  if (pasteHtml2) cmd.pasteHtml(this.editor, pasteHtml2);
9402
9413
  else if (pasteText) cmd.pastePlainText(this.editor, pasteText);
9414
+ if (clipboardContainsImageMarkup) {
9415
+ const pastedImages = this.editor.getDoc().blocks.filter(
9416
+ (block) => block.type === "image" && !existingImageIds.has(block.id)
9417
+ );
9418
+ if (!pastedImages.some((block) => {
9419
+ var _a22, _b2;
9420
+ return sanitizeUrl(String((_b2 = (_a22 = block.attrs) == null ? void 0 : _a22.src) != null ? _b2 : ""), "media");
9421
+ })) {
9422
+ showToast("\u672A\u80FD\u4ECE\u526A\u8D34\u677F\u8BFB\u53D6\u56FE\u7247\u6587\u4EF6\u6216\u6709\u6548\u56FE\u7247\u5730\u5740\u3002\u8BF7\u68C0\u67E5 Word \u590D\u5236\u5185\u5BB9\uFF0C\u6216\u5728 options \u4E2D\u914D\u7F6E uploadImage \u56FE\u7247\u4E0A\u4F20\u63A5\u53E3\u3002", 6500);
9423
+ }
9424
+ }
9403
9425
  });
9404
9426
  };
9405
9427
  this.handleDragOver = (e) => {