Skip to content

Commit 88bbc16

Browse files
mejo-silverkszlo
authored andcommitted
fix(editorApi): allow to disable image lazy-loading
Required in Collectives to load all images straight away in print view. Signed-off-by: Jonas <jonas@freesources.org>
1 parent 02d0c13 commit 88bbc16

8 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/EditorFactory.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const createRichEditor = ({
4444
isEmbedded = false,
4545
mentionSearch = undefined,
4646
openLink = undefined,
47+
noLazyImages = false,
4748
} = {}) => {
4849
return new Editor({
4950
editorProps,
@@ -54,6 +55,7 @@ const createRichEditor = ({
5455
isEmbedded,
5556
mentionSearch,
5657
openLink,
58+
noLazyImages,
5759
}),
5860
FocusTrap,
5961
...extensions,

src/components/Editor.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ export default defineComponent({
219219
type: Boolean,
220220
default: false,
221221
},
222+
noLazyImages: {
223+
type: Boolean,
224+
default: false,
225+
},
222226
},
223227
224228
setup(props) {
@@ -255,6 +259,7 @@ export default defineComponent({
255259
isEmbedded: props.isEmbedded,
256260
mentionSearch,
257261
openLink: openLinkHandler.openLink,
262+
noLazyImages: props.noLazyImages,
258263
})
259264
: createPlainEditor({ language, extensions })
260265
provideEditor(editor)

src/components/Editor/MarkdownContentEditor.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export default {
7979
type: Boolean,
8080
default: true,
8181
},
82+
noLazyImages: {
83+
type: Boolean,
84+
default: false,
85+
},
8286
},
8387
emits: ['update:content'],
8488
@@ -88,6 +92,7 @@ export default {
8892
RichText.configure({
8993
extensions: [UndoRedo],
9094
openLink: openLinkHandler.openLink,
95+
noLazyImages: props.noLazyImages,
9196
}),
9297
FocusTrap,
9398
]

src/editor.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ window.OCA.Text.createEditor = async function ({
251251
props: null,
252252
},
253253
menubarLinkCustomAction = undefined,
254+
noLazyImages = false,
254255

255256
onCreate = ({ markdown }) => {},
256257
onLoaded = () => {},
@@ -324,6 +325,7 @@ window.OCA.Text.createEditor = async function ({
324325
mime: 'text/markdown',
325326
active: true,
326327
autofocus,
328+
noLazyImages,
327329
},
328330
scopedSlots,
329331
})
@@ -334,6 +336,7 @@ window.OCA.Text.createEditor = async function ({
334336
relativePath: filePath,
335337
shareToken,
336338
readOnly: data.readOnly,
339+
noLazyImages,
337340
},
338341
scopedSlots,
339342
})

src/extensions/RichText.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export default Extension.create({
6262
isEmbedded: false,
6363
mentionSearch: undefined,
6464
openLink: undefined,
65+
noLazyImages: false,
6566
}
6667
},
6768

@@ -96,8 +97,8 @@ export default Extension.create({
9697
isEmbedded: this.options.isEmbedded,
9798
}),
9899
Underline,
99-
Image,
100-
ImageInline,
100+
Image.configure({ noLazyImages: this.options.noLazyImages }),
101+
ImageInline.configure({ noLazyImages: this.options.noLazyImages }),
101102
Dropcursor.configure({
102103
color: 'var(--color-primary-element)',
103104
width: 2,

src/nodes/Image.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const Image = TiptapImage.extend({
4949
addOptions() {
5050
return {
5151
...this.parent?.(),
52+
noLazyImages: false,
5253
}
5354
},
5455

src/nodes/ImageInline.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const ImageInline = TiptapImage.extend({
4444
addOptions() {
4545
return {
4646
...this.parent?.(),
47+
noLazyImages: false,
4748
inline: true,
4849
}
4950
},

src/nodes/ImageView.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ export default {
273273
this.loadAttachmentMetadata()
274274
this.setupResizeObserver()
275275
276+
// Load image directly if lazy loading is disabled
277+
if (this.extension?.options?.noLazyImages === true) {
278+
this.loadPreview().catch(this.onImageLoadFailure)
279+
return
280+
}
281+
276282
this.$nextTick(() => {
277283
// nextTick is necessary, intersection detection is slightly unreliable without it
278284
const options = {

0 commit comments

Comments
 (0)