Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): requestAnimationFrame in onResize callbacks #5750

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,12 @@ export default {
subscribe('text:image-node:delete', this.onDeleteImageNode)
this.emit('update:loaded', true)
useResizeObserver(this.$el, (entries) => {
const entry = entries[0]
const { width } = entry.contentRect
const maxWidth = width - 36
this.$el.style.setProperty('--widget-full-width', `${maxWidth}px`)
window.requestAnimationFrame(() => {
const entry = entries[0]
const { width } = entry.contentRect
const maxWidth = width - 36
this.$el.style.setProperty('--widget-full-width', `${maxWidth}px`)
})
})
subscribe('text:translate-modal:show', this.showTranslateModal)
},
Expand Down
21 changes: 9 additions & 12 deletions src/components/Editor/EditorOutline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@
</template>

<script>
import debounce from 'debounce'
import { NcButton } from '@nextcloud/vue'
import TableOfContents from './TableOfContents.vue'
import { useOutlineStateMixin, useOutlineActions } from './Wrapper.provider.js'
import { Close } from './../icons.js'
import useStore from '../../mixins/store.js'

const onResize = debounce((context) => {
context.mobile = context.$el.parentElement.clientWidth < 320
}, 10)

export default {
name: 'EditorOutline',
components: {
Expand All @@ -39,20 +34,22 @@ export default {
mobile: false,
}),
mounted() {
this.$onResize = () => {
onResize(this)
}

this.$resizeObserver = new ResizeObserver(this.$onResize)
this.$resizeObserver = new ResizeObserver(this.onResize)
this.$resizeObserver.observe(this.$el.parentElement)

this.$onResize()
this.onResize()
},
beforeDestroy() {
this.$resizeObserver.unobserve(this.$el.parentElement)
this.$resizeObserver = null
this.$onResize = null
},
methods: {
onResize([el]) {
window.requestAnimationFrame(() => {
this.mobile = el.clientWidth < 320
})
},
},
}
</script>

Expand Down
19 changes: 10 additions & 9 deletions src/components/Menu/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,18 @@ export default {
},
methods: {
onResize(entries) {
const entry = entries[0]
const { width } = entry.contentRect
window.requestAnimationFrame(() => {
const entry = entries[0]
const { width } = entry.contentRect

// leave some buffer - this is necessary so the bar does not wrap during resizing
const spaceToFill = width - 4
const spacePerSlot = this.$isMobile ? 44 : 46
const slots = Math.floor(spaceToFill / spacePerSlot)
// leave some buffer - this is necessary so the bar does not wrap during resizing
const spaceToFill = width - 4
const spacePerSlot = this.$isMobile ? 44 : 46
const slots = Math.floor(spaceToFill / spacePerSlot)

// Leave one slot empty for the three dot menu
this.iconsLimit = slots - 1
this.isReady = true
// Leave one slot empty for the three dot menu
this.iconsLimit = slots - 1
})
},
showHelp() {
this.displayHelp = true
Expand Down
Loading