@banta/sdk 4.4.1 → 4.4.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.
@@ -1,6 +1,6 @@
1
1
  import { Observable, Subject, BehaviorSubject, Subscription } from 'rxjs';
2
2
  import { publish } from 'rxjs/operators';
3
- import { Component, Input, ViewChild, Pipe, Output, HostBinding, NgModule, ElementRef, Injectable, Directive, NgZone, ContentChild, TemplateRef, Inject } from '@angular/core';
3
+ import { Component, Input, ViewChild, Pipe, Output, HostBinding, NgModule, ElementRef, Directive, NgZone, ContentChild, TemplateRef, Injectable, Inject } from '@angular/core';
4
4
  import { marked, Renderer } from 'marked';
5
5
  import { sanitize } from 'dompurify';
6
6
  import { DomSanitizer } from '@angular/platform-browser';
@@ -251,6 +251,15 @@ class BantaAttachmentComponent {
251
251
  this.removed = new Subject();
252
252
  this.activated = new Subject();
253
253
  }
254
+ ngOnInit() {
255
+ if (typeof window !== 'undefined') {
256
+ setTimeout(() => {
257
+ if (!window['twttr'])
258
+ return;
259
+ window['twttr'].widgets.load();
260
+ }, 100);
261
+ }
262
+ }
254
263
  activate() {
255
264
  this.activated.next();
256
265
  }
@@ -274,14 +283,31 @@ class BantaAttachmentComponent {
274
283
  return true;
275
284
  return false;
276
285
  }
286
+ get hasFrame() {
287
+ if (!this.attachment)
288
+ return false;
289
+ return this.attachment.type === 'iframe' || (this.attachment.type === 'card'
290
+ && this.attachment.card.player);
291
+ }
292
+ get frameUrl() {
293
+ if (!this.attachment)
294
+ return undefined;
295
+ if (this.attachment.type === 'iframe') {
296
+ return this.attachment.url;
297
+ }
298
+ else if (this.attachment.type === 'card') {
299
+ return this.attachment.card.player;
300
+ }
301
+ }
277
302
  }
