@ones-editor/editor 2.8.17 → 2.8.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.js CHANGED
@@ -10797,6 +10797,23 @@ var __publicField = (obj, key, value) => {
10797
10797
  function fromBase64ToBlob(data2) {
10798
10798
  return new Blob([jsBase64.Base64.toUint8Array(data2)]);
10799
10799
  }
10800
+ function dataURLToBlob(dataURL) {
10801
+ var _a;
10802
+ const [header, data2] = dataURL.split(",");
10803
+ const mimeString = ((_a = header.match(/:(.*?);/)) == null ? void 0 : _a[1]) || "";
10804
+ const isBase642 = header.includes("base64");
10805
+ let blob;
10806
+ if (isBase642) {
10807
+ blob = fromBase64ToBlob(data2);
10808
+ } else {
10809
+ const byteString = decodeURIComponent(data2);
10810
+ blob = new Blob([byteString], { type: mimeString });
10811
+ }
10812
+ return { blob, mimeString };
10813
+ }
10814
+ function stringToBase64DataUrl(data2, type) {
10815
+ return `data:${type};base64,${toBase64URL(data2)}`;
10816
+ }
10800
10817
  const patch = snabbdom.init([snabbdom.classModule, snabbdom.styleModule, snabbdom.datasetModule, snabbdom.attributesModule, snabbdom.propsModule]);
10801
10818
  function patchNode(oldContent, newContent) {
10802
10819
  const oldVNode = snabbdom.toVNode(oldContent);
@@ -68146,6 +68163,33 @@ ${codeText}
68146
68163
  this.editor.input.addHandler(this);
68147
68164
  });
68148
68165
  }
