@atjson/renderer-hir
Advanced tools
Comparing version 0.10.0 to 0.11.0
@@ -6,2 +6,29 @@ # Change Log | ||
## [0.11.0](https://github.com/CondeNast-Copilot/atjson/compare/@atjson/renderer-hir@0.10.0...@atjson/renderer-hir@0.11.0) (2018-10-22) | ||
### ✨ New Features | ||
* ✨👑✨ Make Annotations classes instead of JS objects ([#57](https://github.com/CondeNast-Copilot/atjson/issues/57)) | ||
### 🚨 Breaking Changes | ||
* This introduces a bunch of breaking changes to AtJSON. The major change is that Annotations are now described as classes instead of a loose schema. | ||
A summary of changes are the following: | ||
⚠️ `@atjson/schema` is now deprecated. Instead of using the schema, instead use `@atjson/offset-annotations`, which provides a library of annotations that closely resemble those provided by `@atjson/schema` | ||
🃏 Schemas are now defined on a document subclass. The schema is a list of annotation classes that are used to identify annotations in the document. | ||
🛸 Any annotations not found in the schema are identified as `unknown` annotations. These annotations are available to be read and updated like any other annotation, but may have incorrect transform behavior because the text transform behavior is undefined. The default behavior should be acceptable for most cases. | ||
🕵🏾♀️ `id`s are required property on Annotations. This is used to identify annotations for speedy updating for Offset | ||
🖍 Annotations are now prefixed at rest. For the CommonMark Link annotation, it will be stored as `-commonmark-link` as the `type` and the attributes will be prefixed with `-commonmark` as well, meaning that instead of seeing `href` in the `attributes`, you will see `-commonmark-href`. When the annotation JSON is hydrated into an annotation class, prefixes are automatically removed. This prevents any collisions that may (and will) happen when converting between document types. | ||
🎨 Renderers now take `Annotation`s instead of the `attributes`. When additional context is required to render an annotation, a `context` object is passed as the second argument, which provides references to the `parent`, `next`, `previous`, and `children` annotations to the current annotation. | ||
## [0.10.0](https://github.com/CondeNast-Copilot/atjson/compare/@atjson/renderer-hir@0.9.3...@atjson/renderer-hir@0.10.0) (2018-10-10) | ||
@@ -8,0 +35,0 @@ |
@@ -1,8 +0,15 @@ | ||
import Document from '@atjson/document'; | ||
import { HIR, HIRNode } from '@atjson/hir'; | ||
import Document, { Annotation } from '@atjson/document'; | ||
import { HIR } from '@atjson/hir'; | ||
export declare function escapeHTML(text: string): string; | ||
export interface Context { | ||
parent: Annotation; | ||
previous: Annotation | null; | ||
next: Annotation | null; | ||
children: Annotation[]; | ||
} | ||
export default class Renderer { | ||
renderAnnotation(annotation: HIRNode): IterableIterator<any>; | ||
renderText(text: string): string; | ||
renderAnnotation(annotation: Annotation, context: Context): IterableIterator<any>; | ||
root(): IterableIterator<any>; | ||
text(text: string): string; | ||
render(document: Document | HIR): any; | ||
} |
@@ -30,4 +30,18 @@ "use strict"; | ||
} | ||
function compile(renderer, node) { | ||
let generator = renderer.renderAnnotation(node); | ||
function compile(renderer, node, parent, previous, next) { | ||
let annotation = node.annotation; | ||
let childNodes = node.children(); | ||
let childAnnotations = childNodes.map(childNode => childNode.annotation); | ||
let generator; | ||
if (parent == null) { | ||
generator = renderer.root(); | ||
} | ||
else { | ||
generator = renderer.renderAnnotation(annotation, { | ||
parent, | ||
previous: previous || null, | ||
next: next || null, | ||
children: childAnnotations | ||
}); | ||
} | ||
let result = generator.next(); | ||
@@ -37,9 +51,8 @@ if (result.done) { | ||
} | ||
let children = node.children(); | ||
return generator.next(flatten(children.map((childNode) => { | ||
if (childNode.type === 'text' && typeof childNode.text === 'string') { | ||
return renderer.renderText(childNode.text); | ||
return generator.next(flatten(childNodes.map((childNode, idx) => { | ||
if (childNode.annotation instanceof hir_1.TextAnnotation) { | ||
return renderer.text(childNode.annotation.attributes.text); | ||
} | ||
else { | ||
return compile(renderer, childNode); | ||
return compile(renderer, childNode, annotation, childAnnotations[idx - 1], childAnnotations[idx + 1]); | ||
} | ||
@@ -49,10 +62,13 @@ }))).value; | ||
class Renderer { | ||
*renderAnnotation(annotation) { | ||
*renderAnnotation(annotation, context) { | ||
let generator = this[annotation.type]; | ||
if (generator) { | ||
return yield* generator.call(this, annotation.attributes); | ||
return yield* generator.call(this, annotation, context); | ||
} | ||
return yield; | ||
} | ||
renderText(text) { | ||
*root() { | ||
return yield; | ||
} | ||
text(text) { | ||
return text; | ||
@@ -68,2 +84,2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ksU0FBUyxHQUFJLElBQVksQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDL0MsSUFBSSxTQUFTLEVBQUU7WUFDYixPQUFPLEtBQUssQ0FBQyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsSUFBSSxFQUFFLFVBQVUsRUFBRSxPQUFPLENBQUMsQ0FBQztTQUN6RDtRQUNELE9BQU8sS0FBSyxDQUFDO0lBQ2YsQ0FBQztJQUVELENBQUMsSUFBSTtRQUNILE9BQU8sS0FBSyxDQUFDO0lBQ2YsQ0FBQztJQUVELElBQUksQ0FBQyxJQUFZO1FBQ2YsT0FBTyxJQUFJLENBQUM7SUFDZCxDQUFDO0lBRUQsTUFBTSxDQUFDLFFBQXdCO1FBQzdCLElBQUksUUFBUSxZQUFZLFNBQUcsRUFBRTtZQUMzQixPQUFPLE9BQU8sQ0FBQyxJQUFJLEVBQUUsUUFBUSxDQUFDLFFBQVEsQ0FBQyxDQUFDO1NBQ3pDO1FBQ0QsT0FBTyxPQUFPLENBQUMsSUFBSSxFQUFFLElBQUksU0FBRyxDQUFDLFFBQVEsQ0FBQyxDQUFDLFFBQVEsQ0FBQyxDQUFDO0lBQ25ELENBQUM7Q0FDRjtBQXhCRCwyQkF3QkMifQ== |
@@ -1,8 +0,15 @@ | ||
import Document from '@atjson/document'; | ||
import { HIR, HIRNode } from '@atjson/hir'; | ||
import Document, { Annotation } from '@atjson/document'; | ||
import { HIR } from '@atjson/hir'; | ||
export declare function escapeHTML(text: string): string; | ||
export interface Context { | ||
parent: Annotation; | ||
previous: Annotation | null; | ||
next: Annotation | null; | ||
children: Annotation[]; | ||
} | ||
export default class Renderer { | ||
renderAnnotation(annotation: HIRNode): IterableIterator<any>; | ||
renderText(text: string): string; | ||
renderAnnotation(annotation: Annotation, context: Context): IterableIterator<any>; | ||
root(): IterableIterator<any>; | ||
text(text: string): string; | ||
render(document: Document | HIR): any; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { HIR } from '@atjson/hir'; | ||
import { HIR, TextAnnotation } from '@atjson/hir'; | ||
const escape = { | ||
@@ -27,4 +27,18 @@ '&': '&', | ||
} | ||
function compile(renderer, node) { | ||
let generator = renderer.renderAnnotation(node); | ||
function compile(renderer, node, parent, previous, next) { | ||
let annotation = node.annotation; | ||
let childNodes = node.children(); | ||
let childAnnotations = childNodes.map(childNode => childNode.annotation); | ||
let generator; | ||
if (parent == null) { | ||
generator = renderer.root(); | ||
} | ||
else { | ||
generator = renderer.renderAnnotation(annotation, { | ||
parent, | ||
previous: previous || null, | ||
next: next || null, | ||
children: childAnnotations | ||
}); | ||
} | ||
let result = generator.next(); | ||
@@ -34,9 +48,8 @@ if (result.done) { | ||
} | ||
let children = node.children(); | ||
return generator.next(flatten(children.map((childNode) => { | ||
if (childNode.type === 'text' && typeof childNode.text === 'string') { | ||
return renderer.renderText(childNode.text); | ||
return generator.next(flatten(childNodes.map((childNode, idx) => { | ||
if (childNode.annotation instanceof TextAnnotation) { | ||
return renderer.text(childNode.annotation.attributes.text); | ||
} | ||
else { | ||
return compile(renderer, childNode); | ||
return compile(renderer, childNode, annotation, childAnnotations[idx - 1], childAnnotations[idx + 1]); | ||
} | ||
@@ -46,10 +59,13 @@ }))).value; | ||
export default class Renderer { | ||
*renderAnnotation(annotation) { | ||
*renderAnnotation(annotation, context) { | ||
let generator = this[annotation.type]; | ||
if (generator) { | ||
return yield* generator.call(this, annotation.attributes); | ||
return yield* generator.call(this, annotation, context); | ||
} | ||
return yield; | ||
} | ||
renderText(text) { | ||
*root() { | ||
return yield; | ||
} | ||
text(text) { | ||
return text; | ||
@@ -64,2 +80,2 @@ } | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLE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FBUyxDQUFDLElBQUksQ0FBQyxJQUFJLEVBQUUsVUFBVSxFQUFFLE9BQU8sQ0FBQyxDQUFDO1NBQ3pEO1FBQ0QsT0FBTyxLQUFLLENBQUM7SUFDZixDQUFDO0lBRUQsQ0FBQyxJQUFJO1FBQ0gsT0FBTyxLQUFLLENBQUM7SUFDZixDQUFDO0lBRUQsSUFBSSxDQUFDLElBQVk7UUFDZixPQUFPLElBQUksQ0FBQztJQUNkLENBQUM7SUFFRCxNQUFNLENBQUMsUUFBd0I7UUFDN0IsSUFBSSxRQUFRLFlBQVksR0FBRyxFQUFFO1lBQzNCLE9BQU8sT0FBTyxDQUFDLElBQUksRUFBRSxRQUFRLENBQUMsUUFBUSxDQUFDLENBQUM7U0FDekM7UUFDRCxPQUFPLE9BQU8sQ0FBQyxJQUFJLEVBQUUsSUFBSSxHQUFHLENBQUMsUUFBUSxDQUFDLENBQUMsUUFBUSxDQUFDLENBQUM7SUFDbkQsQ0FBQztDQUNGIn0= |
{ | ||
"name": "@atjson/renderer-hir", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "A brand new TypeScript library.", | ||
@@ -19,6 +19,6 @@ "main": "dist/commonjs/index.js", | ||
"dependencies": { | ||
"@atjson/document": "0.9.0", | ||
"@atjson/hir": "0.9.0" | ||
"@atjson/document": "0.11.0", | ||
"@atjson/hir": "0.11.0" | ||
}, | ||
"gitHead": "8d0640410453bbfc1495644c346145b502cc7400" | ||
"gitHead": "36b48214b21591d09269f01d351d805a02447369" | ||
} |
@@ -1,3 +0,3 @@ | ||
import Document from '@atjson/document'; | ||
import { HIR, HIRNode } from '@atjson/hir'; | ||
import Document, { Annotation } from '@atjson/document'; | ||
import { HIR, HIRNode, TextAnnotation } from '@atjson/hir'; | ||
@@ -37,4 +37,26 @@ interface Mapping { | ||
function compile(renderer: Renderer, node: HIRNode): any { | ||
let generator = renderer.renderAnnotation(node); | ||
export interface Context { | ||
parent: Annotation; | ||
previous: Annotation | null; | ||
next: Annotation | null; | ||
children: Annotation[]; | ||
} | ||
function compile(renderer: Renderer, node: HIRNode, parent?: Annotation, previous?: Annotation, next?: Annotation): any { | ||
let annotation = node.annotation; | ||
let childNodes = node.children(); | ||
let childAnnotations = childNodes.map(childNode => childNode.annotation); | ||
let generator; | ||
if (parent == null) { | ||
generator = renderer.root(); | ||
} else { | ||
generator = renderer.renderAnnotation(annotation, { | ||
parent, | ||
previous: previous || null, | ||
next: next || null, | ||
children: childAnnotations | ||
}); | ||
} | ||
let result = generator.next(); | ||
@@ -45,8 +67,7 @@ if (result.done) { | ||
let children = node.children(); | ||
return generator.next(flatten(children.map((childNode: HIRNode) => { | ||
if (childNode.type === 'text' && typeof childNode.text === 'string') { | ||
return renderer.renderText(childNode.text); | ||
return generator.next(flatten(childNodes.map((childNode: HIRNode, idx: number) => { | ||
if (childNode.annotation instanceof TextAnnotation) { | ||
return renderer.text(childNode.annotation.attributes.text); | ||
} else { | ||
return compile(renderer, childNode); | ||
return compile(renderer, childNode, annotation, childAnnotations[idx - 1], childAnnotations[idx + 1]); | ||
} | ||
@@ -58,6 +79,6 @@ }))).value; | ||
*renderAnnotation(annotation: HIRNode): IterableIterator<any> { | ||
*renderAnnotation(annotation: Annotation, context: Context): IterableIterator<any> { | ||
let generator = (this as any)[annotation.type]; | ||
if (generator) { | ||
return yield* generator.call(this, annotation.attributes); | ||
return yield* generator.call(this, annotation, context); | ||
} | ||
@@ -67,3 +88,7 @@ return yield; | ||
renderText(text: string): string { | ||
*root(): IterableIterator<any> { | ||
return yield; | ||
} | ||
text(text: string): string { | ||
return text; | ||
@@ -70,0 +95,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31221
300
+ Added@atjson/document@0.11.0(transitive)
+ Added@atjson/hir@0.11.0(transitive)
+ Added@types/uuid@3.4.13(transitive)
+ Addeduuid@3.4.0(transitive)
- Removed@atjson/document@0.9.0(transitive)
- Removed@atjson/hir@0.9.0(transitive)
Updated@atjson/document@0.11.0
Updated@atjson/hir@0.11.0