공동 편집
협업 편집은 브라우저 편집기를 백엔드에 연결합니다. 협업 통합로 시작하여 애플리케이션의 정체성, 권한 및 저장을 실행합니다. 브라우저 및 서버 구성은 협업 빠른 시작에 설명됩니다.
응용 프로그램에서 인증된 API를 통해 문서를 작성한 후 아래 방법으로 반환하는 Unit 식별자를 로드합니다. 다시 문서를 열 때 동일한 식별자를 사용하십시오.
문서 로드
문서를 로딩하기 전에 현재 사용자를 설정합니다. 현재 사용자는 콜레터를 식별하고 로컬 오프라인 캐시를 소유합니다. 현재 사용자가 설정한 후 Facade를 통해 명시된 문서를로드하십시오.
import { UserManagerService } from '@univerjs/core'import '@univerjs-pro/collaboration-client/facade'univer.__getInjector().get(UserManagerService).setCurrentUser({ userID, name, avatar })const collaboration = univerAPI.getCollaboration()const unit = await collaboration.loadDocAsync('your-unit-id')동기화 상태, retries 및 충돌 복구 페이지는 득점방해 지시자를 건설하고 reload의 앞에 unacknowledged 편집을 보호하는 방법을 설명합니다.
공동 편집 문서의 기본 URL 로드 기능 제거
* 이름 *
1.2.0 버전으로 Univer는 협업 문서를 위한 내장 URL 로딩을 제거했습니다. 더 이상 unit 및 type URL 매개 변수를 자동으로 읽습니다.
응용 프로그램이 그 행동에 따라 달라지면 사용자 정의 플러그인이 복원 할 수 있습니다.
사용자 정의 플러그인 연결
프로젝트 아래에 네 파일을 복사, 이 디렉토리 구조를 보존:
custom-url-load/├── plugin.ts├── controllers/│ └── data-loader.controller.ts└── services/ ├── url.service.ts └── web-url.service.ts편집기와 협업 플러그인을 먼저 초기화하고, 현재의 사용자를 다음 설정하고 CustomUrlLoadPlugin를 마지막으로 등록하십시오. 이 접근 방식은 플러그인 모드와 미리 설정 모드에서 작동합니다.
import { UserManagerService } from '@univerjs/core'import { CustomUrlLoadPlugin } from './custom-url-load/plugin'univer.__getInjector().get(UserManagerService).setCurrentUser({ userID, name, avatar })univer.registerPlugin(CustomUrlLoadPlugin)등록 후, 플러그인은 문서를로드하므로 loadDocAsync()는 해당 문서에 필요하지 않습니다. 응용 프로그램을 이미 Facade를 통해 문서를로드하면 이전 섹션에 설명 된 접근 방식을 유지하고 응용 프로그램으로 URL을 처리해야합니다.
전체 플러그인 코드
import { UniverCollaborationClientPlugin } from '@univerjs-pro/collaboration-client'import { DependentOn, Inject, Injector, Plugin } from '@univerjs/core'import { CollaborationDataLoaderController } from './controllers/data-loader.controller'import { IURLService } from './services/url.service'import { WebURLService } from './services/web-url.service'@DependentOn(UniverCollaborationClientPlugin)export class CustomUrlLoadPlugin extends Plugin { static override pluginName = 'CUSTOM_URL_LOAD_PLUGIN' constructor( _config: undefined, @Inject(Injector) protected override readonly _injector: Injector ) { super() } override onStarting(): void { this._injector.add([IURLService, { useClass: WebURLService }]) this._injector.add([CollaborationDataLoaderController]) this.disposeWithMe(this._injector.get(IURLService)) this.disposeWithMe(this._injector.get(CollaborationDataLoaderController)) }}import { DataLoaderService } from '@univerjs-pro/collaboration-client'import { ILogService, Inject, RxDisposable } from '@univerjs/core'import { IURLService } from '../services/url.service'/** * URL 매개변수로 공동 편집 문서를 로드한다. */export class CollaborationDataLoaderController extends RxDisposable { constructor( @IURLService private readonly _urlService: IURLService, @ILogService private readonly _logService: ILogService, @Inject(DataLoaderService) private readonly _dataLoaderService: DataLoaderService ) { super() const unitId = this._urlService.getParam('unit') const type = this._urlService.getParam('type') if (!unitId || !type) { return } this._dataLoaderService.loadUnit(unitId, Number(type)) .catch((error: unknown) => { this._logService.error('[CollaborationDataLoaderController]', error) }) }}import type { IDisposable } from '@univerjs/core'import type { Observable } from 'rxjs'import { createIdentifier } from '@univerjs/core'export interface IURLService extends IDisposable { getParam: (key: string) => string | undefined setParam: (key: string, value: string, useReplace?: boolean) => void removeParam: (key: string, useReplace?: boolean) => void readonly urlChange$: Observable<void>}export const IURLService = createIdentifier<IURLService>('demo.custom-url-load.url-service')import type { IURLService } from './url.service'import { RxDisposable } from '@univerjs/core'import { fromEvent, map, shareReplay, takeUntil } from 'rxjs'export class WebURLService extends RxDisposable implements IURLService { readonly urlChange$ = fromEvent(window, 'popstate').pipe( map(() => undefined), takeUntil(this.dispose$), shareReplay({ bufferSize: 1, refCount: true }) ) getParam(key: string): string | undefined { return new URL(window.location.href).searchParams.get(key) ?? undefined } setParam(key: string, value: string, useReplace = false): void { const url = new URL(window.location.href) url.searchParams.set(key, value) this._updateUrl(url, useReplace) } removeParam(key: string, useReplace = false): void { const url = new URL(window.location.href) url.searchParams.delete(key) this._updateUrl(url, useReplace) } private _updateUrl(url: URL, useReplace: boolean): void { if (useReplace) { window.history.replaceState(window.history.state, '', url.toString()) } else { window.history.pushState(window.history.state, '', url.toString()) } }}이 가이드는 어떠셨나요?