68166
+ async handleBeforePasteDoc(editor, doc2) {
68167
+ for (const blocks of Object.values(doc2.blocks)) {
68168
+ for (const blockData of blocks) {
68169
+ if (blockData.type === "embed" && blockData.embedType === "image") {
68170
+ const imageData = blockData.embedData;
68171
+ const resources = Array.isArray(imageData.src) ? imageData.src : [imageData.src];
68172
+ const uploadedResources = resources.map(async (src) => {
68173
+ if (src.startsWith("data:")) {
68174
+ const { blob, mimeString } = dataURLToBlob(src);
68175
+ let ext = mimeString.split("/")[1] || "png";
68176
+ if (ext.indexOf("+") > 0) {
68177
+ ext = ext.split("+")[0];
68178
+ }
68179
+ const fileName = `image.${ext}`;
68180
+ const file2 = new File([blob], fileName, { type: mimeString });
68181
+ const ret = await editor.doc.uploadResource(file2);
68182
+ return ret.resourceId;
68183
+ }
68184
+ return src;
68185
+ });
68186
+ const newSrc = await Promise.all(uploadedResources);
68187
+ imageData.src = Array.isArray(imageData.src) ? newSrc : newSrc[0];
68188
+ }
68189
+ }
68190
+ }
68191
+ return false;
68192
+ }
68149
68193
  async handleAfterPasteDoc(editor, doc2, cloneDocResult) {
68150
68194
  Object.values(doc2.blocks).forEach((blocks) => {
68151
68195
  blocks.forEach((blockData) => {
@@ -76082,6 +76126,23 @@ ${content}
76082
76126
  }
76083
76127
  Array.from(element.children).forEach(removeHiddenElements);
76084
76128
  }
76129
+ function processDataUrl(fragment) {
76130
+ const images = fragment.querySelectorAll("img");
76131
+ images.forEach((img) => {
76132
+ var _a;
76133
+ const src = img.getAttribute("src");
76134
+ if (src && src.startsWith("data:")) {
76135
+ const [header, data2] = src.split(",");
76136
+ const mimeString = ((_a = header.split(":")[1]) == null ? void 0 : _a.split(";")[0]) || "image/png";
76137
+ const isBase642 = header.includes("base64");
76138
+ if (!isBase642) {
76139
+ const byteString = decodeURIComponent(data2);
76140
+ const url = stringToBase64DataUrl(byteString, mimeString);
76141
+ img.setAttribute("src", url);
76142
+ }
76143
+ }
76144
+ });
76145
+ }
76085
76146
  function processHtml(html, options) {
76086
76147
  const fragment = htmlToFragment(html);
76087
76148
  fragment.querySelectorAll("td.js-line-number").forEach((cell) => cell.remove());
@@ -76092,6 +76153,7 @@ ${content}
76092
76153
  Array.from(fragment.children).forEach((node) => convertAllTables(node, options));
76093
76154
  Array.from(fragment.children).forEach(removeStyleElement);
76094
76155
  replaceHljsFragmentToCode(fragment);
76156
+ processDataUrl(fragment);
76095
76157
  const newHtml = fragmentToHtml(fragment);
76096
76158
  return newHtml;
76097
76159
  }
@@ -92069,7 +92131,7 @@ ${data2.plantumlText}
92069
92131
  class InsertImageItem {
92070
92132
  constructor() {
92071
92133
  __publicField(this, "id", "insert-image");
92072
- __publicField(this, "name", "Insert Image");
92134
+ __publicField(this, "name", i18n$1.t("toolbar.image"));
92073
92135
  __publicField(this, "icon", ImageIcon);
92074
92136
  }
92075
92137
  onClick(editor, item) {
@@ -92085,7 +92147,7 @@ ${data2.plantumlText}
92085
92147
  class InsertLinkItem {
92086
92148
  constructor() {
92087
92149
  __publicField(this, "id", "insert-link");
92088
- __publicField(this, "name", "Insert Link");
92150
+ __publicField(this, "name", i18n$1.t("toolbar.link"));
92089
92151
  __publicField(this, "icon", LinkIcon);
92090
92152
  __publicField(this, "states", []);
92091
92153
  }
@@ -92112,7 +92174,7 @@ ${data2.plantumlText}
92112
92174
  class OrderedListItem {
92113
92175
  constructor() {
92114
92176
  __publicField(this, "id", "ordered-list");
92115
- __publicField(this, "name", "Ordered List");
92177
+ __publicField(this, "name", i18n$1.t("toolbar.orderedList"));
92116
92178
  __publicField(this, "icon", OrderedListIcon);
92117
92179
  __publicField(this, "states", []);
92118
92180
  }
@@ -92141,7 +92203,7 @@ ${data2.plantumlText}
92141
92203
  class UnorderedListItem {
92142
92204
  constructor() {
92143
92205
  __publicField(this, "id", "unordered-list");
92144
- __publicField(this, "name", "Unordered List");
92206
+ __publicField(this, "name", i18n$1.t("toolbar.unorderedList"));
92145
92207
  __publicField(this, "icon", UnorderedListIcon);
92146
92208
  __publicField(this, "states", []);
92147
92209
  }
@@ -92170,7 +92232,7 @@ ${data2.plantumlText}
92170
92232
  class CheckListItem {
92171
92233
  constructor() {
92172
92234
  __publicField(this, "id", "check-list");
92173
- __publicField(this, "name", "Check List");
92235
+ __publicField(this, "name", i18n$1.t("toolbar.checkList"));
92174
92236
  __publicField(this, "icon", CheckListIcon);
92175
92237
  __publicField(this, "states", []);
92176
92238
  }
@@ -92272,7 +92334,7 @@ ${data2.plantumlText}
92272
92334
  class QuoteItem {
92273
92335
  constructor() {
92274
92336
  __publicField(this, "id", "quoted");
92275
- __publicField(this, "name", "Quote");
92337
+ __publicField(this, "name", i18n$1.t("toolbar.quote"));
92276
92338
  __publicField(this, "icon", QuoteIcon);
92277
92339
  __publicField(this, "states", []);
92278
92340
  }
@@ -92335,17 +92397,17 @@ ${data2.plantumlText}
92335
92397
  }
92336
92398
  class AlignLeftItem extends AlignBaseItem {
92337
92399
  constructor() {
92338
- super("align-left", "Align left", AlignLeftIcon);
92400
+ super("align-left", i18n$1.t("commands.alignLeft"), AlignLeftIcon);
92339
92401
  }
92340
92402
  }
92341
92403
  class AlignCenterItem extends AlignBaseItem {
92342
92404
  constructor() {
92343
- super("align-center", "Align center", AlignCenterIcon);
92405
+ super("align-center", i18n$1.t("commands.alignCenter"), AlignCenterIcon);
92344
92406
  }
92345
92407
  }
92346
92408
  class AlignRightItem extends AlignBaseItem {
92347
92409
  constructor() {
92348
- super("align-right", "Align right", AlignRightIcon);
92410
+ super("align-right", i18n$1.t("commands.alignRight"), AlignRightIcon);
92349
92411
  }
92350
92412
  }
92351
92413
  const UndoIcon = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M6 2L2.5 5.49999L6 9" stroke="currentColor" stroke-linejoin="round"></path>\n<path d="M3 5.5H9.5C11.7091 5.5 13.5 7.29086 13.5 9.5V9.5C13.5 11.7091 11.7091 13.5 9.5 13.5H8" stroke="currentColor"></path>\n</svg>';
@@ -92635,7 +92697,13 @@ ${data2.plantumlText}
92635
92697
  undo: "\u64A4\u9500",
92636
92698
  redo: "\u91CD\u505A",
92637
92699
  insert: "\u63D2\u5165",
92638
- findReplace: "\u67E5\u627E\u548C\u66FF\u6362"
92700
+ findReplace: "\u67E5\u627E\u548C\u66FF\u6362",
92701
+ image: "\u63D2\u5165\u56FE\u7247",
92702
+ link: "\u63D2\u5165\u94FE\u63A5",
92703
+ quote: "\u5F15\u7528",
92704
+ checkList: "\u4EFB\u52A1\u5217\u8868",
92705
+ orderedList: "\u6709\u5E8F\u5217\u8868",
92706
+ unorderedList: "\u65E0\u5E8F\u5217\u8868"
92639
92707
  }
92640
92708
  };
92641
92709
  const enUS = {
@@ -92643,7 +92711,13 @@ ${data2.plantumlText}
92643
92711
  undo: "Undo",
92644
92712
  redo: "Redo",
92645
92713
  insert: "Insert",
92646
- findReplace: "Find & Replace"
92714
+ findReplace: "Find & Replace",
92715
+ image: "Insert Image",
92716
+ link: "Insert Link",
92717
+ quote: "Quote",
92718
+ checkList: "Check List",
92719
+ orderedList: "Ordered List",
92720
+ unorderedList: "Unordered List"
92647
92721
  }
92648
92722
  };
92649
92723
  const jaJP = {
@@ -92651,7 +92725,13 @@ ${data2.plantumlText}
92651
92725
  undo: "\u5143\u306B\u623B\u3059",
92652
92726
  redo: "\u3084\u308A\u76F4\u3059",
92653
92727
  insert: "\u633F\u5165",
92654
- findReplace: "\u691C\u7D22\u3068\u7F6E\u63DB"
92728
+ findReplace: "\u691C\u7D22\u3068\u7F6E\u63DB",
92729
+ image: "\u753B\u50CF\u3092\u633F\u5165",
92730
+ link: "\u30EA\u30F3\u30AF\u3092\u633F\u5165",
92731
+ quote: "\u5F15\u7528",
92732
+ checkList: "\u30C1\u30A7\u30C3\u30AF\u30EA\u30B9\u30C8",
92733
+ orderedList: "\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",
92734
+ unorderedList: "\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8"
92655
92735
  }
92656
92736
  };
92657
92737
  i18n$1.mergeLang({
@@ -92984,7 +93064,7 @@ ${data2.plantumlText}
92984
93064
  }
92985
93065
  }
92986
93066
  });
92987
- editor.version = "2.8.17";
93067
+ editor.version = "2.8.19";
92988
93068
  return editor;
92989
93069
  }
92990
93070
  function isDoc(doc2) {
@@ -93097,7 +93177,7 @@ ${data2.plantumlText}
93097
93177
  }
93098
93178
  });
