Skip to content

Commit a228d24

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 df0cfc4 commit a228d24

8 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/EditorFactory.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ const createRichEditor = ({
4242
connection,
4343
relativePath,
4444
isEmbedded = false,
45+
noLazyImages = false,
4546
} = {}) => {
4647
return new Editor({
4748
editorProps,
4849
extensions: [
49-
RichText.configure({ connection, relativePath, isEmbedded }),
50+
RichText.configure({
51+
connection,
52+
relativePath,
53+
isEmbedded,
54+
noLazyImages,
55+
}),
5056
FocusTrap,
5157
...extensions,
5258
],

src/components/Editor.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ export default defineComponent({
218218
type: Boolean,
219219
default: false,
220220
},
221+
noLazyImages: {
222+
type: Boolean,
223+
default: false,
224+
},
221225
},
222226
223227
setup(props) {
@@ -249,6 +253,7 @@ export default defineComponent({
249253
relativePath: props.relativePath,
250254
extensions,
251255
isEmbedded: props.isEmbedded,
256+
noLazyImages: props.noLazyImages,
252257
})
253258
: createPlainEditor({ language, extensions })
254259
provideEditor(editor)

src/components/Editor/MarkdownContentEditor.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,18 @@ export default {
8383
type: Boolean,
8484
default: false,
8585
},
86+
noLazyImages: {
87+
type: Boolean,
88+
default: false,
89+
},
8690
},
8791
emits: ['update:content'],
8892
8993
setup(props) {
9094
const extensions = [
9195
RichText.configure({
9296
extensions: [History],
97+
noLazyImages: props.noLazyImages,
9398
}),
9499
FocusTrap,
95100
]

src/editor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ window.OCA.Text.createEditor = async function ({
248248
props: null,
249249
},
250250
menubarLinkCustomAction = undefined,
251+
noLazyImages = false,
251252

252253
onCreate = ({ markdown }) => {},
253254
onLoaded = () => {},

src/extensions/RichText.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export default Extension.create({
9898
isEmbedded: this.options.isEmbedded,
9999
}),
100100
Underline,
101-
Image,
102-
ImageInline,
101+
Image.configure({ noLazyImages: this.options.noLazyImages }),
102+
ImageInline.configure({ noLazyImages: this.options.noLazyImages }),
103103
Dropcursor.configure({
104104
color: 'var(--color-primary-element)',
105105
width: 2,

src/nodes/Image.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const Image = TiptapImage.extend({
3636
addOptions() {
3737
return {
3838
...this.parent?.(),
39+
noLazyImages: false,
3940
}
4041
},
4142

src/nodes/ImageInline.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const ImageInline = TiptapImage.extend({
3131
addOptions() {
3232
return {
3333
...this.parent?.(),
34+
noLazyImages: false,
3435
inline: true,
3536
}
3637
},

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)