slate-angular 20.2.0-next.15 → 20.2.0-next.17

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.
@@ -362,6 +362,7 @@ const PLACEHOLDER_SYMBOL = Symbol('placeholder');
362
362
  */
363
363
  const ELEMENT_TO_COMPONENT = new WeakMap();
364
364
  const IS_ENABLED_VIRTUAL_SCROLL = new WeakMap();
365
+ const EDITOR_TO_VIRTUAL_SCROLL_SELECTION = new WeakMap();
365
366
  const EDITOR_TO_AFTER_VIEW_INIT_QUEUE = new WeakMap();
366
367
 
367
368
  const AngularEditor = {
@@ -474,7 +475,6 @@ const HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY &&
474
475
  globalThis.InputEvent &&
475
476
  // @ts-ignore The `getTargetRanges` property isn't recognized.
476
477
  typeof globalThis.InputEvent.prototype.getTargetRanges === 'function';
477
- const VIRTUAL_SCROLL_DEFAULT_BUFFER_COUNT = 3;
478
478
  const VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT = 40;
479
479
  const SLATE_DEBUG_KEY = '__SLATE_DEBUG__';
480
480
 
@@ -971,7 +971,14 @@ const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
971
971
  }
972
972
  // Create a fake selection so that we can add a Base64-encoded copy of the
973
973
  // fragment to the HTML, to decode on future pastes.
974
- const domRange = AngularEditor.toDOMRange(e, selection);
974
+ let domRange;
975
+ if (AngularEditor.isEnabledVirtualScroll(e)) {
976
+ const virtualScrollSelection = EDITOR_TO_VIRTUAL_SCROLL_SELECTION.get(e);
977
+ if (virtualScrollSelection) {
978
+ domRange = AngularEditor.toDOMRange(e, virtualScrollSelection);
979
+ }
980
+ }
981
+ domRange = domRange ?? AngularEditor.toDOMRange(e, selection);
975
982
  let contents = domRange.cloneContents();
976
983
  let attach = contents.childNodes[0];
977
984
  // Make sure attach is non-empty, since empty nodes will not get copied.
@@ -2288,6 +2295,7 @@ class ListRender {
2288
2295
  this.viewContainerRef = viewContainerRef;
2289
2296
  this.getOutletParent = getOutletParent;
2290
2297
  this.getOutletElement = getOutletElement;
2298
+ this.children = [];
2291
2299
  this.views = [];
2292
2300
  this.blockCards = [];
2293
2301
  this.contexts = [];
@@ -2437,6 +2445,7 @@ class ListRender {
2437
2445
  this.blockCards[index].destroy();
2438
2446
  }
2439
2447
  });
2448
+ this.children = [];
2440
2449
  this.views = [];
2441
2450
  this.blockCards = [];
2442
2451
  this.contexts = [];
@@ -3249,26 +3258,35 @@ class SlateEditable {
3249
3258
  this.addEventListener(event.name, () => { });
3250
3259
  });
3251
3260
  }
