智慧水务管理系统 - 精河县供水工程综合管理平台

mention-match.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { __extends } from "tslib";
  2. import { assertNever } from '../utils';
  3. import { AbstractMatch } from './abstract-match';
  4. /**
  5. * @class Autolinker.match.Mention
  6. * @extends Autolinker.match.AbstractMatch
  7. *
  8. * Represents a Mention match found in an input string which should be Autolinked.
  9. *
  10. * See this class's superclass ({@link Autolinker.match.Match}) for more details.
  11. */
  12. var MentionMatch = /** @class */ (function (_super) {
  13. __extends(MentionMatch, _super);
  14. /**
  15. * @method constructor
  16. * @param {Object} cfg The configuration properties for the Match
  17. * instance, specified in an Object (map).
  18. */
  19. function MentionMatch(cfg) {
  20. var _this = _super.call(this, cfg) || this;
  21. /**
  22. * @public
  23. * @property {'mention'} type
  24. *
  25. * A string name for the type of match that this class represents. Can be
  26. * used in a TypeScript discriminating union to type-narrow from the
  27. * `Match` type.
  28. */
  29. _this.type = 'mention';
  30. /**
  31. * @cfg {String} serviceName
  32. *
  33. * The service to point mention matches to. See {@link Autolinker#mention}
  34. * for available values.
  35. */
  36. _this.serviceName = 'twitter'; // default value just to get the above doc comment in the ES5 output and documentation generator
  37. /**
  38. * @cfg {String} mention (required)
  39. *
  40. * The Mention that was matched, without the '@' character.
  41. */
  42. _this.mention = ''; // default value just to get the above doc comment in the ES5 output and documentation generator
  43. _this.mention = cfg.mention;
  44. _this.serviceName = cfg.serviceName;
  45. return _this;
  46. }
  47. /**
  48. * Returns a string name for the type of match that this class represents.
  49. * For the case of MentionMatch, returns 'mention'.
  50. *
  51. * @return {String}
  52. */
  53. MentionMatch.prototype.getType = function () {
  54. return 'mention';
  55. };
  56. /**
  57. * Returns the mention, without the '@' character.
  58. *
  59. * @return {String}
  60. */
  61. MentionMatch.prototype.getMention = function () {
  62. return this.mention;
  63. };
  64. /**
  65. * Returns the configured {@link #serviceName} to point the mention to.
  66. * Ex: 'instagram', 'twitter', 'soundcloud'.
  67. *
  68. * @return {String}
  69. */
  70. MentionMatch.prototype.getServiceName = function () {
  71. return this.serviceName;
  72. };
  73. /**
  74. * Returns the anchor href that should be generated for the match.
  75. *
  76. * @return {String}
  77. */
  78. MentionMatch.prototype.getAnchorHref = function () {
  79. switch (this.serviceName) {
  80. case 'twitter':
  81. return 'https://twitter.com/' + this.mention;
  82. case 'instagram':
  83. return 'https://instagram.com/' + this.mention;
  84. case 'soundcloud':
  85. return 'https://soundcloud.com/' + this.mention;
  86. case 'tiktok':
  87. return 'https://www.tiktok.com/@' + this.mention;
  88. case 'youtube':
  89. return 'https://youtube.com/@' + this.mention;
  90. /* istanbul ignore next */
  91. default:
  92. // Should never happen because Autolinker's constructor should block any invalid values, but just in case.
  93. assertNever(this.serviceName);
  94. }
  95. };
  96. /**
  97. * Returns the anchor text that should be generated for the match.
  98. *
  99. * @return {String}
  100. */
  101. MentionMatch.prototype.getAnchorText = function () {
  102. return '@' + this.mention;
  103. };
  104. /**
  105. * Returns the CSS class suffixes that should be used on a tag built with
  106. * the match. See {@link Autolinker.match.Match#getCssClassSuffixes} for
  107. * details.
  108. *
  109. * @return {String[]}
  110. */
  111. MentionMatch.prototype.getCssClassSuffixes = function () {
  112. var cssClassSuffixes = _super.prototype.getCssClassSuffixes.call(this), serviceName = this.getServiceName();
  113. if (serviceName) {
  114. cssClassSuffixes.push(serviceName);
  115. }
  116. return cssClassSuffixes;
  117. };
  118. return MentionMatch;
  119. }(AbstractMatch));
  120. export { MentionMatch };
  121. //# sourceMappingURL=mention-match.js.map