@ones-editor/editor 2.8.14-beta.1 → 2.8.14-beta.3

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
@@ -76814,25 +76814,8 @@ ${docStr}
76814
76814
  };
76815
76815
  }
76816
76816
  }
76817
- function isContainHyperlink(text2) {
76818
- const pattern = /^([\d\w\u4e00-\u9fa5\s]*[\u4e00-\u9fa5\s]{1}|)((https|http|ftp)?:\/\/)[^\s]+/;
76819
- return pattern.test(text2);
76820
- }
76821
- function transText2TextOp(text2) {
76822
- const ret = [];
76823
- const prefix = text2.split(/https|http|ftp/)[0];
76824
- const link2 = text2.substring(prefix.length).trim();
76825
- if (prefix && prefix.length) {
76826
- const textOp = createTextOp(prefix, null);
76827
- ret.push(textOp, createTextOp(" ", null));
76828
- }
76829
- const linkOp = createTextOp(link2, { link: link2 });
76830
- ret.push(linkOp, createTextOp(" ", null));
76831
- return ret;
76832
- }
76833
76817
  class TextDataConverter {
76834
- async fromData(editor, data2, options) {
76835
- const { toPlainText: toPlainText2 = false } = options || {};
76818
+ async fromData(editor, data2) {
76836
76819
  const result = {};
76837
76820
  const text2 = data2.getData("text/plain");
76838
76821
  if (text2) {
@@ -76842,10 +76825,6 @@ ${docStr}
76842
76825
  id: genId(),
76843
76826
  type: "text"
76844
76827
  };
76845
- if (isContainHyperlink(line) && !toPlainText2) {
76846
- block.text = transText2TextOp(line);
76847
- return block;
76848
- }
76849
76828
  const text22 = line ? [createTextOp(line, null)] : [];
76850
76829
  block.text = text22;
76851
76830
  return block;
@@ -76862,6 +76841,103 @@ ${docStr}
76862
76841
  return result;
76863
76842
  }
76864
76843
  }
76844
+ function findLinks(text2) {
76845
+ const pattern = /https?:\/\/[^\s/$.?#].[^\s]*/g;
76846
+ const results = [];
76847
+ let match;
76848
+ while ((match = pattern.exec(text2)) !== null) {
76849
+ const url = match[0];
76850
+ const startIndex = match.index;
76851
+ const endIndex = pattern.lastIndex;
76852
+ results.push({ url, startIndex, endIndex });
76853
+ }
76854
+ return results;
76855
+ }
76856
+ function urlToLinkOp(result) {
76857
+ const attributes = {
76858
+ link: result.url
76859
+ };
76860
+ return {
76861
+ insert: result.url,
76862
+ attributes
76863
+ };
76864
+ }
76865
+ function opToLinks(op) {
76866
+ var _a, _b;
76867
+ if ((_a = op.attributes) == null ? void 0 : _a.box) {
76868
+ return [op];
76869
+ }
76870
+ if ((_b = op.attributes) == null ? void 0 : _b.link) {
76871
+ return [op];
76872
+ }
76873
+ const text2 = op.insert;
76874
+ const attributes = op.attributes;
76875
+ const results = findLinks(text2);
76876
+ if (results.length === 0) {
76877
+ return [op];
76878
+ }
76879
+ let current = text2;
76880
+ const ops = [];
76881
+ for (let i = results.length - 1; i >= 0; i--) {
76882
+ const result = results[i];
76883
+ const right = current.substring(result.endIndex);
76884
+ if (right) {
76885
+ const rightOp = {
76886
+ insert: right
76887
+ };
76888
+ if (attributes) {
76889
+ rightOp.attributes = JSON.parse(JSON.stringify(attributes));
76890
+ }
76891
+ ops.unshift(rightOp);
76892
+ }
76893
+ const boxOp = urlToLinkOp(result);
76894
+ if (boxOp) {
76895
+ ops.unshift(boxOp);
76896
+ } else {
76897
+ const keepText = current.substring(result.startIndex, result.endIndex);
76898
+ const keepOp = {
76899
+ insert: keepText
76900
+ };
76901
+ if (attributes) {
76902
+ keepOp.attributes = attributes;
76903
+ }
76904
+ ops.unshift(keepOp);
76905
+ }
76906
+ current = current.substring(0, result.startIndex);
76907
+ }
76908
+ if (current) {
76909
+ const lastOp = {
76910
+ insert: current
76911
+ };
76912
+ if (attributes) {
76913
+ lastOp.attributes = attributes;
76914
+ }
76915
+ ops.unshift(lastOp);
76916
+ }
76917
+ return ops;
76918
+ }
76919
+ class ConvertLinkPasteHandler {
76920
+ constructor() {
76921
+ __publicField(this, "order");
76922
+ this.order = 200;
76923
+ }
76924
+ async handleBeforePasteDoc(editor, doc2) {
76925
+ for (const blocks of Object.values(doc2.blocks)) {
76926
+ for (const block of blocks) {
76927
+ if (block.type === "text") {
76928
+ const ops = block.text || [];
76929
+ const newOps = [];
76930
+ for (const op of ops) {
76931
+ const subOps = opToLinks(op);
76932
+ newOps.push(...subOps);
76933
+ }
76934
+ block.text = newOps;
76935
+ }
76936
+ }
76937
+ }
76938
+ return false;
76939
+ }
76940
+ }
76865
76941
  function getImages(files) {
76866
76942
  const images = [];
76867
76943
  for (let i = 0; i < files.length; i++) {
@@ -76875,6 +76951,7 @@ ${docStr}
76875
76951
  }
76876
76952
  class OnesEditorPasteHandler {
76877
76953
  constructor(editor) {
76954
+ editor.input.addHandler(new ConvertLinkPasteHandler());
76878
76955
  editor.dataConverter.addConverter(new HtmlDataConverter());
76879
76956
  editor.dataConverter.addConverter(new TextDataConverter());
76880
76957
  editor.dataConverter.addConverter(new MarkdownDataConverter());
@@ -86653,7 +86730,7 @@ ${data2.plantumlText}
86653
86730
  this.editor.removeListener("selectionChanged", this.handleSelectionChange);
86654
86731
  this.editor.removeListener("docChanged", this.handleSelectionChange);
86655
86732
  document.removeEventListener("touchstart", this.handleTouchStart);
86656
- document.removeEventListener("touchend", this.handleTouchEnd);
86733
+ document.removeEventListener("touchend", this.handleTouchEnd, { capture: true });
86657
86734
  document.removeEventListener("touchmove", this.handleTouchMove);
86658
86735
  this.mobileEmbedMask.destroy();
86659
86736
  this.cursorToolbar.destroy();
@@ -92662,7 +92739,7 @@ ${data2.plantumlText}
92662
92739
  }
92663
92740
  }
92664
92741
  });
92665
- editor.version = "2.8.14-beta.1";
92742
+ editor.version = "2.8.14-beta.3";
92666
92743
  return editor;
92667
92744
  }
92668
92745
  function isDoc(doc2) {
@@ -92775,7 +92852,7 @@ ${data2.plantumlText}
92775
92852
  }
92776
92853
  });
92777
92854
  OnesEditorToolbar.register(editor);
92778
- editor.version = "2.8.14-beta.1";
92855
+ editor.version = "2.8.14-beta.3";
92779
92856
  return editor;
92780
92857
  }
92781
92858
  async function showDocVersions(editor, options, serverUrl) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "2.8.14-beta.1",
3
+ "version": "2.8.14-beta.3",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {