@thecodeblogs/blog 0.20.1 → 0.20.2

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,15 +5,10 @@ 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 as Utility$1 } from '@blog/services/utility';
9
8
  import * as i6 from '@angular/common';
10
9
  import { isPlatformBrowser, NgIf, CommonModule } from '@angular/common';
11
10
  import * as i2 from 'ngx-device-detector';
12
11
  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';
17
12
  import { ENTER, COMMA, TAB } from '@angular/cdk/keycodes';
18
13
  import * as i1$2 from '@angular/material/dialog';
19
14
  import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
@@ -270,6 +265,167 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImpor
270
265
  }]
271
266
  }], ctorParameters: () => [{ type: i1.HttpClient }] });
272
267
 
268
+ class Utility {
269
+ static replaceNbsps(str) {
270
+ var re = new RegExp(String.fromCharCode(160), "g");
271
+ return str.replace(re, " ");
272
+ }
273
+ static convertHTMLToType(el) {
274
+ var value = "";
275
+ var contentType = "";
276
+ // First test for custom objects
277
+ var testValue = el.innerText;
278
+ try {
279
+ var obj = JSON.parse(testValue);
280
+ return obj;
281
+ }
282
+ catch (error) {
283
+ //console.error(error);
284
+ }
285
+ //console.log(el.tagName);
286
+ switch (el.tagName.toLowerCase()) {
287
+ case "p":
288
+ if (el.children.length > 0) {
289
+ var child = el.children[0];
290
+ if (child.tagName.toLowerCase() === "a") {
291
+ var c = new Content();
292
+ value = child.href;
293
+ c.value = value;
294
+ c.title = Utility.replaceNbsps(child.innerText);
295
+ c.type = ContentType.URL;
296
+ return c;
297
+ }
298
+ else if (child.tagName.toLowerCase() === 'img') {
299
+ var c = new Content();
300
+ value = child.src;
301
+ c.value = value;
302
+ c.type = ContentType.IMAGE;
303
+ return c;
304
+ }
305
+ }
306
+ else {
307
+ var c = new Content();
308
+ value = Utility.replaceNbsps(el.innerText);
309
+ c.value = value;
310
+ c.type = ContentType.TEXT;
311
+ return c;
312
+ }
313
+ break;
314
+ case "a":
315
+ var c = new Content();
316
+ value = el.href;
317
+ c.value = value;
318
+ c.title = Utility.replaceNbsps(el.innerText);
319
+ c.type = ContentType.URL;
320
+ return c;
321
+ break;
322
+ case "h4":
323
+ var s = new Section();
324
+ value = Utility.replaceNbsps(el.innerText);
325
+ s.subheading = Utility.replaceNbsps(value);
326
+ return s;
327
+ break;
328
+ case "blockquote":
329
+ var c = new Content();
330
+ value = el.innerHTML;
331
+ c.value = "<blockquote>" + value + "</blockquote>";
332
+ c.type = ContentType.HTML;
333
+ return c;
334
+ break;
335
+ default:
336
+ var c = new Content();
337
+ value = el.innerHTML;
338
+ c.value = value;
339
+ c.type = ContentType.HTML;
340
+ return c;
341
+ break;
342
+ }
343
+ }
344
+ static convertHtmlToBlogFormat(entry, html) {
345
+ entry.sections = [];
346
+ var newEntry = new Entry(entry);
347
+ var el = document.createElement('html');
348
+ el.innerHTML = html;
349
+ // Creating the HTML element adds a head and body
350
+ // We hardcode to 1 to reference the body, and its
351
+ // child elements
352
+ var children = el.children[1].children;
353
+ ;
354
+ var section = new Section();
355
+ section.subheading = "";
356
+ for (let i = 0; i < children.length; i++) {
357
+ var child = children[i];
358
+ var thing = Utility.convertHTMLToType(child);
359
+ //console.log('Thing: ' + JSON.stringify(thing));
360
+ //console.log('Typeof: ' + JSON.stringify(typeof(thing)));
361
+ if (thing instanceof Section) {
362
+ section = thing;
363
+ section.order = i * 10;
364
+ entry.sections.push(section);
365
+ }
366
+ else if (thing instanceof Content) {
367
+ if (entry.sections.length === 0) {
368
+ thing.order = i * 10;
369
+ section.contents.push(thing);
370
+ entry.sections.push(section);
371
+ section.order = i * 10;
372
+ }
373
+ else {
374
+ thing.order = i * 10;
375
+ section.contents.push(thing);
376
+ }
377
+ }
378
+ else {
379
+ if (thing !== null && typeof (thing) !== 'undefined') {
380
+ thing.order = i * 10;
381
+ section.contents.push(thing);
382
+ }
383
+ }
384
+ }
385
+ //console.log('E: ' + JSON.stringify(entry));
386
+ return entry;
387
+ }
388
+ static convertTypeToHTML(content) {
389
+ switch (content.type) {
390
+ case ContentType.CODE:
391
+ return '<pre><code class="language-ts">' + content?.value + '</code></pre>';
392
+ break;
393
+ case ContentType.IMAGE:
394
+ return '<img src="' + content?.value + '"/>';
395
+ break;
396
+ case ContentType.MEDIA:
397
+ return '<pre>' + JSON.stringify(content) + '</pre>';
398
+ break;
399
+ case ContentType.HTML:
400
+ return content.value;
401
+ break;
402
+ case ContentType.URL:
403
+ return '<a target="_blank" href="' + content.value + '">' + content.title + '</a><br>';
404
+ break;
405
+ case ContentType.TEXT:
406
+ return '<p>' + content.value + '</p>';
407
+ break;
408
+ default:
409
+ return '<pre>' + JSON.stringify(content) + '</pre>';
410
+ break;
411
+ }
412
+ }
413
+ static convertBlogToHtml(blog) {
414
+ var html = "";
415
+ var sections = blog.sections;
416
+ for (var i = 0; i < sections.length; i++) {
417
+ var section = sections[i];
418
+ html = html + '<h4>' + section.subheading + '</h4>';
419
+ var contents = section.contents;
420
+ for (var j = 0; j < contents.length; j++) {
421
+ var content = contents[j];
422
+ html = html + Utility.convertTypeToHTML(content);
423
+ }
424
+ }
425
+ return html;
426
+ }
427
+ }
428
+
273
429
  class EntryService extends DjangoRestFrameworkEndpointService {
274
430
  handleResponse(obj) {
275
431
  return new Entry(obj);
@@ -358,10 +514,10 @@ class EntryService extends DjangoRestFrameworkEndpointService {
358
514
  return this.http.delete(this.adminEndpoint + entity.id + '/').pipe(map((val) => this.triggerCoreEvent(val, CoreEventType.DELETE)), map(this.handleResponse.bind(this)));
359
515
  }
360
516
  convertHtmlToBlogFormat(entry, html) {
361
- return Utility$1.convertHtmlToBlogFormat(entry, html);
517
+ return Utility.convertHtmlToBlogFormat(entry, html);
362
518
  }
363
519
  convertBlogToHtmlFormat(entry) {
364
- return Utility$1.convertBlogToHtml(entry);
520
+ return Utility.convertBlogToHtml(entry);
365
521
  }
366
522
  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 }); }
367
523
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: EntryService, providedIn: 'root' }); }
@@ -577,167 +733,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImpor
577
733
  }]
578
734
  }], ctorParameters: () => [{ type: i1.HttpClient }] });
579
735
 
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
-
741
736
  class EntrySelectorDialogData {
742
737
  }
743
738