mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-18 14:56:59 +08:00
refactor(editor): playground doc collection typing migration (#9593)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ZipTransformer } from '@blocksuite/blocks';
|
||||
import { type DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text, type Workspace } from '@blocksuite/store';
|
||||
|
||||
export async function affineSnapshot(collection: DocCollection, id: string) {
|
||||
export async function affineSnapshot(collection: Workspace, id: string) {
|
||||
const doc = collection.createDoc({ id });
|
||||
doc.load();
|
||||
// Add root block and surface block at root level
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { type DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text, type Workspace } from '@blocksuite/store';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
export const embed: InitFn = (collection: DocCollection, id: string) => {
|
||||
export const embed: InitFn = (collection: Workspace, id: string) => {
|
||||
const doc = collection.getDoc(id) ?? collection.createDoc({ id });
|
||||
doc.clear();
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { type DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text, type Workspace } from '@blocksuite/store';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
export const empty: InitFn = (collection: DocCollection, id: string) => {
|
||||
export const empty: InitFn = (collection: Workspace, id: string) => {
|
||||
const doc = collection.getDoc(id) ?? collection.createDoc({ id });
|
||||
doc.clear();
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ import { DEFAULT_ROUGHNESS } from '@blocksuite/affine-model';
|
||||
import type { SerializedXYWH } from '@blocksuite/global/utils';
|
||||
import {
|
||||
Boxed,
|
||||
type DocCollection,
|
||||
nanoid,
|
||||
native2Y,
|
||||
Text,
|
||||
type Y,
|
||||
type Workspace,
|
||||
} from '@blocksuite/store';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
@@ -46,10 +46,7 @@ function createShapes(count: number): Record<string, unknown> {
|
||||
const SHAPES_COUNT = 100;
|
||||
const RANGE = 2000;
|
||||
|
||||
export const heavyWhiteboard: InitFn = (
|
||||
collection: DocCollection,
|
||||
id: string
|
||||
) => {
|
||||
export const heavyWhiteboard: InitFn = (collection: Workspace, id: string) => {
|
||||
const count = Number(params.get('count')) || SHAPES_COUNT;
|
||||
const enableShapes = !!params.get('shapes');
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { type DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text, type Workspace } from '@blocksuite/store';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
const params = new URLSearchParams(location.search);
|
||||
|
||||
export const heavy: InitFn = (collection: DocCollection, docId: string) => {
|
||||
export const heavy: InitFn = (collection: Workspace, docId: string) => {
|
||||
const count = Number(params.get('count')) || 1000;
|
||||
|
||||
const doc = collection.createDoc({ id: docId });
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { type DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text, type Workspace } from '@blocksuite/store';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
export const linked: InitFn = (collection: DocCollection, id: string) => {
|
||||
export const linked: InitFn = (collection: Workspace, id: string) => {
|
||||
const docA = collection.getDoc(id) ?? collection.createDoc({ id });
|
||||
|
||||
const docBId = 'doc:linked-page';
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { RefNodeSlotsProvider } from '@blocksuite/affine-components/rich-text';
|
||||
import { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import { type DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text, type Workspace } from '@blocksuite/store';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
export const multiEditor: InitFn = (collection: DocCollection, id: string) => {
|
||||
export const multiEditor: InitFn = (collection: Workspace, id: string) => {
|
||||
const doc = collection.createDoc({ id });
|
||||
doc.load(() => {
|
||||
// Add root block and surface block at root level
|
||||
@@ -48,7 +48,7 @@ multiEditor.displayName = 'Multiple Editor Example';
|
||||
multiEditor.description = 'Multiple Editor basic example';
|
||||
|
||||
export const multiEditorVertical: InitFn = (
|
||||
collection: DocCollection,
|
||||
collection: Workspace,
|
||||
docId: string
|
||||
) => {
|
||||
const doc = collection.createDoc({ id: docId });
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { type DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text, type Workspace } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
export const pendingStructs: InitFn = (
|
||||
collection: DocCollection,
|
||||
id: string
|
||||
) => {
|
||||
export const pendingStructs: InitFn = (collection: Workspace, id: string) => {
|
||||
const doc = collection.createDoc({ id });
|
||||
const tempDoc = collection.createDoc({ id: 'tempDoc' });
|
||||
doc.load();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { MarkdownTransformer } from '@blocksuite/blocks';
|
||||
import { type DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text, type Workspace } from '@blocksuite/store';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
const presetMarkdown = `Click the 🔁 button to switch between editors dynamically - they are fully compatible!`;
|
||||
|
||||
export const preset: InitFn = async (collection: DocCollection, id: string) => {
|
||||
export const preset: InitFn = async (collection: Workspace, id: string) => {
|
||||
const doc = collection.createDoc({ id });
|
||||
doc.load();
|
||||
// Add root block and surface block at root level
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { MarkdownTransformer } from '@blocksuite/blocks';
|
||||
import { type DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text, type Workspace } from '@blocksuite/store';
|
||||
|
||||
import type { InitFn } from './utils';
|
||||
|
||||
@@ -11,7 +11,7 @@ This article has also been published [in PDF format](https://www.inkandswitch.co
|
||||
|
||||
We welcome your feedback: [@inkandswitch](https://twitter.com/inkandswitch) or hello@inkandswitch.com.`;
|
||||
|
||||
export const synced: InitFn = (collection: DocCollection, id: string) => {
|
||||
export const synced: InitFn = (collection: Workspace, id: string) => {
|
||||
const docMain = collection.getDoc(id) ?? collection.createDoc({ id });
|
||||
|
||||
const docSyncedPageId = 'doc:synced-page';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import type { Workspace } from '@blocksuite/store';
|
||||
|
||||
export interface InitFn {
|
||||
(collection: DocCollection, docId: string): Promise<void> | void;
|
||||
(collection: Workspace, docId: string): Promise<void> | void;
|
||||
id: string;
|
||||
displayName: string;
|
||||
description: string;
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import type { Workspace } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
export const versionMismatch: InitFn = (
|
||||
collection: DocCollection,
|
||||
id: string
|
||||
) => {
|
||||
export const versionMismatch: InitFn = (collection: Workspace, id: string) => {
|
||||
const doc = collection.createDoc({ id });
|
||||
const tempDoc = collection.createDoc({ id: 'tempDoc' });
|
||||
doc.load();
|
||||
|
||||
Reference in New Issue
Block a user