Rename MessageText
to RichText
since it's now used to render more than just messages
This commit is contained in:
parent
b31eaadfab
commit
7f5a1d205e
@ -1,4 +1,4 @@
|
|||||||
import { MessageText } from 'shared/message/text.js';
|
import { RichText } from 'shared/message/text.js';
|
||||||
import { directive, html } from "lit-html";
|
import { directive, html } from "lit-html";
|
||||||
import { until } from 'lit-html/directives/until.js';
|
import { until } from 'lit-html/directives/until.js';
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ class RichTextRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async transform () {
|
async transform () {
|
||||||
const text = new MessageText(this.text, this.offset, this.mentions, this.options);
|
const text = new RichText(this.text, this.offset, this.mentions, this.options);
|
||||||
await text.addTemplates();
|
await text.addTemplates();
|
||||||
return text.payload;
|
return text.payload;
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@ const tpl_mention = (o) => html`<span class="mention">${o.mention}</span>`;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class MessageText
|
* @class RichText
|
||||||
* A String subclass that is used to represent the rich text
|
* A String subclass that is used to render rich text (i.e. text that contains
|
||||||
* of a chat message.
|
* hyperlinks, images, mentions, styling etc.).
|
||||||
*
|
*
|
||||||
* The "rich" parts of the text is represented by lit-html TemplateResult
|
* The "rich" parts of the text is represented by lit-html TemplateResult
|
||||||
* objects which are added via the {@link MessageText.addTemplateResult}
|
* objects which are added via the {@link RichText.addTemplateResult}
|
||||||
* method and saved as metadata.
|
* method and saved as metadata.
|
||||||
*
|
*
|
||||||
* By default Converse adds TemplateResults to support emojis, hyperlinks,
|
* By default Converse adds TemplateResults to support emojis, hyperlinks,
|
||||||
@ -31,18 +31,18 @@ const tpl_mention = (o) => html`<span class="mention">${o.mention}</span>`;
|
|||||||
*
|
*
|
||||||
* 3rd party plugins can listen for the `beforeMessageBodyTransformed`
|
* 3rd party plugins can listen for the `beforeMessageBodyTransformed`
|
||||||
* and/or `afterMessageBodyTransformed` events and then call
|
* and/or `afterMessageBodyTransformed` events and then call
|
||||||
* `addTemplateResult` on the MessageText instance in order to add their own
|
* `addTemplateResult` on the RichText instance in order to add their own
|
||||||
* rich features.
|
* rich features.
|
||||||
*/
|
*/
|
||||||
export class MessageText extends String {
|
export class RichText extends String {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link MessageText} instance.
|
* Create a new {@link RichText} instance.
|
||||||
* @param { String } text - The text to be annotated
|
* @param { String } text - The text to be annotated
|
||||||
* @param { Integer } offset - The offset of this particular piece of text
|
* @param { Integer } offset - The offset of this particular piece of text
|
||||||
* from the start of the original message text. This is necessary because
|
* from the start of the original message text. This is necessary because
|
||||||
* MessageText instances can be nested when templates call directives
|
* RichText instances can be nested when templates call directives
|
||||||
* which create new MessageText instances (as happens with XEP-393 styling directives).
|
* which create new RichText instances (as happens with XEP-393 styling directives).
|
||||||
* @param { Array } mentions - An array of mention references
|
* @param { Array } mentions - An array of mention references
|
||||||
* @param { Object } options
|
* @param { Object } options
|
||||||
* @param { String } options.nick - The current user's nickname (only relevant if the message is in a XEP-0045 MUC)
|
* @param { String } options.nick - The current user's nickname (only relevant if the message is in a XEP-0045 MUC)
|
||||||
@ -137,7 +137,7 @@ export class MessageText extends String {
|
|||||||
* rendering them.
|
* rendering them.
|
||||||
* @param { String } text
|
* @param { String } text
|
||||||
* @param { Integer } local_offset - The index of the passed in text relative to
|
* @param { Integer } local_offset - The index of the passed in text relative to
|
||||||
* the start of this MessageText instance (which is not necessarily the same as the
|
* the start of this RichText instance (which is not necessarily the same as the
|
||||||
* offset from the start of the original message stanza's body text).
|
* offset from the start of the original message stanza's body text).
|
||||||
*/
|
*/
|
||||||
addMentions (text, local_offset) {
|
addMentions (text, local_offset) {
|
||||||
@ -210,7 +210,7 @@ export class MessageText extends String {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look for plaintext (i.e. non-templated) sections of this MessageText
|
* Look for plaintext (i.e. non-templated) sections of this RichText
|
||||||
* instance and add references via the passed in function.
|
* instance and add references via the passed in function.
|
||||||
* @param { Function } func
|
* @param { Function } func
|
||||||
*/
|
*/
|
||||||
@ -233,7 +233,7 @@ export class MessageText extends String {
|
|||||||
/**
|
/**
|
||||||
* Parse the text and add template references for rendering the "rich" parts.
|
* Parse the text and add template references for rendering the "rich" parts.
|
||||||
*
|
*
|
||||||
* @param { MessageText } text
|
* @param { RichText } text
|
||||||
* @param { Boolean } show_images - Should URLs of images be rendered as `<img>` tags?
|
* @param { Boolean } show_images - Should URLs of images be rendered as `<img>` tags?
|
||||||
* @param { Function } onImgLoad
|
* @param { Function } onImgLoad
|
||||||
* @param { Function } onImgClick
|
* @param { Function } onImgClick
|
||||||
@ -243,8 +243,8 @@ export class MessageText extends String {
|
|||||||
* Synchronous event which provides a hook for transforming a chat message's body text
|
* Synchronous event which provides a hook for transforming a chat message's body text
|
||||||
* before the default transformations have been applied.
|
* before the default transformations have been applied.
|
||||||
* @event _converse#beforeMessageBodyTransformed
|
* @event _converse#beforeMessageBodyTransformed
|
||||||
* @param { MessageText } text - A {@link MessageText } instance. You
|
* @param { RichText } text - A {@link RichText } instance. You
|
||||||
* can call {@link MessageText#addTemplateResult } on it in order to
|
* can call {@link RichText#addTemplateResult } on it in order to
|
||||||
* add TemplateResult objects meant to render rich parts of the message.
|
* add TemplateResult objects meant to render rich parts of the message.
|
||||||
* @example _converse.api.listen.on('beforeMessageBodyTransformed', (view, text) => { ... });
|
* @example _converse.api.listen.on('beforeMessageBodyTransformed', (view, text) => { ... });
|
||||||
*/
|
*/
|
||||||
@ -262,8 +262,8 @@ export class MessageText extends String {
|
|||||||
* Synchronous event which provides a hook for transforming a chat message's body text
|
* Synchronous event which provides a hook for transforming a chat message's body text
|
||||||
* after the default transformations have been applied.
|
* after the default transformations have been applied.
|
||||||
* @event _converse#afterMessageBodyTransformed
|
* @event _converse#afterMessageBodyTransformed
|
||||||
* @param { MessageText } text - A {@link MessageText } instance. You
|
* @param { RichText } text - A {@link RichText } instance. You
|
||||||
* can call {@link MessageText#addTemplateResult} on it in order to
|
* can call {@link RichText#addTemplateResult} on it in order to
|
||||||
* add TemplateResult objects meant to render rich parts of the message.
|
* add TemplateResult objects meant to render rich parts of the message.
|
||||||
* @example _converse.api.listen.on('afterMessageBodyTransformed', (view, text) => { ... });
|
* @example _converse.api.listen.on('afterMessageBodyTransformed', (view, text) => { ... });
|
||||||
*/
|
*/
|
||||||
@ -281,7 +281,7 @@ export class MessageText extends String {
|
|||||||
* This method can be used to add new template results to this message's
|
* This method can be used to add new template results to this message's
|
||||||
* text.
|
* text.
|
||||||
*
|
*
|
||||||
* @method MessageText.addTemplateResult
|
* @method RichText.addTemplateResult
|
||||||
* @param { Number } begin - The starting index of the plain message text
|
* @param { Number } begin - The starting index of the plain message text
|
||||||
* which is being replaced with markup.
|
* which is being replaced with markup.
|
||||||
* @param { Number } end - The ending index of the plain message text
|
* @param { Number } end - The ending index of the plain message text
|
||||||
@ -303,7 +303,7 @@ export class MessageText extends String {
|
|||||||
/**
|
/**
|
||||||
* Take the annotations and return an array of text and TemplateResult
|
* Take the annotations and return an array of text and TemplateResult
|
||||||
* instances to be rendered to the DOM.
|
* instances to be rendered to the DOM.
|
||||||
* @method MessageText#marshall
|
* @method RichText#marshall
|
||||||
*/
|
*/
|
||||||
marshall () {
|
marshall () {
|
||||||
let list = [this.toString()];
|
let list = [this.toString()];
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { MessageText } from '../../shared/message/text.js';
|
import { RichText } from '../../shared/message/text.js';
|
||||||
import { directive, html } from 'lit-html';
|
import { directive, html } from 'lit-html';
|
||||||
import { until } from 'lit-html/directives/until.js';
|
import { until } from 'lit-html/directives/until.js';
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ async function transform (t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderer (text, offset, mentions, options) {
|
function renderer (text, offset, mentions, options) {
|
||||||
const t = new MessageText(text, offset, mentions, Object.assign(options, { 'show_images': false }));
|
const t = new RichText(text, offset, mentions, Object.assign(options, { 'show_images': false }));
|
||||||
return html`${until(transform(t), html`${t}`)}`;
|
return html`${until(transform(t), html`${t}`)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user