-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Atom model * First stab at rendering cards with editor-dom renderer * Atoms have length of 1 * Atoms use DocumentFragment to render * Clear child nodes in AtomNode teardown * Use -mobiledoc-kit__atom for atom className * Atoms and Markers are both Markerupable
- Loading branch information
Showing
12 changed files
with
297 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { clearChildNodes } from '../utils/dom-utils'; | ||
|
||
export default class AtomNode { | ||
constructor(editor, atom, model, element, atomOptions) { | ||
this.editor = editor; | ||
this.atom = atom; | ||
this.model = model; | ||
this.atomOptions = atomOptions; | ||
this.element = element; | ||
|
||
this._teardown = null; | ||
} | ||
|
||
render() { | ||
this.teardown(); | ||
|
||
let fragment = document.createDocumentFragment(); | ||
|
||
this._teardown = this.atom.render({ | ||
options: this.atomOptions, | ||
env: this.env, | ||
value: this.model.value, | ||
payload: this.model.payload, | ||
fragment | ||
}); | ||
|
||
this.element.appendChild(fragment); | ||
} | ||
|
||
get env() { | ||
return { | ||
name: this.atom.name | ||
}; | ||
} | ||
|
||
teardown() { | ||
if (this._teardown) { | ||
this._teardown(); | ||
} | ||
|
||
clearChildNodes(this.element); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ATOM_TYPE } from './types'; | ||
import mixin from '../utils/mixin'; | ||
import MarkuperableMixin from '../utils/markuperable'; | ||
import LinkedItem from '../utils/linked-item'; | ||
|
||
export default class Atom extends LinkedItem { | ||
constructor(name, value, payload, markups=[]) { | ||
super(); | ||
this.name = name; | ||
this.value = value; | ||
this.payload = payload; | ||
this.type = ATOM_TYPE; | ||
this.length = 1; | ||
|
||
this.markups = []; | ||
markups.forEach(m => this.addMarkup(m)); | ||
} | ||
} | ||
|
||
mixin(Atom, MarkuperableMixin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.