@coolon/angular-ui-powerups 12.4.0-alpha.77 → 12.4.0-alpha.79

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,34 +1,62 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import { Component, ElementRef, Input } from '@angular/core';
2
+ import { Component, ElementRef, Inject, Input, PLATFORM_ID } from '@angular/core';
3
3
  import { Dsl, StoreInValueModel, TrackExternal, ValueModel } from '@coolon/pectin';
4
4
  import * as _ from 'lodash';
5
5
  import { MarkdownService } from '../../../services/markdown/markdown.service';
6
6
  import { DisposableComponent } from '../../disposable-component';
7
+ /**
8
+ * @example
9
+ * <aup-markdown [content]="..."></aup-markdown>
10
+ * <aup-markdown [content$]="stringValueModel$"></aup-markdown>
11
+ * <aup-markdown ngPreserveWhitespaces>
12
+ * # This is markdown content
13
+ *
14
+ * With a list
15
+ * - a
16
+ * - b
17
+ * </aup-markdown>
18
+ */
7
19
  export class MarkdownComponent extends DisposableComponent {
8
- constructor(element, markdownService) {
20
+ constructor(platform, element, markdownService) {
9
21
  super();
22
+ this.platform = platform;
10
23
  this.element = element;
11
24
  this.markdownService = markdownService;
12
25
  this.inline = false;
13
26
  const { chain } = Dsl.disposeWith(this);
14
27
  }
15
28
  ngOnInit() {
16
- const { chain } = Dsl.disposeWith(this);
17
- chain(this.content$).subscribe(content => {
18
- this.element.nativeElement.innerHTML = _.isEmpty(content) ? '' :
19
- this.inline ? this.markdownService.renderInline(content) :
20
- this.markdownService.render(content);
21
- }, { initialValue: 'evaluate' });
29
+ const { when } = Dsl.disposeWith(this);
30
+ when(this.content$).changes(content => this.renderContent(content), { initialValue: 'triggerChangeUnlessNil' });
31
+ if (_.isNil(this.content) && !_.isEmpty(this.element.nativeElement.innerHTML)) {
32
+ this.renderContent(this.extractInnerContent(this.element.nativeElement.innerHTML));
33
+ }
34
+ }
35
+ extractInnerContent(content) {
36
+ const lines = content.split("\n");
37
+ const prefix = lines.reduce((maxPrefix, line) => {
38
+ return Math.max(maxPrefix, line.search(/\S/));
39
+ }, 0);
40
+ return lines.map(l => l.substr(prefix)).join("\n");
41
+ }
42
+ renderContent(content) {
43
+ if (!_.isNil(content)) {
44
+ const markdown = this.inline ?
45
+ this.markdownService.renderInline(content) :
46
+ this.markdownService.render(content);
47
+ this.element.nativeElement.innerHTML = markdown;
48
+ }
22
49
  }
23
50
  }
24
51
  MarkdownComponent.decorators = [
25
52
  { type: Component, args: [{
26
53
  selector: 'aup-markdown',
27
- template: "<p>markdown works!</p>\n",
54
+ template: "<ng-content></ng-content>\n",
28
55
  styles: [":host{display:inline-block}\n"]
29
56
  },] }
30
57
  ];
31
58
  MarkdownComponent.ctorParameters = () => [
59
+ { type: Object, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] },
32
60
  { type: ElementRef },
33
61
  { type: MarkdownService }
34
62
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.component.js","sourceRoot":"","sources":["../../../../../../../../libs/angular-ui-powerups/src/lib/components/text/markdown/markdown.component.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAU,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,GAAG,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAOjE,MAAM,OAAO,iBAAkB,SAAQ,mBAAmB;IAaxD,YAA6B,OAAmB,EAAmB,eAAgC;QACjG,KAAK,EAAE,CAAC;QADmB,YAAO,GAAP,OAAO,CAAY;QAAmB,oBAAe,GAAf,eAAe,CAAiB;QAFnG,WAAM,GAAG,KAAK,CAAC;QAIb,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,QAAQ;QACN,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACxC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;YACvC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBAC9D,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;oBACxD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3C,CAAC,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,CAAC;IACnC,CAAC;;;YA9BF,SAAS,SAAC;gBACT,QAAQ,EAAE,cAAc;gBACxB,oCAAwC;;aAEzC;;;YAVmB,UAAU;YAGrB,eAAe;;;uBAUrB,KAAK;sBAIL,KAAK;qBAIL,KAAK;;AANN;IADC,aAAa,EAAE;8BACN,UAAU;mDAAS;AAI7B;IADC,iBAAiB,CAAC,UAAU,CAAC;;kDACd","sourcesContent":["import { Component, ElementRef, Input, OnInit } from '@angular/core';\nimport { Dsl, StoreInValueModel, TrackExternal, ValueModel } from '@coolon/pectin';\nimport * as _ from 'lodash';\nimport { MarkdownService } from '../../../services/markdown/markdown.service';\nimport { DisposableComponent } from '../../disposable-component';\n\n@Component({\n selector: 'aup-markdown',\n templateUrl: './markdown.component.html',\n styleUrls: ['./markdown.component.scss']\n})\nexport class MarkdownComponent extends DisposableComponent implements OnInit {\n\n @Input()\n @TrackExternal()\n content$: ValueModel<string>;\n\n @Input()\n @StoreInValueModel('content$')\n content: string;\n\n @Input()\n inline = false;\n\n constructor(private readonly element: ElementRef, private readonly markdownService: MarkdownService) {\n super();\n const { chain } = Dsl.disposeWith(this);\n }\n\n ngOnInit() {\n const { chain } = Dsl.disposeWith(this);\n chain(this.content$).subscribe(content => {\n this.element.nativeElement.innerHTML = _.isEmpty(content) ? '' :\n this.inline ? this.markdownService.renderInline(content) :\n this.markdownService.render(content);\n }, { initialValue: 'evaluate' });\n }\n}\n"]}
1
+ {"version":3,"file":"markdown.component.js","sourceRoot":"","sources":["../../../../../../../../libs/angular-ui-powerups/src/lib/components/text/markdown/markdown.component.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAU,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAE,GAAG,EAAE,iBAAiB,EAAS,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC1F,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;;;;;;;;;GAWG;AAMH,MAAM,OAAO,iBAAkB,SAAQ,mBAAmB;IAaxD,YAC+B,QAAgB,EAC5B,OAAgC,EAChC,eAAgC;QACjD,KAAK,EAAE,CAAC;QAHqB,aAAQ,GAAR,QAAQ,CAAQ;QAC5B,YAAO,GAAP,OAAO,CAAyB;QAChC,oBAAe,GAAf,eAAe,CAAiB;QALnD,WAAM,GAAG,KAAK,CAAC;QAOb,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,QAAQ;QACN,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,EAAE,YAAY,EAAE,wBAAwB,EAAE,CAAC,CAAC;QAChH,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE;YAC7E,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;SACpF;IACH,CAAC;IAEO,mBAAmB,CAAC,OAAe;QACzC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE;YAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAChD,CAAC,EAAE,CAAC,CAAC,CAAC;QACN,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAEO,aAAa,CAAC,OAAe;QACnC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;YACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC5B,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC5C,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACvC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,GAAG,QAAQ,CAAC;SACjD;IACH,CAAC;;;YAjDF,SAAS,SAAC;gBACT,QAAQ,EAAE,cAAc;gBACxB,uCAAwC;;aAEzC;;;YAe0C,MAAM,uBAA5C,MAAM,SAAC,WAAW;YArCH,UAAU;YAGrB,eAAe;;;uBAsBrB,KAAK;sBAIL,KAAK;qBAIL,KAAK;;AANN;IADC,aAAa,EAAE;8BACN,UAAU;mDAAS;AAI7B;IADC,iBAAiB,CAAC,UAAU,CAAC;;kDACd","sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport { Component, ElementRef, Inject, Input, OnInit, PLATFORM_ID } from '@angular/core';\nimport { Dsl, StoreInValueModel, Trace, TrackExternal, ValueModel } from '@coolon/pectin';\nimport * as _ from 'lodash';\nimport { MarkdownService } from '../../../services/markdown/markdown.service';\nimport { DisposableComponent } from '../../disposable-component';\n\n/**\n * @example\n * <aup-markdown [content]=\"...\"></aup-markdown>\n * <aup-markdown [content$]=\"stringValueModel$\"></aup-markdown>\n * <aup-markdown ngPreserveWhitespaces>\n * # This is markdown content\n *\n * With a list\n * - a\n * - b\n * </aup-markdown>\n */\n@Component({\n selector: 'aup-markdown',\n templateUrl: './markdown.component.html',\n styleUrls: ['./markdown.component.scss']\n})\nexport class MarkdownComponent extends DisposableComponent implements OnInit {\n\n @Input()\n @TrackExternal()\n content$: ValueModel<string>;\n\n @Input()\n @StoreInValueModel('content$')\n content: string;\n\n @Input()\n inline = false;\n\n constructor(\n @Inject(PLATFORM_ID) private platform: Object,\n private readonly element: ElementRef<HTMLElement>,\n private readonly markdownService: MarkdownService) {\n super();\n const { chain } = Dsl.disposeWith(this);\n }\n\n ngOnInit() {\n const { when } = Dsl.disposeWith(this);\n when(this.content$).changes(content => this.renderContent(content), { initialValue: 'triggerChangeUnlessNil' });\n if (_.isNil(this.content) && !_.isEmpty(this.element.nativeElement.innerHTML)) {\n this.renderContent(this.extractInnerContent(this.element.nativeElement.innerHTML));\n }\n }\n\n private extractInnerContent(content: string) {\n const lines = content.split(\"\\n\");\n const prefix = lines.reduce((maxPrefix, line) => {\n return Math.max(maxPrefix, line.search(/\\S/));\n }, 0);\n return lines.map(l => l.substr(prefix)).join(\"\\n\");\n }\n\n private renderContent(content: string) {\n if (!_.isNil(content)) {\n const markdown = this.inline ?\n this.markdownService.renderInline(content) :\n this.markdownService.render(content);\n this.element.nativeElement.innerHTML = markdown;\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"MarkdownComponent":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"../../disposable-component","name":"DisposableComponent","line":11,"character":39},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":6,"character":1},"arguments":[{"selector":"aup-markdown","template":"<p>markdown works!</p>\n","styles":[":host{display:inline-block}\n"]}]}],"members":{"content$":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":13,"character":3}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"TrackExternal","line":14,"character":3}}]}],"content":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":17,"character":3}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"StoreInValueModel","line":18,"character":3},"arguments":["content$"]}]}],"inline":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":21,"character":3}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ElementRef","line":24,"character":40},{"__symbolic":"reference","module":"../../../services/markdown/markdown.service","name":"MarkdownService","line":24,"character":86}]}],"ngOnInit":[{"__symbolic":"method"}]}}}}]
1
+ [{"__symbolic":"module","version":4,"metadata":{"MarkdownComponent":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"../../disposable-component","name":"DisposableComponent","line":24,"character":39},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":19,"character":1},"arguments":[{"selector":"aup-markdown","template":"<ng-content></ng-content>\n","styles":[":host{display:inline-block}\n"]}]}],"members":{"content$":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":26,"character":3}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"TrackExternal","line":27,"character":3}}]}],"content":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":30,"character":3}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"StoreInValueModel","line":31,"character":3},"arguments":["content$"]}]}],"inline":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":34,"character":3}}]}],"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":38,"character":5},"arguments":[{"__symbolic":"reference","module":"@angular/core","name":"PLATFORM_ID","line":38,"character":12}]}],null,null],"parameters":[{"__symbolic":"reference","name":"Object"},{"__symbolic":"reference","module":"@angular/core","name":"ElementRef","line":39,"character":30,"arguments":[{"__symbolic":"error","message":"Could not resolve type","line":39,"character":41,"context":{"typeName":"HTMLElement"}}]},{"__symbolic":"reference","module":"../../../services/markdown/markdown.service","name":"MarkdownService","line":40,"character":38}]}],"ngOnInit":[{"__symbolic":"method"}],"extractInnerContent":[{"__symbolic":"method"}],"renderContent":[{"__symbolic":"method"}]}}}}]
@@ -6,7 +6,6 @@ export class MarkdownService {
6
6
  }
