slate-angular 20.2.8 → 20.2.10
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/fesm2022/slate-angular.mjs +111 -58
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +6 -5
- package/package.json +1 -1
|
@@ -1449,6 +1449,49 @@ class VirtualScrollDebugOverlay {
|
|
|
1449
1449
|
}
|
|
1450
1450
|
}
|
|
1451
1451
|
|
|
1452
|
+
const SLATE_BLOCK_CARD_CLASS_NAME = 'slate-block-card';
|
|
1453
|
+
class SlateBlockCard {
|
|
1454
|
+
onInit() {
|
|
1455
|
+
const nativeElement = document.createElement('div');
|
|
1456
|
+
nativeElement.classList.add(SLATE_BLOCK_CARD_CLASS_NAME);
|
|
1457
|
+
this.nativeElement = nativeElement;
|
|
1458
|
+
this.createContent();
|
|
1459
|
+
}
|
|
1460
|
+
createContent() {
|
|
1461
|
+
const leftCaret = document.createElement('span');
|
|
1462
|
+
leftCaret.setAttribute(`card-target`, 'card-left');
|
|
1463
|
+
leftCaret.classList.add('card-left');
|
|
1464
|
+
leftCaret.appendChild(getZeroTextNode());
|
|
1465
|
+
const rightCaret = document.createElement('span');
|
|
1466
|
+
rightCaret.setAttribute(`card-target`, 'card-right');
|
|
1467
|
+
rightCaret.classList.add('card-right');
|
|
1468
|
+
rightCaret.appendChild(getZeroTextNode());
|
|
1469
|
+
const center = document.createElement('div');
|
|
1470
|
+
center.setAttribute(`card-target`, 'card-center');
|
|
1471
|
+
this.nativeElement.appendChild(leftCaret);
|
|
1472
|
+
this.nativeElement.appendChild(center);
|
|
1473
|
+
this.nativeElement.appendChild(rightCaret);
|
|
1474
|
+
this.centerContainer = center;
|
|
1475
|
+
}
|
|
1476
|
+
append() {
|
|
1477
|
+
this.centerRootNodes.forEach(rootNode => !this.centerContainer.contains(rootNode) && this.centerContainer.appendChild(rootNode));
|
|
1478
|
+
}
|
|
1479
|
+
initializeCenter(rootNodes) {
|
|
1480
|
+
this.centerRootNodes = rootNodes;
|
|
1481
|
+
this.append();
|
|
1482
|
+
}
|
|
1483
|
+
onDestroy() {
|
|
1484
|
+
this.nativeElement.remove();
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
const getBlockCardByNativeElement = (nativeElement) => {
|
|
1488
|
+
const blockCardElement = nativeElement?.parentElement?.parentElement;
|
|
1489
|
+
if (blockCardElement && blockCardElement.classList.contains(SLATE_BLOCK_CARD_CLASS_NAME)) {
|
|
1490
|
+
return blockCardElement;
|
|
1491
|
+
}
|
|
1492
|
+
return null;
|
|
1493
|
+
};
|
|
1494
|
+
|
|
1452
1495
|
const isDebug = localStorage.getItem(SLATE_DEBUG_KEY) === 'true';
|
|
1453
1496
|
const isDebugScrollTop = localStorage.getItem(SLATE_DEBUG_KEY_SCROLL_TOP) === 'true';
|
|
1454
1497
|
const ELEMENT_KEY_TO_HEIGHTS = new WeakMap();
|
|
@@ -1459,16 +1502,54 @@ const debugLog = (type, ...args) => {
|
|
|
1459
1502
|
const doc = document;
|
|
1460
1503
|
VirtualScrollDebugOverlay.log(doc, type, ...args);
|
|
1461
1504
|
};
|
|
1462
|
-
const
|
|
1505
|
+
const cacheHeightByElement = (editor, element, height) => {
|
|
1506
|
+
if (!AngularEditor.isEnabledVirtualScroll(editor)) {
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
if (typeof height !== 'number') {
|
|
1510
|
+
console.error('cacheHeightByElement: height must be number', height);
|
|
1511
|
+
return;
|
|
1512
|
+
}
|
|
1463
1513
|
const key = AngularEditor.findKey(editor, element);
|
|
1514
|
+
const heights = ELEMENT_KEY_TO_HEIGHTS.get(editor);
|
|
1515
|
+
heights.set(key.id, height);
|
|
1516
|
+
};
|
|
1517
|
+
const setMinHeightByElement = (editor, element, rootElementMarginBottom) => {
|
|
1518
|
+
if (!AngularEditor.isEnabledVirtualScroll(editor)) {
|
|
1519
|
+
return;
|
|
1520
|
+
}
|
|
1521
|
+
const realHeight = getCachedHeightByElement(editor, element);
|
|
1522
|
+
if (realHeight) {
|
|
1523
|
+
const nativeElement = AngularEditor.toDOMNode(editor, element);
|
|
1524
|
+
const blockCard = getBlockCardByNativeElement(nativeElement);
|
|
1525
|
+
if (blockCard) {
|
|
1526
|
+
const minHeight = realHeight - rootElementMarginBottom;
|
|
1527
|
+
blockCard.style.minHeight = minHeight + 'px';
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
};
|
|
1531
|
+
const clearMinHeightByElement = (editor, element) => {
|
|
1532
|
+
if (!AngularEditor.isEnabledVirtualScroll(editor)) {
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
const nativeElement = AngularEditor.toDOMNode(editor, element);
|
|
1536
|
+
const blockCard = getBlockCardByNativeElement(nativeElement);
|
|
1537
|
+
if (blockCard && blockCard.style.minHeight) {
|
|
1538
|
+
blockCard.style.minHeight = '';
|
|
1539
|
+
return true;
|
|
1540
|
+
}
|
|
1541
|
+
else {
|
|
1542
|
+
return false;
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
const calcHeightByElement = (editor, element) => {
|
|
1464
1546
|
const view = ELEMENT_TO_COMPONENT.get(element);
|
|
1465
1547
|
if (!view) {
|
|
1466
1548
|
return;
|
|
1467
1549
|
}
|
|
1468
|
-
const
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
return ret;
|
|
1550
|
+
const height = view.calcHeight();
|
|
1551
|
+
cacheHeightByElement(editor, element, height);
|
|
1552
|
+
return height;
|
|
1472
1553
|
};
|
|
1473
1554
|
const measureHeightByIndics = (editor, indics, force = false) => {
|
|
1474
1555
|
let hasChanged = false;
|
|
@@ -1510,7 +1591,8 @@ const buildHeightsAndAccumulatedHeights = (editor) => {
|
|
|
1510
1591
|
const accumulatedHeights = new Array(children.length + 1);
|
|
1511
1592
|
accumulatedHeights[0] = 0;
|
|
1512
1593
|
for (let i = 0; i < children.length; i++) {
|
|
1513
|
-
|
|
1594
|
+
const isVisible = editor.isVisible(children[i]);
|
|
1595
|
+
let height = isVisible ? getCachedHeightByElement(editor, children[i]) : 0;
|
|
1514
1596
|
if (height === null) {
|
|
1515
1597
|
try {
|
|
1516
1598
|
height = editor.getRoughHeight(children[i]);
|
|
@@ -2298,49 +2380,6 @@ class BaseFlavour {
|
|
|
2298
2380
|
}
|
|
2299
2381
|
}
|
|
2300
2382
|
|
|
2301
|
-
const SLATE_BLOCK_CARD_CLASS_NAME = 'slate-block-card';
|
|
2302
|
-
class SlateBlockCard {
|
|
2303
|
-
onInit() {
|
|
2304
|
-
const nativeElement = document.createElement('div');
|
|
2305
|
-
nativeElement.classList.add(SLATE_BLOCK_CARD_CLASS_NAME);
|
|
2306
|
-
this.nativeElement = nativeElement;
|
|
2307
|
-
this.createContent();
|
|
2308
|
-
}
|
|
2309
|
-
createContent() {
|
|
2310
|
-
const leftCaret = document.createElement('span');
|
|
2311
|
-
leftCaret.setAttribute(`card-target`, 'card-left');
|
|
2312
|
-
leftCaret.classList.add('card-left');
|
|
2313
|
-
leftCaret.appendChild(getZeroTextNode());
|
|
2314
|
-
const rightCaret = document.createElement('span');
|
|
2315
|
-
rightCaret.setAttribute(`card-target`, 'card-right');
|
|
2316
|
-
rightCaret.classList.add('card-right');
|
|
2317
|
-
rightCaret.appendChild(getZeroTextNode());
|
|
2318
|
-
const center = document.createElement('div');
|
|
2319
|
-
center.setAttribute(`card-target`, 'card-center');
|
|
2320
|
-
this.nativeElement.appendChild(leftCaret);
|
|
2321
|
-
this.nativeElement.appendChild(center);
|
|
2322
|
-
this.nativeElement.appendChild(rightCaret);
|
|
2323
|
-
this.centerContainer = center;
|
|
2324
|
-
}
|
|
2325
|
-
append() {
|
|
2326
|
-
this.centerRootNodes.forEach(rootNode => !this.centerContainer.contains(rootNode) && this.centerContainer.appendChild(rootNode));
|
|
2327
|
-
}
|
|
2328
|
-
initializeCenter(rootNodes) {
|
|
2329
|
-
this.centerRootNodes = rootNodes;
|
|
2330
|
-
this.append();
|
|
2331
|
-
}
|
|
2332
|
-
onDestroy() {
|
|
2333
|
-
this.nativeElement.remove();
|
|
2334
|
-
}
|
|
2335
|
-
}
|
|
2336
|
-
const getBlockCardByNativeElement = (nativeElement) => {
|
|
2337
|
-
const blockCardElement = nativeElement?.parentElement?.parentElement;
|
|
2338
|
-
if (blockCardElement && blockCardElement.classList.contains(SLATE_BLOCK_CARD_CLASS_NAME)) {
|
|
2339
|
-
return blockCardElement;
|
|
2340
|
-
}
|
|
2341
|
-
return null;
|
|
2342
|
-
};
|
|
2343
|
-
|
|
2344
2383
|
const DEFAULT_ELEMENT_HEIGHT = 24;
|
|
2345
2384
|
class BaseElementFlavour extends BaseFlavour {
|
|
2346
2385
|
constructor() {
|
|
@@ -2437,9 +2476,6 @@ class BaseElementFlavour extends BaseFlavour {
|
|
|
2437
2476
|
readonly: this._context.readonly
|
|
2438
2477
|
};
|
|
2439
2478
|
}
|
|
2440
|
-
hasStableHeight() {
|
|
2441
|
-
return true;
|
|
2442
|
-
}
|
|
2443
2479
|
calcHeight() {
|
|
2444
2480
|
const blockCard = getBlockCardByNativeElement(this.nativeElement);
|
|
2445
2481
|
const target = blockCard || this.nativeElement;
|
|
@@ -2886,11 +2922,13 @@ const createText = (text) => {
|
|
|
2886
2922
|
return { nativeElement };
|
|
2887
2923
|
};
|
|
2888
2924
|
|
|
2925
|
+
const PRE_RENDERING_ELEMENT_ON_TOP_CLASS = 'pre-rendering-element-on-top';
|
|
2889
2926
|
const setPreRenderingElementStyle = (editor, rootNode, isClear = false) => {
|
|
2890
2927
|
if (isClear) {
|
|
2891
2928
|
rootNode.style.top = '';
|
|
2892
2929
|
rootNode.style.width = '';
|
|
2893
2930
|
rootNode.style.position = '';
|
|
2931
|
+
rootNode.classList.remove(PRE_RENDERING_ELEMENT_ON_TOP_CLASS);
|
|
2894
2932
|
return;
|
|
2895
2933
|
}
|
|
2896
2934
|
const preRenderingWidth = EDITOR_TO_ROOT_NODE_WIDTH.get(editor) ?? 0;
|
|
@@ -2902,6 +2940,20 @@ const setPreRenderingElementStyle = (editor, rootNode, isClear = false) => {
|
|
|
2902
2940
|
rootNode.style.width = '100%';
|
|
2903
2941
|
}
|
|
2904
2942
|
rootNode.style.position = 'absolute';
|
|
2943
|
+
rootNode.classList.add(PRE_RENDERING_ELEMENT_ON_TOP_CLASS);
|
|
2944
|
+
};
|
|
2945
|
+
const updatePreRenderingElementWidth = (editor) => {
|
|
2946
|
+
const editorDom = AngularEditor.toDOMNode(editor, editor);
|
|
2947
|
+
const rootNodes = editorDom.querySelectorAll(`.${PRE_RENDERING_ELEMENT_ON_TOP_CLASS}`);
|
|
2948
|
+
const preRenderingWidth = EDITOR_TO_ROOT_NODE_WIDTH.get(editor) ?? 0;
|
|
2949
|
+
rootNodes.forEach(rootNode => {
|
|
2950
|
+
if (preRenderingWidth) {
|
|
2951
|
+
rootNode.style.width = `${preRenderingWidth}px`;
|
|
2952
|
+
}
|
|
2953
|
+
else {
|
|
2954
|
+
rootNode.style.width = '100%';
|
|
2955
|
+
}
|
|
2956
|
+
});
|
|
2905
2957
|
};
|
|
2906
2958
|
class ListRender {
|
|
2907
2959
|
constructor(viewContext, viewContainerRef, getOutletParent, getOutletElement) {
|
|
@@ -3747,12 +3799,16 @@ class SlateEditable {
|
|
|
3747
3799
|
this.elementRef.nativeElement.appendChild(this.virtualCenterOutlet);
|
|
3748
3800
|
this.elementRef.nativeElement.appendChild(this.virtualBottomHeightElement);
|
|
3749
3801
|
let editorResizeObserverRectWidth = this.elementRef.nativeElement.getBoundingClientRect().width;
|
|
3750
|
-
EDITOR_TO_ROOT_NODE_WIDTH.set(this.editor, this.virtualTopHeightElement.
|
|
3802
|
+
EDITOR_TO_ROOT_NODE_WIDTH.set(this.editor, this.virtualTopHeightElement.offsetWidth);
|
|
3751
3803
|
this.editorResizeObserver = new ResizeObserver(entries => {
|
|
3752
3804
|
if (entries.length > 0 && entries[0].contentRect.width !== editorResizeObserverRectWidth) {
|
|
3753
3805
|
editorResizeObserverRectWidth = entries[0].contentRect.width;
|
|
3754
3806
|
this.keyHeightMap.clear();
|
|
3755
|
-
|
|
3807
|
+
const firstElement = this.inViewportChildren[0];
|
|
3808
|
+
const firstDomElement = AngularEditor.toDOMNode(this.editor, firstElement);
|
|
3809
|
+
const target = firstDomElement || this.virtualTopHeightElement;
|
|
3810
|
+
EDITOR_TO_ROOT_NODE_WIDTH.set(this.editor, target.offsetWidth);
|
|
3811
|
+
updatePreRenderingElementWidth(this.editor);
|
|
3756
3812
|
this.viewportRefresh$.next();
|
|
3757
3813
|
if (isDebug) {
|
|
3758
3814
|
debugLog('log', 'editorResizeObserverRectWidth: ', editorResizeObserverRectWidth, 'EDITOR_TO_ROOT_NODE_WIDTH: ', EDITOR_TO_ROOT_NODE_WIDTH.get(this.editor));
|
|
@@ -5127,9 +5183,6 @@ class BaseElementComponent extends BaseComponent {
|
|
|
5127
5183
|
readonly: this._context.readonly
|
|
5128
5184
|
};
|
|
5129
5185
|
}
|
|
5130
|
-
hasStableHeight() {
|
|
5131
|
-
return true;
|
|
5132
|
-
}
|
|
5133
5186
|
calcHeight() {
|
|
5134
5187
|
const blockCard = getBlockCardByNativeElement(this.nativeElement);
|
|
5135
5188
|
const target = blockCard || this.nativeElement;
|
|
@@ -5295,5 +5348,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
|
|
|
5295
5348
|
* Generated bundle index. Do not edit.
|
|
5296
5349
|
*/
|
|
5297
5350
|
|
|
5298
|
-
export { AngularEditor, BaseComponent, BaseElementComponent, BaseElementFlavour, BaseFlavour, BaseLeafComponent, BaseLeafFlavour, BaseTextComponent, BaseTextFlavour, BlockCardRef, DEFAULT_ELEMENT_HEIGHT, DefaultTextFlavour, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, EDITOR_TO_BUSINESS_TOP, EDITOR_TO_IS_FROM_SCROLL_TO, EDITOR_TO_ROOT_NODE_WIDTH, 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, PLACEHOLDER_SYMBOL, SLATE_BLOCK_CARD_CLASS_NAME, SLATE_DEBUG_KEY, SLATE_DEBUG_KEY_SCROLL_TOP, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, SlateString, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, VoidTextFlavour, blobAsString, buildHTMLText, buildHeightsAndAccumulatedHeights, calcHeightByElement, calculateVirtualTopHeight, check, completeTable, createClipboardData, createText, createThrottleRAF, debugLog, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, getBusinessTop, getCachedHeightByElement, 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, isDebug, isDebugScrollTop, isDecoratorRangeListEqual, isFlavourType, isInvalidTable, isTemplateRef, isValid, measureHeightByIndics, normalize, scrollToElement, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
|
|
5351
|
+
export { AngularEditor, BaseComponent, BaseElementComponent, BaseElementFlavour, BaseFlavour, BaseLeafComponent, BaseLeafFlavour, BaseTextComponent, BaseTextFlavour, BlockCardRef, DEFAULT_ELEMENT_HEIGHT, DefaultTextFlavour, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, EDITOR_TO_BUSINESS_TOP, EDITOR_TO_IS_FROM_SCROLL_TO, EDITOR_TO_ROOT_NODE_WIDTH, 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, PLACEHOLDER_SYMBOL, SLATE_BLOCK_CARD_CLASS_NAME, SLATE_DEBUG_KEY, SLATE_DEBUG_KEY_SCROLL_TOP, SlateBlockCard, SlateChildrenOutlet, SlateEditable, SlateErrorCode, SlateFragmentAttributeKey, SlateModule, SlateString, VIRTUAL_SCROLL_DEFAULT_BLOCK_HEIGHT, VoidTextFlavour, blobAsString, buildHTMLText, buildHeightsAndAccumulatedHeights, cacheHeightByElement, calcHeightByElement, calculateVirtualTopHeight, check, clearMinHeightByElement, completeTable, createClipboardData, createText, createThrottleRAF, debugLog, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, getBusinessTop, getCachedHeightByElement, 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, isDebug, isDebugScrollTop, isDecoratorRangeListEqual, isFlavourType, isInvalidTable, isTemplateRef, isValid, measureHeightByIndics, normalize, scrollToElement, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setMinHeightByElement, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
|
|
5299
5352
|
//# sourceMappingURL=slate-angular.mjs.map
|