mirror of
https://github.com/flarum/core.git
synced 2025-08-02 22:47:33 +02:00
feat: added compat exports and extensibility (#76)
* Added extensibility * Corrected object export * Exported the `insertMention` util * Return a `Promise` in the `reply` util (for extensibility) * Removed initialization utils Co-authored-by: Rafael Horvat <rafael.horvat@glowingblue.com>
This commit is contained in:
23
extensions/mentions/js/src/forum/compat.js
Normal file
23
extensions/mentions/js/src/forum/compat.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import MentionsUserPage from './components/MentionsUserPage';
|
||||||
|
import PostMentionedNotification from './components/PostMentionedNotification';
|
||||||
|
import UserMentionedNotification from './components/UserMentionedNotification';
|
||||||
|
import AutocompleteDropdown from './fragments/AutocompleteDropdown';
|
||||||
|
import PostQuoteButton from './fragments/PostQuoteButton';
|
||||||
|
import getCleanDisplayName from './utils/getCleanDisplayName';
|
||||||
|
import getMentionText from './utils/getMentionText';
|
||||||
|
import * as reply from './utils/reply';
|
||||||
|
import selectedText from './utils/selectedText';
|
||||||
|
import * as textFormatter from './utils/textFormatter';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
'mentions/components/MentionsUserPage': MentionsUserPage,
|
||||||
|
'mentions/components/PostMentionedNotification': PostMentionedNotification,
|
||||||
|
'mentions/components/UserMentionedNotification': UserMentionedNotification,
|
||||||
|
'mentions/fragments/AutocompleteDropdown': AutocompleteDropdown,
|
||||||
|
'mentions/fragments/PostQuoteButton': PostQuoteButton,
|
||||||
|
'mentions/utils/getCleanDisplayName': getCleanDisplayName,
|
||||||
|
'mentions/utils/getMentionText': getMentionText,
|
||||||
|
'mentions/utils/reply': reply,
|
||||||
|
'mentions/utils/selectedText': selectedText,
|
||||||
|
'mentions/utils/textFormatter': textFormatter
|
||||||
|
};
|
@@ -71,3 +71,9 @@ app.initializers.add('flarum-mentions', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export * from './utils/textFormatter';
|
export * from './utils/textFormatter';
|
||||||
|
|
||||||
|
// Expose compat API
|
||||||
|
import mentionsCompat from './compat';
|
||||||
|
import { compat } from '@flarum/core/forum';
|
||||||
|
|
||||||
|
Object.assign(compat, mentionsCompat);
|
||||||
|
@@ -2,7 +2,8 @@ import DiscussionControls from 'flarum/forum/utils/DiscussionControls';
|
|||||||
import EditPostComposer from 'flarum/forum/components/EditPostComposer';
|
import EditPostComposer from 'flarum/forum/components/EditPostComposer';
|
||||||
import getMentionText from './getMentionText';
|
import getMentionText from './getMentionText';
|
||||||
|
|
||||||
function insertMention(post, composer, quote) {
|
export function insertMention(post, composer, quote) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
const user = post.user();
|
const user = post.user();
|
||||||
const mention = getMentionText(user, post.id()) + ' ';
|
const mention = getMentionText(user, post.id()) + ' ';
|
||||||
|
|
||||||
@@ -22,17 +23,19 @@ function insertMention(post, composer, quote) {
|
|||||||
(quote ? '> ' + mention + quote.trim().replace(/\n/g, '\n> ') + '\n\n' : mention),
|
(quote ? '> ' + mention + quote.trim().replace(/\n/g, '\n> ') + '\n\n' : mention),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
return resolve(composer);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function reply(post, quote) {
|
export default function reply(post, quote) {
|
||||||
if (app.composer.bodyMatches(EditPostComposer) && app.composer.body.attrs.post.discussion() === post.discussion()) {
|
if (app.composer.bodyMatches(EditPostComposer) && app.composer.body.attrs.post.discussion() === post.discussion()) {
|
||||||
// If we're already editing a post in the discussion of post we're quoting,
|
// If we're already editing a post in the discussion of post we're quoting,
|
||||||
// insert the mention directly.
|
// insert the mention directly.
|
||||||
insertMention(post, app.composer, quote);
|
return insertMention(post, app.composer, quote);
|
||||||
} else {
|
} else {
|
||||||
// The default "Reply" action behavior will only open a new composer if
|
// The default "Reply" action behavior will only open a new composer if
|
||||||
// necessary, but it will always be a ReplyComposer, hence the exceptional
|
// necessary, but it will always be a ReplyComposer, hence the exceptional
|
||||||
// case above.
|
// case above.
|
||||||
DiscussionControls.replyAction.call(post.discussion()).then((composer) => insertMention(post, composer, quote));
|
return DiscussionControls.replyAction.call(post.discussion()).then((composer) => insertMention(post, composer, quote));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user