feat: Implement full width support for widgets

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2024-03-01 11:17:14 +01:00 коммит произвёл Maksim Sukharev
Родитель 6c01ac7b82
Коммит 83a778ba2e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 6349D071889BD1D5
3 изменённых файлов: 25 добавлений и 2 удалений

Просмотреть файл

@ -128,6 +128,10 @@ export default {
}
</script>
<style lang="scss" scoped>
.widget--list {
width: var(--widget-full-width, 100%);
}
.widgets--list.icon-loading {
min-height: 44px;
}

Просмотреть файл

@ -1,6 +1,9 @@
<template>
<div :class="{'toggle-interactive': hasInteractiveView && !isInteractive }">
<div v-if="reference && hasCustomWidget" ref="customWidget" class="widget-custom" />
<div v-if="reference && hasCustomWidget"
ref="customWidget"
class="widget-custom"
:class="{ 'full-width': hasFullWidth }" />
<component :is="referenceWidgetLinkComponent"
v-else-if="!noAccess && reference && reference.openGraphObject && !hasCustomWidget"
@ -30,7 +33,7 @@ import { useIntersectionObserver, useResizeObserver } from '@vueuse/core'
import { RouterLink } from 'vue-router'
import { getRoute } from './autolink.ts'
import { renderWidget, isWidgetRegistered, destroyWidget, hasInteractiveView } from './../../functions/reference/widgets.ts'
import { renderWidget, isWidgetRegistered, destroyWidget, hasInteractiveView, hasFullWidth } from './../../functions/reference/widgets.ts'
import NcButton from '../../components/NcButton/NcButton.vue'
import { t } from '../../l10n.js'
@ -66,6 +69,9 @@ export default {
isInteractive() {
return (!this.interactiveOptIn && this.interactive) || this.showInteractive
},
hasFullWidth() {
return hasFullWidth(this.reference.richObjectType)
},
hasCustomWidget() {
return isWidgetRegistered(this.reference.richObjectType)
},
@ -195,6 +201,12 @@ export default {
.widget-custom {
@include widget;
&.full-width {
width: var(--widget-full-width, 100%) !important;
left: calc( (var(--widget-full-width, 100%) - 100%) / 2 * -1);
position: relative;
}
}
.widget-access {

Просмотреть файл

@ -11,12 +11,14 @@ type widgetDestroyCallback = (el: HTMLElement) => void;
interface WidgetProps {
id: string;
hasInteractiveView: boolean;
fullWidth: boolean;
callback: widgetRenderCallback;
onDestroy: widgetDestroyCallback;
}
interface WidgetPropsOptional {
hasInteractiveView?: boolean;
fullWidth?: boolean;
}
declare global {
@ -38,10 +40,15 @@ const hasInteractiveView = (id: string) => {
return !!window._vue_richtext_widgets[id]?.hasInteractiveView
}
export const hasFullWidth = (id: string) => {
return !!window._vue_richtext_widgets[id]?.fullWidth ?? false
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const registerWidget = (id: string, callback: widgetRenderCallback, onDestroy = (el: HTMLElement) => {}, props: WidgetPropsOptional) => {
const propsWithDefaults = {
hasInteractiveView: true,
fullWidth: false,
...props,
}