Skip to content

Commit dd53497

Browse files
committed
FEATURE: rich editor image toolbar for scale/alt text/delete
1 parent 4637c3c commit dd53497

File tree

5 files changed

+29
-28
lines changed

5 files changed

+29
-28
lines changed

app/assets/javascripts/discourse/app/static/prosemirror/components/image-node-view.gjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ export default class ImageNodeView extends Component {
299299
selectNode() {
300300
this.nodeView.dom.classList.add("ProseMirror-selectednode");
301301
this.showMenu();
302+
this.editAltText();
302303
}
303304

304305
deselectNode() {

app/assets/javascripts/discourse/app/static/prosemirror/components/prosemirror-editor.gjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ const AUTOCOMPLETE_KEY_DOWN_SUPPRESS = ["Enter", "Tab"];
5959
* @property {ProsemirrorEditorArgs} Args
6060
*/
6161

62+
/**
63+
* @typedef {Object} GlimmerNodeViewDef
64+
* @property {HTMLElement} element The DOM element where the node view will be rendered
65+
* @property {any} component The Glimmer component class
66+
* @property {Record<string, unknown>} data Data to pass to the component
67+
*/
68+
6269
/**
6370
* @extends {Component<ProsemirrorEditorSignature>}
6471
*/
@@ -73,6 +80,7 @@ export default class ProsemirrorEditor extends Component {
7380
schema = createSchema(this.extensions, this.args.includeDefault);
7481
view;
7582

83+
/** @type {TrackedArray<GlimmerNodeViewDef>} */
7684
glimmerNodeViews = new TrackedArray();
7785
#lastSerialized;
7886
/** @type {undefined | (() => void)} */

app/assets/stylesheets/common/rich-editor/rich-editor.scss

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269

270270
.fk-d-menu[data-identifier="composer-image-alt-text"] {
271271
min-width: calc(100% - 1rem);
272-
background-color: rgba(var(--primary-rgb), 0.2);
272+
background-color: rgb(var(--primary-rgb), 0.2);
273273
backdrop-filter: blur(8px);
274274
color: var(--secondary);
275275
isolation: auto;
@@ -309,11 +309,6 @@
309309
display: flex;
310310
position: relative;
311311

312-
&.--expanded {
313-
display: flex;
314-
align-items: center;
315-
}
316-
317312
&__field {
318313
height: 1.5em;
319314
flex: 1;
@@ -481,10 +476,3 @@ span:focus .fake-cursor {
481476
position: relative;
482477
z-index: 1;
483478
}
484-
485-
.image-alt-text-input {
486-
&.--expanded {
487-
display: flex;
488-
align-items: center;
489-
}
490-
}

config/locales/client.en.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2880,6 +2880,12 @@ en:
28802880
aria_label: Alt text for image
28812881
title: "Add image description"
28822882

2883+
image_toolbar:
2884+
alt_text: "Add image description"
2885+
zoom_out: "Decrease image size"
2886+
zoom_in: "Increase image size"
2887+
remove: "Remove image"
2888+
28832889
image_scale_button: "Scale image to %{percent}%"
28842890
delete_image_button: Delete Image
28852891
toggle_image_grid: Toggle image grid
@@ -3308,7 +3314,7 @@ en:
33083314
hot: "There are no hot topics."
33093315
filter: "There are no topics."
33103316
education:
3311-
topic_tracking_preferences: "You can view and change your new topic tracking settings in <a href=\"%{basePath}/my/preferences/tracking\">your preferences</a>."
3317+
topic_tracking_preferences: 'You can view and change your new topic tracking settings in <a href="http://github.com/%{basePath}/my/preferences/tracking">your preferences</a>.'
33123318
unread: "Nothing left unread...impressive!"
33133319
new_new: "Nothing new at the moment...check back soon!"
33143320
new: "Nothing new at the moment...check back soon!"

lib/freedom_patches/propshaft_patches.rb

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@ def already_digested?
1212
Module.new do
1313
def compute_asset_path(path, options = {})
1414
attempts = 0
15-
begin
16-
super
17-
rescue Propshaft::MissingAssetError => e
18-
if Rails.env.development?
19-
# Ember-cli might've replaced the assets
20-
Rails.application.assets.load_path.send(:clear_cache)
21-
attempts += 1
22-
retry if attempts < 3
23-
elsif Rails.env.test?
24-
# Assets might not be compiled in test mode. Just return a fake path
25-
"/assets/#{path.sub(".", "-aaaaaaaa.")}"
26-
else
27-
raise e
28-
end
15+
super
16+
rescue Propshaft::MissingAssetError => e
17+
if Rails.env.development?
18+
# Ember-cli might've replaced the assets
19+
Rails.application.assets.load_path.send(:clear_cache)
20+
attempts += 1
21+
retry if attempts < 3
22+
elsif Rails.env.test?
23+
# Assets might not be compiled in test mode. Just return a fake path
24+
"/assets/#{path.sub(".", "-aaaaaaaa.")}"
25+
else
26+
raise e
2927
end
3028
end
3129
end,

0 commit comments

Comments
 (0)