278
303
  BantaAttachmentComponent.decorators = [
279
304
  { type: Component, args: [{
280
305
  selector: 'banta-attachment',
281
- template: "<button type=\"button\" (click)=\"remove()\" mat-mini-fab color=\"primary\" class=\"remove-button\" *ngIf=\"editing\">\r\n <mat-icon>close</mat-icon>\r\n</button>\r\n\r\n<ng-container *ngIf=\"isError\">\r\n <mat-icon class=\"error\">close</mat-icon>\r\n <em class=\"error\">{{theErrorMessage}}</em>\r\n</ng-container>\r\n<ng-container *ngIf=\"!isError\">\r\n <ng-container *ngIf=\"isLoading\">\r\n <mat-spinner></mat-spinner>\r\n <em>{{loadingMessage}}</em>\r\n </ng-container>\r\n <ng-container *ngIf=\"!isLoading\">\r\n <iframe \r\n *ngIf=\"attachment.type === 'iframe'\" \r\n sandbox=\"allow-scripts allow-popups allow-same-origin allow-presentation\" \r\n [src]=\"attachment.url | trustResourceUrl\"></iframe>\r\n <a *ngIf=\"attachment.type === 'card'\" class=\"card\" [href]=\"attachment.url\" target=\"_blank\">\r\n <img \r\n *ngIf=\"attachment.card.image\"\r\n class=\"thumbnail\" \r\n [src]=\"attachment.card.image\"\r\n />\r\n <div class=\"description\">\r\n <h1>{{attachment.card.title}}</h1>\r\n {{attachment.card.description}}\r\n </div>\r\n </a>\r\n <a class=\"image-attachment\" *ngIf=\"isImageAttachment\" href=\"javascript:;\" (click)=\"activate()\">\r\n <img [src]=\"attachment.url\" alt=\"Image Attachment\">\r\n </a>\r\n </ng-container>\r\n</ng-container>",
282
- styles: [":host{position:relative;display:block}:host.loading{outline:1px solid #333;padding:1em 0;width:300px;text-align:center}:host.loading mat-spinner{display:block;margin:0 auto .5em;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content}a.card{display:flex;align-items:flex-start;gap:1em;width:100%;border:1px solid #666;border-radius:4px;padding:1em;box-sizing:border-box;background-color:#191919}a.card img{width:300px;aspect-ratio:16/9;-o-object-fit:cover;object-fit:cover;border-radius:10px}a.card h1{margin:0;font-size:30px}.remove-button{position:absolute;right:10px;top:10px;margin:0;z-index:1}a.image-attachment{width:300px;position:relative;text-align:center}a.image-attachment.with-border{outline:1px solid #333;padding:1em 0}a.image-attachment mat-spinner{display:block;margin:0 auto .5em;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content}a.image-attachment mat-icon.error{display:block;font-size:48px;width:48px;height:48px;margin:0 auto .5em}a.image-attachment .error{color:#b76363}a.image-attachment img{width:300px;border-radius:10px;max-width:100%;max-height:20em;-o-object-fit:cover;object-fit:cover}iframe{border:none;width:100%;aspect-ratio:16/9}"]
306
+ template: "<button type=\"button\" (click)=\"remove()\" mat-mini-fab color=\"primary\" class=\"remove-button\" *ngIf=\"editing\">\r\n <mat-icon>close</mat-icon>\r\n</button>\r\n\r\n<ng-container *ngIf=\"isError\">\r\n <mat-icon class=\"error\">close</mat-icon>\r\n <em class=\"error\">{{theErrorMessage}}</em>\r\n</ng-container>\r\n<ng-container *ngIf=\"!isError\">\r\n <ng-container *ngIf=\"isLoading\">\r\n <mat-spinner></mat-spinner>\r\n <em>{{loadingMessage}}</em>\r\n </ng-container>\r\n <ng-container *ngIf=\"!isLoading\">\r\n <iframe *ngIf=\"hasFrame\"\r\n sandbox=\"allow-scripts allow-popups allow-same-origin allow-presentation\" \r\n [src]=\"frameUrl | trustResourceUrl\"></iframe>\r\n <a *ngIf=\"attachment.type === 'card'\" class=\"card\" [href]=\"attachment.url\" target=\"_blank\" [class.has-image]=\"attachment.card.image\">\r\n <img \r\n *ngIf=\"attachment.card.image\"\r\n class=\"thumbnail\" \r\n [src]=\"attachment.card.image\"\r\n />\r\n <div class=\"description\">\r\n <h1>{{attachment.card.title}}</h1>\r\n <div>\r\n {{attachment.card.description}}\r\n </div>\r\n <cite>{{attachment.card.url}}</cite>\r\n </div>\r\n </a>\r\n <a class=\"image-attachment\" *ngIf=\"isImageAttachment\" href=\"javascript:;\" (click)=\"activate()\">\r\n <img [src]=\"attachment.url\" alt=\"Image Attachment\">\r\n </a>\r\n <blockquote *ngIf=\"attachment.type === 'tweet'\" \r\n class=\"twitter-tweet\">\r\n <p lang=\"en\" dir=\"ltr\"></p>\r\n <a href=\"https://twitter.com/seldo/status/1562553608083714050?ref_src=twsrc%5Etfw\"></a>\r\n </blockquote>\r\n </ng-container>\r\n</ng-container>",
307
+ styles: [":host{position:relative;display:block}:host.loading{outline:1px solid #333;padding:1em 0;width:300px;text-align:center}:host.loading mat-spinner{display:block;margin:0 auto .5em;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content}a.card{display:flex;align-items:flex-start;gap:1em;width:100%;border:1px solid #666;border-radius:4px;padding:1em;box-sizing:border-box;background-color:#191919;margin:1em 0}a.card img{width:250px;aspect-ratio:16/9;-o-object-fit:cover;object-fit:cover;border-radius:10px}a.card.has-image h1{font-size:22px}a.card h1{min-width:0;margin:0 0 .5em;font-size:26px}a.card cite{min-width:0;opacity:.75;margin-top:1em;display:block;font-size:90%;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}a.card .description{min-width:0}.remove-button{position:absolute;right:10px;top:10px;margin:0;z-index:1}a.image-attachment{width:300px;position:relative;text-align:center}a.image-attachment.with-border{outline:1px solid #333;padding:1em 0}a.image-attachment mat-spinner{display:block;margin:0 auto .5em;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content}a.image-attachment mat-icon.error{display:block;font-size:48px;width:48px;height:48px;margin:0 auto .5em}a.image-attachment .error{color:#b76363}a.image-attachment img{width:300px;border-radius:10px;max-width:100%;max-height:20em;-o-object-fit:cover;object-fit:cover}iframe{border:none;width:100%;aspect-ratio:16/9}"]
283
308
  },] }
284
309
  ];
