@agorapulse/ui-components 13.2.1 → 13.2.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.
@@ -3244,10 +3244,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImpor
3244
3244
  const PART_START = '<ng-container data-mst="';
3245
3245
  const PARSE_MIDDLE = '">';
3246
3246
  const PARSE_END = '</ng-container>';
3247
- const CLASS_SEPARATOR = ',';
3247
+ const DATA_SEPARATOR = ',';
3248
+ const OPTIONAL_EVENTS_SEPARATOR = ';';
3248
3249
  /**
3249
- * This directive aims to parse simple string to extract some specific tags and to turn them into SPAN with styling classes attributes.
3250
- * The specific tags must this schema: <ng-container data-mst="STYLING-CLASSES>TEXT</ng-container>.
3250
+ * This directive aims to parse simple string to extract some specific tags and to turn them into SPAN with styling classes attributes and optional event listening.
3251
+ * The specific tags must this schema: <ng-container data-mst="STYLING-CLASSES">TEXT</ng-container>.
3251
3252
  * Example: 'Lorem <ng-container data-mst="my-style">ipsum</ng-container> dolor sit amet'.
3252
3253
  */
3253
3254
  class MultiStyleTextDirective {
@@ -3255,43 +3256,54 @@ class MultiStyleTextDirective {
3255
3256
  this.elRef = elRef;
3256
3257
  this.renderer = renderer;
3257
3258
  this.childrenCreated = [];
3259
+ this.partEvent = new EventEmitter();
3258
3260
  }
3259
3261
  set multiStyleText(fullText) {
3260
3262
  // First remove previously added children (on update).
3261
3263
  for (const child of this.childrenCreated) {
3262
3264
  this.renderer.removeChild(this.elRef.nativeElement, child);
3263
3265
  }
3264
- const parts = MultiStyleTextDirective.parse(fullText);
3265
- for (const part of parts) {
3266
- if (part.clazz) {
3266
+ MultiStyleTextDirective.parse(fullText).forEach((part) => {
3267
+ if (part.clazz || part.clickName) {
3268
+ // Parsed item with styling classes and/or event listening.
3267
3269
  const span = this.renderer.createElement('span');
3268
3270
  const text = this.renderer.createText(part.content);
3269
3271
  this.renderer.appendChild(span, text);
3270
- part.clazz.forEach(clazz => this.renderer.addClass(span, clazz));
3272
+ if (part.clazz) {
3273
+ part.clazz.forEach(clazz => this.renderer.addClass(span, clazz));
3274
+ }
3275
+ if (part.clickName) {
3276
+ this.renderer.listen(span, 'click', () => this.partEvent.emit(part.clickName));
3277
+ }
3271
3278
  this.renderer.appendChild(this.elRef.nativeElement, span);
3272
3279
  this.childrenCreated.push(span);
3273
3280
  }
3274
3281
  else {
3282
+ // Specific of part without styling classes (could be used to get event listening only)
3275
3283
  const text = this.renderer.createText(part.content);
3276
3284
  this.renderer.appendChild(this.elRef.nativeElement, text);
3277
3285
  this.childrenCreated.push(text);
3278
3286
  }
3279
- }
3287
+ });
3280
3288
  }
3281
3289
  static parse(toParse) {
3282
3290
  const parts = [];
3283
3291
  let startIndex = toParse.indexOf(PART_START);
3284
3292
  while (startIndex >= 0) {
3285
3293
  if (startIndex > 0) {
3286
- // Optional start before parser start.
3287
- parts.push({ content: toParse.substr(0, startIndex) });
3294
+ // Optional text before first parsed part.
3295
+ parts.push({ content: toParse.substring(0, startIndex) });
3288
3296
  }
3289
- const elem = this.cutFirstGroup(toParse.substr(startIndex));
3297
+ const elem = this.cutFirstGroup(toParse.substring(startIndex));
3290
3298
  if (elem === 'invalid') {
3291
3299
  return [];
3292
3300
  }
3293
3301
  else if (elem) {
3294
- parts.push({ content: elem.content, clazz: elem.classes });
3302
+ parts.push({
3303
+ content: elem.content,
3304
+ clazz: elem.classes,
3305
+ clickName: elem.clickName
3306
+ });
3295
3307
  toParse = elem.rest;
3296
3308
  startIndex = toParse.indexOf(PART_START);
3297
3309
  }
@@ -3307,29 +3319,47 @@ class MultiStyleTextDirective {
3307
3319
  }
3308
3320
  static cutFirstGroup(toCut) {
3309
3321
  if (!toCut.startsWith(PART_START)) {
3310
- // String doesnt start with expected parser start.
3322
+ // String doesn't start with expected parser start.
3311
3323
  return null;
3312
3324
  }
3313
- const afterParserStart = toCut.substr(PART_START.length);
3325
+ const afterParserStart = toCut.substring(PART_START.length);
3314
3326
  let index = afterParserStart.indexOf(PARSE_MIDDLE);
3315
3327
  if (index <= 0) {
3316
3328
  console.error('Not able to parse invalid string: ' + toCut);
3317
3329
  return 'invalid';
3318
3330
  }
3319
- const classes = afterParserStart.substr(0, index);
3320
- let rest = afterParserStart.substr(index + PARSE_MIDDLE.length);
3331
+ const data = afterParserStart.substring(0, index);
3332
+ let classes;
3333
+ let clickName;
3334
+ const eventsPartSeparatorIndex = data.indexOf(OPTIONAL_EVENTS_SEPARATOR);
3335
+ if (eventsPartSeparatorIndex > 0) {
3336
+ // Case the data contains events part with dedicated separator
3337
+ classes = data.substring(0, eventsPartSeparatorIndex);
3338
+ clickName = data.substring(eventsPartSeparatorIndex + 1);
3339
+ }
3340
+ else {
3341
+ // Otherwise, only design classes are provided
3342
+ classes = data;
3343
+ clickName = undefined;
3344
+ }
3345
+ let rest = afterParserStart.substring(index + PARSE_MIDDLE.length);
3321
3346
  index = rest.indexOf(PARSE_END);
3322
3347
  if (index <= 0) {
3323
3348
  console.error('Not able to parse invalid string: ' + toCut);
3324
3349
  return 'invalid';
3325
3350
  }
3326
- const content = rest.substr(0, index);
3327
- rest = rest.substr(index + PARSE_END.length);
3328
- return { content, classes: classes.split(CLASS_SEPARATOR), rest };
3351
+ const content = rest.substring(0, index);
3352
+ rest = rest.substring(index + PARSE_END.length);
3353
+ return {
3354
+ content,
3355
+ classes: classes.split(DATA_SEPARATOR),
3356
+ clickName,
3357
+ rest
3358
+ };
3329
3359
  }
3330
3360
  }
3331
3361
  /** @nocollapse */ /** @nocollapse */ MultiStyleTextDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: MultiStyleTextDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive });
3332
- /** @nocollapse */ /** @nocollapse */ MultiStyleTextDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: MultiStyleTextDirective, selector: "[multiStyleText]", inputs: { multiStyleText: "multiStyleText" }, ngImport: i0 });
3362
+ /** @nocollapse */ /** @nocollapse */ MultiStyleTextDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.3", type: MultiStyleTextDirective, selector: "[multiStyleText]", inputs: { multiStyleText: "multiStyleText" }, outputs: { partEvent: "partEvent" }, ngImport: i0 });
3333
3363
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImport: i0, type: MultiStyleTextDirective, decorators: [{
3334
3364
  type: Directive,
3335
3365
  args: [{
@@ -3338,6 +3368,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImpor
3338
3368
  }]
3339
3369
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }]; }, propDecorators: { multiStyleText: [{
3340
3370
  type: Input
3371
+ }], partEvent: [{
3372
+ type: Output
3341
3373
  }] } });
3342
3374
 
3343
3375
  // Angular