@thecodeblogs/blog 0.20.0 → 0.20.1

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.
@@ -5,11 +5,15 @@ import * as i1 from '@angular/common/http';
5
5
  import { HttpParams } from '@angular/common/http';
6
6
  import { map, debounceTime } from 'rxjs/operators';
7
7
  import { Subject, of, Subscription } from 'rxjs';
8
- import { Utility } from '@blog/services/utility';
8
+ import { Utility as Utility$1 } from '@blog/services/utility';
9
9
  import * as i6 from '@angular/common';
10
10
  import { isPlatformBrowser, NgIf, CommonModule } from '@angular/common';
11
11
  import * as i2 from 'ngx-device-detector';
12
12
  import * as i1$1 from '@angular/platform-browser';
13
+ import { Entry as Entry$1 } from '@blog/data/entry';
14
+ import { Section as Section$1 } from '@blog/data/section';
15
+ import { Content as Content$1 } from '@blog/data/content';
16
+ import { ContentType as ContentType$1 } from '@blog/data/content-type';
13
17
  import { ENTER, COMMA, TAB } from '@angular/cdk/keycodes';
14
18
  import * as i1$2 from '@angular/material/dialog';
15
19
  import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
@@ -354,10 +358,10 @@ class EntryService extends DjangoRestFrameworkEndpointService {
354
358
  return this.http.delete(this.adminEndpoint + entity.id + '/').pipe(map((val) => this.triggerCoreEvent(val, CoreEventType.DELETE)), map(this.handleResponse.bind(this)));
355
359
  }
356
360
  convertHtmlToBlogFormat(entry, html) {
357
- return Utility.convertHtmlToBlogFormat(entry, html);
361
+ return Utility$1.convertHtmlToBlogFormat(entry, html);
358
362
  }
359
363
  convertBlogToHtmlFormat(entry) {
360
- return Utility.convertBlogToHtml(entry);
364
+ return Utility$1.convertBlogToHtml(entry);
361
365
  }
362
366
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: EntryService, deps: [{ token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
363
367
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: EntryService, providedIn: 'root' }); }
@@ -573,6 +577,167 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImpor
573
577
  }]
574
578
  }], ctorParameters: () => [{ type: i1.HttpClient }] });
575
579
 