3261
+ calculateVirtualScrollSelection(selection) {
3262
+ if (selection) {
3263
+ const indics = Array.from(this.inViewportIndics.values());
3264
+ if (indics.length > 0) {
3265
+ const currentVisibleRange = {
3266
+ anchor: Editor.start(this.editor, [indics[0]]),
3267
+ focus: Editor.end(this.editor, [indics[indics.length - 1]])
3268
+ };
3269
+ const [start, end] = Range.edges(selection);
3270
+ const forwardSelection = { anchor: start, focus: end };
3271
+ const intersectedSelection = Range.intersection(forwardSelection, currentVisibleRange);
3272
+ EDITOR_TO_VIRTUAL_SCROLL_SELECTION.set(this.editor, intersectedSelection);
3273
+ if (!intersectedSelection || !Range.equals(intersectedSelection, forwardSelection)) {
3274
+ if (isDebug) {
3275
+ this.debugLog('log', `selection is not in visible range, selection: ${JSON.stringify(selection)}, intersectedSelection: ${JSON.stringify(intersectedSelection)}`);
3276
+ }
3277
+ return intersectedSelection;
3278
+ }
3279
+ return selection;
3280
+ }
3281
+ }
3282
+ EDITOR_TO_VIRTUAL_SCROLL_SELECTION.set(this.editor, null);
3283
+ return selection;
3284
+ }
3252
3285
  toNativeSelection() {
3253
3286
  try {
3254
3287
  let { selection } = this.editor;
3255
- if (this.isEnabledVirtualScroll() && selection) {
3256
- const indics = Array.from(this.inViewportIndics.values());
3257
- if (indics.length > 0) {
3258
- const currentVisibleRange = {
3259
- anchor: Editor.start(this.editor, [indics[0]]),
3260
- focus: Editor.end(this.editor, [indics[indics.length - 1]])
3261
- };
3262
- const [start, end] = Range.edges(selection);
3263
- const forwardSelection = { anchor: start, focus: end };
3264
- const intersectedSelection = Range.intersection(forwardSelection, currentVisibleRange);
3265
- if (!intersectedSelection || !Range.equals(intersectedSelection, forwardSelection)) {
3266
- selection = intersectedSelection;
3267
- if (isDebug) {
3268
- this.debugLog('log', `selection is not in visible range, selection: ${JSON.stringify(selection)}, intersectedSelection: ${JSON.stringify(intersectedSelection)}`);
3269
- }
3270
- }
3271
- }
3288
+ if (this.isEnabledVirtualScroll()) {
3289
+ selection = this.calculateVirtualScrollSelection(selection);
3272
3290
  }
3273
3291
  const root = AngularEditor.findDocumentOrShadowRoot(this.editor);
3274
3292
  const { activeElement } = root;
@@ -3828,6 +3846,9 @@ class SlateEditable {
3828
3846
  toSlateSelection() {
3829
3847
  if ((!this.isComposing || IS_ANDROID) && !this.isUpdatingSelection && !this.isDraggingInternally) {
3830
3848
  try {
3849
+ if (isDebug) {
3850
+ console.log('toSlateSelection');
3851
+ }
3831
3852
  const root = AngularEditor.findDocumentOrShadowRoot(this.editor);
3832
3853
  const { activeElement } = root;
3833
3854
  const el = AngularEditor.toDOMNode(this.editor, this.editor);
@@ -5025,5 +5046,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
5025
5046
  * Generated bundle index. Do not edit.
5026
5047
  */
5027
5048
 
5028
- export { AngularEditor, BaseComponent, BaseElementComponent, BaseElementFlavour, BaseFlavour, BaseLeafComponent, BaseLeafFlavour, BaseTextComponent, BaseTextFlavour, BlockCardRef, DEFAULT_ELEMENT_HEIGHT, DefaultTextFlavour, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, ELEMENT_KEY_TO_HEIGHTS, ELEMENT_TO_COMPONENT, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, FlavourRef, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_ENABLED_VIRTUAL_SCROLL, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_IOS, IS_QQBROWSER, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, JUST_NOW_UPDATED_VIRTUAL_VIEW, PLACEHOLDER_SYMBOL, SLATE_BLOCK_CARD_CLASS_NAME, SLATE_DEBUG_KEY, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, VIRTUAL_SCROLL_DEFAULT_BUFFER_COUNT, VoidTextFlavour, blobAsString, buildHTMLText, check, completeTable, createClipboardData, createText, createThrottleRAF, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getContentHeight, getDataTransferClipboard, getDataTransferClipboardText, getNavigatorClipboard, getPlainText, getSelection, getSlateFragmentAttribute, getZeroTextNode, hasAfterContextChange, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isClipboardFile, isClipboardReadSupported, isClipboardWriteSupported, isClipboardWriteTextSupported, isComponentType, isDOMText, isDecoratorRangeListEqual, isFlavourType, isInvalidTable, isTemplateRef, isValid, normalize, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
5049
+ export { AngularEditor, BaseComponent, BaseElementComponent, BaseElementFlavour, BaseFlavour, BaseLeafComponent, BaseLeafFlavour, BaseTextComponent, BaseTextFlavour, BlockCardRef, DEFAULT_ELEMENT_HEIGHT, DefaultTextFlavour, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, EDITOR_TO_VIRTUAL_SCROLL_SELECTION, ELEMENT_KEY_TO_HEIGHTS, ELEMENT_TO_COMPONENT, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, FlavourRef, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_ENABLED_VIRTUAL_SCROLL, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_IOS, IS_QQBROWSER, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, JUST_NOW_UPDATED_VIRTUAL_VIEW, PLACEHOLDER_SYMBOL, SLATE_BLOCK_CARD_CLASS_NAME, SLATE_DEBUG_KEY, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, VoidTextFlavour, blobAsString, buildHTMLText, check, completeTable, createClipboardData, createText, createThrottleRAF, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getContentHeight, getDataTransferClipboard, getDataTransferClipboardText, getNavigatorClipboard, getPlainText, getSelection, getSlateFragmentAttribute, getZeroTextNode, hasAfterContextChange, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isClipboardFile, isClipboardReadSupported, isClipboardWriteSupported, isClipboardWriteTextSupported, isComponentType, isDOMText, isDecoratorRangeListEqual, isFlavourType, isInvalidTable, isTemplateRef, isValid, normalize, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
5029
5050
  //# sourceMappingURL=slate-angular.mjs.map