Exemplo n.º 1
0
        it('should add nodes in the stack', () => {
            const state = new State()
                .push(Block.create({ type: 'heading' }))
                .push(Block.create({ type: 'paragraph' }));

            const types = state.nodes.map(n => n.type).toArray();
            expect(types).toEqual(['heading', 'paragraph']);
        });
Exemplo n.º 2
0
        it('should return the first node', () => {
            const state = new State()
                .push(Block.create({ type: 'heading' }))
                .push(Block.create({ type: 'paragraph' }));

            const node = state.peek();
            expect(node.type).toBe('heading');
        });
Exemplo n.º 3
0
        it('should process all nodes', () => {
            const state = State.create({
                block: [{ serialize }]
            });
            const text = state
                .use('block')
                .serialize([
                    Block.create({ type: 'heading' }),
                    Block.create({ type: 'paragraph' })
                ]);

            expect(text).toBe('heading\nparagraph\n');
        });
Exemplo n.º 4
0
/**
 * Exit the current table, by inserting a default block after the table.
 */
function onModEnter(
    event: *,
    change: Change,
    editor: *,
    opts: Options
): void | Change {
    const { value } = change;
    if (!value.isCollapsed) {
        return undefined;
    }

    event.preventDefault();

    const exitBlock = Block.create({
        type: opts.exitBlockType,
        nodes: [Text.create('')]
    });

    const table = TablePosition.create(opts, value.document, value.startKey)
        .table;
    const tableParent = value.document.getParent(table.key);
    const insertionIndex = tableParent.nodes.indexOf(table) + 1;

    return change
        .insertNodeByKey(tableParent.key, insertionIndex, exitBlock)
        .collapseToStartOf(exitBlock);
}
Exemplo n.º 5
0
        const deserialize = state => {
            const { text } = state;
            let nextLine = text.indexOf('\n');
            nextLine = nextLine < 0 ? text.length : nextLine + 1;
            const type = text.slice(0, nextLine);

            return state.skip(nextLine).push(Block.create({ type }));
        };
Exemplo n.º 6
0
/**
 * Deserialize a text into a code block
 */
function deserializeCode(opts: Options, text: string): Block {
    const sep = detectNewline(text) || DEFAULT_NEWLINE;

    const lines = List(text.split(sep)).map(line =>
        Block.create({
            type: opts.lineType,
            nodes: [Text.create(line)]
        })
    );

    const code = Block.create({
        type: opts.containerType,
        nodes: lines
    });

    return code;
}
Exemplo n.º 7
0
 const lines = List(text.split(sep)).map(line =>
     Block.create({
         type: opts.lineType,
         nodes: [Text.create(line)]
     })
Exemplo n.º 8
0
 return lines.map(line =>
     Block.create({
         type: BLOCKS.CODE_LINE,
         nodes: [Text.create(line)]
     })