• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

worktile / slate-angular / 481f38a4-0122-4a38-ac16-5467b1fdb7c2

15 Dec 2025 03:04AM UTC coverage: 38.108% (-8.7%) from 46.809%
481f38a4-0122-4a38-ac16-5467b1fdb7c2

push

circleci

pubuzhixing8
build: release 20.2.0-next.12

386 of 1205 branches covered (32.03%)

Branch coverage included in aggregate %.

1072 of 2621 relevant lines covered (40.9%)

24.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.75
/packages/src/plugins/angular-editor.ts
1
import { Editor, Node, Path, Transforms, Element } from 'slate';
2
import { Injector } from '@angular/core';
3
import { SlateError } from '../types/error';
4
import { FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET } from '../utils/block-card';
5
import { CustomDOMEditor } from './with-dom';
6
import { DOMEditor, EDITOR_TO_ELEMENT, IS_FOCUSED } from 'slate-dom';
7
import { ClipboardData } from '../types/clipboard';
8

9
/**
10
 * An Angular and DOM-specific version of the `Editor` interface.
11
 */
12
export interface AngularEditor extends CustomDOMEditor {
13
    deleteCutData: () => void;
14
    selectAll: () => void;
15
    isVisible: (element: Element) => boolean;
16
    onKeydown: (event: KeyboardEvent) => void;
17
    onClick: (event: MouseEvent) => void;
18
    injector: Injector;
19
    isBlockCard: (node: Node) => boolean;
20
    isExpanded: (node: Element) => boolean;
21
    onError: (errorData: SlateError) => void;
22
    customInsertFragmentData: (data: DataTransfer, clipboardData: ClipboardData | null) => Promise<boolean>;
23
    customInsertTextData: (data: DataTransfer) => Promise<boolean>;
24
}
25

26
export const AngularEditor = {
1✔
27
    ...CustomDOMEditor,
28
    /**
29
     * handle editor error.
30
     */
31

32
    onError(errorData: SlateError) {
33
        if (errorData.nativeError) {
×
34
            throw errorData.nativeError;
×
35
        }
36
    },
37

38
    /**
39
     * onKeydown hook.
40
     */
41
    onKeydown(editor: AngularEditor, data: KeyboardEvent): void {
42
        editor.onKeydown(data);
×
43
    },
44

45
    /**
46
     * onClick hook.
47
     */
48
    onClick(editor: AngularEditor, data: MouseEvent): void {
49
        editor.onClick(data);
×
50
    },
51

52
    deleteCutData(editor: AngularEditor): void {
53
        editor.deleteCutData();
×
54
    },
55

56
    isLeafBlock(editor: AngularEditor, node: Node): boolean {
57
        return Element.isElement(node) && !editor.isInline(node) && Editor.hasInlines(editor, node);
159✔
58
    },
59

60
    /**
61
     * move native selection to card-left or card-right
62
     * @param editor
63
     * @param blockCardNode
64
     * @param options
65
     */
66
    moveBlockCard(
67
        editor: AngularEditor,
68
        blockCardNode: Node,
69
        options: {
70
            direction: 'left' | 'right';
71
        }
72
    ) {
73
        const cursorNode = AngularEditor.getCardCursorNode(editor, blockCardNode, options);
×
74
        const window = AngularEditor.getWindow(editor);
×
75
        const domSelection = window.getSelection();
×
76
        domSelection.setBaseAndExtent(cursorNode, 1, cursorNode, 1);
×
77
    },
78

79
    /**
80
     * move slate selection to card-left or card-right
81
     * @param editor
82
     * @param path
83
     * @param options
84
     */
85
    moveBlockCardCursor(
86
        editor: AngularEditor,
87
        path: Path,
88
        options: {
89
            direction: 'left' | 'right';
90
        }
91
    ) {
92
        const cursor = {
×
93
            path,
94
            offset: options.direction === 'left' ? FAKE_LEFT_BLOCK_CARD_OFFSET : FAKE_RIGHT_BLOCK_CARD_OFFSET
×
95
        };
96
        Transforms.select(editor, { anchor: cursor, focus: cursor });
×
97
    },
98
    focus: (editor, options = { retries: 5 }) => {
2✔
99
        // Return if already focused
100
        if (IS_FOCUSED.get(editor)) {
2!
101
            return;
×
102
        }
103

104
        // Return if no dom node is associated with the editor, which means the editor is not yet mounted
105
        // or has been unmounted. This can happen especially, while retrying to focus the editor.
106
        if (!EDITOR_TO_ELEMENT.get(editor)) {
2!
107
            return;
×
108
        }
109

110
        IS_FOCUSED.set(editor, true);
2✔
111
        const el = DOMEditor.toDOMNode(editor, editor);
2✔
112
        const root = DOMEditor.findDocumentOrShadowRoot(editor);
2✔
113
        if (root.activeElement !== el) {
2✔
114
            // IS_FOCUSED should be set before calling el.focus() to ensure that
115
            // FocusedContext is updated to the correct value
116
            el.focus({ preventScroll: true });
2✔
117
        }
118
    }
119
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc