Skip to content

Commit 303bf94

Browse files
author
Zaydek Michels-Gualtieri
committed
Removed virtual naming convention
1 parent 59f108d commit 303bf94

12 files changed

Lines changed: 93 additions & 77 deletions

File tree

src/Editor/components/elements.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import toReact from "./toReact"
88
const Element = ({ id, style, children, ...props }) => {
99
const ref = React.useRef(null)
1010

11-
// NOTE: React **does not** manage rendered children.
11+
// NOTE: React does not manage rendered children.
1212
React.useLayoutEffect(() => {
1313
if (!ref.current) {
1414
// No-op

src/Editor/model/Editor/Editor.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import VirtualRange from "./VirtualRange"
1+
import Range from "./Range"
22
import { immerable } from "immer"
33

44
// Describes an editor.
55
class Editor {
66
[immerable] = true
77

8-
// Is read-only mode enabled?
9-
//
108
// NOTE: DOMContentLoaded disables read-only mode.
119
isReadOnlyModeEnabled = true
12-
// Is the active element?
1310
isActiveElement = false
14-
// Virtual elements.
1511
elements = []
16-
// Virtual range.
17-
range = new VirtualRange()
18-
// Render counter; use as an effect dependency.
12+
range = new Range()
1913
shouldRerender = 0
2014

2115
constructor(elements) {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import hash from "lib/hash"
22
import { immerable } from "immer"
33

4-
// Describes a virtual element.
5-
class VirtualElement {
4+
// Describes an element.
5+
class Element {
66
[immerable] = true
77

88
type = ""
@@ -22,4 +22,4 @@ class VirtualElement {
2222
}
2323
}
2424

25-
export default VirtualElement
25+
export default Element

src/Editor/model/Editor/VirtualInlineElement.js renamed to src/Editor/model/Editor/InlineElement.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Describes a virtual inline element.
2-
class VirtualInlineElement {
1+
// Describes an inline element.
2+
class InlineElement {
33
// Zero-to-many types.
44
types = []
55
// Zero-to-many props.
@@ -16,4 +16,4 @@ class VirtualInlineElement {
1616
}
1717
}
1818

19-
export default VirtualInlineElement
19+
export default InlineElement

src/Editor/model/Editor/VirtualMultilineElement.js renamed to src/Editor/model/Editor/MultilineElement.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
import hash from "lib/hash"
22
import { immerable } from "immer"
33

4-
// Describes a virtual multiline element.
5-
class VirtualMultilineElement {
4+
// Describes a multiline element.
5+
//
6+
// {
7+
// props: {
8+
// elements: [
9+
// {
10+
// props: {
11+
// children: [
12+
// ...
13+
// ],
14+
// },
15+
// },
16+
// ],
17+
// },
18+
// }
19+
//
20+
class MultilineElement {
621
[immerable] = true
722

823
type = ""
@@ -22,4 +37,4 @@ class VirtualMultilineElement {
2237
}
2338
}
2439

25-
export default VirtualMultilineElement
40+
export default MultilineElement

src/Editor/model/Editor/VirtualPosition.js renamed to src/Editor/model/Editor/Position.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import {
33
produce,
44
} from "immer"
55

6-
// Describes a virtual position.
7-
class VirtualPosition {
6+
// Describes a position; a start and end position compose a
7+
// range.
8+
class Position {
89
[immerable] = true
910

1011
key = ""
@@ -30,4 +31,4 @@ class VirtualPosition {
3031
}
3132
}
3233

33-
export default VirtualPosition
34+
export default Position
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
import VirtualPosition from "./VirtualPosition"
1+
import Position from "./Position"
22

33
import {
44
immerable,
55
produce,
66
} from "immer"
77

8-
// Describes a virtual range.
8+
// Describes a range.
99
class Range {
1010
[immerable] = true
1111

12-
start = new VirtualPosition()
13-
end = new VirtualPosition()
12+
start = new Position()
13+
end = new Position()
1414

1515
// Constructs from the current range, scoped to a tree and
1616
// [contenteditable="true"] descendants.
1717
static getCurrent(tree) {
1818
// ...
1919
}
2020

21-
// Returns whether virtual positions are collapsed.
21+
// Computes whether the positions are collapsed.
2222
get collapsed() {
2323
return this.start.isEqualTo(this.end)
2424
}
2525

26-
// Collapses virtual positions.
27-
collapse() {
26+
// Collapses end-to-start.
27+
collapseToStart() {
2828
return produce(this, draft => {
2929
draft.end = draft.start
3030
})
3131
}
3232

33+
// Collapses start-to-end.
34+
collapseToEnd() {
35+
return produce(this, draft => {
36+
draft.start = draft.end
37+
})
38+
}
39+
3340
// Converts to a range literal.
3441
toRangeLiteral() {
3542
// ...
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import Editor from "../Editor"
2-
import VirtualElement from "../VirtualElement"
3-
import VirtualInlineElement from "../VirtualInlineElement"
4-
import VirtualMultilineElement from "../VirtualMultilineElement"
5-
import VirtualPosition from "../VirtualPosition"
6-
import VirtualRange from "../VirtualRange"
2+
import Element from "../Element"
3+
import InlineElement from "../InlineElement"
4+
import MultilineElement from "../MultilineElement"
5+
import Position from "../Position"
6+
import Range from "../Range"
77

88
describe("", () => {
99
test("", () => expect(new Editor() instanceof Editor).toBeTruthy())
10-
test("", () => expect(new VirtualElement() instanceof VirtualElement).toBeTruthy())
11-
test("", () => expect(new VirtualInlineElement() instanceof VirtualInlineElement).toBeTruthy())
12-
test("", () => expect(new VirtualMultilineElement() instanceof VirtualMultilineElement).toBeTruthy())
13-
test("", () => expect(new VirtualPosition() instanceof VirtualPosition).toBeTruthy())
14-
test("", () => expect(new VirtualRange() instanceof VirtualRange).toBeTruthy())
10+
test("", () => expect(new Element() instanceof Element).toBeTruthy())
11+
test("", () => expect(new InlineElement() instanceof InlineElement).toBeTruthy())
12+
test("", () => expect(new MultilineElement() instanceof MultilineElement).toBeTruthy())
13+
test("", () => expect(new Position() instanceof Position).toBeTruthy())
14+
test("", () => expect(new Range() instanceof Range).toBeTruthy())
1515
})

src/Editor/model/Scanners/AbstractScanner.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import domUtils from "lib/domUtils"
2+
import Element from "../Editor/Element"
3+
import InlineElement from "../Editor/InlineElement"
24
import JSONClone from "lib/JSONClone"
3-
import VirtualElement from "../Editor/VirtualElement"
4-
import VirtualInlineElement from "../Editor/VirtualInlineElement"
55

6-
// Describes an abstract scanner; a scanner implements scan
7-
// to scan virtual elements and children.
6+
// Describes an abstract scanner.
87
class AbstractScanner {
98
// Scans types and props.
109
scanner = null
1110

12-
// Scans virtual children from an element.
1311
scanChildren(element) {
1412
const children = []
1513
const recurse = (on, types = [], props = {}) => {
1614
if (domUtils.isTextNode(on)) {
1715
const value = on.nodeValue
18-
children.push(new VirtualInlineElement({ types, props, value }))
16+
children.push(new InlineElement({ types, props, value }))
1917
return
2018
}
2119
for (const each of on.childNodes) {
@@ -36,14 +34,13 @@ class AbstractScanner {
3634
return children
3735
}
3836

39-
// Scans virtual elements from a tree.
4037
scan(tree) {
4138
const elements = []
4239
for (const each of tree.children) {
4340
const [T, P] = this.scanner(each)
4441
switch (T) {
4542
case "p":
46-
elements.push(new VirtualElement({
43+
elements.push(new Element({
4744
type: T,
4845
key: each.id,
4946
props: {

src/Editor/model/Scanners/RenderedScanner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import AbstractScanner from "./AbstractScanner"
99
class RenderedScanner extends AbstractScanner {
1010
constructor() {
1111
super()
12+
const scanner = scanners.rendered
1213
Object.assign(this, {
13-
scanner: scanners.rendered,
14+
scanner,
1415
})
1516
}
1617
}

0 commit comments

Comments
 (0)