-
Notifications
You must be signed in to change notification settings - Fork 3
Add doc & rename & add type information #191
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Modifiers | ||
A modifier is: ... | ||
|
||
The main modifiers are `Attribute` and `Format`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. And they are on plugins ^^ |
||
|
||
## Attributes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On XML Plugin. |
||
When parsing and rendering a document, we need to save the attributes that a | ||
DOM node has and save it in our VNode. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Attributes exists to: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "exist" |
||
- retrieve HTML attributes that a DOM node has originally | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- render the HTML attributes that a VNode has | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok well then why not just in one line: "Attributes serve the purpose of parsing, manipulating and rendering XML attributes of a DOM node". Admittedly, "manipulating" might soon not be true anymore if we start using |
||
|
||
## Format | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Inline Plugin (though that might have to move to |
||
The DOM inline nodes (e.g. span, strong, em, b, a, ...) in HTML are difficult to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The existence of a dichotomy between blocks and inline nodes is what causes a level of complexity that we managed to eliminate by introducing |
||
manipulate. We therefore we transform them into a Format modifiers that we | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
attach to a VNode through the "modifiers" properties. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everywhere in the DOC please don't forget to use `` for the references to classes etc. |
||
|
||
Format themselve have modifiers. For instance, a HTML strong tag migh have | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. " |
||
attributes (styles, classes, ...). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,15 @@ export interface Modifier { | |
constructor: ModifierConstructor & this; | ||
} | ||
export class Modifier { | ||
/** | ||
* The name of the this Modifier. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The this? :-) |
||
*/ | ||
get name(): string { | ||
return ''; | ||
} | ||
/** | ||
* Return the string representation of this Modifier. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the capital letter? |
||
*/ | ||
toString(): string { | ||
return this.name; | ||
} | ||
|
@@ -22,9 +28,17 @@ export class Modifier { | |
applyTo(node: VNode): void { | ||
node.modifiers.prepend(this); | ||
} | ||
/** | ||
* Compare two modifiers. | ||
* | ||
* Meant to be overridden if necessary. | ||
Comment on lines
+32
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Return true if this modifier is the same as the given modifier, false otherwise. This can be overridden to change the meaning of equality between modifiers." |
||
*/ | ||
isSameAs(otherModifier: Modifier): boolean { | ||
return this === otherModifier; | ||
} | ||
/** | ||
* Clone this modifier. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Return a clone of this modifier." |
||
*/ | ||
clone(): this { | ||
return new this.constructor(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import { Modifier } from './Modifier'; | ||
import { Constructor, isConstructor } from '../../utils/src/utils'; | ||
|
||
/** | ||
* When parsing dom elements, modifiers can be DOM inline nodes (a, b, strong). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't write this here.
|
||
* | ||
* The order of modifiers are important because it impact the way they will | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "The order" -> "is" => "The order of modifiers is important because it may impact their rendering." ? |
||
* be rendered. | ||
*/ | ||
export class Modifiers { | ||
private _contents: Modifier[]; | ||
constructor(...modifiers: Array<Modifier | Constructor<Modifier>>) { | ||
|
@@ -86,7 +92,6 @@ export class Modifiers { | |
* for `this._contents`. | ||
* | ||
* @see Array.find | ||
* @param modifier | ||
*/ | ||
find<T extends Modifier>(callback: (modifier: T) => boolean): T; | ||
find<T extends Modifier>(modifier: T | Constructor<T>): T; | ||
|
@@ -110,8 +115,6 @@ export class Modifiers { | |
* modifier class or create one, append it and return it. | ||
* If the modifier passed is a modifier instance, return it if it was | ||
* present in the array. | ||
* | ||
* @param modifier | ||
*/ | ||
get<T extends Modifier>(modifier: T | Constructor<T>): T { | ||
let found = this.find(modifier); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,31 @@ import { Modifier } from '../../core/src/Modifier'; | |
import { Modifiers } from '../../core/src/Modifiers'; | ||
import { Attributes } from '../../plugin-xml/src/Attributes'; | ||
|
||
/** | ||
* A Format might represent DOM inline nodes (a, b, strong) that were parsed or | ||
* the DOM inline node (a, b, strong) that we might render. | ||
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a TODO just below: "remove this reference to DOM." Now what this does however is reveal how a |
||
*/ | ||
export class Format extends Modifier { | ||
htmlTag: string; // TODO: remove this reference to DOM. | ||
/** | ||
* The modifiers for a format is `Attribute`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea what that sentence is supposed to mean. If you mean that the only modifier a |
||
* Used to be rendered. | ||
*/ | ||
modifiers = new Modifiers(); | ||
|
||
constructor(htmlTag?: string) { | ||
super(); | ||
this.htmlTag = htmlTag; | ||
} | ||
/** | ||
* @override | ||
*/ | ||
get name(): string { | ||
return this.htmlTag.toLowerCase(); | ||
} | ||
/** | ||
* @override | ||
*/ | ||
toString(): string { | ||
const nonEmptyAttributes = this.modifiers.filter( | ||
modifier => !(modifier instanceof Attributes) || !!modifier.length, | ||
|
@@ -31,6 +46,11 @@ export class Format extends Modifier { | |
// Public | ||
//-------------------------------------------------------------------------- | ||
|
||
/** | ||
* Render the current format into a dom Node. | ||
* | ||
* Meant to be used with `FormatDomRenderer`. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
render(): Element { | ||
const domNode = document.createElement(this.htmlTag); | ||
const attributes = this.modifiers.find(Attributes); | ||
|
@@ -51,12 +71,18 @@ export class Format extends Modifier { | |
} | ||
return domNode; | ||
} | ||
/** | ||
* @override | ||
*/ | ||
clone(): this { | ||
const clone = new this.constructor(); | ||
clone.htmlTag = this.htmlTag; | ||
clone.modifiers = this.modifiers.clone(); | ||
return clone; | ||
} | ||
/** | ||
* @override | ||
*/ | ||
isSameAs(otherFormat: Format): boolean { | ||
const aModifiers = this.modifiers; | ||
const bModifiers = otherFormat?.modifiers; | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
You could think of a modifier the way you think of a loadable but for nodes: they are simple holders of information that have the potential of modifying the node.