mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +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
282 lines
8.8 KiB
Vue
282 lines
8.8 KiB
Vue
<!-- eslint-disable vue/no-v-html -->
|
|
<template>
|
|
<div
|
|
ref="cell"
|
|
class="grid-view__cell grid-field-rich-text__cell active"
|
|
:class="{
|
|
editing: opened && !isModalOpen(),
|
|
'field-rich-text--preview': !opened || isModalOpen(),
|
|
invalid: editing && !isModalOpen() && !isValid(),
|
|
}"
|
|
@contextmenu="stopContextIfEditing($event)"
|
|
>
|
|
<div
|
|
v-if="!opened || isModalOpen()"
|
|
class="grid-field-rich-text__cell-content"
|
|
:class="{
|
|
'grid-field-rich-text__cell-content--preview': !opened || isModalOpen(),
|
|
}"
|
|
v-html="formattedValue"
|
|
/>
|
|
<RichTextEditor
|
|
v-else
|
|
ref="input"
|
|
v-model="richCopy"
|
|
v-prevent-parent-scroll.whenScrollable="editing"
|
|
class="grid-field-rich-text__textarea"
|
|
:class="{ 'grid-field-rich-text__textarea--resizable': editing }"
|
|
:editable="editing && !isModalOpen()"
|
|
:enable-rich-text-formatting="true"
|
|
:enable-images="enableImages"
|
|
:mentionable-users="mentionableUsers"
|
|
:allow-identity-suggestions="false"
|
|
:thin-scrollbar="true"
|
|
:menu-container="getMenuContainer"
|
|
:scrollable-area-element="getScrollableAreaElement"
|
|
:clipboard-markdown-resolver="resolveClipboardMarkdown"
|
|
:upload-file="editing && enableImages ? uploadUserFile : null"
|
|
/>
|
|
<i
|
|
v-if="editing && !isModalOpen()"
|
|
class="baserow-icon-enlarge grid-field-rich-text__textarea-expand-icon"
|
|
@click="($refs.expandedModal.toggle(), resetCellSize())"
|
|
/>
|
|
<div
|
|
v-show="editing && !isModalOpen() && !isValid()"
|
|
class="grid-view__cell-error align-right"
|
|
>
|
|
{{ getError() }}
|
|
</div>
|
|
<slot
|
|
v-if="!isModalOpen()"
|
|
name="default"
|
|
:slot-props="{ editing, opened }"
|
|
></slot>
|
|
<FieldRichTextModal
|
|
ref="expandedModal"
|
|
v-model="richCopy"
|
|
:field="field"
|
|
:error="getModalError()"
|
|
:mentionable-users="mentionableUsers"
|
|
:enable-images="enableImages"
|
|
:upload-file="enableImages ? uploadUserFile : null"
|
|
@hidden="onExpandedModalHidden"
|
|
/>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import RichTextEditor from '@baserow/modules/core/components/editor/RichTextEditor.vue'
|
|
import UserFileService from '@baserow/modules/core/services/userFile'
|
|
import gridField from '@baserow/modules/database/mixins/gridField'
|
|
import gridFieldInput from '@baserow/modules/database/mixins/gridFieldInput'
|
|
import FieldRichTextModal from '@baserow/modules/database/components/view/FieldRichTextModal'
|
|
import { parseMarkdown } from '@baserow/modules/core/editor/markdown'
|
|
import { stripImageUrls } from '@baserow/modules/core/editor/richTextImageUtils'
|
|
import { getRichTextClipboardContent } from '@baserow/modules/database/utils/clipboard'
|
|
|
|
export default {
|
|
components: { RichTextEditor, FieldRichTextModal },
|
|
mixins: [gridField, gridFieldInput],
|
|
props: {
|
|
enableMentions: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
enableImages: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
richCopy: '',
|
|
hasEdits: false,
|
|
applyingExternalValue: false,
|
|
}
|
|
},
|
|
computed: {
|
|
formattedValue() {
|
|
return parseMarkdown(this.value, {
|
|
openLinkOnClick: true,
|
|
enableImages: this.enableImages,
|
|
workspaceUsers: this.mentionableUsers,
|
|
loggedUserId: this.$store.getters['auth/getUserId'],
|
|
})
|
|
},
|
|
workspace() {
|
|
return this.$store.getters['workspace/get'](this.workspaceId)
|
|
},
|
|
mentionableUsers() {
|
|
return this.enableMentions && this.workspace
|
|
? this.$store.getters['workspace/getCollaborators'](this.workspace.id)
|
|
: null
|
|
},
|
|
},
|
|
watch: {
|
|
value: {
|
|
handler(value) {
|
|
// A new value from the outside (a realtime update, an undo) is not a
|
|
// user edit. Without this flag the `richCopy` watcher below would mark
|
|
// the cell dirty, and `beforeSave` would then serialize the editor
|
|
// over the value that just arrived.
|
|
this.applyingExternalValue = true
|
|
// Until the rows refetch after a field is converted to rich text, the
|
|
// cell can still hold a value of the previous type, which the editor
|
|
// would take for its JSON content.
|
|
this.richCopy = typeof value === 'string' ? value : ''
|
|
this.$nextTick(() => {
|
|
this.applyingExternalValue = false
|
|
})
|
|
},
|
|
immediate: true,
|
|
},
|
|
editing(editing) {
|
|
this.hasEdits = false
|
|
if (!editing) {
|
|
this.richCopy = typeof this.value === 'string' ? this.value : ''
|
|
}
|
|
},
|
|
richCopy() {
|
|
if (this.editing && !this.applyingExternalValue) {
|
|
this.hasEdits = true
|
|
}
|
|
},
|
|
},
|
|
mounted() {
|
|
this.cellDragoverHandler = (e) => {
|
|
if (!this.editing) {
|
|
e.preventDefault()
|
|
e.dataTransfer.dropEffect = 'none'
|
|
}
|
|
}
|
|
this.cellDropHandler = (e) => {
|
|
if (!this.editing) {
|
|
e.preventDefault()
|
|
}
|
|
}
|
|
this.$refs.cell.addEventListener('dragover', this.cellDragoverHandler)
|
|
this.$refs.cell.addEventListener('drop', this.cellDropHandler)
|
|
},
|
|
beforeUnmount() {
|
|
this.$refs.cell?.removeEventListener('dragover', this.cellDragoverHandler)
|
|
this.$refs.cell?.removeEventListener('drop', this.cellDropHandler)
|
|
},
|
|
methods: {
|
|
resolveClipboardMarkdown: getRichTextClipboardContent,
|
|
async uploadUserFile(file) {
|
|
return await UserFileService(this.$client).uploadFile(file)
|
|
},
|
|
getMenuContainer() {
|
|
return document.body
|
|
},
|
|
getScrollableAreaElement() {
|
|
return this.$el?.closest('.grid-view__body') ?? null
|
|
},
|
|
isModalOpen() {
|
|
return this.$refs.expandedModal?.isOpen()
|
|
},
|
|
scrollHeight() {
|
|
return {
|
|
sh: this.$refs.container.scrollHeight,
|
|
st: this.$refs.container.scrollTop,
|
|
}
|
|
},
|
|
cancel() {
|
|
// While the modal is open it owns closing (it blocks close on invalid content).
|
|
if (this.isModalOpen()) {
|
|
return
|
|
}
|
|
if (!this.isValid()) {
|
|
this.opened = false
|
|
this.editing = false
|
|
return
|
|
}
|
|
return this.save()
|
|
},
|
|
getError() {
|
|
if (!this.editing) {
|
|
return this.getValidationError(this.value)
|
|
}
|
|
const ref = this.isModalOpen() ? 'expandedModal' : 'input'
|
|
// The backend strips resolved image URLs before checking max_length, so
|
|
// measure the same string or a valid value is rejected.
|
|
return this.getValidationError(
|
|
stripImageUrls(this.$refs[ref]?.serializeToMarkdown())
|
|
)
|
|
},
|
|
getModalError() {
|
|
return this.isModalOpen() ? this.getError() : null
|
|
},
|
|
beforeSave() {
|
|
if (!this.hasEdits) {
|
|
return this.value
|
|
}
|
|
// Set by onExpandedModalHidden: the modal editor is already torn down by
|
|
// the time save() runs from there.
|
|
if (this.$modalMarkdown != null) {
|
|
return this.$modalMarkdown
|
|
}
|
|
// A save reached while the modal is still open (e.g. the cell being
|
|
// unselected) must read the modal, not the stale inline editor.
|
|
if (this.isModalOpen()) {
|
|
return this.$refs.expandedModal?.serializeToMarkdown() ?? this.value
|
|
}
|
|
return this.$refs.input?.serializeToMarkdown() ?? this.value
|
|
},
|
|
afterEdit() {
|
|
this.$nextTick(() => {
|
|
this.$refs.input.focus()
|
|
})
|
|
},
|
|
onExpandedModalHidden() {
|
|
this.preventNextUnselect = true
|
|
if (!this.isValid()) {
|
|
this.opened = false
|
|
this.editing = false
|
|
return
|
|
}
|
|
this.$modalMarkdown =
|
|
this.$refs.expandedModal?.serializeToMarkdown() ?? null
|
|
this.save()
|
|
this.$modalMarkdown = null
|
|
},
|
|
onPaste() {
|
|
// Prevent the grid paste handler from intercepting TipTap editor pastes.
|
|
return this.editing
|
|
},
|
|
canSaveByPressingEnter() {
|
|
return false
|
|
},
|
|
resetCellSize() {
|
|
// remove any custom width and height set by the user resizing the cell
|
|
this.$refs.input.$el.style.width = ''
|
|
this.$refs.input.$el.style.height = ''
|
|
},
|
|
canUnselectByClickingOutside(event) {
|
|
// The RichTextEditorBubbleMenuContext component is a context menu and so it's not
|
|
// a direct child of the RichTextEditorBubbleMenu component. This means that the
|
|
// when you click on an item, we have to prevent the next unselect event from
|
|
// happening otherwise the cell will lose focus and the editor will close.
|
|
if (this.preventNextUnselect || event === this.preventedUnselectEvent) {
|
|
this.preventNextUnselect = false
|
|
// A wrapping cell (the AI field) asks again about the same click.
|
|
this.preventedUnselectEvent = event
|
|
return false
|
|
}
|
|
|
|
return (
|
|
!this.editing ||
|
|
(!this.$refs.input?.isEventTargetInside(event) && !this.isModalOpen())
|
|
)
|
|
},
|
|
canSelectNext(event) {
|
|
if (this.isModalOpen()) {
|
|
return false
|
|
}
|
|
return !this.editing || event.key === 'Tab'
|
|
},
|
|
},
|
|
}
|
|
</script>
|