580
+ class Utility {
581
+ static replaceNbsps(str) {
582
+ var re = new RegExp(String.fromCharCode(160), "g");
583
+ return str.replace(re, " ");
584
+ }
585
+ static convertHTMLToType(el) {
586
+ var value = "";
587
+ var contentType = "";
588
+ // First test for custom objects
589
+ var testValue = el.innerText;
590
+ try {
591
+ var obj = JSON.parse(testValue);
592
+ return obj;
593
+ }
594
+ catch (error) {
595
+ //console.error(error);
596
+ }
597
+ //console.log(el.tagName);
598
+ switch (el.tagName.toLowerCase()) {
599
+ case "p":
600
+ if (el.children.length > 0) {
601
+ var child = el.children[0];
602
+ if (child.tagName.toLowerCase() === "a") {
603
+ var c = new Content$1();
604
+ value = child.href;
605
+ c.value = value;
606
+ c.title = Utility.replaceNbsps(child.innerText);
607
+ c.type = ContentType$1.URL;
608
+ return c;
609
+ }
610
+ else if (child.tagName.toLowerCase() === 'img') {
611
+ var c = new Content$1();
612
+ value = child.src;
613
+ c.value = value;
614
+ c.type = ContentType$1.IMAGE;
615
+ return c;
616
+ }
617
+ }
618
+ else {
619
+ var c = new Content$1();
620
+ value = Utility.replaceNbsps(el.innerText);
621
+ c.value = value;
622
+ c.type = ContentType$1.TEXT;
623
+ return c;
624
+ }
625
+ break;
626
+ case "a":
627
+ var c = new Content$1();
628
+ value = el.href;
629
+ c.value = value;
630
+ c.title = Utility.replaceNbsps(el.innerText);
631
+ c.type = ContentType$1.URL;
632
+ return c;
633
+ break;
634
+ case "h4":
635
+ var s = new Section$1();
636
+ value = Utility.replaceNbsps(el.innerText);
637
+ s.subheading = Utility.replaceNbsps(value);
638
+ return s;
639
+ break;
640
+ case "blockquote":
641
+ var c = new Content$1();
642
+ value = el.innerHTML;
643
+ c.value = "<blockquote>" + value + "</blockquote>";
644
+ c.type = ContentType$1.HTML;
645
+ return c;
646
+ break;
647
+ default:
648
+ var c = new Content$1();
649
+ value = el.innerHTML;
650
+ c.value = value;
651
+ c.type = ContentType$1.HTML;
652
+ return c;
653
+ break;
654
+ }
655
+ }
656
+ static convertHtmlToBlogFormat(entry, html) {
657
+ entry.sections = [];
658
+ var newEntry = new Entry$1(entry);
659
+ var el = document.createElement('html');
660
+ el.innerHTML = html;
661
+ // Creating the HTML element adds a head and body
662
+ // We hardcode to 1 to reference the body, and its
663
+ // child elements
664
+ var children = el.children[1].children;
665
+ ;
666
+ var section = new Section$1();
667
+ section.subheading = "";
668
+ for (let i = 0; i < children.length; i++) {
669
+ var child = children[i];
670
+ var thing = Utility.convertHTMLToType(child);
671
+ //console.log('Thing: ' + JSON.stringify(thing));
672
+ //console.log('Typeof: ' + JSON.stringify(typeof(thing)));
673
+ if (thing instanceof Section$1) {
674
+ section = thing;
675
+ section.order = i * 10;
676
+ entry.sections.push(section);
677
+ }
678
+ else if (thing instanceof Content$1) {
679
+ if (entry.sections.length === 0) {
680
+ thing.order = i * 10;
681
+ section.contents.push(thing);
682
+ entry.sections.push(section);
683
+ section.order = i * 10;
684
+ }
685
+ else {
686
+ thing.order = i * 10;
687
+ section.contents.push(thing);
688
+ }
689
+ }
690
+ else {
691
+ if (thing !== null && typeof (thing) !== 'undefined') {
692
+ thing.order = i * 10;
693
+ section.contents.push(thing);
694
+ }
695
+ }
696
+ }
697
+ //console.log('E: ' + JSON.stringify(entry));
698
+ return entry;
699
+ }
700
+ static convertTypeToHTML(content) {
701
+ switch (content.type) {
702
+ case ContentType$1.CODE:
703
+ return '<pre><code class="language-ts">' + content?.value + '</code></pre>';
704
+ break;
705
+ case ContentType$1.IMAGE:
706
+ return '<img src="' + content?.value + '"/>';
707
+ break;
708
+ case ContentType$1.MEDIA:
709
+ return '<pre>' + JSON.stringify(content) + '</pre>';
710
+ break;
711
+ case ContentType$1.HTML:
712
+ return content.value;
713
+ break;
714
+ case ContentType$1.URL:
715
+ return '<a target="_blank" href="' + content.value + '">' + content.title + '</a><br>';
716
+ break;
717
+ case ContentType$1.TEXT:
718
+ return '<p>' + content.value + '</p>';
719
+ break;
720
+ default:
721
+ return '<pre>' + JSON.stringify(content) + '</pre>';
722
+ break;
723
+ }
724
+ }
725
+ static convertBlogToHtml(blog) {
726
+ var html = "";
727
+ var sections = blog.sections;
728
+ for (var i = 0; i < sections.length; i++) {
729
+ var section = sections[i];
730
+ html = html + '<h4>' + section.subheading + '</h4>';
731
+ var contents = section.contents;
732
+ for (var j = 0; j < contents.length; j++) {
733
+ var content = contents[j];
734
+ html = html + Utility.convertTypeToHTML(content);
735
+ }
736
+ }
737
+ return html;
738
+ }
739
+ }
740
+
576
741
  class EntrySelectorDialogData {
577
742
  }
578
743
 
@@ -2072,5 +2237,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImpor
2072
2237
  * Generated bundle index. Do not edit.
2073
2238
  */
2074
2239
 
2075
- export { Base, CommentService, Content, ContentType, CoreEvent, CoreEventType, CoreModule, DjangoRestFrameworkEndpointService, Entry, EntryCreatorComponent, EntryRendererComponent, EntryRendererWrapperComponent, EntrySelectorDialogComponent, EntryService, EntrySummaryComponent, Guid, IdentityService, Interaction, InteractionService, JsonRendererComponent, LandingPageComponent, LinkyPipe, ListResponse, MainComponent, MediaUploadModalComponent, OutlineViewComponent, PrismService, Routes, Section, SideNavigationComponent, StaticHtmlComponent, StaticHtmlService, TagService, TimeAgoPipe, Upload, UploadService, View, ViewService, VisitorProfile, VisitorProfileService };
2240
+ export { Base, CommentService, Content, ContentType, CoreEvent, CoreEventType, CoreModule, DjangoRestFrameworkEndpointService, Entry, EntryCreatorComponent, EntryRendererComponent, EntryRendererWrapperComponent, EntrySelectorDialogComponent, EntryService, EntrySummaryComponent, Guid, IdentityService, Interaction, InteractionService, JsonRendererComponent, LandingPageComponent, LinkyPipe, ListResponse, MainComponent, MediaUploadModalComponent, OutlineViewComponent, PrismService, Routes, Section, SideNavigationComponent, StaticHtmlComponent, StaticHtmlService, TagService, TimeAgoPipe, Upload, UploadService, Utility, View, ViewService, VisitorProfile, VisitorProfileService };
2076
2241
  //# sourceMappingURL=thecodeblogs-blog.mjs.map