FEATURE: Add buildQuoteMarkdown for post toolbar (#24326)

This allows outlets for the post-text-selection-toolbar to
get just the raw markdown of the selected text for a quote,
rather than opening the composer.
This commit is contained in:
Martin Brennan 2023-11-14 08:47:39 +10:00 committed by GitHub
parent 9919046c1c
commit d128dc0e61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 0 deletions

View File

@ -235,6 +235,7 @@ export default class PostTextSelectionToolbar extends Component {
<PluginOutlet <PluginOutlet
@name="quote-share-buttons-after" @name="quote-share-buttons-after"
@connectorTagName="span" @connectorTagName="span"
@outletArgs={{hash data=@data}}
/> />
</span> </span>
</span> </span>

View File

@ -209,6 +209,7 @@ export default class PostTextSelection extends Component {
topic: this.args.topic, topic: this.args.topic,
quoteState, quoteState,
insertQuote: this.insertQuote, insertQuote: this.insertQuote,
buildQuote: this.buildQuote,
hideToolbar: this.hideToolbar, hideToolbar: this.hideToolbar,
}, },
}; };
@ -271,6 +272,11 @@ export default class PostTextSelection extends Component {
await this.hideToolbar(); await this.hideToolbar();
} }
@action
async buildQuote() {
return await this.args.buildQuoteMarkdown();
}
<template> <template>
<div <div
{{this.documentListeners}} {{this.documentListeners}}

View File

@ -457,6 +457,18 @@ export default Controller.extend(bufferedProperty("model"), {
}); });
}, },
buildQuoteMarkdown() {
const { postId, buffer, opts } = this.quoteState;
const loadedPost = this.get("model.postStream").findLoadedPost(postId);
const promise = loadedPost
? Promise.resolve(loadedPost)
: this.get("model.postStream").loadPost(postId);
return promise.then((post) => {
return buildQuote(post, buffer, opts);
});
},
fillGapBefore(args) { fillGapBefore(args) {
return this.get("model.postStream").fillGapBefore(args.post, args.gap); return this.get("model.postStream").fillGapBefore(args.post, args.gap);
}, },

View File

@ -596,6 +596,7 @@
<PostTextSelection <PostTextSelection
@quoteState={{this.quoteState}} @quoteState={{this.quoteState}}
@selectText={{action "selectText"}} @selectText={{action "selectText"}}
@buildQuoteMarkdown={{this.buildQuoteMarkdown}}
@editPost={{action "editPost"}} @editPost={{action "editPost"}}
@topic={{this.model}} @topic={{this.model}}
/> />