93099
93179
  OnesEditorToolbar.register(editor);
93100
- editor.version = "2.8.17";
93180
+ editor.version = "2.8.19";
93101
93181
  return editor;
93102
93182
  }
93103
93183
  async function showDocVersions(editor, options, serverUrl) {
@@ -139266,6 +139346,7 @@ ${data2.plantumlText}
139266
139346
  exports2.createTextButton = createTextButton;
139267
139347
  exports2.createTextOp = createTextOp;
139268
139348
  exports2.createTextWithReplaceSoftReturn = createTextWithReplaceSoftReturn;
139349
+ exports2.dataURLToBlob = dataURLToBlob;
139269
139350
  exports2.daysAfter = daysAfter;
139270
139351
  exports2.deleteColor = deleteColor;
139271
139352
  exports2.deleteText = deleteText;
@@ -139662,6 +139743,7 @@ ${data2.plantumlText}
139662
139743
  exports2.showToast = showToast;
139663
139744
  exports2.splitText = splitText;
139664
139745
  exports2.splitToThree = splitToThree;
139746
+ exports2.stringToBase64DataUrl = stringToBase64DataUrl;
139665
139747
  exports2.stringToDataUrl = stringToDataUrl;
139666
139748
  exports2.stringToObjectUrl = stringToObjectUrl;
139667
139749
  exports2.subText = subText;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "2.8.17",
3
+ "version": "2.8.19",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {