diff --git a/l10n/messages.pot b/l10n/messages.pot index e124504676..70a6639a33 100644 --- a/l10n/messages.pot +++ b/l10n/messages.pot @@ -124,6 +124,9 @@ msgstr "" msgid "Emoji picker" msgstr "" +msgid "Enable interactive view" +msgstr "" + msgid "Enter link" msgstr "" diff --git a/src/components/NcRichText/NcReferenceList.vue b/src/components/NcRichText/NcReferenceList.vue index 48a73f1f00..1f59b950cb 100644 --- a/src/components/NcRichText/NcReferenceList.vue +++ b/src/components/NcRichText/NcReferenceList.vue @@ -1,7 +1,7 @@ @@ -35,6 +35,10 @@ export default { default: false, }, interactive: { + type: Boolean, + default: true, + }, + interactiveOptIn: { type: Boolean, default: false, }, @@ -65,12 +69,7 @@ export default { return this.values[0] ?? null }, displayedReferences() { - return this.values.slice(0, this.limit).map(reference => { - return { - ...reference, - interactive: this.interactive, - } - }) + return this.values.slice(0, this.limit) }, fallbackReference() { return { @@ -129,6 +128,10 @@ export default { } diff --git a/src/components/NcRichText/index.js b/src/components/NcRichText/index.js index 4d9580c093..56b11ea8c9 100644 --- a/src/components/NcRichText/index.js +++ b/src/components/NcRichText/index.js @@ -22,7 +22,7 @@ import NcRichText from './NcRichText.vue' -import { registerWidget, renderWidget, isWidgetRegistered } from './../../functions/reference/widgets.js' +import { registerWidget, renderWidget, isWidgetRegistered } from './../../functions/reference/widgets.ts' import NcReferenceList from './NcReferenceList.vue' import NcReferenceWidget from './NcReferenceWidget.vue' import NcReferencePicker from './NcReferencePicker/NcReferencePicker.vue' diff --git a/src/functions/reference/index.js b/src/functions/reference/index.js index 7d6e54beb2..24077ae1e5 100644 --- a/src/functions/reference/index.js +++ b/src/functions/reference/index.js @@ -1,4 +1,4 @@ -import { registerWidget, renderWidget, isWidgetRegistered } from './widgets.js' +import { registerWidget, renderWidget, isWidgetRegistered, hasInteractiveView } from './widgets.ts' import { getLinkWithPicker } from './referencePickerModal.js' import { getProvider, @@ -18,6 +18,7 @@ export { registerWidget, renderWidget, isWidgetRegistered, + hasInteractiveView, NcCustomPickerRenderResult, registerCustomPickerElement, diff --git a/src/functions/reference/widgets.js b/src/functions/reference/widgets.js deleted file mode 100644 index 5b304f271c..0000000000 --- a/src/functions/reference/widgets.js +++ /dev/null @@ -1,54 +0,0 @@ -if (!window._vue_richtext_widgets) { - window._vue_richtext_widgets = {} -} - -const isWidgetRegistered = (id) => { - return !!window._vue_richtext_widgets[id] -} - -const registerWidget = (id, callback, onDestroy = (el) => {}) => { - if (window._vue_richtext_widgets[id]) { - console.error('Widget for id ' + id + ' already registered') - return - } - - window._vue_richtext_widgets[id] = { - id, - callback, - onDestroy, - } -} - -const renderWidget = (el, { richObjectType, richObject, accessible, interactive }) => { - if (richObjectType === 'open-graph') { - return - } - - if (!window._vue_richtext_widgets[richObjectType]) { - console.error('Widget for rich object type ' + richObjectType + ' not registered') - return - } - - window._vue_richtext_widgets[richObjectType].callback(el, { richObjectType, richObject, accessible, interactive }) -} - -const destroyWidget = (richObjectType, el) => { - if (richObjectType === 'open-graph') { - return - } - - if (!window._vue_richtext_widgets[richObjectType]) { - return - } - - window._vue_richtext_widgets[richObjectType].onDestroy(el) -} - -window._registerWidget = registerWidget - -export { - registerWidget, - renderWidget, - destroyWidget, - isWidgetRegistered, -} diff --git a/src/functions/reference/widgets.ts b/src/functions/reference/widgets.ts new file mode 100644 index 0000000000..85095eb9dd --- /dev/null +++ b/src/functions/reference/widgets.ts @@ -0,0 +1,103 @@ +interface WidgetRenderProperties { + richObjectType: string; + richObject: object; + accessible: boolean; + interactive: boolean; +} + +type widgetRenderCallback = (el: HTMLElement, properties: WidgetRenderProperties) => void; +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 { + interface Window { + _vue_richtext_widgets: Record; + _registerWidget: (id: string, callback: widgetRenderCallback, onDestroy: widgetDestroyCallback, props: WidgetPropsOptional) => void; + } +} + +if (!window._vue_richtext_widgets) { + window._vue_richtext_widgets = {} +} + +const isWidgetRegistered = (id: string) => { + return !!window._vue_richtext_widgets[id] +} + +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, + } + + if (window._vue_richtext_widgets[id]) { + console.error('Widget for id ' + id + ' already registered') + return + } + + window._vue_richtext_widgets[id] = { + id, + callback, + onDestroy, + ...propsWithDefaults, + } +} + +const renderWidget = (el: HTMLElement, { richObjectType, richObject, accessible, interactive }) => { + if (richObjectType === 'open-graph') { + return + } + + if (!window._vue_richtext_widgets[richObjectType]) { + console.error('Widget for rich object type ' + richObjectType + ' not registered') + return + } + + window._vue_richtext_widgets[richObjectType].callback(el, { richObjectType, richObject, accessible, interactive }) +} + +const destroyWidget = (richObjectType: string, el: HTMLElement) => { + if (richObjectType === 'open-graph') { + return + } + + if (!window._vue_richtext_widgets[richObjectType]) { + return + } + + window._vue_richtext_widgets[richObjectType].onDestroy(el) +} + +window._registerWidget = (id: string, callback: widgetRenderCallback, onDestroy: widgetDestroyCallback, props: WidgetPropsOptional) => { + registerWidget(id, callback, onDestroy, props) +} + +export { + registerWidget, + renderWidget, + destroyWidget, + isWidgetRegistered, + hasInteractiveView, +} diff --git a/src/functions/registerReference/index.js b/src/functions/registerReference/index.js index 2d6f64f850..ec3ad70905 100644 --- a/src/functions/registerReference/index.js +++ b/src/functions/registerReference/index.js @@ -3,7 +3,7 @@ export { renderWidget, destroyWidget, isWidgetRegistered, -} from './../reference/widgets.js' +} from './../reference/widgets.ts' export { NcCustomPickerRenderResult, registerCustomPickerElement,