@worktile/theia 19.5.0-next.1 → 19.5.0-next.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.
@@ -8774,7 +8774,7 @@ const withDeserializeMd = (editor) => {
8774
8774
  closeConversionHint(editor);
8775
8775
  onKeydown(event);
8776
8776
  };
8777
- editor.customInsertFragmentData = async (data) => {
8777
+ editor.customInsertFragmentData = async (data, contextClipboardData) => {
8778
8778
  const popover = editor.injector.get(ThyPopover);
8779
8779
  const viewContainerRef = editor.injector.get(ViewContainerRef);
8780
8780
  const cdr = editor.injector.get(ChangeDetectorRef);
@@ -8845,7 +8845,7 @@ const withDeserializeMd = (editor) => {
8845
8845
  cdr.markForCheck();
8846
8846
  });
8847
8847
  }
8848
- return customInsertFragmentData(data);
8848
+ return customInsertFragmentData(data, contextClipboardData);
8849
8849
  };
8850
8850
  return editor;
8851
8851
  };
@@ -10695,7 +10695,7 @@ const createTheHistoryPlugin = createPluginFactory({
10695
10695
 
10696
10696
  const withInsertDataByInvalidType = (editor) => {
10697
10697
  const { customInsertFragmentData } = editor;
10698
- editor.customInsertFragmentData = async (data) => {
10698
+ editor.customInsertFragmentData = async (data, clipboardData) => {
10699
10699
  const fragment = await extractFragment(data);
10700
10700
  if (fragment) {
10701
10701
  const isContinue = insertDataByInvalidType(editor, fragment);
@@ -10703,7 +10703,7 @@ const withInsertDataByInvalidType = (editor) => {
10703
10703
  return true;
10704
10704
  }
10705
10705
  }
10706
- return customInsertFragmentData(data);
10706
+ return customInsertFragmentData(data, clipboardData);
10707
10707
  };
10708
10708
  return editor;
10709
10709
  };
@@ -10956,24 +10956,25 @@ const createResetTypePlugin = createPluginFactory({
10956
10956
 
10957
10957
  const withDeserializeHTML = (editor) => {
10958
10958
  const { customInsertFragmentData } = editor;
10959
- editor.customInsertFragmentData = async (data) => {
10959
+ editor.customInsertFragmentData = async (data, contextClipboardData) => {
10960
10960
  const fragmentFromHTML = await extractFragmentByHTML(data);
10961
10961
  if (fragmentFromHTML) {
10962
+ const newContextClipboardData = { elements: fragmentFromHTML };
10962
10963
  // 识别粘贴的 HTML 只有纯链接, 跳至 link
10963
10964
  if (fragmentFromHTML.length === 1 && fragmentFromHTML.every(block => isUrl(block?.children?.[0]?.['text']))) {
10964
- return customInsertFragmentData(data);
10965
+ return customInsertFragmentData(data, newContextClipboardData);
10965
10966
  }
10966
10967
  // 无法识别HTML内容时后退一下:识别纯文本
10967
10968
  if (fragmentFromHTML.every(block => block.type === ElementKinds.paragraph && isLogicEmptyParagraphElement(editor, block))) {
10968
- return customInsertFragmentData(data);
10969
+ return customInsertFragmentData(data, null);
10969
10970
  }
10970
10971
  // 识出纯图片并且粘贴板中存在文件则不进行处理, hook 直接右键复制图片的场景,流转到上传图片流程
10971
10972
  // 后续需要做识别html图片后自动上传处理
10972
10973
  if (fragmentFromHTML.length === 1 && fragmentFromHTML[0].type === ElementKinds.image && data.files.length > 0) {
10973
- return customInsertFragmentData(data);
10974
+ return customInsertFragmentData(data, contextClipboardData || null);
10974
10975
  }
10975
- if (fragmentFromHTML.length === 1 && fragmentFromHTML[0].type === ElementKinds.table) {
10976
- return customInsertFragmentData(data);
10976
+ if (isLogicTableElement(editor, fragmentFromHTML)) {
10977
+ return customInsertFragmentData(data, newContextClipboardData);
10977
10978
  }
10978
10979
  // 过滤 text 节点的 color/background-color 属性
10979
10980
  fragmentFromHTML.forEach(node => filterTextFormat(node));
@@ -10997,7 +10998,7 @@ const withDeserializeHTML = (editor) => {
10997
10998
  Transforms.insertFragment(editor, fragmentFromHTML);
10998
10999
  return true;
10999
11000
  }
11000
- return customInsertFragmentData(data);
11001
+ return customInsertFragmentData(data, contextClipboardData || null);
11001
11002
  };
11002
11003
  return editor;
11003
11004
  };
@@ -11005,6 +11006,10 @@ const createDeserializeHTMLPlugin = createPluginFactory({
11005
11006
  key: PluginKeys.deserializeHtml,
11006
11007
  withOverrides: withDeserializeHTML
11007
11008
  });
11009
+ const isLogicTableElement = (editor, elements) => {
11010
+ const elementsFiltered = elements.filter(element => element.type !== ElementKinds.paragraph || !isLogicEmptyParagraphElement(editor, element));
11011
+ return elementsFiltered.length === 1 && elementsFiltered[0].type === ElementKinds.table;
11012
+ };
11008
11013
 
11009
11014
  const FontSizeEditor = {
11010
11015
  setFontSize(editor, size) {
@@ -11888,9 +11893,10 @@ const withImage = (editor) => {
11888
11893
  editor.isVoid = (element) => {
11889
11894
  return element.type === ElementKinds.image || isVoid(element);
11890
11895
  };
11891
- editor.customInsertFragmentData = async (data) => {
11896
+ editor.customInsertFragmentData = async (data, contextClipboardData) => {
11892
11897
  const clipboardData = await getClipboardData(data);
11893
- if (clipboardData?.files?.length) {
11898
+ const res = await customInsertFragmentData(data, contextClipboardData);
11899
+ if (!res && clipboardData?.files?.length) {
11894
11900
  const imageFiles = [];
11895
11901
  const imageTypes = getPluginOptions(editor, PluginKeys.image)?.imageTypes;
11896
11902
  for (const file of data.files) {
@@ -11903,7 +11909,7 @@ const withImage = (editor) => {
11903
11909
  return true;
11904
11910
  }
11905
11911
  }
11906
- return customInsertFragmentData(data);
11912
+ return res;
11907
11913
  };
11908
11914
  editor.renderElement = (element) => {
11909
11915
  if (element.type === ElementKinds.image) {
@@ -12464,7 +12470,7 @@ const withLink = (editor) => {
12464
12470
  insertText(text);
12465
12471
  }
12466
12472
  };
12467
- editor.customInsertFragmentData = async (data) => {
12473
+ editor.customInsertFragmentData = async (data, contextClipboardData) => {
12468
12474
  const clipboardData = await getClipboardData(data);
12469
12475
  const text = clipboardData?.text;
12470
12476
  if (!clipboardData?.elements && text && isUrl(text)) {
@@ -12485,7 +12491,7 @@ const withLink = (editor) => {
12485
12491
  return true;
12486
12492
  }
12487
12493
  }
12488
- return customInsertFragmentData(data);
12494
+ return customInsertFragmentData(data, contextClipboardData);
12489
12495
  };
12490
12496
  editor.renderElement = (element) => {
12491
12497
  if (element.type === ElementKinds.link) {
@@ -13409,7 +13415,7 @@ const withList = (editor) => {
13409
13415
  }
13410
13416
  deleteBackward(unit);
13411
13417
  };
13412
- editor.customInsertFragmentData = async (data) => {
13418
+ editor.customInsertFragmentData = async (data, clipboardData) => {
13413
13419
  const fragment = await extractFragment(data);
13414
13420
  if (fragment) {
13415
13421
  const aboveEntry = Editor.above(editor, {
@@ -13425,7 +13431,7 @@ const withList = (editor) => {
13425
13431
  return true;
13426
13432
  }
13427
13433
  }
13428
- return customInsertFragmentData(data);
13434
+ return customInsertFragmentData(data, clipboardData);
13429
13435
  };
13430
13436
  editor.onKeydown = (event) => {
13431
13437
  const isContinue = !onKeyDownList(event, editor);
@@ -17602,17 +17608,16 @@ const withTable = (editor) => {
17602
17608
  }
17603
17609
  setFragmentData(data, originEvent);
17604
17610
  };
17605
- editor.customInsertFragmentData = async (data) => {
17611
+ editor.customInsertFragmentData = async (data, contextClipboardData) => {
17606
17612
  let fragment = await extractFragment(data);
17607
17613
  if (!fragment) {
17608
- fragment = await extractFragmentByHTML(data);
17614
+ fragment = contextClipboardData ? contextClipboardData.elements : null;
17609
17615
  }
17610
17616
  if (fragment) {
17611
17617
  const opts = new TableOptions();
17612
- if (isSelectionInTable(opts, editor) &&
17613
- fragment.length === 1 &&
17614
- Element.isElement(fragment[0]) &&
17615
- fragment[0].type === ElementKinds.table) {
17618
+ const isTableFragment = fragment.length === 1 && Element.isElement(fragment[0]) && fragment[0].type === ElementKinds.table;
17619
+ if (isSelectionInTable(opts, editor) && (isTableFragment || isLogicTableElement(editor, fragment))) {
17620
+ fragment = fragment.filter(node => node.type === ElementKinds.table);
17616
17621
  const tablePosition = createTablePosition(editor);
17617
17622
  const clipboardTable = fragment[0].children;
17618
17623
  const clipboardRow = clipboardTable[0].children;
@@ -17678,9 +17683,9 @@ const withTable = (editor) => {
17678
17683
  });
17679
17684
  });
17680
17685
  }
17681
- return customInsertFragmentData(data);
17686
+ return customInsertFragmentData(data, contextClipboardData);
17682
17687
  }
17683
- return customInsertFragmentData(data);
17688
+ return customInsertFragmentData(data, null);
17684
17689
  };
17685
17690
  editor.normalizeNode = ([node, path]) => {
17686
17691
  if (Element.isElement(node) && node.type === ElementKinds.table) {