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

mention-match.js 4.3KB

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