slate-angular 20.2.7 → 20.2.9
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 +109 -61
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/index.d.ts +8 -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,40 +1502,78 @@ 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;
|
|
1475
1556
|
indics.forEach((index, i) => {
|
|
1476
1557
|
const element = editor.children[index];
|
|
1477
|
-
const preHeight =
|
|
1558
|
+
const preHeight = getCachedHeightByElement(editor, element);
|
|
1478
1559
|
if (preHeight && !force) {
|
|
1479
1560
|
if (isDebug) {
|
|
1480
|
-
const height =
|
|
1561
|
+
const height = calcHeightByElement(editor, element);
|
|
1481
1562
|
if (height !== preHeight) {
|
|
1482
|
-
debugLog('warn', '
|
|
1563
|
+
debugLog('warn', 'calcHeightByElement: height not equal, index: ', index, 'preHeight: ', preHeight, 'height: ', height);
|
|
1483
1564
|
}
|
|
1484
1565
|
}
|
|
1485
1566
|
return;
|
|
1486
1567
|
}
|
|
1487
1568
|
hasChanged = true;
|
|
1488
|
-
|
|
1569
|
+
calcHeightByElement(editor, element);
|
|
1489
1570
|
});
|
|
1490
1571
|
return hasChanged;
|
|
1491
1572
|
};
|
|
1492
1573
|
const getBusinessTop = (editor) => {
|
|
1493
1574
|
return EDITOR_TO_BUSINESS_TOP.get(editor) ?? 0;
|
|
1494
1575
|
};
|
|
1495
|
-
const
|
|
1576
|
+
const getCachedHeightByElement = (editor, element) => {
|
|
1496
1577
|
const heights = ELEMENT_KEY_TO_HEIGHTS.get(editor);
|
|
1497
1578
|
const key = AngularEditor.findKey(editor, element);
|
|
1498
1579
|
const height = heights?.get(key.id);
|
|
@@ -1510,7 +1591,15 @@ 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
|
+
let height = getCachedHeightByElement(editor, children[i]);
|
|
1595
|
+
if (height === null) {
|
|
1596
|
+
try {
|
|
1597
|
+
height = editor.getRoughHeight(children[i]);
|
|
1598
|
+
}
|
|
1599
|
+
catch (error) {
|
|
1600
|
+
console.error('buildHeightsAndAccumulatedHeights: getRoughHeight error', error);
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1514
1603
|
heights[i] = height;
|
|
1515
1604
|
accumulatedHeights[i + 1] = accumulatedHeights[i] + height;
|
|
1516
1605
|
}
|
|
@@ -2290,49 +2379,6 @@ class BaseFlavour {
|
|
|
2290
2379
|
}
|
|
2291
2380
|
}
|
|
2292
2381
|
|
|
2293
|
-
const SLATE_BLOCK_CARD_CLASS_NAME = 'slate-block-card';
|
|
2294
|
-
class SlateBlockCard {
|
|
2295
|
-
onInit() {
|
|
2296
|
-
const nativeElement = document.createElement('div');
|
|
2297
|
-
nativeElement.classList.add(SLATE_BLOCK_CARD_CLASS_NAME);
|
|
2298
|
-
this.nativeElement = nativeElement;
|
|
2299
|
-
this.createContent();
|
|
2300
|
-
}
|
|
2301
|
-
createContent() {
|
|
2302
|
-
const leftCaret = document.createElement('span');
|
|
2303
|
-
leftCaret.setAttribute(`card-target`, 'card-left');
|
|
2304
|
-
leftCaret.classList.add('card-left');
|
|
2305
|
-
leftCaret.appendChild(getZeroTextNode());
|
|
2306
|
-
const rightCaret = document.createElement('span');
|
|
2307
|
-
rightCaret.setAttribute(`card-target`, 'card-right');
|
|
2308
|
-
rightCaret.classList.add('card-right');
|
|
2309
|
-
rightCaret.appendChild(getZeroTextNode());
|
|
2310
|
-
const center = document.createElement('div');
|
|
2311
|
-
center.setAttribute(`card-target`, 'card-center');
|
|
2312
|
-
this.nativeElement.appendChild(leftCaret);
|
|
2313
|
-
this.nativeElement.appendChild(center);
|
|
2314
|
-
this.nativeElement.appendChild(rightCaret);
|
|
2315
|
-
this.centerContainer = center;
|
|
2316
|
-
}
|
|
2317
|
-
append() {
|
|
2318
|
-
this.centerRootNodes.forEach(rootNode => !this.centerContainer.contains(rootNode) && this.centerContainer.appendChild(rootNode));
|
|
2319
|
-
}
|
|
2320
|
-
initializeCenter(rootNodes) {
|
|
2321
|
-
this.centerRootNodes = rootNodes;
|
|
2322
|
-
this.append();
|
|
2323
|
-
}
|
|
2324
|
-
onDestroy() {
|
|
2325
|
-
this.nativeElement.remove();
|
|
2326
|
-
}
|
|
2327
|
-
}
|
|
2328
|
-
const getBlockCardByNativeElement = (nativeElement) => {
|
|
2329
|
-
const blockCardElement = nativeElement?.parentElement?.parentElement;
|
|
2330
|
-
if (blockCardElement && blockCardElement.classList.contains(SLATE_BLOCK_CARD_CLASS_NAME)) {
|
|
2331
|
-
return blockCardElement;
|
|
2332
|
-
}
|
|
2333
|
-
return null;
|
|
2334
|
-
};
|
|
2335
|
-
|
|
2336
2382
|
const DEFAULT_ELEMENT_HEIGHT = 24;
|
|
2337
2383
|
class BaseElementFlavour extends BaseFlavour {
|
|
2338
2384
|
constructor() {
|
|
@@ -2429,7 +2475,7 @@ class BaseElementFlavour extends BaseFlavour {
|
|
|
2429
2475
|
readonly: this._context.readonly
|
|
2430
2476
|
};
|
|
2431
2477
|
}
|
|
2432
|
-
|
|
2478
|
+
calcHeight() {
|
|
2433
2479
|
const blockCard = getBlockCardByNativeElement(this.nativeElement);
|
|
2434
2480
|
const target = blockCard || this.nativeElement;
|
|
2435
2481
|
const computedStyle = getComputedStyle(target);
|
|
@@ -3085,11 +3131,11 @@ class ListRender {
|
|
|
3085
3131
|
}
|
|
3086
3132
|
}
|
|
3087
3133
|
}
|
|
3088
|
-
if (isDebug) {
|
|
3134
|
+
if (isDebug && isRoot) {
|
|
3089
3135
|
for (let i = 0; i < children.length; i++) {
|
|
3090
3136
|
const rootNodes = [...getRootNodes(this.views[i], this.blockCards[i])];
|
|
3091
3137
|
const index = this.viewContext.editor.children.indexOf(children[i]);
|
|
3092
|
-
const height =
|
|
3138
|
+
const height = getCachedHeightByElement(this.viewContext.editor, children[i]) ||
|
|
3093
3139
|
this.viewContext.editor.getRoughHeight(children[i]);
|
|
3094
3140
|
rootNodes.forEach(rootNode => {
|
|
3095
3141
|
rootNode.setAttribute('debug-index', index.toString());
|
|
@@ -4029,9 +4075,11 @@ class SlateEditable {
|
|
|
4029
4075
|
debugLog('log', 'oldIndexesInViewport:', oldIndexesInViewport);
|
|
4030
4076
|
debugLog('log', 'newIndexesInViewport:', newIndexesInViewport);
|
|
4031
4077
|
// this.editor.children[index] will be undefined when it is removed
|
|
4032
|
-
debugLog('log', 'changedIndexesOfTop:', needRemoveOnTop ? '-' : needAddOnTop ? '+' : '-', changedIndexesOfTop, changedIndexesOfTop.map(index => (this.editor.children[index] &&
|
|
4078
|
+
debugLog('log', 'changedIndexesOfTop:', needRemoveOnTop ? '-' : needAddOnTop ? '+' : '-', changedIndexesOfTop, changedIndexesOfTop.map(index => (this.editor.children[index] &&
|
|
4079
|
+
getCachedHeightByElement(this.editor, this.editor.children[index])) ||
|
|
4033
4080
|
0));
|
|
4034
|
-
debugLog('log', 'changedIndexesOfBottom:', needAddOnBottom ? '+' : needRemoveOnBottom ? '-' : '+', changedIndexesOfBottom, changedIndexesOfBottom.map(index => (this.editor.children[index] &&
|
|
4081
|
+
debugLog('log', 'changedIndexesOfBottom:', needAddOnBottom ? '+' : needRemoveOnBottom ? '-' : '+', changedIndexesOfBottom, changedIndexesOfBottom.map(index => (this.editor.children[index] &&
|
|
4082
|
+
getCachedHeightByElement(this.editor, this.editor.children[index])) ||
|
|
4035
4083
|
0));
|
|
4036
4084
|
const needTop = virtualView.heights.slice(0, newIndexesInViewport[0]).reduce((acc, height) => acc + height, 0);
|
|
4037
4085
|
const needBottom = virtualView.heights
|
|
@@ -5114,7 +5162,7 @@ class BaseElementComponent extends BaseComponent {
|
|
|
5114
5162
|
readonly: this._context.readonly
|
|
5115
5163
|
};
|
|
5116
5164
|
}
|
|
5117
|
-
|
|
5165
|
+
calcHeight() {
|
|
5118
5166
|
const blockCard = getBlockCardByNativeElement(this.nativeElement);
|
|
5119
5167
|
const target = blockCard || this.nativeElement;
|
|
5120
5168
|
const computedStyle = getComputedStyle(target);
|
|
@@ -5279,5 +5327,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImpo
|
|
|
5279
5327
|
* Generated bundle index. Do not edit.
|
|
5280
5328
|
*/
|
|
5281
5329
|
|
|
5282
|
-
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, calculateVirtualTopHeight, check, completeTable, createClipboardData, createText, createThrottleRAF, debugLog, defaultScrollSelectionIntoView, fallbackCopyText, getBlockCardByNativeElement, getBusinessTop, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getContentHeight, getDataTransferClipboard, getDataTransferClipboardText, getNavigatorClipboard, getPlainText,
|
|
5330
|
+
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 };
|
|
5283
5331
|
//# sourceMappingURL=slate-angular.mjs.map
|