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

kommitters / editorjs-toggle-block / 10856842690

13 Sep 2024 10:17PM UTC coverage: 31.442% (-0.7%) from 32.139%
10856842690

Pull #242

github

web-flow
Merge c2da1ab21 into 152a5cd00
Pull Request #242: General decoupling in functions

77 of 370 branches covered (20.81%)

Branch coverage included in aggregate %.

95 of 477 new or added lines in 22 files covered. (19.92%)

3 existing lines in 1 file now uncovered.

250 of 670 relevant lines covered (37.31%)

29.51 hits per line

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

0.0
/src/render/renderItems.js
1
/**
2
   * Renders the items view and assigns the properties required to look
3
   * like a block inside the toggle.
4
   */
5
export function renderItems() {
NEW
6
    const blocksInEditor = this.api.blocks.getBlocksCount();
×
NEW
7
    const icon = this.wrapper.firstChild;
×
8
    let toggleRoot;
9

NEW
10
    if (this.readOnly) {
×
NEW
11
      const redactor = document.getElementsByClassName(
×
12
        "codex-editor__redactor"
13
      )[0];
NEW
14
      const { children } = redactor;
×
NEW
15
      const { length } = children;
×
16

NEW
17
      for (let i = 0; i < length; i += 1) {
×
NEW
18
        const blockCover = children[i].firstChild;
×
NEW
19
        const blockContainer = blockCover.firstChild;
×
NEW
20
        const { id } = blockContainer;
×
21

NEW
22
        if (id === this.wrapper.id) {
×
NEW
23
          toggleRoot = i;
×
NEW
24
          break;
×
25
        }
26
      }
27
    } else {
NEW
28
      const toggle = this.wrapper.children[1];
×
NEW
29
      let currentBlock = {};
×
NEW
30
      let index = this.api.blocks.getCurrentBlockIndex();
×
NEW
31
      const delta = index === blocksInEditor - 1 ? -1 : 1;
×
32

NEW
33
      while (currentBlock[1] !== toggle) {
×
NEW
34
        toggleRoot = index;
×
NEW
35
        const block = this.api.blocks.getBlockByIndex(toggleRoot);
×
NEW
36
        if (!block) break;
×
NEW
37
        const { holder } = block;
×
NEW
38
        const blockCover = holder.firstChild;
×
NEW
39
        const blockContent = blockCover.firstChild;
×
NEW
40
        currentBlock = blockContent.children;
×
41

NEW
42
        index += delta;
×
43
      }
44
    }
45

NEW
46
    if (toggleRoot + this.data.items < blocksInEditor) {
×
NEW
47
      for (
×
NEW
48
        let i = toggleRoot + 1, j = 0;
×
49
        i <= toggleRoot + this.data.items;
50
        i += 1
51
      ) {
NEW
52
        const block = this.api.blocks.getBlockByIndex(i);
×
NEW
53
        const { holder } = block;
×
NEW
54
        const cover = holder.firstChild;
×
NEW
55
        const content = cover.firstChild;
×
56

NEW
57
        if (!this.isPartOfAToggle(content)) {
×
NEW
58
          this.setAttributesToNewBlock(i);
×
NEW
59
          j += 1;
×
60
        } else {
NEW
61
          this.data.items = j;
×
NEW
62
          break;
×
63
        }
64
      }
65
    } else {
NEW
66
      this.data.items = 0;
×
67
    }
68

NEW
69
    icon.addEventListener("click", () => {
×
NEW
70
      this.resolveToggleAction();
×
NEW
71
      setTimeout(() => {
×
NEW
72
        this.hideAndShowBlocks();
×
73
      });
74
    });
75

NEW
76
    this.hideAndShowBlocks();
×
77
  }
78

79

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

© 2025 Coveralls, Inc