mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-05 15:24:22 +00:00
[EZQMS-287] Added generic menu items and collaborator utils (#3837)
* [EZQMS-287] Added generic menu items and collaborator utils Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com> * Added copyright Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com> * [EZQMS-287] Formatting and component fixes Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com> * Fixed menu popups Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com> * Addressed review comments Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com> * Formatting Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com> * Changed temp provider disposal Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com> * Formatting Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com> --------- Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
This commit is contained in:
parent
aa14547fd0
commit
98564ba10a
@ -39,6 +39,7 @@
|
|||||||
import textEditorPlugin from '../plugin'
|
import textEditorPlugin from '../plugin'
|
||||||
import { TiptapCollabProvider } from '../provider'
|
import { TiptapCollabProvider } from '../provider'
|
||||||
import { CollaborationIds, TextFormatCategory, TextNodeAction } from '../types'
|
import { CollaborationIds, TextFormatCategory, TextNodeAction } from '../types'
|
||||||
|
import { copyDocumentContent, copyDocumentField } from '../utils'
|
||||||
|
|
||||||
import { calculateDecorations } from './diff/decorations'
|
import { calculateDecorations } from './diff/decorations'
|
||||||
import { noSelectionRender } from './editor/collaboration'
|
import { noSelectionRender } from './editor/collaboration'
|
||||||
@ -150,7 +151,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function takeSnapshot (snapshotId: string) {
|
export function takeSnapshot (snapshotId: string) {
|
||||||
provider.copyContent(documentId, snapshotId)
|
copyDocumentContent(documentId, snapshotId, { provider }, initialContentId)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function copyField (srcFieldId: string, dstFieldId: string) {
|
||||||
|
copyDocumentField(documentId, srcFieldId, dstFieldId, { provider }, initialContentId)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unregisterPlugin (nameOrPluginKey: string | PluginKey) {
|
export function unregisterPlugin (nameOrPluginKey: string | PluginKey) {
|
||||||
|
@ -31,6 +31,7 @@ export { default as TextEditorStyleToolbar } from './components/TextEditorStyleT
|
|||||||
export { default as AttachIcon } from './components/icons/Attach.svelte'
|
export { default as AttachIcon } from './components/icons/Attach.svelte'
|
||||||
export { default } from './plugin'
|
export { default } from './plugin'
|
||||||
export * from './types'
|
export * from './types'
|
||||||
|
export * from './utils'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
IsEmptyContentExtension,
|
IsEmptyContentExtension,
|
||||||
|
@ -31,6 +31,14 @@ export class TiptapCollabProvider extends HocuspocusProvider {
|
|||||||
this.sendStateless(JSON.stringify(payload))
|
this.sendStateless(JSON.stringify(payload))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copyField (documentId: string, srcFieldId: string, dstFieldId: string): void {
|
||||||
|
const payload = {
|
||||||
|
action: 'document.field.copy',
|
||||||
|
params: { documentId, srcFieldId, dstFieldId }
|
||||||
|
}
|
||||||
|
this.sendStateless(JSON.stringify(payload))
|
||||||
|
}
|
||||||
|
|
||||||
destroy (): void {
|
destroy (): void {
|
||||||
this.configuration.websocketProvider.disconnect()
|
this.configuration.websocketProvider.disconnect()
|
||||||
super.destroy()
|
super.destroy()
|
||||||
|
78
packages/text-editor/src/utils.ts
Normal file
78
packages/text-editor/src/utils.ts
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
//
|
||||||
|
// Copyright © 2023 Hardcore Engineering Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License. You may
|
||||||
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
//
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import { onStatelessParameters } from '@hocuspocus/provider'
|
||||||
|
import * as Y from 'yjs'
|
||||||
|
|
||||||
|
import { TiptapCollabProvider } from './provider'
|
||||||
|
|
||||||
|
type ProviderData = (
|
||||||
|
| {
|
||||||
|
provider: TiptapCollabProvider
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
collaboratorURL: string
|
||||||
|
token: string
|
||||||
|
}
|
||||||
|
) & { ydoc?: Y.Doc }
|
||||||
|
|
||||||
|
function getProvider (documentId: string, providerData: ProviderData, initialContentId?: string): TiptapCollabProvider {
|
||||||
|
if (!('provider' in providerData)) {
|
||||||
|
const provider = new TiptapCollabProvider({
|
||||||
|
url: providerData.collaboratorURL,
|
||||||
|
name: documentId,
|
||||||
|
document: providerData.ydoc ?? new Y.Doc(),
|
||||||
|
token: providerData.token,
|
||||||
|
parameters: {
|
||||||
|
initialContentId: initialContentId ?? ''
|
||||||
|
},
|
||||||
|
onStateless (data: onStatelessParameters) {
|
||||||
|
try {
|
||||||
|
const payload = JSON.parse(data.payload)
|
||||||
|
if ('status' in payload && payload.status === 'completed') {
|
||||||
|
provider.destroy()
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to check provider operation status', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return provider
|
||||||
|
} else {
|
||||||
|
return providerData.provider
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function copyDocumentField (
|
||||||
|
documentId: string,
|
||||||
|
srcFieldId: string,
|
||||||
|
dstFieldId: string,
|
||||||
|
providerData: ProviderData,
|
||||||
|
initialContentId?: string
|
||||||
|
): void {
|
||||||
|
const provider = getProvider(documentId, providerData, initialContentId)
|
||||||
|
provider.copyField(documentId, srcFieldId, dstFieldId)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function copyDocumentContent (
|
||||||
|
documentId: string,
|
||||||
|
snapshotId: string,
|
||||||
|
providerData: ProviderData,
|
||||||
|
initialContentId?: string
|
||||||
|
): void {
|
||||||
|
const provider = getProvider(documentId, providerData, initialContentId)
|
||||||
|
provider.copyContent(documentId, snapshotId)
|
||||||
|
}
|
@ -16,9 +16,8 @@
|
|||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import { Doc, Ref } from '@hcengineering/core'
|
import { Doc, Ref } from '@hcengineering/core'
|
||||||
import type { Asset, IntlString } from '@hcengineering/platform'
|
import type { Asset, IntlString } from '@hcengineering/platform'
|
||||||
import type { AnySvelteComponent } from '@hcengineering/ui'
|
import type { AnySvelteComponent, Action } from '@hcengineering/ui'
|
||||||
import { Icon, IconChevronDown, IconMoreH, Label, Menu, showPopup } from '@hcengineering/ui'
|
import { Icon, IconChevronDown, IconMoreH, Label, Menu, showPopup } from '@hcengineering/ui'
|
||||||
import { Action } from '@hcengineering/view'
|
|
||||||
|
|
||||||
export let _id: Ref<Doc> | undefined = undefined
|
export let _id: Ref<Doc> | undefined = undefined
|
||||||
export let icon: Asset | AnySvelteComponent | undefined = undefined
|
export let icon: Asset | AnySvelteComponent | undefined = undefined
|
||||||
|
Loading…
Reference in New Issue
Block a user