Skip to content

Commit

Permalink
Added type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
nozer committed Jun 10, 2018
1 parent 4e32f3d commit 8123ae9
Show file tree
Hide file tree
Showing 25 changed files with 474 additions and 166 deletions.
100 changes: 54 additions & 46 deletions dist/browser/QuillDeltaToHtmlConverter.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ var QuillDeltaToHtmlConverter = (function () {
};
this.rawDeltaOps = deltaOps;
}
QuillDeltaToHtmlConverter.prototype.getListTag = function (op) {
QuillDeltaToHtmlConverter.prototype._getListTag = function (op) {
return op.isOrderedList() ? this.options.orderedListTag + ''
: op.isBulletList() ? this.options.bulletListTag + ''
: '';
Expand All @@ -536,28 +536,28 @@ var QuillDeltaToHtmlConverter = (function () {
return this.getGroupedOps()
.map(function (group) {
if (group instanceof group_types_1.ListGroup) {
return _this.renderWithCallbacks(value_types_1.GroupType.List, group, function () { return _this.renderList(group); });
return _this._renderWithCallbacks(value_types_1.GroupType.List, group, function () { return _this._renderList(group); });
}
else if (group instanceof group_types_1.BlockGroup) {
var g = group;
return _this.renderWithCallbacks(value_types_1.GroupType.Block, group, function () { return _this.renderBlock(g.op, g.ops); });
return _this._renderWithCallbacks(value_types_1.GroupType.Block, group, function () { return _this._renderBlock(g.op, g.ops); });
}
else if (group instanceof group_types_1.VideoItem) {
return _this.renderWithCallbacks(value_types_1.GroupType.Video, group, function () {
return _this._renderWithCallbacks(value_types_1.GroupType.Video, group, function () {
var g = group;
var converter = new OpToHtmlConverter_1.OpToHtmlConverter(g.op, _this.converterOptions);
return converter.getHtml();
});
}
else {
return _this.renderWithCallbacks(value_types_1.GroupType.InlineGroup, group, function () {
return _this.renderInlines(group.ops);
return _this._renderWithCallbacks(value_types_1.GroupType.InlineGroup, group, function () {
return _this._renderInlines(group.ops);
});
}
})
.join("");
};
QuillDeltaToHtmlConverter.prototype.renderWithCallbacks = function (groupType, group, myRenderFn) {
QuillDeltaToHtmlConverter.prototype._renderWithCallbacks = function (groupType, group, myRenderFn) {
var html = '';
var beforeCb = this.callbacks['beforeRender_cb'];
html = typeof beforeCb === 'function' ? beforeCb.apply(null, [groupType, group]) : '';
Expand All @@ -568,39 +568,39 @@ var QuillDeltaToHtmlConverter = (function () {
html = typeof afterCb === 'function' ? afterCb.apply(null, [groupType, html]) : html;
return html;
};
QuillDeltaToHtmlConverter.prototype.renderList = function (list, isOuterMost) {
QuillDeltaToHtmlConverter.prototype._renderList = function (list, isOuterMost) {
var _this = this;
if (isOuterMost === void 0) { isOuterMost = true; }
var firstItem = list.items[0];
return funcs_html_1.makeStartTag(this.getListTag(firstItem.item.op))
+ list.items.map(function (li) { return _this.renderListItem(li, isOuterMost); }).join('')
+ funcs_html_1.makeEndTag(this.getListTag(firstItem.item.op));
return funcs_html_1.makeStartTag(this._getListTag(firstItem.item.op))
+ list.items.map(function (li) { return _this._renderListItem(li, isOuterMost); }).join('')
+ funcs_html_1.makeEndTag(this._getListTag(firstItem.item.op));
};
QuillDeltaToHtmlConverter.prototype.renderListItem = function (li, isOuterMost) {
QuillDeltaToHtmlConverter.prototype._renderListItem = function (li, isOuterMost) {
var converterOptions = Object._assign({}, this.converterOptions);
li.item.op.attributes.indent = 0;
var converter = new OpToHtmlConverter_1.OpToHtmlConverter(li.item.op, this.converterOptions);
var parts = converter.getHtmlParts();
var liElementsHtml = this.renderInlines(li.item.ops, false);
var liElementsHtml = this._renderInlines(li.item.ops, false);
return parts.openingTag + (liElementsHtml) +
(li.innerList ? this.renderList(li.innerList, false) : '')
(li.innerList ? this._renderList(li.innerList, false) : '')
+ parts.closingTag;
};
QuillDeltaToHtmlConverter.prototype.renderBlock = function (bop, ops) {
QuillDeltaToHtmlConverter.prototype._renderBlock = function (bop, ops) {
var _this = this;
var converter = new OpToHtmlConverter_1.OpToHtmlConverter(bop, this.converterOptions);
var htmlParts = converter.getHtmlParts();
if (bop.isCodeBlock()) {
return htmlParts.openingTag +
funcs_html_1.encodeHtml(ops.map(function (iop) {
return iop.isCustom() ? _this.renderCustom(iop, bop) : iop.insert.value;
return iop.isCustom() ? _this._renderCustom(iop, bop) : iop.insert.value;
}).join(""))
+ htmlParts.closingTag;
}
var inlines = ops.map(function (op) { return _this._renderInline(op, bop); }).join('');
return htmlParts.openingTag + (inlines || BrTag) + htmlParts.closingTag;
};
QuillDeltaToHtmlConverter.prototype.renderInlines = function (ops, wrapInParagraphTag) {
QuillDeltaToHtmlConverter.prototype._renderInlines = function (ops, wrapInParagraphTag) {
var _this = this;
if (wrapInParagraphTag === void 0) { wrapInParagraphTag = true; }
var opsLen = ops.length - 1;
Expand All @@ -618,12 +618,12 @@ var QuillDeltaToHtmlConverter = (function () {
};
QuillDeltaToHtmlConverter.prototype._renderInline = function (op, contextOp) {
if (op.isCustom()) {
return this.renderCustom(op, contextOp);
return this._renderCustom(op, contextOp);
}
var converter = new OpToHtmlConverter_1.OpToHtmlConverter(op, this.converterOptions);
return converter.getHtml().replace(/\n/g, BrTag);
};
QuillDeltaToHtmlConverter.prototype.renderCustom = function (op, contextOp) {
QuillDeltaToHtmlConverter.prototype._renderCustom = function (op, contextOp) {
var renderCb = this.callbacks['renderCustomOp_cb'];
if (typeof renderCb === 'function') {
return renderCb.apply(null, [op, contextOp]);
Expand Down Expand Up @@ -1104,39 +1104,47 @@ exports.MentionSanitizer = MentionSanitizer;
Object.defineProperty(exports, "__esModule", { value: true });
var NewLine = "\n";
exports.NewLine = NewLine;
var ListType = {
Ordered: 'ordered',
Bullet: 'bullet'
};
var ListType;
(function (ListType) {
ListType["Ordered"] = "ordered";
ListType["Bullet"] = "bullet";
})(ListType || (ListType = {}));
exports.ListType = ListType;
var ScriptType = {
Sub: "sub",
Super: "super"
};
var ScriptType;
(function (ScriptType) {
ScriptType["Sub"] = "sub";
ScriptType["Super"] = "super";
})(ScriptType || (ScriptType = {}));
exports.ScriptType = ScriptType;
var DirectionType = {
Rtl: "rtl"
};
var DirectionType;
(function (DirectionType) {
DirectionType["Rtl"] = "rtl";
})(DirectionType || (DirectionType = {}));
exports.DirectionType = DirectionType;
var AlignType = {
Center: "center",
Right: "right"
};
var AlignType;
(function (AlignType) {
AlignType["Center"] = "center";
AlignType["Right"] = "right";
})(AlignType || (AlignType = {}));
exports.AlignType = AlignType;
var DataType = {
Image: "image",
Video: "video",
Formula: "formula",
Text: "text"
};
var DataType;
(function (DataType) {
DataType["Image"] = "image";
DataType["Video"] = "video";
DataType["Formula"] = "formula";
DataType["Text"] = "text";
})(DataType || (DataType = {}));
exports.DataType = DataType;
var GroupType = {
Block: 'block',
InlineGroup: 'inline-group',
List: 'list',
Video: 'video'
};
;
var GroupType;
(function (GroupType) {
GroupType["Block"] = "block";
GroupType["InlineGroup"] = "inline-group";
GroupType["List"] = "list";
GroupType["Video"] = "video";
})(GroupType || (GroupType = {}));
exports.GroupType = GroupType;
;

},{}]},{},[7])(7)
});; window.QuillDeltaToHtmlConverter = window.QuillDeltaToHtmlConverter.QuillDeltaToHtmlConverter;
30 changes: 30 additions & 0 deletions dist/commonjs/DeltaInsertOp.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { IOpAttributes } from "./OpAttributeSanitizer";
import { InsertData } from './InsertData';
declare class DeltaInsertOp {
readonly insert: InsertData;
readonly attributes: IOpAttributes;
constructor(insertVal: InsertData | string, attributes?: IOpAttributes);
static createNewLineOp(): DeltaInsertOp;
isContainerBlock(): boolean;
isBlockquote(): boolean;
isHeader(): boolean;
isSameHeaderAs(op: DeltaInsertOp): boolean;
hasSameAdiAs(op: DeltaInsertOp): boolean;
hasSameIndentationAs(op: DeltaInsertOp): boolean;
hasHigherIndentThan(op: DeltaInsertOp): boolean;
isInline(): boolean;
isCodeBlock(): boolean;
isJustNewline(): boolean;
isList(): boolean;
isOrderedList(): boolean;
isBulletList(): boolean;
isSameListAs(op: DeltaInsertOp): boolean;
isText(): boolean;
isImage(): boolean;
isFormula(): boolean;
isVideo(): boolean;
isLink(): boolean;
isCustom(): boolean;
isMentions(): boolean;
}
export { DeltaInsertOp };
13 changes: 13 additions & 0 deletions dist/commonjs/InsertData.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { DataType } from './value-types';
declare class InsertDataQuill {
readonly type: DataType;
readonly value: string;
constructor(type: DataType, value: string);
}
declare class InsertDataCustom {
readonly type: string;
readonly value: any;
constructor(type: string, value: any);
}
declare type InsertData = InsertDataCustom | InsertDataQuill;
export { InsertData, InsertDataCustom, InsertDataQuill };
6 changes: 6 additions & 0 deletions dist/commonjs/InsertOpDenormalizer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import './extensions/String';
import './extensions/Object';
declare class InsertOpDenormalizer {
static denormalize(op: any): any[];
}
export { InsertOpDenormalizer };
7 changes: 7 additions & 0 deletions dist/commonjs/InsertOpsConverter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DeltaInsertOp } from './DeltaInsertOp';
import { InsertData } from './InsertData';
declare class InsertOpsConverter {
static convert(deltaOps: any[]): DeltaInsertOp[];
static convertInsertVal(insertPropVal: any): InsertData | null;
}
export { InsertOpsConverter };
37 changes: 37 additions & 0 deletions dist/commonjs/OpAttributeSanitizer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ListType, AlignType, DirectionType, ScriptType } from './value-types';
import './extensions/String';
import { IMention } from "./mentions/MentionSanitizer";
interface IOpAttributes {
background?: string;
color?: string;
font?: string;
size?: string;
width?: string;
link?: string;
bold?: boolean;
italic?: boolean;
underline?: boolean;
strike?: boolean;
script?: ScriptType;
code?: boolean;
list?: ListType;
blockquote?: boolean;
'code-block'?: boolean;
header?: number;
align?: AlignType;
direction?: DirectionType;
indent?: number;
mentions?: boolean;
mention?: IMention;
target?: string;
}
declare class OpAttributeSanitizer {
static sanitize(dirtyAttrs: IOpAttributes): IOpAttributes;
static IsValidHexColor(colorStr: string): boolean;
static IsValidColorLiteral(colorStr: string): boolean;
static IsValidFontName(fontName: string): boolean;
static IsValidSize(size: string): boolean;
static IsValidWidth(width: string): boolean;
static isValidTarget(target: string): boolean;
}
export { OpAttributeSanitizer, IOpAttributes };
34 changes: 34 additions & 0 deletions dist/commonjs/OpToHtmlConverter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ITagKeyValue } from './funcs-html';
import { DeltaInsertOp } from './DeltaInsertOp';
import './extensions/String';
import './extensions/Object';
import './extensions/Array';
interface IOpToHtmlConverterOptions {
classPrefix?: string;
encodeHtml?: boolean;
listItemTag?: string;
paragraphTag?: string;
linkRel?: string;
linkTarget?: string;
allowBackgroundClasses?: boolean;
}
interface IHtmlParts {
openingTag: string;
content: string;
closingTag: string;
}
declare class OpToHtmlConverter {
private options;
private op;
constructor(op: DeltaInsertOp, options?: IOpToHtmlConverterOptions);
prefixClass(className: string): string;
getHtml(): string;
getHtmlParts(): IHtmlParts;
getContent(): string;
getCssClasses(): string[];
getCssStyles(): string[];
getTagAttributes(): Array<ITagKeyValue>;
getTags(): string[];
static IsValidRel(relStr: string): boolean;
}
export { OpToHtmlConverter, IOpToHtmlConverterOptions, IHtmlParts };
39 changes: 39 additions & 0 deletions dist/commonjs/QuillDeltaToHtmlConverter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { DeltaInsertOp } from './DeltaInsertOp';
import { ListGroup, ListItem, TDataGroup } from './grouper/group-types';
import './extensions/Object';
import { GroupType } from './value-types';
interface IQuillDeltaToHtmlConverterOptions {
orderedListTag?: string;
bulletListTag?: string;
listItemTag?: string;
paragraphTag?: string;
classPrefix?: string;
encodeHtml?: boolean;
multiLineBlockquote?: boolean;
multiLineHeader?: boolean;
multiLineCodeblock?: boolean;
linkRel?: string;
linkTarget?: string;
allowBackgroundClasses?: boolean;
}
declare class QuillDeltaToHtmlConverter {
private options;
private rawDeltaOps;
private converterOptions;
private callbacks;
constructor(deltaOps: any[], options?: IQuillDeltaToHtmlConverterOptions);
_getListTag(op: DeltaInsertOp): string;
getGroupedOps(): TDataGroup[];
convert(): string;
_renderWithCallbacks(groupType: GroupType, group: TDataGroup, myRenderFn: () => string): string;
_renderList(list: ListGroup, isOuterMost?: boolean): string;
_renderListItem(li: ListItem, isOuterMost: boolean): string;
_renderBlock(bop: DeltaInsertOp, ops: DeltaInsertOp[]): string;
_renderInlines(ops: DeltaInsertOp[], wrapInParagraphTag?: boolean): string;
_renderInline(op: DeltaInsertOp, contextOp: DeltaInsertOp): any;
_renderCustom(op: DeltaInsertOp, contextOp: DeltaInsertOp): any;
beforeRender(cb: (group: GroupType, data: TDataGroup) => string): void;
afterRender(cb: (group: GroupType, html: string) => string): void;
renderCustomWith(cb: (op: DeltaInsertOp, contextOp: DeltaInsertOp) => string): void;
}
export { QuillDeltaToHtmlConverter };
Loading

0 comments on commit 8123ae9

Please sign in to comment.