mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 16:28:31 +00:00
* feat(database): assign and mention identities behind a field option - Collaborator fields get `include_identities` and long text fields `long_text_include_identities`, both off by default. - With the option on, active identities of the workspace can be assigned or suggested as mentions; they are shown with their icon and renamed in realtime, and they never receive notifications. - Turning the collaborator option off backs up the column, deletes the identity assignments and strips identities from the view defaults, so the update can be undone. - Identities can author row comments and be mentioned in them. - Exports write an identity as `Name <identity>`. * refactor: hide internal emails in collaborator exports through one check * fix: import a personal view only for a person, without a query per owner * fix: show collaborator identities with the icon of the user subject type * refactor: drop a redundant local import of the core handler * fix: unify identity icons and space field options * fix: keep identity field menus and saved mentions readable * fix: limit identity mention suggestions to row comments * perf: prefetch available collaborators once per workspace * fix: use workspace members as authors of generated rows * fix: resolve linked collaborator values by member email * fix: use workspace collaborators for field pickers and paste * refactor: move identity avatar styles to the avatar stylesheet * fix: address review feedback on identity collaborators
112 lines
3.3 KiB
Vue
112 lines
3.3 KiB
Vue
<!-- eslint-disable vue/no-v-html -->
|
|
<template>
|
|
<div
|
|
class="field-rich-text--preview grid-view__cell grid-field-rich-text__cell"
|
|
>
|
|
<div
|
|
class="grid-field-rich-text__cell-content grid-field-rich-text__cell-content--preview"
|
|
v-html="renderFormattedValue()"
|
|
></div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { parseMarkdown } from '@baserow/modules/core/editor/markdown'
|
|
import {
|
|
IMAGE_PLACEHOLDER,
|
|
replaceImagesWithPlaceholder,
|
|
stripImageUrls,
|
|
trimUnfinishedImageRef,
|
|
} from '@baserow/modules/core/editor/richTextImageUtils'
|
|
|
|
const PREVIEW_LENGTH = 200
|
|
// Bounds the work on every scroll render, with room for long signed image URLs.
|
|
const RAW_PREVIEW_LENGTH = 5000
|
|
|
|
/**
|
|
* The start of the value as the cell shows it, each image as its placeholder.
|
|
*
|
|
* @param {string} value The cell value, with resolved image URLs.
|
|
* @return {string} Markdown of at most PREVIEW_LENGTH chars plus an ellipsis.
|
|
*/
|
|
function previewMarkdown(value) {
|
|
const rawCut = value.length > RAW_PREVIEW_LENGTH
|
|
const visible = replaceImagesWithPlaceholder(
|
|
rawCut ? trimUnfinishedImageRef(value.slice(0, RAW_PREVIEW_LENGTH)) : value
|
|
)
|
|
if (!rawCut && visible.length <= PREVIEW_LENGTH) {
|
|
return visible
|
|
}
|
|
const placeholderStart = visible.lastIndexOf(
|
|
IMAGE_PLACEHOLDER,
|
|
PREVIEW_LENGTH - 1
|
|
)
|
|
const end =
|
|
placeholderStart >= 0 &&
|
|
placeholderStart + IMAGE_PLACEHOLDER.length > PREVIEW_LENGTH
|
|
? placeholderStart
|
|
: PREVIEW_LENGTH
|
|
return `${visible.slice(0, end).trimEnd()}...`
|
|
}
|
|
|
|
/**
|
|
* The start of the value as the cell shows it, each image as its markdown.
|
|
*
|
|
* @param {string} value The cell value, with resolved image URLs.
|
|
* @return {string} Markdown of at most PREVIEW_LENGTH chars plus an ellipsis.
|
|
*/
|
|
function literalPreviewMarkdown(value) {
|
|
const rawCut = value.length > RAW_PREVIEW_LENGTH
|
|
const visible = stripImageUrls(value.slice(0, RAW_PREVIEW_LENGTH))
|
|
return rawCut || visible.length > PREVIEW_LENGTH
|
|
? `${visible.slice(0, PREVIEW_LENGTH).trimEnd()}...`
|
|
: visible
|
|
}
|
|
|
|
export default {
|
|
name: 'FunctionalGridViewFieldRichText',
|
|
props: {
|
|
value: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
workspaceId: {
|
|
type: Number,
|
|
required: true,
|
|
},
|
|
enableMentions: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
enableImages: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
},
|
|
methods: {
|
|
renderFormattedValue() {
|
|
const { value, workspaceId, enableMentions, enableImages } = this
|
|
const workspace = this.$store.getters['workspace/get'](workspaceId)
|
|
const loggedUserId = this.$store.getters['auth/getUserId']
|
|
// Until the rows refetch after a field is converted to rich text, the
|
|
// cell can still hold a value of the previous type.
|
|
const textValue = typeof value === 'string' ? value : ''
|
|
// Replacing an image nested in an alt can complete the image around it.
|
|
const markdown = enableImages
|
|
? replaceImagesWithPlaceholder(previewMarkdown(textValue))
|
|
: literalPreviewMarkdown(textValue)
|
|
|
|
return parseMarkdown(markdown, {
|
|
openLinkOnClick: false,
|
|
enableImages: false,
|
|
workspaceUsers:
|
|
enableMentions && workspace
|
|
? this.$store.getters['workspace/getCollaborators'](workspace.id)
|
|
: null,
|
|
loggedUserId,
|
|
})
|
|
},
|
|
},
|
|
}
|
|
</script>
|