7
7
  render(content) {
8
8
  return marked.parse(content, {
9
- gfm: true,
10
9
  smartLists: true
11
10
  });
12
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.service.js","sourceRoot":"","sources":["../../../../../../../libs/angular-ui-powerups/src/lib/services/markdown/markdown.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGtD,MAAM,OAAO,eAAe;IAE1B;IACA,CAAC;IAED,MAAM,CAAC,OAAe;QACpB,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE;YAC3B,GAAG,EAAE,IAAI;YACT,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAC,OAAe;QAC1B,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,gBAAgB,CAAC,QAAsC;QACrD,MAAM,CAAC,GAAG,CAAC;YACT,UAAU,EAAE,CAAC,qBAAqB,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,CAAC,IAAI,CAAC,EAAE,CAAC,0BAA0B,IAAI,QAAQ,CAAC,CAAC,CAAC;SAClG,CAAC,CAAC;IACL,CAAC;;;YArBF,UAAU","sourcesContent":["import { Injectable } from '@angular/core';\n\nimport { marked } from 'marked';\nimport { markdownPillExtension } from './pill-plugin';\n\n@Injectable()\nexport class MarkdownService {\n\n constructor() {\n }\n\n render(content: string) {\n return marked.parse(content, {\n gfm: true,\n smartLists: true\n });\n }\n\n renderInline(content: string) {\n return marked.parseInline(content);\n }\n\n usePillExtension(renderer?: (content: string) => string) {\n marked.use({\n extensions: [markdownPillExtension(renderer ?? (text => `<span class='aup-pill'>${text}<span>`))]\n });\n }\n}\n\n\n"]}
1
+ {"version":3,"file":"markdown.service.js","sourceRoot":"","sources":["../../../../../../../libs/angular-ui-powerups/src/lib/services/markdown/markdown.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGtD,MAAM,OAAO,eAAe;IAE1B;IACA,CAAC;IAED,MAAM,CAAC,OAAe;QACpB,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE;YAC3B,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAC,OAAe;QAC1B,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,gBAAgB,CAAC,QAAsC;QACrD,MAAM,CAAC,GAAG,CAAC;YACT,UAAU,EAAE,CAAC,qBAAqB,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,CAAC,IAAI,CAAC,EAAE,CAAC,0BAA0B,IAAI,QAAQ,CAAC,CAAC,CAAC;SAClG,CAAC,CAAC;IACL,CAAC;;;YApBF,UAAU","sourcesContent":["import { Injectable } from '@angular/core';\n\nimport { marked } from 'marked';\nimport { markdownPillExtension } from './pill-plugin';\n\n@Injectable()\nexport class MarkdownService {\n\n constructor() {\n }\n\n render(content: string) {\n return marked.parse(content, {\n smartLists: true\n });\n }\n\n renderInline(content: string) {\n return marked.parseInline(content);\n }\n\n usePillExtension(renderer?: (content: string) => string) {\n marked.use({\n extensions: [markdownPillExtension(renderer ?? (text => `<span class='aup-pill'>${text}<span>`))]\n });\n }\n}\n\n\n"]}
@@ -1,7 +1,7 @@
1
1
  import * as i2 from '@angular/common';
2
2
  import { DOCUMENT, CommonModule, Location } from '@angular/common';
3
3
  import * as i0 from '@angular/core';
4
- import { Directive, ElementRef, Inject, Host, Optional, Input, HostListener, NgZone, Injectable, Pipe, NgModule, Component, ContentChild, HostBinding, ViewEncapsulation, InjectionToken, ViewChildren, SkipSelf, EventEmitter, ViewChild, Output, Self, TemplateRef, ChangeDetectorRef, ContentChildren, ViewContainerRef, Injector, ComponentFactoryResolver } from '@angular/core';
4
+ import { Directive, ElementRef, Inject, Host, Optional, Input, HostListener, NgZone, Injectable, Pipe, NgModule, Component, ContentChild, HostBinding, ViewEncapsulation, InjectionToken, ViewChildren, SkipSelf, EventEmitter, ViewChild, Output, Self, TemplateRef, ChangeDetectorRef, ContentChildren, ViewContainerRef, PLATFORM_ID, Injector, ComponentFactoryResolver } from '@angular/core';
5
5
  import { FormsModule } from '@angular/forms';
6
6
  import { MatFormFieldModule } from '@angular/material/form-field';
7
7
  import { MatInputModule } from '@angular/material/input';
@@ -436,7 +436,6 @@ class MarkdownService {
436
436
  }
437
437
  render(content) {
438
438
  return marked.parse(content, {
439
- gfm: true,
440
439
  smartLists: true
441
440
  });
442
441
  }
@@ -4262,31 +4261,59 @@ LabelledValueComponent.propDecorators = {
4262
4261
  label: [{ type: Input }]
4263
4262
  };
4264
4263
 
4264
+ /**
4265
+ * @example
4266
+ * <aup-markdown [content]="..."></aup-markdown>
4267
+ * <aup-markdown [content$]="stringValueModel$"></aup-markdown>
4268
+ * <aup-markdown ngPreserveWhitespaces>
4269
+ * # This is markdown content
4270
+ *
4271
+ * With a list
4272
+ * - a
4273
+ * - b
4274
+ * </aup-markdown>
4275
+ */
4265
4276
  class MarkdownComponent extends DisposableComponent {
4266
- constructor(element, markdownService) {
4277
+ constructor(platform, element, markdownService) {
4267
4278
  super();
4279
+ this.platform = platform;
4268
4280
  this.element = element;
4269
4281
  this.markdownService = markdownService;
4270
4282
  this.inline = false;
4271
4283
  const { chain } = Dsl.disposeWith(this);
4272
4284
  }
4273
4285
  ngOnInit() {
4274
- const { chain } = Dsl.disposeWith(this);
4275
- chain(this.content$).subscribe(content => {
4276
- this.element.nativeElement.innerHTML = _.isEmpty(content) ? '' :
4277
- this.inline ? this.markdownService.renderInline(content) :
4278
- this.markdownService.render(content);
4279
- }, { initialValue: 'evaluate' });
4286
+ const { when } = Dsl.disposeWith(this);
4287
+ when(this.content$).changes(content => this.renderContent(content), { initialValue: 'triggerChangeUnlessNil' });
4288
+ if (_.isNil(this.content) && !_.isEmpty(this.element.nativeElement.innerHTML)) {
4289
+ this.renderContent(this.extractInnerContent(this.element.nativeElement.innerHTML));
4290
+ }
4291
+ }
4292
+ extractInnerContent(content) {
4293
+ const lines = content.split("\n");
4294
+ const prefix = lines.reduce((maxPrefix, line) => {
4295
+ return Math.max(maxPrefix, line.search(/\S/));
4296
+ }, 0);
4297
+ return lines.map(l => l.substr(prefix)).join("\n");
4298
+ }
4299
+ renderContent(content) {
4300
+ if (!_.isNil(content)) {
4301
+ const markdown = this.inline ?
4302
+ this.markdownService.renderInline(content) :
4303
+ this.markdownService.render(content);
4304
+ this.element.nativeElement.innerHTML = markdown;
4305
+ }
4280
4306
  }
4281
4307
  }
4282
4308
  MarkdownComponent.decorators = [
4283
4309
  { type: Component, args: [{
4284
4310
  selector: 'aup-markdown',
4285
- template: "<p>markdown works!</p>\n",
4311
+ template: "<ng-content></ng-content>\n",
4286
4312
  styles: [":host{display:inline-block}\n"]
4287
4313
  },] }
4288
4314
  ];
4289
4315
  MarkdownComponent.ctorParameters = () => [
4316
+ { type: Object, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] },
4290
4317
  { type: ElementRef },
4291
4318
  { type: MarkdownService }
4292
4319
  ];