@worktile/theia 19.1.5 → 19.1.7

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.
@@ -77,7 +77,7 @@ export declare class TheListboxDirective implements AfterContentInit {
77
77
  setPreviousLineActive(): void;
78
78
  enterNextGroup(): void;
79
79
  enterPreviousGroup(): void;
80
- setActiveItem(previous: TheListboxOptionDirective | null, option: TheListboxOptionDirective, type: TheListboxChangeEventType): void;
80
+ setActiveItem(previous: TheListboxOptionDirective | null, option: TheListboxOptionDirective, type: TheListboxChangeEventType, triggerFrom?: 'mouse' | 'keyboard'): void;
81
81
  getOption(key: ThePluginMenuItemKey): TheListboxOptionDirective;
82
82
  clearActiveItem(): void;
83
83
  static ɵfac: i0.ɵɵFactoryDeclaration<TheListboxDirective, never>;
@@ -1,7 +1,8 @@
1
1
  import { ChangeDetectorRef, DestroyRef, ElementRef, EventEmitter, Injector, NgZone, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewContainerRef } from '@angular/core';
2
2
  import { ThyIconRegistry } from 'ngx-tethys/icon';
3
3
  import { Descendant, Editor, Element, NodeEntry, Range, Text } from 'slate';
4
- import { DOMRange, SlateError } from 'slate-angular';
4
+ import { SlateError } from 'slate-angular';
5
+ import { DOMRange } from 'slate-dom';
5
6
  import { TheTemplate, TheText, TheToolbarComponent } from './components';
6
7
  import { TheEditor, TheOptions, ThePresetConfig, ThePlugin, ToolbarEntity, DomEventDataInfo } from './interfaces';
7
8
  import { TheContextService } from './services/context.service';
@@ -10,8 +10,9 @@ import { cloneDeep, map, assign, defaults, groupBy, uniq, isEqual } from 'lodash
10
10
  export { assign, cloneDeep, debounce, defaults, groupBy, isEqual, map, uniq } from 'lodash';
11
11
  import { Editor, Element, Span, Range, Path, Node, Point, Text, Transforms, Operation, createEditor } from 'slate';
12
12
  import * as i4 from 'slate-angular';
13
- import { FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, NODE_TO_PARENT, NODE_TO_INDEX, getClipboardData, AngularEditor, hotkeys, getPlainText as getPlainText$1, createClipboardData, setClipboardData, isClipboardWriteSupported, BaseElementComponent, IS_SAFARI, ELEMENT_TO_COMPONENT, NODE_TO_ELEMENT, BaseTextComponent, SlateModule, hasBlockCard, isCardLeft, SlateChildrenOutlet, EDITOR_TO_ELEMENT, defaultScrollSelectionIntoView, getDataTransferClipboard, withAngular } from 'slate-angular';
13
+ import { FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, getClipboardData, AngularEditor, hotkeys, getPlainText as getPlainText$1, createClipboardData, setClipboardData, isClipboardWriteSupported, BaseElementComponent, IS_SAFARI, ELEMENT_TO_COMPONENT, BaseTextComponent, SlateModule, hasBlockCard, isCardLeft, SlateChildrenOutlet, defaultScrollSelectionIntoView, getDataTransferClipboard, withAngular } from 'slate-angular';
14
14
  import { HistoryEditor, withHistory } from 'slate-history';
15
+ import { NODE_TO_PARENT, NODE_TO_INDEX, NODE_TO_ELEMENT, EDITOR_TO_ELEMENT } from 'slate-dom';
15
16
  import { TheiaConverter } from '@atinc/selene';
16
17
  import { isObject, isArray, isString, isUndefined } from 'ngx-tethys/util';
17
18
  import * as i1 from 'ngx-tethys/popover';
@@ -4324,12 +4325,15 @@ class TheListboxDirective {
4324
4325
  }
4325
4326
  this.setActiveItem(this.activeOption, groups[newGroupIndex].getLast(), 'turn');
4326
4327
  }
