@covalent/flavored-markdown 6.3.0-beta.4 → 6.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,820 +0,0 @@
1
- import * as i0 from '@angular/core';
2
- import { Component, Input, ViewChild, EventEmitter, HostBinding, Output, Directive, ChangeDetectionStrategy, NgModule } from '@angular/core';
3
- import { MatCheckbox, MatCheckboxModule } from '@angular/material/checkbox';
4
- import * as i4 from '@angular/material/sort';
5
- import { MatSort, MatSortModule } from '@angular/material/sort';
6
- import * as i3$1 from '@angular/material/table';
7
- import { MatTableDataSource, MatTableModule } from '@angular/material/table';
8
- import { Subject } from 'rxjs';
9
- import { takeUntil } from 'rxjs/operators';
10
- import * as i1 from '@angular/common';
11
- import { CommonModule } from '@angular/common';
12
- import * as i2 from '@angular/material/list';
13
- import { MatListModule } from '@angular/material/list';
14
- import * as i3 from '@angular/material/divider';
15
- import { TdHighlightComponent, CovalentHighlightModule } from '@covalent/highlight';
16
- import * as i1$1 from '@covalent/markdown';
17
- import { scrollToAnchor, TdMarkdownComponent, CovalentMarkdownModule } from '@covalent/markdown';
18
- import * as i5 from '@angular/material/button';
19
- import { MatButtonModule } from '@angular/material/button';
20
- import * as i3$2 from '@angular/material/progress-bar';
21
- import { MatProgressBarModule } from '@angular/material/progress-bar';
22
- import { __awaiter } from 'tslib';
23
-
24
- function TdFlavoredListComponent_ng_template_1_p_3_Template(rf, ctx) {
25
- if (rf & 1) {
26
- i0.ɵɵelementStart(0, "p", 4);
27
- i0.ɵɵtext(1);
28
- i0.ɵɵelementEnd();
29
- }
30
- if (rf & 2) {
31
- const subline_r5 = ctx.$implicit;
32
- i0.ɵɵadvance(1);
33
- i0.ɵɵtextInterpolate1(" ", subline_r5, " ");
34
- }
35
- }
36
- function TdFlavoredListComponent_ng_template_1_mat_divider_4_Template(rf, ctx) {
37
- if (rf & 1) {
38
- i0.ɵɵelement(0, "mat-divider", 4);
39
- }
40
- }
41
- function TdFlavoredListComponent_ng_template_1_Template(rf, ctx) {
42
- if (rf & 1) {
43
- i0.ɵɵelementStart(0, "mat-list-item")(1, "h4", 1);
44
- i0.ɵɵtext(2);
45
- i0.ɵɵelementEnd();
46
- i0.ɵɵtemplate(3, TdFlavoredListComponent_ng_template_1_p_3_Template, 2, 1, "p", 2);
47
- i0.ɵɵtemplate(4, TdFlavoredListComponent_ng_template_1_mat_divider_4_Template, 1, 0, "mat-divider", 3);
48
- i0.ɵɵelementEnd();
49
- }
50
- if (rf & 2) {
51
- const line_r1 = ctx.$implicit;
52
- const last_r2 = ctx.last;
53
- i0.ɵɵadvance(2);
54
- i0.ɵɵtextInterpolate1(" ", line_r1.line, " ");
55
- i0.ɵɵadvance(1);
56
- i0.ɵɵproperty("ngForOf", line_r1.sublines);
57
- i0.ɵɵadvance(1);
58
- i0.ɵɵproperty("ngIf", !last_r2);
59
- }
60
- }
61
- class TdFlavoredListComponent {
62
- constructor() {
63
- this.dense = false;
64
- }
65
- }
66
- TdFlavoredListComponent.ɵfac = function TdFlavoredListComponent_Factory(t) { return new (t || TdFlavoredListComponent)(); };
67
- TdFlavoredListComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TdFlavoredListComponent, selectors: [["td-cfm-list"]], inputs: { lines: "lines", dense: "dense" }, decls: 2, vars: 2, consts: [["ngFor", "", 3, "ngForOf"], ["matListItemTitle", ""], ["matListItemLine", "", 4, "ngFor", "ngForOf"], ["matListItemLine", "", 4, "ngIf"], ["matListItemLine", ""]], template: function TdFlavoredListComponent_Template(rf, ctx) {
68
- if (rf & 1) {
69
- i0.ɵɵelementStart(0, "mat-list");
70
- i0.ɵɵtemplate(1, TdFlavoredListComponent_ng_template_1_Template, 5, 3, "ng-template", 0);
71
- i0.ɵɵelementEnd();
72
- }
73
- if (rf & 2) {
74
- i0.ɵɵattribute("dense", ctx.dense ? true : null);
75
- i0.ɵɵadvance(1);
76
- i0.ɵɵproperty("ngForOf", ctx.lines);
77
- }
78
- }, dependencies: [i1.NgForOf, i1.NgIf, i2.MatList, i2.MatListItem, i3.MatDivider, i2.MatListItemLine, i2.MatListItemTitle] });
79
- (function () {
80
- (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredListComponent, [{
81
- type: Component,
82
- args: [{ selector: 'td-cfm-list', template: "<mat-list [attr.dense]=\"dense ? true : null\">\n <ng-template let-line let-last=\"last\" ngFor [ngForOf]=\"lines\">\n <mat-list-item>\n <h4 matListItemTitle>\n {{ line.line }}\n </h4>\n <p *ngFor=\"let subline of line.sublines\" matListItemLine>\n {{ subline }}\n </p>\n <mat-divider *ngIf=\"!last\" matListItemLine></mat-divider>\n </mat-list-item>\n </ng-template>\n</mat-list>\n" }]
83
- }], null, { lines: [{
84
- type: Input
85
- }], dense: [{
86
- type: Input
87
- }] });
88
- })();
89
-
90
- function TdFlavoredMarkdownTableComponent_ng_template_1_mat_header_cell_1_Template(rf, ctx) {
91
- if (rf & 1) {
92
- i0.ɵɵelementStart(0, "mat-header-cell", 7);
93
- i0.ɵɵtext(1);
94
- i0.ɵɵelementEnd();
95
- }
96
- if (rf & 2) {
97
- const column_r3 = i0.ɵɵnextContext().$implicit;
98
- i0.ɵɵadvance(1);
99
- i0.ɵɵtextInterpolate(column_r3.label);
100
- }
101
- }
102
- function TdFlavoredMarkdownTableComponent_ng_template_1_mat_cell_2_Template(rf, ctx) {
103
- if (rf & 1) {
104
- i0.ɵɵelementStart(0, "mat-cell")(1, "td-markdown");
105
- i0.ɵɵtext(2);
106
- i0.ɵɵelementEnd()();
107
- }
108
- if (rf & 2) {
109
- const row_r7 = ctx.$implicit;
110
- const column_r3 = i0.ɵɵnextContext().$implicit;
111
- i0.ɵɵadvance(2);
112
- i0.ɵɵtextInterpolate(row_r7[column_r3.name]);
113
- }
114
- }
115
- function TdFlavoredMarkdownTableComponent_ng_template_1_Template(rf, ctx) {
116
- if (rf & 1) {
117
- i0.ɵɵelementContainerStart(0, 4);
118
- i0.ɵɵtemplate(1, TdFlavoredMarkdownTableComponent_ng_template_1_mat_header_cell_1_Template, 2, 1, "mat-header-cell", 5);
119
- i0.ɵɵtemplate(2, TdFlavoredMarkdownTableComponent_ng_template_1_mat_cell_2_Template, 3, 1, "mat-cell", 6);
120
- i0.ɵɵelementContainerEnd();
121
- }
122
- if (rf & 2) {
123
- const column_r3 = ctx.$implicit;
124
- i0.ɵɵproperty("matColumnDef", column_r3.name);
125
- }
126
- }
127
- function TdFlavoredMarkdownTableComponent_mat_header_row_2_Template(rf, ctx) {
128
- if (rf & 1) {
129
- i0.ɵɵelement(0, "mat-header-row");
130
- }
131
- }
132
- function TdFlavoredMarkdownTableComponent_mat_row_3_Template(rf, ctx) {
133
- if (rf & 1) {
134
- i0.ɵɵelement(0, "mat-row");
135
- }
136
- }
137
- const _c0 = ["*"];
138
- class TdFlavoredMarkdownTableComponent {
139
- constructor() {
140
- this.columnDefs = [];
141
- }
142
- ngOnInit() {
143
- this.displayedColumns = this.columnDefs.map((c) => c.name);
144
- this.dataSource = new MatTableDataSource(this.data);
145
- }
146
- ngAfterViewInit() {
147
- this.dataSource.sort = this.sort;
148
- }
149
- }
150
- TdFlavoredMarkdownTableComponent.ɵfac = function TdFlavoredMarkdownTableComponent_Factory(t) { return new (t || TdFlavoredMarkdownTableComponent)(); };
151
- TdFlavoredMarkdownTableComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TdFlavoredMarkdownTableComponent, selectors: [["ng-component"]], viewQuery: function TdFlavoredMarkdownTableComponent_Query(rf, ctx) {
152
- if (rf & 1) {
153
- i0.ɵɵviewQuery(MatSort, 5);
154
- }
155
- if (rf & 2) {
156
- let _t;
157
- i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.sort = _t.first);
158
- }
159
- }, inputs: { columnDefs: "columnDefs", data: "data" }, decls: 4, vars: 4, consts: [["matSort", "", 3, "dataSource"], ["ngFor", "", 3, "ngForOf"], [4, "matHeaderRowDef"], [4, "matRowDef", "matRowDefColumns"], [3, "matColumnDef"], ["mat-sort-header", "", 4, "matHeaderCellDef"], [4, "matCellDef"], ["mat-sort-header", ""]], template: function TdFlavoredMarkdownTableComponent_Template(rf, ctx) {
160
- if (rf & 1) {
161
- i0.ɵɵelementStart(0, "mat-table", 0);
162
- i0.ɵɵtemplate(1, TdFlavoredMarkdownTableComponent_ng_template_1_Template, 3, 1, "ng-template", 1);
163
- i0.ɵɵtemplate(2, TdFlavoredMarkdownTableComponent_mat_header_row_2_Template, 1, 0, "mat-header-row", 2);
164
- i0.ɵɵtemplate(3, TdFlavoredMarkdownTableComponent_mat_row_3_Template, 1, 0, "mat-row", 3);
165
- i0.ɵɵelementEnd();
166
- }
167
- if (rf & 2) {
168
- i0.ɵɵproperty("dataSource", ctx.dataSource);
169
- i0.ɵɵadvance(1);
170
- i0.ɵɵproperty("ngForOf", ctx.columnDefs);
171
- i0.ɵɵadvance(1);
172
- i0.ɵɵproperty("matHeaderRowDef", ctx.displayedColumns);
173
- i0.ɵɵadvance(1);
174
- i0.ɵɵproperty("matRowDefColumns", ctx.displayedColumns);
175
- }
176
- }, dependencies: [i1.NgForOf, i1$1.TdMarkdownComponent, i3$1.MatTable, i3$1.MatHeaderCellDef, i3$1.MatHeaderRowDef, i3$1.MatColumnDef, i3$1.MatCellDef, i3$1.MatRowDef, i3$1.MatHeaderCell, i3$1.MatCell, i3$1.MatHeaderRow, i3$1.MatRow, i4.MatSort, i4.MatSortHeader], encapsulation: 2 });
177
- (function () {
178
- (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredMarkdownTableComponent, [{
179
- type: Component,
180
- args: [{
181
- template: `
182
- <mat-table [dataSource]="dataSource" matSort>
183
- <!-- Column Definition -->
184
- <ng-template ngFor let-column [ngForOf]="columnDefs">
185
- <ng-container [matColumnDef]="column.name">
186
- <mat-header-cell *matHeaderCellDef mat-sort-header>{{
187
- column.label
188
- }}</mat-header-cell>
189
- <mat-cell *matCellDef="let row"
190
- ><td-markdown>{{ row[column.name] }}</td-markdown></mat-cell
191
- >
192
- </ng-container>
193
- </ng-template>
194
- <!-- Header and Row Declarations -->
195
- <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
196
- <mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
197
- </mat-table>
198
- `,
199
- }]
200
- }], null, { columnDefs: [{
201
- type: Input
202
- }], data: [{
203
- type: Input
204
- }], sort: [{
205
- type: ViewChild,
206
- args: [MatSort]
207
- }] });
208
- })();
209
- class TdFlavoredMarkdownButtonComponent {
210
- constructor() {
211
- this.display = 'inline-block';
212
- this.text = '';
213
- this.data = '';
214
- this.clicked = new EventEmitter();
215
- }
216
- emitClick() {
217
- this.clicked.emit({ text: this.text, data: this.data });
218
- }
219
- }
220
- TdFlavoredMarkdownButtonComponent.ɵfac = function TdFlavoredMarkdownButtonComponent_Factory(t) { return new (t || TdFlavoredMarkdownButtonComponent)(); };
221
- TdFlavoredMarkdownButtonComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TdFlavoredMarkdownButtonComponent, selectors: [["ng-component"]], hostVars: 2, hostBindings: function TdFlavoredMarkdownButtonComponent_HostBindings(rf, ctx) {
222
- if (rf & 2) {
223
- i0.ɵɵstyleProp("display", ctx.display);
224
- }
225
- }, inputs: { text: "text", data: "data" }, outputs: { clicked: "clicked" }, decls: 2, vars: 1, consts: [["mat-raised-button", "", 3, "click"]], template: function TdFlavoredMarkdownButtonComponent_Template(rf, ctx) {
226
- if (rf & 1) {
227
- i0.ɵɵelementStart(0, "button", 0);
228
- i0.ɵɵlistener("click", function TdFlavoredMarkdownButtonComponent_Template_button_click_0_listener() { return ctx.emitClick(); });
229
- i0.ɵɵtext(1);
230
- i0.ɵɵelementEnd();
231
- }
232
- if (rf & 2) {
233
- i0.ɵɵadvance(1);
234
- i0.ɵɵtextInterpolate1(" ", ctx.text, " ");
235
- }
236
- }, dependencies: [i5.MatButton], encapsulation: 2 });
237
- (function () {
238
- (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredMarkdownButtonComponent, [{
239
- type: Component,
240
- args: [{
241
- template: `
242
- <button mat-raised-button (click)="emitClick()">
243
- {{ text }}
244
- </button>
245
- `,
246
- }]
247
- }], null, { display: [{
248
- type: HostBinding,
249
- args: ['style.display']
250
- }], text: [{
251
- type: Input
252
- }], data: [{
253
- type: Input
254
- }], clicked: [{
255
- type: Output
256
- }] });
257
- })();
258
- class TdFlavoredMarkdownContainerDirective {
259
- constructor(viewContainerRef, _renderer) {
260
- this.viewContainerRef = viewContainerRef;
261
- this._renderer = _renderer;
262
- }
263
- clear() {
264
- this._renderer.setProperty(this.viewContainerRef.element.nativeElement, 'innerHTML', '');
265
- this.viewContainerRef.clear();
266
- }
267
- }
268
- TdFlavoredMarkdownContainerDirective.ɵfac = function TdFlavoredMarkdownContainerDirective_Factory(t) { return new (t || TdFlavoredMarkdownContainerDirective)(i0.ɵɵdirectiveInject(i0.ViewContainerRef), i0.ɵɵdirectiveInject(i0.Renderer2)); };
269
- TdFlavoredMarkdownContainerDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: TdFlavoredMarkdownContainerDirective, selectors: [["", "tdFlavoredMarkdownContainer", ""]] });
270
- (function () {
271
- (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredMarkdownContainerDirective, [{
272
- type: Directive,
273
- args: [{
274
- selector: '[tdFlavoredMarkdownContainer]',
275
- }]
276
- }], function () { return [{ type: i0.ViewContainerRef }, { type: i0.Renderer2 }]; }, null);
277
- })();
278
- class TdFlavoredMarkdownComponent {
279
- /**
280
- * content?: string
281
- *
282
- * Markdown format content to be parsed as material/covalent markup.
283
- *
284
- * e.g. README.md content.
285
- */
286
- set content(content) {
287
- this._content = content;
288
- }
289
- /**
290
- * simpleLineBreaks?: string
291
- *
292
- * Sets whether newline characters inside paragraphs and spans are parsed as <br/>.
293
- * Defaults to false.
294
- */
295
- set simpleLineBreaks(simpleLineBreaks) {
296
- this._simpleLineBreaks = simpleLineBreaks;
297
- }
298
- /**
299
- * hostedUrl?: string
300
- *
301
- * If markdown contains relative paths, this is required to generate correct urls
302
- *
303
- */
304
- set hostedUrl(hostedUrl) {
305
- this._hostedUrl = hostedUrl;
306
- }
307
- /**
308
- * anchor?: string
309
- *
310
- * Anchor to jump to
311
- *
312
- */
313
- set anchor(anchor) {
314
- this._anchor = anchor;
315
- }
316
- constructor(_componentFactoryResolver, _renderer, _changeDetectorRef, _injector, _elementRef) {
317
- this._componentFactoryResolver = _componentFactoryResolver;
318
- this._renderer = _renderer;
319
- this._changeDetectorRef = _changeDetectorRef;
320
- this._injector = _injector;
321
- this._elementRef = _elementRef;
322
- this._simpleLineBreaks = false;
323
- this._components = {};
324
- this._viewInit = false;
325
- /**
326
- * copyCodeToClipboard?: boolean
327
- *
328
- * Display copy button on code snippets to copy code to clipboard.
329
- *
330
- */
331
- this.copyCodeToClipboard = false;
332
- /**
333
- * copyCodeTooltips?: ICopyCodeTooltips
334
- *
335
- * Tooltips for copy button to copy and upon copying.
336
- */
337
- this.copyCodeTooltips = {};
338
- /**
339
- * useCfmList?: boolean = false;
340
- * Use CFM list component instead of vanilla markdown list. Used in covalent documentation app.
341
- */
342
- this.useCfmList = false;
343
- /**
344
- * contentReady?: function
345
- * Event emitted after the markdown content rendering is finished.
346
- */
347
- this.contentReady = new EventEmitter();
348
- /**
349
- * buttonClicked?: ITdFlavoredMarkdownButtonClickEvent
350
- * Event emitted when a button is clicked
351
- * Is an object containing text and data of button
352
- */
353
- this.buttonClicked = new EventEmitter();
354
- this._destroy$ = new Subject();
355
- }
356
- ngOnChanges(changes) {
357
- // only anchor changed
358
- if (changes['anchor'] &&
359
- !changes['content'] &&
360
- !changes['simpleLineBreaks'] &&
361
- !changes['hostedUrl']) {
362
- scrollToAnchor(this._elementRef.nativeElement, this._anchor, false);
363
- }
364
- else {
365
- this.refresh();
366
- }
367
- }
368
- ngAfterViewInit() {
369
- var _a;
370
- if (!this._content) {
371
- this._loadContent((_a = this.container.viewContainerRef.element.nativeElement
372
- .textContent) !== null && _a !== void 0 ? _a : '');
373
- Promise.resolve().then(() => {
374
- this._viewInit = true;
375
- this._changeDetectorRef.markForCheck();
376
- });
377
- }
378
- }
379
- ngOnDestroy() {
380
- this._destroy$.next();
381
- }
382
- refresh() {
383
- var _a;
384
- if (this._content) {
385
- this._loadContent(this._content);
386
- }
387
- else if (this._viewInit) {
388
- this._loadContent((_a = this.container.viewContainerRef.element.nativeElement
389
- .textContent) !== null && _a !== void 0 ? _a : '');
390
- }
391
- this._changeDetectorRef.markForCheck();
392
- }
393
- _loadContent(markdown) {
394
- if (markdown && markdown.trim().length > 0) {
395
- this.container.clear();
396
- markdown = markdown
397
- .replace(/^(\s|\t)*\n+/g, '')
398
- .replace(/(\s|\t)*\n+(\s|\t)*$/g, '');
399
- // Split markdown by line characters
400
- let lines = markdown.split('\n');
401
- // check how much indentation is used by the first actual markdown line
402
- const firstLineWhitespaceMatch = lines[0].match(/^(\s|\t)*/);
403
- const firstLineWhitespace = firstLineWhitespaceMatch
404
- ? firstLineWhitespaceMatch[0]
405
- : null;
406
- // Remove all indentation spaces so markdown can be parsed correctly
407
- // Remove all \r characters
408
- const startingWhitespaceRegex = new RegExp('^' + firstLineWhitespace);
409
- lines = lines.map(function (line) {
410
- return line.replace(startingWhitespaceRegex, '').replace('\r', '');
411
- });
412
- // Join lines again with line characters
413
- markdown = [...lines, '', ''].join('\n');
414
- markdown = this._replaceCodeBlocks(markdown);
415
- markdown = this._replaceCheckbox(markdown);
416
- markdown = this._replaceTables(markdown);
417
- markdown = this._replaceButtons(markdown);
418
- if (this.useCfmList) {
419
- markdown = this._replaceLists(markdown);
420
- }
421
- const keys = Object.keys(this._components);
422
- // need to sort the placeholders in order of encounter in markdown content
423
- keys.sort((compA, compB) => {
424
- return markdown.indexOf(compA) > markdown.indexOf(compB) ? 1 : -1;
425
- });
426
- this._render(markdown, keys[0], keys);
427
- // TODO: timeout required since resizing of html elements occurs which causes a change in the scroll position
428
- setTimeout(() => scrollToAnchor(this._elementRef.nativeElement, this._anchor, false), 250);
429
- this.contentReady.emit();
430
- Promise.resolve().then(() => {
431
- this._changeDetectorRef.markForCheck();
432
- });
433
- }
434
- }
435
- _render(markdown, key, keys) {
436
- if (!markdown) {
437
- return;
438
- }
439
- if (key && markdown.indexOf(key) > -1) {
440
- const markdownParts = markdown.split(key);
441
- keys.shift();
442
- this._render(markdownParts[0], '', []);
443
- this.container.viewContainerRef.insert(this._components[key].hostView, this.container.viewContainerRef.length);
444
- delete this._components[key];
445
- this._render(markdownParts[1], keys[0], keys);
446
- }
447
- else {
448
- const contentRef = this._componentFactoryResolver
449
- .resolveComponentFactory(TdMarkdownComponent)
450
- .create(this._injector);
451
- contentRef.instance.content = markdown;
452
- contentRef.instance.hostedUrl = this._hostedUrl;
453
- contentRef.instance.simpleLineBreaks = this._simpleLineBreaks;
454
- contentRef.instance.refresh();
455
- this.container.viewContainerRef.insert(contentRef.hostView, this.container.viewContainerRef.length);
456
- }
457
- }
458
- _replaceComponent(markdown, type, regExp, replacerFunc) {
459
- let componentIndex = 0;
460
- return markdown.replace(regExp, (...args) => {
461
- const componentFactory = this._componentFactoryResolver.resolveComponentFactory(type);
462
- const componentRef = componentFactory.create(this._injector);
463
- replacerFunc(componentRef, ...args);
464
- const key = '[' +
465
- componentFactory.selector +
466
- '-placeholder-' +
467
- componentIndex++ +
468
- ']';
469
- this._components[key] = componentRef;
470
- return key;
471
- });
472
- }
473
- _replaceCheckbox(markdown) {
474
- const checkboxRegExp = /(?:^|\n)- \[(x| )\](.*)/gi;
475
- return this._replaceComponent(markdown, MatCheckbox, checkboxRegExp, (componentRef, match, checked, label) => {
476
- componentRef.instance.checked = !!checked.trim();
477
- componentRef.instance.ariaLabel = label;
478
- componentRef.instance.labelPosition = 'after';
479
- this._renderer.setProperty((componentRef.instance._elementRef.nativeElement).getElementsByTagName('label')[0], 'innerHTML', label);
480
- });
481
- }
482
- _replaceButtons(markdown) {
483
- const buttonRegExp = /\[([^[]+)\](\(#data=(.*?)\))/i;
484
- const globalButtonRegExp = new RegExp(buttonRegExp.source, buttonRegExp.flags + 'g');
485
- return this._replaceComponent(markdown, TdFlavoredMarkdownButtonComponent, globalButtonRegExp, (componentRef, match) => {
486
- const matches = buttonRegExp.exec(match);
487
- if (!matches) {
488
- return;
489
- }
490
- const text = matches[1];
491
- const data = matches[3];
492
- componentRef.instance.text = text;
493
- componentRef.instance.data = data;
494
- componentRef.instance.clicked
495
- .pipe(takeUntil(this._destroy$))
496
- .subscribe((clickEvent) => this.buttonClicked.emit(clickEvent));
497
- });
498
- }
499
- _replaceCodeBlocks(markdown) {
500
- const codeBlockRegExp = /(?:^|\n)```(.*)\n([\s\S]*?)\n```/g;
501
- return this._replaceComponent(markdown, TdHighlightComponent, codeBlockRegExp, (componentRef, match, language, codeblock) => {
502
- if (language) {
503
- componentRef.instance.codeLang = language;
504
- }
505
- componentRef.instance.copyCodeToClipboard = this.copyCodeToClipboard;
506
- componentRef.instance.copyCodeTooltips = this.copyCodeTooltips;
507
- componentRef.instance.content = codeblock;
508
- });
509
- }
510
- _replaceTables(markdown) {
511
- const tableRgx = /^ {0,3}\|?.+\|.+\n[ \t]{0,3}\|?[ \t]*:?[ \t]*(?:-|=){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:-|=){2,}[\s\S]+?(?:\n\n|~0)/gm;
512
- return this._replaceComponent(markdown, TdFlavoredMarkdownTableComponent, tableRgx, (componentRef, match) => {
513
- const dataTableLines = match
514
- .replace(/(\s|\t)*\n+(\s|\t)*$/g, '')
515
- .split('\n');
516
- const columns = dataTableLines[0]
517
- .split('|')
518
- .filter((col) => {
519
- return col;
520
- })
521
- .map((s) => {
522
- return s.trim();
523
- });
524
- const alignment = dataTableLines[1]
525
- .split('|')
526
- .filter((v) => {
527
- return v;
528
- })
529
- .map((s) => {
530
- return s.trim();
531
- });
532
- const data = [];
533
- for (let i = 2; i < dataTableLines.length; i++) {
534
- const rowSplit = dataTableLines[i]
535
- .split('|')
536
- .filter((cell) => {
537
- return cell;
538
- })
539
- .map((s) => {
540
- return s.trim();
541
- });
542
- const row = {};
543
- columns.forEach((col, index) => {
544
- const rowSplitCell = rowSplit[index];
545
- if (rowSplitCell) {
546
- row[col.toLowerCase().trim()] = rowSplitCell.replace(/`(.*)`/, (m, value) => {
547
- return value;
548
- });
549
- }
550
- });
551
- data.push(row);
552
- }
553
- componentRef.instance.columnDefs = columns.map((col, index) => {
554
- return {
555
- label: col,
556
- name: col ? col.toLowerCase().trim() : `column ${index}`,
557
- numeric: /^--*[ \t]*:[ \t]*$/.test(alignment[index]),
558
- };
559
- });
560
- componentRef.instance.data = data;
561
- });
562
- }
563
- _replaceLists(markdown) {
564
- const listRegExp = /(?:^|\n)(( *(\+|\*|-))[ |\t](.*)\n)+/g;
565
- const listCharRegExp = new RegExp(/^(\+|\*|-)/);
566
- return this._replaceComponent(markdown, TdFlavoredListComponent, listRegExp, (componentRef, match) => {
567
- const start = /(\+|\*|-)/.exec(match);
568
- const matchIndex = start !== null ? start.index : 1;
569
- const lineTexts = match.split(new RegExp('\\n {' + (matchIndex - 1).toString() + '}(\\+|\\*|\\-)[ |\\t]'));
570
- lineTexts.shift();
571
- const lines = [];
572
- lineTexts.forEach((text) => {
573
- var _a;
574
- const sublineTexts = text.split(/\n *(\+|\*|-) /);
575
- const lineText = (_a = sublineTexts.shift()) !== null && _a !== void 0 ? _a : '';
576
- if (listCharRegExp.test(lineText)) {
577
- return;
578
- }
579
- lines.push({
580
- line: lineText,
581
- sublines: sublineTexts
582
- .map((subline) => {
583
- if (listCharRegExp.test(subline)) {
584
- return '';
585
- }
586
- return subline.trim();
587
- })
588
- .filter((line) => !!line),
589
- });
590
- });
591
- componentRef.instance.lines = lines;
592
- });
593
- }
594
- }
595
- TdFlavoredMarkdownComponent.ɵfac = function TdFlavoredMarkdownComponent_Factory(t) { return new (t || TdFlavoredMarkdownComponent)(i0.ɵɵdirectiveInject(i0.ComponentFactoryResolver), i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject(i0.ElementRef)); };
596
- TdFlavoredMarkdownComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TdFlavoredMarkdownComponent, selectors: [["td-flavored-markdown"]], viewQuery: function TdFlavoredMarkdownComponent_Query(rf, ctx) {
597
- if (rf & 1) {
598
- i0.ɵɵviewQuery(TdFlavoredMarkdownContainerDirective, 7);
599
- }
600
- if (rf & 2) {
601
- let _t;
602
- i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.container = _t.first);
603
- }
604
- }, inputs: { content: "content", simpleLineBreaks: "simpleLineBreaks", hostedUrl: "hostedUrl", anchor: "anchor", copyCodeToClipboard: "copyCodeToClipboard", copyCodeTooltips: "copyCodeTooltips", useCfmList: "useCfmList" }, outputs: { contentReady: "contentReady", buttonClicked: "buttonClicked" }, features: [i0.ɵɵNgOnChangesFeature], ngContentSelectors: _c0, decls: 2, vars: 0, consts: [["tdFlavoredMarkdownContainer", ""]], template: function TdFlavoredMarkdownComponent_Template(rf, ctx) {
605
- if (rf & 1) {
606
- i0.ɵɵprojectionDef();
607
- i0.ɵɵelementStart(0, "div", 0);
608
- i0.ɵɵprojection(1);
609
- i0.ɵɵelementEnd();
610
- }
611
- }, dependencies: [TdFlavoredMarkdownContainerDirective], styles: ["[_nghost-%COMP%] td-markdown:first-of-type>div:first-of-type>h1:first-of-type, [_nghost-%COMP%] td-markdown:first-of-type>div:first-of-type>h2:first-of-type{margin-top:0}[_nghost-%COMP%] mat-checkbox{display:block}[_nghost-%COMP%] td-highlight, [_nghost-%COMP%] mat-table, [_nghost-%COMP%] mat-checkbox:last-of-type{margin-bottom:16px}[_nghost-%COMP%] :not(pre)>code{font-family:Menlo,Monaco,Andale Mono,lucida console,Courier New,monospace;padding-left:2px;padding-right:2px}[_nghost-%COMP%] td-highlight{display:flex;flex-direction:row;justify-content:space-between}"], changeDetection: 0 });
612
- (function () {
613
- (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredMarkdownComponent, [{
614
- type: Component,
615
- args: [{ selector: 'td-flavored-markdown', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div tdFlavoredMarkdownContainer>\n <ng-content></ng-content>\n</div>\n", styles: [":host ::ng-deep td-markdown:first-of-type>div:first-of-type>h1:first-of-type,:host ::ng-deep td-markdown:first-of-type>div:first-of-type>h2:first-of-type{margin-top:0}:host ::ng-deep mat-checkbox{display:block}:host ::ng-deep td-highlight,:host ::ng-deep mat-table,:host ::ng-deep mat-checkbox:last-of-type{margin-bottom:16px}:host ::ng-deep :not(pre)>code{font-family:Menlo,Monaco,Andale Mono,lucida console,Courier New,monospace;padding-left:2px;padding-right:2px}:host ::ng-deep td-highlight{display:flex;flex-direction:row;justify-content:space-between}\n"] }]
616
- }], function () { return [{ type: i0.ComponentFactoryResolver }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }, { type: i0.Injector }, { type: i0.ElementRef }]; }, { content: [{
617
- type: Input
618
- }], simpleLineBreaks: [{
619
- type: Input
620
- }], hostedUrl: [{
621
- type: Input
622
- }], anchor: [{
623
- type: Input
624
- }], copyCodeToClipboard: [{
625
- type: Input
626
- }], copyCodeTooltips: [{
627
- type: Input
628
- }], useCfmList: [{
629
- type: Input
630
- }], contentReady: [{
631
- type: Output
632
- }], buttonClicked: [{
633
- type: Output
634
- }], container: [{
635
- type: ViewChild,
636
- args: [TdFlavoredMarkdownContainerDirective, { static: true }]
637
- }] });
638
- })();
639
-
640
- function TdFlavoredMarkdownLoaderComponent_mat_progress_bar_0_Template(rf, ctx) {
641
- if (rf & 1) {
642
- i0.ɵɵelement(0, "mat-progress-bar", 2);
643
- }
644
- if (rf & 2) {
645
- i0.ɵɵproperty("ngClass", "delay");
646
- }
647
- }
648
- function TdFlavoredMarkdownLoaderComponent_td_flavored_markdown_1_Template(rf, ctx) {
649
- if (rf & 1) {
650
- const _r3 = i0.ɵɵgetCurrentView();
651
- i0.ɵɵelementStart(0, "td-flavored-markdown", 3);
652
- i0.ɵɵlistener("contentReady", function TdFlavoredMarkdownLoaderComponent_td_flavored_markdown_1_Template_td_flavored_markdown_contentReady_0_listener() { i0.ɵɵrestoreView(_r3); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.contentReady.emit()); })("buttonClicked", function TdFlavoredMarkdownLoaderComponent_td_flavored_markdown_1_Template_td_flavored_markdown_buttonClicked_0_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.buttonClicked.emit($event)); });
653
- i0.ɵɵelementEnd();
654
- }
655
- if (rf & 2) {
656
- const ctx_r1 = i0.ɵɵnextContext();
657
- let tmp_1_0;
658
- let tmp_2_0;
659
- i0.ɵɵproperty("content", ctx_r1.content)("hostedUrl", (tmp_1_0 = ctx_r1.url) !== null && tmp_1_0 !== undefined ? tmp_1_0 : "")("anchor", (tmp_2_0 = ctx_r1.anchor) !== null && tmp_2_0 !== undefined ? tmp_2_0 : "")("copyCodeToClipboard", ctx_r1.copyCodeToClipboard)("copyCodeTooltips", ctx_r1.copyCodeTooltips)("useCfmList", ctx_r1.useCfmList);
660
- }
661
- }
662
- // TODO: make a td-markdown-loader component
663
- class TdFlavoredMarkdownLoaderComponent {
664
- constructor(_changeDetectorRef, _markdownUrlLoaderService) {
665
- this._changeDetectorRef = _changeDetectorRef;
666
- this._markdownUrlLoaderService = _markdownUrlLoaderService;
667
- /**
668
- * copyCodeToClipboard?: boolean
669
- *
670
- * Display copy button on code snippets to copy code to clipboard.
671
- *
672
- */
673
- this.copyCodeToClipboard = false;
674
- /**
675
- * copyCodeTooltips?: ICopyCodeTooltips
676
- *
677
- * Tooltips for copy button to copy and upon copying.
678
- */
679
- this.copyCodeTooltips = {};
680
- /**
681
- * useCfmList?: boolean = false;
682
- * Use CFM list component instead of vanilla markdown list. Used in covalent documentation app.
683
- */
684
- this.useCfmList = false;
685
- /**
686
- * contentReady: void
687
- * Emitted when markdown rendering is finished.
688
- */
689
- this.contentReady = new EventEmitter();
690
- /**
691
- * loadFailed: Error
692
- * Emitted when loading of markdown file fails.
693
- */
694
- this.loadFailed = new EventEmitter();
695
- this.buttonClicked = new EventEmitter();
696
- this.loading = true;
697
- }
698
- ngOnChanges(changes) {
699
- if (changes['url'] || changes['httpOptions']) {
700
- this.loadMarkdown();
701
- }
702
- }
703
- loadMarkdown() {
704
- var _a;
705
- return __awaiter(this, void 0, void 0, function* () {
706
- this.loading = true;
707
- this._changeDetectorRef.markForCheck();
708
- try {
709
- this.content = yield this._markdownUrlLoaderService.load((_a = this.url) !== null && _a !== void 0 ? _a : '', this.httpOptions);
710
- }
711
- catch (error) {
712
- this.loadFailed.emit(error);
713
- }
714
- finally {
715
- this.loading = false;
716
- this._changeDetectorRef.markForCheck();
717
- }
718
- });
719
- }
720
- }
721
- TdFlavoredMarkdownLoaderComponent.ɵfac = function TdFlavoredMarkdownLoaderComponent_Factory(t) { return new (t || TdFlavoredMarkdownLoaderComponent)(i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(i1$1.TdMarkdownLoaderService)); };
722
- TdFlavoredMarkdownLoaderComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TdFlavoredMarkdownLoaderComponent, selectors: [["td-flavored-markdown-loader"]], inputs: { url: "url", httpOptions: "httpOptions", anchor: "anchor", copyCodeToClipboard: "copyCodeToClipboard", copyCodeTooltips: "copyCodeTooltips", useCfmList: "useCfmList" }, outputs: { contentReady: "contentReady", loadFailed: "loadFailed", buttonClicked: "buttonClicked" }, features: [i0.ɵɵNgOnChangesFeature], decls: 2, vars: 2, consts: [["mode", "indeterminate", "color", "accent", "class", "sticky", 3, "ngClass", 4, "ngIf"], [3, "content", "hostedUrl", "anchor", "copyCodeToClipboard", "copyCodeTooltips", "useCfmList", "contentReady", "buttonClicked", 4, "ngIf"], ["mode", "indeterminate", "color", "accent", 1, "sticky", 3, "ngClass"], [3, "content", "hostedUrl", "anchor", "copyCodeToClipboard", "copyCodeTooltips", "useCfmList", "contentReady", "buttonClicked"]], template: function TdFlavoredMarkdownLoaderComponent_Template(rf, ctx) {
723
- if (rf & 1) {
724
- i0.ɵɵtemplate(0, TdFlavoredMarkdownLoaderComponent_mat_progress_bar_0_Template, 1, 1, "mat-progress-bar", 0);
725
- i0.ɵɵtemplate(1, TdFlavoredMarkdownLoaderComponent_td_flavored_markdown_1_Template, 1, 6, "td-flavored-markdown", 1);
726
- }
727
- if (rf & 2) {
728
- i0.ɵɵproperty("ngIf", ctx.loading);
729
- i0.ɵɵadvance(1);
730
- i0.ɵɵproperty("ngIf", !ctx.loading);
731
- }
732
- }, dependencies: [i1.NgClass, i1.NgIf, i3$2.MatProgressBar, TdFlavoredMarkdownComponent], styles: ["[_nghost-%COMP%]{display:block}.sticky[_ngcontent-%COMP%]{position:absolute;top:0}.delay[_ngcontent-%COMP%]{animation:_ngcontent-%COMP%_delay-animation;animation-duration:.6s}@keyframes _ngcontent-%COMP%_delay-animation{0%{opacity:0}99%{opacity:0}to{opacity:1}}"], changeDetection: 0 });
733
- (function () {
734
- (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredMarkdownLoaderComponent, [{
735
- type: Component,
736
- args: [{ selector: 'td-flavored-markdown-loader', changeDetection: ChangeDetectionStrategy.OnPush, template: "<mat-progress-bar\n [ngClass]=\"'delay'\"\n *ngIf=\"loading\"\n mode=\"indeterminate\"\n color=\"accent\"\n class=\"sticky\"\n></mat-progress-bar>\n<td-flavored-markdown\n *ngIf=\"!loading\"\n [content]=\"content\"\n [hostedUrl]=\"url ?? ''\"\n [anchor]=\"anchor ?? ''\"\n [copyCodeToClipboard]=\"copyCodeToClipboard\"\n [copyCodeTooltips]=\"copyCodeTooltips\"\n [useCfmList]=\"useCfmList\"\n (contentReady)=\"contentReady.emit()\"\n (buttonClicked)=\"buttonClicked.emit($event)\"\n></td-flavored-markdown>\n", styles: [":host{display:block}.sticky{position:absolute;top:0}.delay{animation:delay-animation;animation-duration:.6s}@keyframes delay-animation{0%{opacity:0}99%{opacity:0}to{opacity:1}}\n"] }]
737
- }], function () { return [{ type: i0.ChangeDetectorRef }, { type: i1$1.TdMarkdownLoaderService }]; }, { url: [{
738
- type: Input
739
- }], httpOptions: [{
740
- type: Input
741
- }], anchor: [{
742
- type: Input
743
- }], copyCodeToClipboard: [{
744
- type: Input
745
- }], copyCodeTooltips: [{
746
- type: Input
747
- }], useCfmList: [{
748
- type: Input
749
- }], contentReady: [{
750
- type: Output
751
- }], loadFailed: [{
752
- type: Output
753
- }], buttonClicked: [{
754
- type: Output
755
- }] });
756
- })();
757
-
758
- class CovalentFlavoredMarkdownModule {
759
- }
760
- CovalentFlavoredMarkdownModule.ɵfac = function CovalentFlavoredMarkdownModule_Factory(t) { return new (t || CovalentFlavoredMarkdownModule)(); };
761
- CovalentFlavoredMarkdownModule.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: CovalentFlavoredMarkdownModule });
762
- CovalentFlavoredMarkdownModule.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule,
763
- MatCheckboxModule,
764
- MatListModule,
765
- MatProgressBarModule,
766
- CovalentHighlightModule,
767
- CovalentMarkdownModule,
768
- MatButtonModule,
769
- MatTableModule,
770
- MatSortModule] });
771
- (function () {
772
- (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CovalentFlavoredMarkdownModule, [{
773
- type: NgModule,
774
- args: [{
775
- imports: [
776
- CommonModule,
777
- MatCheckboxModule,
778
- MatListModule,
779
- MatProgressBarModule,
780
- CovalentHighlightModule,
781
- CovalentMarkdownModule,
782
- MatButtonModule,
783
- MatTableModule,
784
- MatSortModule,
785
- ],
786
- declarations: [
787
- TdFlavoredListComponent,
788
- TdFlavoredMarkdownComponent,
789
- TdFlavoredMarkdownContainerDirective,
790
- TdFlavoredMarkdownLoaderComponent,
791
- TdFlavoredMarkdownButtonComponent,
792
- TdFlavoredMarkdownTableComponent,
793
- ],
794
- exports: [TdFlavoredMarkdownComponent, TdFlavoredMarkdownLoaderComponent],
795
- }]
796
- }], null, null);
797
- })();
798
- (function () {
799
- (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(CovalentFlavoredMarkdownModule, { declarations: [TdFlavoredListComponent,
800
- TdFlavoredMarkdownComponent,
801
- TdFlavoredMarkdownContainerDirective,
802
- TdFlavoredMarkdownLoaderComponent,
803
- TdFlavoredMarkdownButtonComponent,
804
- TdFlavoredMarkdownTableComponent], imports: [CommonModule,
805
- MatCheckboxModule,
806
- MatListModule,
807
- MatProgressBarModule,
808
- CovalentHighlightModule,
809
- CovalentMarkdownModule,
810
- MatButtonModule,
811
- MatTableModule,
812
- MatSortModule], exports: [TdFlavoredMarkdownComponent, TdFlavoredMarkdownLoaderComponent] });
813
- })();
814
-
815
- /**
816
- * Generated bundle index. Do not edit.
817
- */
818
-
819
- export { CovalentFlavoredMarkdownModule, TdFlavoredMarkdownButtonComponent, TdFlavoredMarkdownComponent, TdFlavoredMarkdownContainerDirective, TdFlavoredMarkdownLoaderComponent, TdFlavoredMarkdownTableComponent };
820
- //# sourceMappingURL=covalent-flavored-markdown.mjs.map