310
+ BantaAttachmentComponent.ctorParameters = () => [];
285
311
  BantaAttachmentComponent.propDecorators = {
286
312
  attachment: [{ type: Input }],
287
313
  loading: [{ type: Input }],
@@ -7124,99 +7150,11 @@ ChatMessageComponent.propDecorators = {
7124
7150
  upvoted: [{ type: Output }]
7125
7151
  };
7126
7152
 
7127
- const URL_REGEX = new RegExp('(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?', 'ig');
7128
- class UrlAttachmentScraper {
7129
- findFragments(message) {
7130
- var _a;
7131
- // If a message already has a URL attachment, don't add another one.
7132
- if (message.attachments && message.attachments.filter(x => x.type === 'url').length > 0)
7133
- return null;
7134
- return (Array.from((_a = message.message.match(URL_REGEX)) !== null && _a !== void 0 ? _a : []))
7135
- .reduce((a, item) => (a.includes(item) ? undefined : a.push(item), a), [])
7136
- .map(url => ({
7137
- text: url,
7138
- offset: message.message.indexOf(url),
7139
- type: 'url'
7140
- }));
7141
- }
7142
- }
7143
- class GiphyAttachmentResolver {
7144
- resolveFragment(message, fragment) {
7145
- var _a;
7146
- return __awaiter(this, void 0, void 0, function* () {
7147
- if (fragment.type === 'url' && fragment.text.startsWith('https://giphy.com/gifs')) {
7148
- let gifId = (_a = /[^-\/]+$/.exec(fragment.text)) === null || _a === void 0 ? void 0 : _a.toString();
7149
- if (!gifId)
7150
- return null;
7151
- return {
7152
- type: 'iframe',
7153
- url: `https://giphy.com/embed/${gifId}`,
7154
- style: 'inline'
7155
- };
7156
- }
7157
- return null;
7158
- });
7159
- }
7160
- }
7161
- class YouTubeAttachmentResolver {
7162
- resolveFragment(message, fragment) {
7163
- return __awaiter(this, void 0, void 0, function* () {
7164
- if (fragment.type !== 'url')
7165
- return null;
7166
- let videoId;
7167
- if (fragment.text.match(/https?:\/\/(www\.)?youtube.com\/watch\?v=/)) {
7168
- let match = /watch\?v=([^&]+)/.exec(fragment.text);
7169
- if (match) {
7170
- videoId = match[1];
7171
- }
7172
- }
7173
- if (videoId) {
7174
- return {
7175
- type: 'iframe',
7176
- url: `https://www.youtube.com/embed/${videoId}`,
7177
- style: 'block'
7178
- };
7179
- }
7180
- return null;
7181
- });
7182
- }
7183
- }
7184
- class UrlAttachmentResolver {
7185
- constructor(backend) {
7186
- this.backend = backend;
7187
- }
7188
- resolveFragment(message, fragment) {
7189
- return __awaiter(this, void 0, void 0, function* () {
7190
- if (fragment.type !== 'url')
7191
- return null;
7192
- let urlCard = yield this.backend.getCardForUrl(fragment.text);
7193
- if (urlCard) {
7194
- return {
7195
- type: 'card',
7196
- url: fragment.text,
7197
- card: urlCard,
7198
- style: 'block'
7199
- };
7200
- }
7201
- });
7202
- }
7203
- }
7204
- UrlAttachmentResolver.decorators = [
7205
- { type: Injectable }
7206
- ];
7207
- UrlAttachmentResolver.ctorParameters = () => [
7208
- { type: ChatBackendBase }
7209
- ];
7210
-
7211
7153
  class ChatBackendBase {
7212
7154
  constructor() {
7213
7155
  this._userChanged = new BehaviorSubject(null);
7214
7156
  this._attachmentScrapers = [];
7215
7157
  this._attachmentResolvers = [];
7216
- this.registerAttachmentScraper(new UrlAttachmentScraper());
7217
- this.registerAttachmentResolver(new GiphyAttachmentResolver());
7218
- this.registerAttachmentResolver(new YouTubeAttachmentResolver());
7219
- this.registerAttachmentResolver(new UrlAttachmentResolver(this));
7220
7158
  }
7221
7159
  get userChanged() {
7222
7160
  return this._userChanged;
@@ -9664,7 +9602,123 @@ ChatBackend.ctorParameters = () => [
9664
9602
  { type: undefined, decorators: [{ type: Inject, args: [BANTA_SDK_OPTIONS,] }] }
9665
9603
  ];
9666
9604
 
9605
+ const URL_REGEX = new RegExp('(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?', 'ig');
9606
+ class UrlAttachmentScraper {
9607
+ findFragments(message) {
9608
+ var _a;
9609
+ // If a message already has a URL attachment, don't add another one.
9610
+ if (message.attachments && message.attachments.filter(x => x.type === 'url').length > 0)
9611
+ return null;
9612
+ return (Array.from((_a = message.message.match(URL_REGEX)) !== null && _a !== void 0 ? _a : []))
9613
+ .reduce((a, item) => (a.includes(item) ? undefined : a.push(item), a), [])
9614
+ .map(url => ({
9615
+ text: url,
9616
+ offset: message.message.indexOf(url),
9617
+ type: 'url'
9618
+ }));
9619
+ }
9620
+ }
9621
+ class UrlAttachmentResolver {
9622
+ constructor(backend) {
9623
+ this.backend = backend;
9624
+ }
9625
+ resolveFragment(message, fragment) {
9626
+ return __awaiter(this, void 0, void 0, function* () {
9627
+ if (fragment.type !== 'url')
9628
+ return null;
9629
+ let urlCard = yield this.backend.getCardForUrl(fragment.text);
9630
+ if (urlCard) {
9631
+ return {
9632
+ type: 'card',
9633
+ url: fragment.text,
9634
+ card: urlCard,
9635
+ style: 'block'
9636
+ };
9637
+ }
9638
+ });
9639
+ }
9640
+ }
9641
+ UrlAttachmentResolver.decorators = [
9642
+ { type: Injectable }
9643
+ ];
9644
+ UrlAttachmentResolver.ctorParameters = () => [
9645
+ { type: ChatBackendBase }
9646
+ ];
9647
+
9648
+ class YouTubeAttachmentResolver {
9649
+ resolveFragment(message, fragment) {
9650
+ return __awaiter(this, void 0, void 0, function* () {
9651
+ if (fragment.type !== 'url')
9652
+ return null;
9653
+ let videoId;
9654
+ if (fragment.text.match(/https?:\/\/(www\.)?youtube.com\/watch\?v=/)) {
9655
+ let match = /watch\?v=([^&]+)/.exec(fragment.text);
9656
+ if (match) {
9657
+ videoId = match[1];
9658
+ }
9659
+ }
9660
+ if (videoId) {
9661
+ return {
9662
+ type: 'iframe',
9663
+ url: `https://www.youtube.com/embed/${videoId}`,
9664
+ style: 'block'
9665
+ };
9666
+ }
9667
+ return null;
9668
+ });
9669
+ }
9670
+ }
9671
+
9672
+ class GiphyAttachmentResolver {
9673
+ resolveFragment(message, fragment) {
9674
+ var _a;
9675
+ return __awaiter(this, void 0, void 0, function* () {
9676
+ if (fragment.type === 'url' && fragment.text.startsWith('https://giphy.com/gifs')) {
9677
+ let gifId = (_a = /[^-\/]+$/.exec(fragment.text)) === null || _a === void 0 ? void 0 : _a.toString();
9678
+ if (!gifId)
9679
+ return null;
9680
+ return {
9681
+ type: 'iframe',
9682
+ url: `https://giphy.com/embed/${gifId}`,
9683
+ style: 'inline'
9684
+ };
9685
+ }
9686
+ return null;
9687
+ });
9688
+ }
9689
+ }
9690
+
9691
+ class TweetAttachmentResolver {
9692
+ resolveFragment(message, fragment) {
9693
+ return __awaiter(this, void 0, void 0, function* () {
9694
+ if (fragment.type === 'url' && fragment.text.startsWith('https://twitter.com/')) {
9695
+ return {
9696
+ type: 'tweet',
9697
+ url: fragment.text,
9698
+ style: 'block'
9699
+ };
9700
+ }
9701
+ return null;
9702
+ });
9703
+ }
9704
+ }
9705
+
9667
9706
  class BantaSdkModule {
9707
+ constructor(chatBackend) {
9708
+ if (typeof window !== 'undefined') {
9709
+ if (!document.querySelector('script[src="https://platform.twitter.com/widgets.js"]')) {
9710
+ let script = document.createElement('script');
9711
+ script.src = 'https://platform.twitter.com/widgets.js';
9712
+ script.async = true;
9713
+ document.body.appendChild(script);
9714
+ }
9715
+ }
9716
+ chatBackend.registerAttachmentScraper(new UrlAttachmentScraper());
9717
+ chatBackend.registerAttachmentResolver(new GiphyAttachmentResolver());
9718
+ chatBackend.registerAttachmentResolver(new YouTubeAttachmentResolver());
9719
+ chatBackend.registerAttachmentResolver(new TweetAttachmentResolver());
9720
+ chatBackend.registerAttachmentResolver(new UrlAttachmentResolver(chatBackend));
9721
+ }
9668
9722
  static configure(options) {
9669
9723
  return {
9670
9724
  ngModule: BantaSdkModule,
@@ -9712,6 +9766,9 @@ BantaSdkModule.decorators = [
9712
9766
  CommentsModule
9713
9767
  ]
9714
9768
  },] }
9769
+ ];
9770
+ BantaSdkModule.ctorParameters = () => [
9771
+ { type: ChatBackendBase }
9715
9772
  ];
9716
9773
 
9717
9774
  /*
@@ -9722,5 +9779,5 @@ BantaSdkModule.decorators = [
9722
9779
  * Generated bundle index. Do not edit.
9723
9780
  */
9724
9781
 
9725
- export { AttachmentButtonComponent, BANTA_SDK_OPTIONS, BantaAttachmentComponent, BantaAttachmentsComponent, BantaChatComponent, BantaCommentsComponent, BantaCommonModule, BantaComponent, BantaLogoComponent, BantaMarkdownToHtmlPipe, BantaReplySendOptionsDirective, BantaSdkModule, BantaTrustResourceUrlPipe, ChatBackend, ChatBackendBase, ChatMessageComponent, ChatModule, ChatSource, ChatViewComponent, CommentComponent, CommentFieldComponent, CommentSortComponent, CommentViewComponent, CommentsModule, EMOJIS, EmojiModule, EmojiSelectorButtonComponent, EmojiSelectorPanelComponent, LightboxComponent, LiveChatMessageComponent, LiveCommentComponent, LiveMessageComponent, TimestampComponent, lazyConnection };
9782
+ export { AttachmentButtonComponent, BANTA_SDK_OPTIONS, BantaAttachmentComponent, BantaAttachmentsComponent, BantaChatComponent, BantaCommentsComponent, BantaCommonModule, BantaComponent, BantaLogoComponent, BantaMarkdownToHtmlPipe, BantaReplySendOptionsDirective, BantaSdkModule, BantaTrustResourceUrlPipe, ChatBackend, ChatBackendBase, ChatMessageComponent, ChatModule, ChatSource, ChatViewComponent, CommentComponent, CommentFieldComponent, CommentSortComponent, CommentViewComponent, CommentsModule, EMOJIS, EmojiModule, EmojiSelectorButtonComponent, EmojiSelectorPanelComponent, GiphyAttachmentResolver, LightboxComponent, LiveChatMessageComponent, LiveCommentComponent, LiveMessageComponent, TimestampComponent, TweetAttachmentResolver, UrlAttachmentResolver, UrlAttachmentScraper, YouTubeAttachmentResolver, lazyConnection };
9726
9783
  //# sourceMappingURL=banta-sdk.js.map