4327
- setActiveItem(previous, option, type) {
4328
+ setActiveItem(previous, option, type, triggerFrom = 'keyboard') {
4328
4329
  if (previous) {
4329
4330
  previous.setActive(false);
4330
4331
  }
4331
4332
  option.setActive(true);
4332
4333
  this.activeOption = option;
4334
+ if (triggerFrom === 'mouse' && type === 'turn') {
4335
+ return;
4336
+ }
4333
4337
  this.theListboxChange.emit({ option, type });
4334
4338
  }
4335
4339
  getOption(key) {
@@ -7988,7 +7992,7 @@ class ThePluginMenuComponent {
7988
7992
  if (listBox) {
7989
7993
  const activeOption = listBox.activeOption;
7990
7994
  const newActiveOption = listBox.getOption(menu?.key);
7991
- listBox.setActiveItem(activeOption, newActiveOption, 'turn');
7995
+ listBox.setActiveItem(activeOption, newActiveOption, 'turn', 'mouse');
7992
7996
  }
7993
7997
  }
7994
7998
  listBoxOptionMouseleave(e, menu) {
@@ -8469,12 +8473,12 @@ const closeConversionHint = (editor) => {
8469
8473
  }
8470
8474
  };
8471
8475
  const withDeserializeMd = (editor) => {
8472
- const { insertFragmentData, onKeydown } = editor;
8476
+ const { customInsertFragmentData, onKeydown } = editor;
8473
8477
  editor.onKeydown = (event) => {
8474
8478
  closeConversionHint(editor);
8475
8479
  onKeydown(event);
8476
8480
  };
8477
- editor.insertFragmentData = async (data) => {
8481
+ editor.customInsertFragmentData = async (data) => {
8478
8482
  const popover = editor.injector.get(ThyPopover);
8479
8483
  const viewContainerRef = editor.injector.get(ViewContainerRef);
8480
8484
  const cdr = editor.injector.get(ChangeDetectorRef);
@@ -8545,7 +8549,7 @@ const withDeserializeMd = (editor) => {
8545
8549
  cdr.markForCheck();
8546
8550
  });
8547
8551
  }
8548
- return insertFragmentData(data);
8552
+ return customInsertFragmentData(data);
8549
8553
  };
8550
8554
  return editor;
8551
8555
  };
@@ -10394,8 +10398,8 @@ const createTheHistoryPlugin = createPluginFactory({
10394
10398
  });
10395
10399
 
10396
10400
  const withInsertDataByInvalidType = (editor) => {
10397
- const { insertFragmentData } = editor;
10398
- editor.insertFragmentData = async (data) => {
10401
+ const { customInsertFragmentData } = editor;
10402
+ editor.customInsertFragmentData = async (data) => {
10399
10403
  const fragment = await extractFragment(data);
10400
10404
  if (fragment) {
10401
10405
  const isContinue = insertDataByInvalidType(editor, fragment);
@@ -10403,7 +10407,7 @@ const withInsertDataByInvalidType = (editor) => {
10403
10407
  return true;
10404
10408
  }
10405
10409
  }
10406
- return insertFragmentData(data);
10410
+ return customInsertFragmentData(data);
10407
10411
  };
10408
10412
  return editor;
10409
10413
  };
@@ -10425,7 +10429,7 @@ const withMoveSelection = (editor) => {
10425
10429
  editor.onClick = (event) => {
10426
10430
  const domSelection = window.getSelection();
10427
10431
  if (domSelection && !domSelection.isCollapsed && event.detail >= 2 && editor.selection) {
10428
- const slateSelection = AngularEditor.toSlateRange(editor, domSelection);
10432
+ const slateSelection = AngularEditor.toSlateRange(editor, domSelection, { exactMatch: false, suppressThrow: false });
10429
10433
  const isNextStart = slateSelection.focus.offset === 0;
10430
10434
  if (Range.isExpanded(slateSelection) && Range.isForward(slateSelection) && isNextStart) {
10431
10435
  const beforePoint = Editor.before(editor, slateSelection.focus);
@@ -10655,24 +10659,24 @@ const createResetTypePlugin = createPluginFactory({
10655
10659
  });
10656
10660
 
10657
10661
  const withDeserializeHTML = (editor) => {
10658
- const { insertFragmentData } = editor;
10659
- editor.insertFragmentData = async (data) => {
10662
+ const { customInsertFragmentData } = editor;
10663
+ editor.customInsertFragmentData = async (data) => {
10660
10664
  const clipboardData = await getClipboardData(data);
10661
10665
  if (!clipboardData?.elements && clipboardData?.html) {
10662
10666
  const htmlDom = new DOMParser().parseFromString(clipboardData?.html, 'text/html');
10663
10667
  const fragment = TheiaConverter.convertToTheia(Array.from(htmlDom.body.children));
10664
10668
  // 识别粘贴的 HTML 只有纯链接, 跳至 link
10665
10669
  if (fragment.length === 1 && fragment.every(block => isUrl(block?.children?.[0]?.['text']))) {
10666
- return insertFragmentData(data);
10670
+ return customInsertFragmentData(data);
10667
10671
  }
10668
10672
  // 无法识别HTML内容时后退一下:识别纯文本
10669
10673
  if (fragment.every(block => block.type === ElementKinds.paragraph && isLogicEmptyParagraphElement(editor, block))) {
10670
- return insertFragmentData(data);
10674
+ return customInsertFragmentData(data);
10671
10675
  }
10672
10676
  // 识出纯图片并且粘贴板中存在文件则不进行处理, hook 直接右键复制图片的场景,流转到上传图片流程
10673
10677
  // 后续需要做识别html图片后自动上传处理
10674
10678
  if (fragment.length === 1 && fragment[0].type === ElementKinds.image && data.files.length > 0) {
10675
- return insertFragmentData(data);
10679
+ return customInsertFragmentData(data);
10676
10680
  }
10677
10681
  // 过滤 text 节点的 color/background-color 属性
10678
10682
  fragment.forEach(node => filterTextFormat(node));
@@ -10696,7 +10700,7 @@ const withDeserializeHTML = (editor) => {
10696
10700
  Transforms.insertFragment(editor, fragment);
10697
10701
  return true;
10698
10702
  }
10699
- return insertFragmentData(data);
10703
+ return customInsertFragmentData(data);
10700
10704
  };
10701
10705
  return editor;
10702
10706
  };
@@ -10810,7 +10814,7 @@ const cleanHeadingEffect = (editor, path) => {
10810
10814
  }
10811
10815
  };
10812
10816
  const withHeading = (editor) => {
10813
- const { insertBreak, isVisible, apply, deleteBackward, onClick } = editor;
10817
+ const { insertBreak, isVisible, apply, deleteBackward, mousedown } = editor;
10814
10818
  editor.apply = operation => {
10815
10819
  try {
10816
10820
  if (operation.type === 'merge_node' && operation.path.length === 1) {
@@ -10926,7 +10930,7 @@ const withHeading = (editor) => {
10926
10930
  }
10927
10931
  return isVisible(node);
10928
10932
  };
10929
- editor.onClick = (event) => {
10933
+ editor.mousedown = (event) => {
10930
10934
  const target = event.target;
10931
10935
  if (target instanceof HTMLElement && target.classList.contains('slate-editable-container')) {
10932
10936
  const index = editor.children.length - 1;
@@ -10935,6 +10939,7 @@ const withHeading = (editor) => {
10935
10939
  const path = [index];
10936
10940
  const collapsedStandardHeadings = getCollapsedStandardHeadingAbove(editor, path);
10937
10941
  if (collapsedStandardHeadings.length > 0) {
10942
+ event.preventDefault();
10938
10943
  const headingPath = collapsedStandardHeadings[collapsedStandardHeadings.length - 1];
10939
10944
  const headingNode = editor.children[headingPath[0]];
10940
10945
  const dom = AngularEditor.toDOMNode(editor, headingNode);
@@ -10951,10 +10956,13 @@ const withHeading = (editor) => {
10951
10956
  Transforms.insertNodes(editor, createEmptyParagraph(), { at: [index + 1] });
10952
10957
  Transforms.select(editor, [index + 1]);
10953
10958
  }
10959
+ AngularEditor.focus(editor);
10954
10960
  }
10955
10961
  }
10962
+ return;
10956
10963
  }
10957
10964
  }
10965
+ mousedown(event);
10958
10966
  };
10959
10967
  return editor;
10960
10968
  };
@@ -11581,11 +11589,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
11581
11589
  }] } });
11582
11590
 
11583
11591
  const withImage = (editor) => {
11584
- const { insertFragmentData, isVoid, renderElement, isBlockCard, mousedown } = editor;
11592
+ const { customInsertFragmentData, isVoid, renderElement, isBlockCard, mousedown } = editor;
11585
11593
  editor.isVoid = (element) => {
11586
11594
  return element.type === ElementKinds.image || isVoid(element);
11587
11595
  };
11588
- editor.insertFragmentData = async (data) => {
11596
+ editor.customInsertFragmentData = async (data) => {
11589
11597
  const clipboardData = await getClipboardData(data);
11590
11598
  if (clipboardData?.files?.length) {
11591
11599
  const imageFiles = [];
@@ -11600,7 +11608,7 @@ const withImage = (editor) => {
11600
11608
  return true;
11601
11609
  }
11602
11610
  }
11603
- return insertFragmentData(data);
11611
+ return customInsertFragmentData(data);
11604
11612
  };
11605
11613
  editor.renderElement = (element) => {
11606
11614
  if (element.type === ElementKinds.image) {
@@ -12148,7 +12156,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
12148
12156
  }] } });
12149
12157
 
12150
12158
  const withLink = (editor) => {
12151
- const { insertText, isInline, insertFragmentData, renderElement } = editor;
12159
+ const { insertText, isInline, customInsertFragmentData, renderElement } = editor;
12152
12160
  editor.isInline = (element) => {
12153
12161
  return element.type === ElementKinds.link ? true : isInline(element);
12154
12162
  };
@@ -12161,7 +12169,7 @@ const withLink = (editor) => {
12161
12169
  insertText(text);
12162
12170
  }
12163
12171
  };
12164
- editor.insertFragmentData = async (data) => {
12172
+ editor.customInsertFragmentData = async (data) => {
12165
12173
  const clipboardData = await getClipboardData(data);
12166
12174
  const text = clipboardData?.text;
12167
12175
  if (!clipboardData?.elements && text && isUrl(text)) {
@@ -12182,7 +12190,7 @@ const withLink = (editor) => {
12182
12190
  return true;
12183
12191
  }
12184
12192
  }
12185
- return insertFragmentData(data);
12193
+ return customInsertFragmentData(data);
12186
12194
  };
12187
12195
  editor.renderElement = (element) => {
12188
12196
  if (element.type === ElementKinds.link) {
@@ -12939,7 +12947,7 @@ const unwrapList = (editor) => {
12939
12947
  };
12940
12948
 
12941
12949
  const withList = (editor) => {
12942
- const { insertBreak, deleteBackward, onKeydown, insertFragmentData, setFragmentData, renderElement } = editor;
12950
+ const { insertBreak, deleteBackward, onKeydown, customInsertFragmentData, setFragmentData, renderElement } = editor;
12943
12951
  const validLiChildrenTypes = getPluginOptions(editor, PluginKeys.list)?.validLiChildrenTypes ?? [];
12944
12952
  const resetBlockTypesListRule = {
12945
12953
  types: [ElementKinds.listItem],
@@ -13106,7 +13114,7 @@ const withList = (editor) => {
13106
13114
  }
13107
13115
  deleteBackward(unit);
13108
13116
  };
13109
- editor.insertFragmentData = async (data) => {
13117
+ editor.customInsertFragmentData = async (data) => {
13110
13118
  const fragment = await extractFragment(data);
13111
13119
  if (fragment) {
13112
13120
  const aboveEntry = Editor.above(editor, {
@@ -13122,7 +13130,7 @@ const withList = (editor) => {
13122
13130
  return true;
13123
13131
  }
13124
13132
  }
13125
- return insertFragmentData(data);
13133
+ return customInsertFragmentData(data);
13126
13134
  };
13127
13135
  editor.onKeydown = (event) => {
13128
13136
  const isContinue = !onKeyDownList(event, editor);
@@ -14095,7 +14103,7 @@ class TableStore {
14095
14103
  }
14096
14104
  selectCellOngoing(cell, editor, event) {
14097
14105
  const pos = createTablePosition(editor);
14098
- if (AngularEditor.isReadonly(editor) || !editor.selection || !pos?.table) {
14106
+ if (AngularEditor.isReadOnly(editor) || !editor.selection || !pos?.table) {
14099
14107
  return;
14100
14108
  }
14101
14109
  let isChanged;
@@ -14259,7 +14267,7 @@ class TableStore {
14259
14267
  * @param cellElement 单元格元素
14260
14268
  */
14261
14269
  setAreaSelectionCells(cellElement, event) {
14262
- if (AngularEditor.isReadonly(this.editor) || !this.editor.selection || !this.isPrepareSelecting) {
14270
+ if (AngularEditor.isReadOnly(this.editor) || !this.editor.selection || !this.isPrepareSelecting) {
14263
14271
  return;
14264
14272
  }
14265
14273
  const currentCellPath = AngularEditor.findPath(this.editor, cellElement);
@@ -14998,7 +15006,7 @@ class TableService {
14998
15006
  * @param editor 编辑器对象
14999
15007
  */
15000
15008
  selectStartPreventDefault(e) {
15001
- const isReadonly = AngularEditor.isReadonly(this.tableStore.editor);
15009
+ const isReadonly = AngularEditor.isReadOnly(this.tableStore.editor);
15002
15010
  const cells = this.tableStore.getSelectedCellPositions();
15003
15011
  if (!isReadonly && e.shiftKey && cells.length > 1) {
15004
15012
  e.preventDefault();
@@ -16877,7 +16885,7 @@ const normalizeTable = (table) => {
16877
16885
  };
16878
16886
 
16879
16887
  const withTable = (editor) => {
16880
- const { deleteBackward, deleteForward, onKeydown, setFragmentData, insertFragmentData, normalizeNode, isBlockCard, renderElement, deleteCutData, isContainer, onChange, onClick, mousedown } = editor;
16888
+ const { deleteBackward, deleteForward, onKeydown, setFragmentData, customInsertFragmentData, normalizeNode, isBlockCard, renderElement, deleteCutData, isContainer, onChange, onClick, mousedown } = editor;
16881
16889
  editor.deleteBackward = unit => {
16882
16890
  const opts = new TableOptions();
16883
16891
  if (!isSelectionInTable(opts, editor)) {
@@ -16915,7 +16923,7 @@ const withTable = (editor) => {
16915
16923
  const isMergedCell = isSelectedCellMerged(editor);
16916
16924
  const domSelection = window.getSelection();
16917
16925
  if (domSelection && !domSelection.isCollapsed && editor.selection) {
16918
- const slateSelection = AngularEditor.toSlateRange(editor, domSelection);
16926
+ const slateSelection = AngularEditor.toSlateRange(editor, domSelection, { exactMatch: false, suppressThrow: false });
16919
16927
  const opts = new TableOptions();
16920
16928
  const startPosition = TablePosition.create(opts, editor, slateSelection.anchor.path);
16921
16929
  const endPosition = TablePosition.create(opts, editor, slateSelection.focus.path);
@@ -17130,7 +17138,7 @@ const withTable = (editor) => {
17130
17138
  }
17131
17139
  setFragmentData(data, originEvent);
17132
17140
  };
17133
- editor.insertFragmentData = async (data) => {
17141
+ editor.customInsertFragmentData = async (data) => {
17134
17142
  const fragment = await extractFragment(data);
17135
17143
  if (fragment) {
17136
17144
  const opts = new TableOptions();
@@ -17203,9 +17211,9 @@ const withTable = (editor) => {
17203
17211
  });
17204
17212
  });
17205
17213
  }
17206
- return insertFragmentData(data);
17214
+ return customInsertFragmentData(data);
17207
17215
  }
17208
- return insertFragmentData(data);
17216
+ return customInsertFragmentData(data);
17209
17217
  };
17210
17218
  editor.normalizeNode = ([node, path]) => {
17211
17219
  if (Element.isElement(node) && node.type === ElementKinds.table) {