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

perf: Optimize lazy imports for reference widgets #825

Merged
merged 1 commit into from
Feb 21, 2024
Merged
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
21 changes: 11 additions & 10 deletions src/reference.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { registerCustomPickerElement, registerWidget, NcCustomPickerRenderResult } from '@nextcloud/vue/dist/Components/NcRichText.js'
import Vue from 'vue'

import TablesSmartPicker from './views/SmartPicker.vue'
import { registerCustomPickerElement, registerWidget, NcCustomPickerRenderResult } from '@nextcloud/vue/dist/Functions/registerReference.js'

__webpack_nonce__ = btoa(OC.requestToken) // eslint-disable-line
__webpack_public_path__ = OC.linkTo('tables', 'js/') // eslint-disable-line

registerWidget('tables_link', async (el, { richObjectType, richObject, accessible }) => {
const { default: Vue } = await import(/* webpackChunkName: "reference-table-lazy" */'vue')
const { default: TableReferenceWidget } = await import(/* webpackChunkName: "reference-table-lazy" */'./views/LinkReferenceWidget.vue')
const { default: Vue } = await import('vue')
const { default: TableReferenceWidget } = await import('./views/LinkReferenceWidget.vue')
Vue.mixin({ methods: { t, n } })
const Widget = Vue.extend(TableReferenceWidget)
new Widget({
Expand All @@ -20,9 +17,11 @@ registerWidget('tables_link', async (el, { richObjectType, richObject, accessibl
}).$mount(el)
})

registerWidget('tables_content', async (el, { richObjectType, richObject, accessible }) => {
registerWidget('tables_content', async (el, { richObjectType, richObject, accessible, interactive = true }) => {
const { default: Vue } = await import(/* webpackChunkName: "reference-table-lazy" */'vue')
const { default: TableReferenceWidget } = await import(/* webpackChunkName: "reference-table-lazy" */'./views/ContentReferenceWidget.vue')
const { default: TableReferenceWidget } = interactive
? await import(/* webpackChunkName: "reference-table-lazy" */'./views/ContentReferenceWidget.vue')
: await import(/* webpackChunkName: "reference-table-lazy" */'./views/LinkReferenceWidget.vue')
Vue.mixin({ methods: { t, n } })
const Widget = Vue.extend(TableReferenceWidget)
new Widget({
Expand All @@ -32,9 +31,11 @@ registerWidget('tables_content', async (el, { richObjectType, richObject, access
accessible,
},
}).$mount(el)
})
}, () => {}, { hasInteractiveView: true })

registerCustomPickerElement('tables-ref-tables', (el, { providerId, accessible }) => {
registerCustomPickerElement('tables-ref-tables', async (el, { providerId, accessible }) => {
const { default: Vue } = await import('vue')
const { default: TablesSmartPicker } = await import('./views/SmartPicker.vue')
const Element = Vue.extend(TablesSmartPicker)
const vueElement = new Element({
propsData: {
Expand Down
Loading