Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 20:02:54 +01:00
FEATURE: Add mentionables integration (#148)
* Add mentionables integration * fix linting issues * bump version * FIX: Use wizard site model * FIX: apply prettier
Dieser Commit ist enthalten in:
Ursprung
d4c25d406b
Commit
538d618ff3
8 geänderte Dateien mit 106 neuen und 11 gelöschten Zeilen
|
@ -3,14 +3,14 @@
|
||||||
Discourse.unofficial_plugins.each do |plugin|
|
Discourse.unofficial_plugins.each do |plugin|
|
||||||
plugin_name = plugin.metadata.name
|
plugin_name = plugin.metadata.name
|
||||||
if require_plugin_assets = CustomWizard::Field.require_assets[plugin_name]
|
if require_plugin_assets = CustomWizard::Field.require_assets[plugin_name]
|
||||||
plugin.each_globbed_asset do |f, is_dir|
|
plugin.each_globbed_asset do |path, is_dir|
|
||||||
next if f.include? "raw.hbs"
|
next if path.include? "raw.hbs"
|
||||||
|
|
||||||
if require_plugin_assets.any? { |dir| f.include?(dir) }
|
if require_plugin_assets.any? { |dir| path.include?(dir) }
|
||||||
if is_dir
|
if is_dir
|
||||||
depend_on(f)
|
depend_on(path)
|
||||||
else
|
else
|
||||||
require_asset(f)
|
require_asset(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {
|
||||||
import { cacheShortUploadUrl } from "pretty-text/upload-short-url";
|
import { cacheShortUploadUrl } from "pretty-text/upload-short-url";
|
||||||
import { alias } from "@ember/object/computed";
|
import { alias } from "@ember/object/computed";
|
||||||
import WizardI18n from "../lib/wizard-i18n";
|
import WizardI18n from "../lib/wizard-i18n";
|
||||||
|
import Site from "../models/site";
|
||||||
|
|
||||||
const uploadMarkdownResolvers = [];
|
const uploadMarkdownResolvers = [];
|
||||||
|
|
||||||
|
@ -55,6 +56,31 @@ export default ComposerEditor.extend({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const siteSettings = this.siteSettings;
|
||||||
|
if (siteSettings.mentionables_enabled) {
|
||||||
|
Site.currentProp("mentionable_items", this.wizard.mentionable_items);
|
||||||
|
const { SEPARATOR } = requirejs(
|
||||||
|
"discourse/plugins/discourse-mentionables/discourse/lib/discourse-markdown/mentionable-items"
|
||||||
|
);
|
||||||
|
const { searchMentionableItem } = requirejs(
|
||||||
|
"discourse/plugins/discourse-mentionables/discourse/lib/mentionable-item-search"
|
||||||
|
);
|
||||||
|
|
||||||
|
$input.autocomplete({
|
||||||
|
template: findRawTemplate("javascripts/mentionable-item-autocomplete"),
|
||||||
|
key: SEPARATOR,
|
||||||
|
afterComplete: (value) => {
|
||||||
|
this.composer.set("reply", value);
|
||||||
|
scheduleOnce("afterRender", () => $input.blur().focus());
|
||||||
|
},
|
||||||
|
transformComplete: (item) => item.model.slug,
|
||||||
|
dataSource: (term) =>
|
||||||
|
term.match(/\s/) ? null : searchMentionableItem(term, siteSettings),
|
||||||
|
triggerRule: (textarea) =>
|
||||||
|
!inCodeBlock(textarea.value, caretPosition(textarea)),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (this._enableAdvancedEditorPreviewSync()) {
|
if (this._enableAdvancedEditorPreviewSync()) {
|
||||||
this._initInputPreviewSync($input, $preview);
|
this._initInputPreviewSync($input, $preview);
|
||||||
} else {
|
} else {
|
||||||
|
@ -293,10 +319,42 @@ export default ComposerEditor.extend({
|
||||||
unshift: true,
|
unshift: true,
|
||||||
sendAction: () => component.set("showHyperlinkBox", true),
|
sendAction: () => component.set("showHyperlinkBox", true),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.siteSettings.mentionables_enabled) {
|
||||||
|
const { SEPARATOR } = requirejs(
|
||||||
|
"discourse/plugins/discourse-mentionables/discourse/lib/discourse-markdown/mentionable-items"
|
||||||
|
);
|
||||||
|
|
||||||
|
toolbar.addButton({
|
||||||
|
id: "insert-mentionable",
|
||||||
|
group: "extras",
|
||||||
|
icon: this.siteSettings.mentionables_composer_button_icon,
|
||||||
|
title: "mentionables.composer.insert.title",
|
||||||
|
perform: () => {
|
||||||
|
this.appEvents.trigger("wizard-editor:insert-text", {
|
||||||
|
fieldId: this.field.id,
|
||||||
|
text: SEPARATOR,
|
||||||
|
});
|
||||||
|
const $textarea = $(
|
||||||
|
document.querySelector(
|
||||||
|
`.composer-field.${this.field.id} textarea.d-editor-input`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$textarea.trigger("keyup.autocomplete");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
previewUpdated($preview) {
|
previewUpdated($preview) {
|
||||||
highlightSyntax($preview[0], this.siteSettings, this.session);
|
highlightSyntax($preview[0], this.siteSettings, this.session);
|
||||||
|
|
||||||
|
if (this.siteSettings.mentionables_enabled) {
|
||||||
|
const { linkSeenMentionableItems } = requirejs(
|
||||||
|
"discourse/plugins/discourse-mentionables/discourse/lib/mentionable-items-preview-styling"
|
||||||
|
);
|
||||||
|
linkSeenMentionableItems($preview, this.siteSettings);
|
||||||
|
}
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import WizardField from "wizard/models/wizard-field";
|
||||||
import { ajax } from "wizard/lib/ajax";
|
import { ajax } from "wizard/lib/ajax";
|
||||||
import Step from "wizard/models/step";
|
import Step from "wizard/models/step";
|
||||||
import EmberObject from "@ember/object";
|
import EmberObject from "@ember/object";
|
||||||
|
import Site from "./site";
|
||||||
|
|
||||||
const CustomWizard = EmberObject.extend({
|
const CustomWizard = EmberObject.extend({
|
||||||
@computed("steps.length")
|
@computed("steps.length")
|
||||||
|
@ -102,11 +103,11 @@ CustomWizard.reopenClass({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Discourse.Site.currentProp("categoriesList", categories);
|
Site.currentProp("categoriesList", categories);
|
||||||
Discourse.Site.currentProp("sortedCategories", categories);
|
Site.currentProp("sortedCategories", categories);
|
||||||
Discourse.Site.currentProp("listByActivity", categories);
|
Site.currentProp("listByActivity", categories);
|
||||||
Discourse.Site.currentProp("categoriesById", categoriesById);
|
Site.currentProp("categoriesById", categoriesById);
|
||||||
Discourse.Site.currentProp(
|
Site.currentProp(
|
||||||
"uncategorized_category_id",
|
"uncategorized_category_id",
|
||||||
wizardJson.uncategorized_category_id
|
wizardJson.uncategorized_category_id
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{{wizard-composer-editor
|
{{wizard-composer-editor
|
||||||
field=field
|
field=field
|
||||||
composer=composer
|
composer=composer
|
||||||
|
wizard=wizard
|
||||||
groupsMentioned=(action "groupsMentioned")
|
groupsMentioned=(action "groupsMentioned")
|
||||||
cannotSeeMention=(action "cannotSeeMention")
|
cannotSeeMention=(action "cannotSeeMention")
|
||||||
importQuote=(action "importQuote")
|
importQuote=(action "importQuote")
|
||||||
|
|
|
@ -81,6 +81,7 @@ img.avatar {
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
color: var(--primary);
|
||||||
|
|
||||||
img {
|
img {
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
|
@ -98,6 +99,7 @@ img.avatar {
|
||||||
}
|
}
|
||||||
&.selected {
|
&.selected {
|
||||||
background-color: var(--tertiary);
|
background-color: var(--tertiary);
|
||||||
|
color: var(--secondary);
|
||||||
}
|
}
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: var(--highlight-low);
|
background-color: var(--highlight-low);
|
||||||
|
|
32
assets/stylesheets/wizard/custom/mentionables.scss
Normale Datei
32
assets/stylesheets/wizard/custom/mentionables.scss
Normale Datei
|
@ -0,0 +1,32 @@
|
||||||
|
span.mentionable-item {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.mentionable-item span {
|
||||||
|
background-color: $primary-low;
|
||||||
|
padding: 3px;
|
||||||
|
border-radius: 3px;
|
||||||
|
color: $primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ac-mentionable-item ul li a {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ac-mentionable-item-name {
|
||||||
|
padding-left: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ac-mentionable-item-image {
|
||||||
|
width: 25px;
|
||||||
|
height: 25px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
img {
|
||||||
|
height: 100%;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,3 +18,4 @@
|
||||||
@import "custom/composer";
|
@import "custom/composer";
|
||||||
@import "custom/events";
|
@import "custom/events";
|
||||||
@import "custom/locations";
|
@import "custom/locations";
|
||||||
|
@import "custom/mentionables";
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
# name: discourse-custom-wizard
|
# name: discourse-custom-wizard
|
||||||
# about: Create custom wizards
|
# about: Create custom wizards
|
||||||
# version: 1.14.0
|
# version: 1.15.0
|
||||||
# authors: Angus McLeod
|
# authors: Angus McLeod
|
||||||
# url: https://github.com/paviliondev/discourse-custom-wizard
|
# url: https://github.com/paviliondev/discourse-custom-wizard
|
||||||
# contact emails: angus@thepavilion.io
|
# contact emails: angus@thepavilion.io
|
||||||
|
|
Laden …
In neuem Issue referenzieren