mirror of
https://github.com/hcengineering/platform.git
synced 2026-10-01 05:55:09 +02:00
qfix: remove indexeddb provider (#10073)
* qfix: remove indexeddb provider Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com> * fix: remove cloud provider Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com> --------- Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
@@ -85,14 +85,12 @@
|
||||
"prosemirror-codemark": "^0.4.2",
|
||||
"y-protocols": "^1.0.6",
|
||||
"y-prosemirror": "^1.3.7",
|
||||
"y-websocket": "^2.1.0",
|
||||
"yjs": "^13.6.27",
|
||||
"fast-equals": "^5.2.2",
|
||||
"rfc6902": "^5.0.1",
|
||||
"diff": "^5.1.0",
|
||||
"slugify": "^1.6.6",
|
||||
"lib0": "^0.2.109",
|
||||
"y-indexeddb": "^9.0.12",
|
||||
"lowlight": "^3.3.0",
|
||||
"mermaid": "^11.12.0",
|
||||
"@hcengineering/theme": "^0.7.0",
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
import { deleteAttachment } from '../command/deleteAttachment'
|
||||
import { textEditorCommandHandler } from '../commands'
|
||||
import { Provider } from '../provider/types'
|
||||
import { createLocalProvider, createRemoteProvider } from '../provider/utils'
|
||||
import { createRemoteProvider } from '../provider/utils'
|
||||
import { addTableHandler } from '../utils'
|
||||
|
||||
import { noSelectionRender, renderCursor } from './editor/collaboration'
|
||||
@@ -124,23 +124,17 @@
|
||||
const ydoc = getContext<YDoc>(CollaborationIds.Doc) ?? new YDoc({ guid: generateId(), gc: false })
|
||||
const contextProvider = getContext<Provider>(CollaborationIds.Provider)
|
||||
|
||||
const localProvider = createLocalProvider(ydoc, collaborativeDoc)
|
||||
const remoteProvider = contextProvider ?? createRemoteProvider(ydoc, collaborativeDoc, content)
|
||||
const provider = contextProvider ?? createRemoteProvider(ydoc, collaborativeDoc, content)
|
||||
|
||||
let contentError = false
|
||||
let localSynced = false
|
||||
let remoteSynced = false
|
||||
let synced = false
|
||||
let editorReady = false
|
||||
|
||||
$: loading = !localSynced
|
||||
$: editable = !readonly && !contentError && remoteSynced && editorReady && hasAccountRole(account, AccountRole.User)
|
||||
$: loading = !synced
|
||||
$: editable = !readonly && !contentError && synced && editorReady && hasAccountRole(account, AccountRole.User)
|
||||
|
||||
void localProvider.loaded.then(() => (localSynced = true))
|
||||
void remoteProvider.loaded.then(() => (remoteSynced = true))
|
||||
|
||||
void Promise.all([localProvider.loaded, remoteProvider.loaded]).then(() => {
|
||||
dispatch('loaded')
|
||||
})
|
||||
void provider.loaded.then(() => (synced = true))
|
||||
void provider.loaded.then(() => dispatch('loaded'))
|
||||
|
||||
let editor: Editor
|
||||
let element: HTMLElement
|
||||
@@ -313,14 +307,12 @@
|
||||
|
||||
const throttle = new ThrottledCaller(100)
|
||||
const updateLastUpdateTime = (): void => {
|
||||
remoteProvider.awareness?.setLocalStateField('lastUpdate', Date.now())
|
||||
provider.awareness?.setLocalStateField('lastUpdate', Date.now())
|
||||
}
|
||||
|
||||
interface SavedBoardRaw {
|
||||
ydoc: YDoc
|
||||
localProvider: Provider
|
||||
remoteProvider: Provider
|
||||
localSynced: boolean
|
||||
remoteSynced: boolean
|
||||
}
|
||||
const savedBoards: Record<string, SavedBoardRaw> = {}
|
||||
@@ -337,10 +329,8 @@
|
||||
objectId: id as Ref<Doc>,
|
||||
objectAttr: 'content'
|
||||
}
|
||||
const localProvider = createLocalProvider(ydoc, collabId)
|
||||
const remoteProvider = createRemoteProvider(ydoc, collabId, id as Ref<Blob>)
|
||||
savedBoards[id] = { ydoc, localProvider, remoteProvider, localSynced: false, remoteSynced: false }
|
||||
void localProvider.loaded.then(() => (savedBoards[id].localSynced = true))
|
||||
savedBoards[id] = { ydoc, remoteProvider, remoteSynced: false }
|
||||
void remoteProvider.loaded.then(() => (savedBoards[id].remoteSynced = true))
|
||||
board = savedBoards[id]
|
||||
}
|
||||
@@ -348,14 +338,14 @@
|
||||
document: board.ydoc,
|
||||
props: board.ydoc.getMap('props'),
|
||||
commands: board.ydoc.getArray<DrawingCmd>('commands'),
|
||||
loading: !board.localSynced || !board.remoteSynced
|
||||
loading: !board.remoteSynced
|
||||
}
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
// it is recommended to wait for the local provider to be loaded
|
||||
// https://discuss.yjs.dev/t/initial-offline-value-of-a-shared-document/465/4
|
||||
await localProvider.loaded
|
||||
await provider.loaded
|
||||
|
||||
const canAttachFiles = attachFile != null
|
||||
|
||||
@@ -410,7 +400,7 @@
|
||||
collaboration: {
|
||||
collaboration: { document: ydoc, field },
|
||||
collaborationCursor: {
|
||||
provider: remoteProvider,
|
||||
provider,
|
||||
user,
|
||||
render: renderCursor,
|
||||
selectionRender: noSelectionRender
|
||||
@@ -420,7 +410,7 @@
|
||||
boundary,
|
||||
popupContainer: editorPopupContainer,
|
||||
requestSideSpace,
|
||||
whenSync: remoteProvider.loaded
|
||||
whenSync: provider.loaded
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -480,9 +470,8 @@
|
||||
} catch (err: any) {}
|
||||
}
|
||||
if (contextProvider === undefined) {
|
||||
void remoteProvider.destroy()
|
||||
void provider.destroy()
|
||||
}
|
||||
void localProvider.destroy()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
//
|
||||
// Copyright © 2024 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 { type Blob, type Ref } from '@hcengineering/core'
|
||||
import { type Doc as YDoc } from 'yjs'
|
||||
import { WebsocketProvider } from 'y-websocket'
|
||||
|
||||
import { type Provider } from './types'
|
||||
|
||||
export interface DatalakeCollabProviderParameters {
|
||||
url: string
|
||||
name: string
|
||||
token: string
|
||||
|
||||
document: YDoc
|
||||
content: Ref<Blob> | null
|
||||
}
|
||||
|
||||
export class CloudCollabProvider extends WebsocketProvider implements Provider {
|
||||
readonly loaded: Promise<void>
|
||||
|
||||
constructor ({ document, url, name, content }: DatalakeCollabProviderParameters) {
|
||||
const params = content != null ? { content } : undefined
|
||||
|
||||
super(url, encodeURIComponent(name), document, { params })
|
||||
|
||||
this.loaded = new Promise<any>((resolve) => {
|
||||
this.on('sync', resolve)
|
||||
})
|
||||
}
|
||||
|
||||
destroy (): void {
|
||||
this.disconnect()
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// Copyright © 2024 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 { type Doc as YDoc } from 'yjs'
|
||||
import { IndexeddbPersistence } from 'y-indexeddb'
|
||||
import { type Awareness } from 'y-protocols/awareness'
|
||||
|
||||
import { type Provider } from './types'
|
||||
|
||||
export class IndexeddbProvider extends IndexeddbPersistence implements Provider {
|
||||
readonly loaded: Promise<void>
|
||||
readonly awareness: Awareness | null = null
|
||||
|
||||
constructor (documentId: string, doc: YDoc) {
|
||||
super(documentId, doc)
|
||||
|
||||
this.loaded = new Promise((resolve) => {
|
||||
this.on('synced', resolve)
|
||||
})
|
||||
}
|
||||
|
||||
async destroy (): Promise<void> {
|
||||
await super.destroy()
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import { Doc as Ydoc } from 'yjs'
|
||||
import plugin from '../plugin'
|
||||
|
||||
import { HocuspocusCollabProvider } from './hocuspocus'
|
||||
import { IndexeddbProvider } from './indexeddb'
|
||||
import { type Provider } from './types'
|
||||
|
||||
function getDocumentId (doc: CollaborativeDoc): string {
|
||||
@@ -30,11 +29,6 @@ function getDocumentId (doc: CollaborativeDoc): string {
|
||||
return encodeDocumentId(workspace, doc)
|
||||
}
|
||||
|
||||
export function createLocalProvider (ydoc: Ydoc, doc: CollaborativeDoc): Provider {
|
||||
const documentId = getDocumentId(doc)
|
||||
return new IndexeddbProvider(documentId, ydoc)
|
||||
}
|
||||
|
||||
export function createRemoteProvider (ydoc: Ydoc, doc: CollaborativeDoc, content: Ref<Blob> | null): Provider {
|
||||
const token = getMetadata(presentation.metadata.Token) ?? ''
|
||||
const collaboratorUrl = getMetadata(presentation.metadata.CollaboratorUrl) ?? ''
|
||||
|
||||
Reference in New Issue
Block a user