mirror of
https://github.com/flarum/framework.git
synced 2025-02-18 10:02:45 +08:00
Make Post component subclasses build on parent content
Extensions may wish to add attributes/content to all posts, regardless of type, by extending methods on the Post component. Now the subclasses will not overwrite, but rather append to, these additions.
This commit is contained in:
parent
2d5a7ce064
commit
31997b8fdf
37
js/forum/dist/app.js
vendored
37
js/forum/dist/app.js
vendored
|
@ -19593,7 +19593,7 @@ System.register('flarum/components/CommentPost', ['flarum/components/Post', 'fla
|
|||
}, {
|
||||
key: 'content',
|
||||
value: function content() {
|
||||
return [m(
|
||||
return babelHelpers.get(Object.getPrototypeOf(CommentPost.prototype), 'content', this).call(this).concat([m(
|
||||
'header',
|
||||
{ className: 'Post-header' },
|
||||
m(
|
||||
|
@ -19605,7 +19605,7 @@ System.register('flarum/components/CommentPost', ['flarum/components/Post', 'fla
|
|||
'div',
|
||||
{ className: 'Post-body' },
|
||||
this.isEditing() ? m('div', { className: 'Post-preview', config: this.configPreview.bind(this) }) : m.trust(this.props.post.contentHtml())
|
||||
)];
|
||||
)]);
|
||||
}
|
||||
}, {
|
||||
key: 'config',
|
||||
|
@ -19634,16 +19634,17 @@ System.register('flarum/components/CommentPost', ['flarum/components/Post', 'fla
|
|||
key: 'attrs',
|
||||
value: function attrs() {
|
||||
var post = this.props.post;
|
||||
var attrs = babelHelpers.get(Object.getPrototypeOf(CommentPost.prototype), 'attrs', this).call(this);
|
||||
|
||||
return {
|
||||
className: classList({
|
||||
'CommentPost': true,
|
||||
'Post--hidden': post.isHidden(),
|
||||
'Post--edited': post.isEdited(),
|
||||
'revealContent': this.revealContent,
|
||||
'editing': this.isEditing()
|
||||
})
|
||||
};
|
||||
attrs.className += ' ' + classList({
|
||||
'CommentPost': true,
|
||||
'Post--hidden': post.isHidden(),
|
||||
'Post--edited': post.isEdited(),
|
||||
'revealContent': this.revealContent,
|
||||
'editing': this.isEditing()
|
||||
});
|
||||
|
||||
return attrs;
|
||||
}
|
||||
}, {
|
||||
key: 'configPreview',
|
||||
|
@ -21909,9 +21910,11 @@ System.register('flarum/components/EventPost', ['flarum/components/Post', 'flaru
|
|||
babelHelpers.createClass(EventPost, [{
|
||||
key: 'attrs',
|
||||
value: function attrs() {
|
||||
return {
|
||||
className: 'EventPost ' + ucfirst(this.props.post.contentType()) + 'Post'
|
||||
};
|
||||
var attrs = babelHelpers.get(Object.getPrototypeOf(EventPost.prototype), 'attrs', this).call(this);
|
||||
|
||||
attrs.className += ' EventPost ' + ucfirst(this.props.post.contentType()) + 'Post';
|
||||
|
||||
return attrs;
|
||||
}
|
||||
}, {
|
||||
key: 'content',
|
||||
|
@ -21927,11 +21930,11 @@ System.register('flarum/components/EventPost', ['flarum/components/Post', 'flaru
|
|||
) : username
|
||||
});
|
||||
|
||||
return [icon(this.icon(), { className: 'EventPost-icon' }), m(
|
||||
return babelHelpers.get(Object.getPrototypeOf(EventPost.prototype), 'content', this).call(this).concat([icon(this.icon(), { className: 'EventPost-icon' }), m(
|
||||
'div',
|
||||
{ 'class': 'EventPost-info' },
|
||||
this.description(data)
|
||||
)];
|
||||
)]);
|
||||
}
|
||||
}, {
|
||||
key: 'icon',
|
||||
|
@ -24317,7 +24320,7 @@ System.register('flarum/components/Post', ['flarum/Component', 'flarum/utils/Sub
|
|||
}, {
|
||||
key: 'content',
|
||||
value: function content() {
|
||||
return '';
|
||||
return [];
|
||||
}
|
||||
}, {
|
||||
key: 'actionItems',
|
||||
|
|
|
@ -42,14 +42,14 @@ export default class CommentPost extends Post {
|
|||
}
|
||||
|
||||
content() {
|
||||
return [
|
||||
return super.content().concat([
|
||||
<header className="Post-header"><ul>{listItems(this.headerItems().toArray())}</ul></header>,
|
||||
<div className="Post-body">
|
||||
{this.isEditing()
|
||||
? <div className="Post-preview" config={this.configPreview.bind(this)}/>
|
||||
: m.trust(this.props.post.contentHtml())}
|
||||
</div>
|
||||
];
|
||||
]);
|
||||
}
|
||||
|
||||
config(isInitialized, context) {
|
||||
|
@ -76,16 +76,17 @@ export default class CommentPost extends Post {
|
|||
|
||||
attrs() {
|
||||
const post = this.props.post;
|
||||
const attrs = super.attrs();
|
||||
|
||||
return {
|
||||
className: classList({
|
||||
'CommentPost': true,
|
||||
'Post--hidden': post.isHidden(),
|
||||
'Post--edited': post.isEdited(),
|
||||
'revealContent': this.revealContent,
|
||||
'editing': this.isEditing()
|
||||
})
|
||||
};
|
||||
attrs.className += ' '+classList({
|
||||
'CommentPost': true,
|
||||
'Post--hidden': post.isHidden(),
|
||||
'Post--edited': post.isEdited(),
|
||||
'revealContent': this.revealContent,
|
||||
'editing': this.isEditing()
|
||||
});
|
||||
|
||||
return attrs;
|
||||
}
|
||||
|
||||
configPreview(element, isInitialized, context) {
|
||||
|
|
|
@ -16,9 +16,11 @@ import icon from 'flarum/helpers/icon';
|
|||
*/
|
||||
export default class EventPost extends Post {
|
||||
attrs() {
|
||||
return {
|
||||
className: 'EventPost ' + ucfirst(this.props.post.contentType()) + 'Post'
|
||||
};
|
||||
const attrs = super.attrs();
|
||||
|
||||
attrs.className += ' EventPost ' + ucfirst(this.props.post.contentType()) + 'Post';
|
||||
|
||||
return attrs;
|
||||
}
|
||||
|
||||
content() {
|
||||
|
@ -31,12 +33,12 @@ export default class EventPost extends Post {
|
|||
: username
|
||||
});
|
||||
|
||||
return [
|
||||
return super.content().concat([
|
||||
icon(this.icon(), {className: 'EventPost-icon'}),
|
||||
<div class="EventPost-info">
|
||||
{this.description(data)}
|
||||
</div>
|
||||
];
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,10 +92,10 @@ export default class Post extends Component {
|
|||
/**
|
||||
* Get the post's content.
|
||||
*
|
||||
* @return {Object}
|
||||
* @return {Array}
|
||||
*/
|
||||
content() {
|
||||
return '';
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user