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();
|
||||
|
||||
@@ -2,7 +2,6 @@ import '../../style.css';
|
||||
import '../dev-format.js';
|
||||
|
||||
import {
|
||||
type ExtensionType,
|
||||
WidgetViewMapExtension,
|
||||
WidgetViewMapIdentifier,
|
||||
} from '@blocksuite/block-std';
|
||||
@@ -19,6 +18,7 @@ import { effects as blocksEffects } from '@blocksuite/blocks/effects';
|
||||
import * as globalUtils from '@blocksuite/global/utils';
|
||||
import * as editor from '@blocksuite/presets';
|
||||
import { effects as presetsEffects } from '@blocksuite/presets/effects';
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||
import * as store from '@blocksuite/store';
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { AffineSchemas, SpecProvider, TestUtils } from '@blocksuite/blocks';
|
||||
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { type BlockCollection, Job, nanoid, Schema } from '@blocksuite/store';
|
||||
import { Job, nanoid, Schema } from '@blocksuite/store';
|
||||
import {
|
||||
createAutoIncrementIdGenerator,
|
||||
type DocCollectionOptions,
|
||||
@@ -50,7 +49,7 @@ export function createStarterDocCollection() {
|
||||
}
|
||||
|
||||
const flags: Partial<BlockSuiteFlags> = Object.fromEntries(
|
||||
[...params.entries()]
|
||||
Array.from(params.entries())
|
||||
.filter(([key]) => key.startsWith('enable_'))
|
||||
.map(([k, v]) => [k, v === 'true'])
|
||||
);
|
||||
@@ -98,32 +97,6 @@ export function createStarterDocCollection() {
|
||||
}
|
||||
|
||||
export async function initStarterDocCollection(collection: TestWorkspace) {
|
||||
// init from other clients
|
||||
if (room && !params.has('init')) {
|
||||
const firstCollection = collection.docs.values().next().value as
|
||||
| BlockCollection
|
||||
| undefined;
|
||||
let firstDoc = firstCollection?.getDoc();
|
||||
if (!firstDoc) {
|
||||
await new Promise<string>(resolve =>
|
||||
collection.slots.docCreated.once(resolve)
|
||||
);
|
||||
const firstCollection = collection.docs.values().next().value as
|
||||
| BlockCollection
|
||||
| undefined;
|
||||
firstDoc = firstCollection?.getDoc();
|
||||
}
|
||||
assertExists(firstDoc);
|
||||
const doc = firstDoc;
|
||||
|
||||
doc.load();
|
||||
if (!doc.root) {
|
||||
await new Promise(resolve => doc.slots.rootAdded.once(resolve));
|
||||
}
|
||||
doc.resetHistory();
|
||||
return;
|
||||
}
|
||||
|
||||
// use built-in init function
|
||||
const functionMap = new Map<
|
||||
string,
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
BlockServiceWatcher,
|
||||
type EditorHost,
|
||||
type ExtensionType,
|
||||
} from '@blocksuite/block-std';
|
||||
import { BlockServiceWatcher, type EditorHost } from '@blocksuite/block-std';
|
||||
import {
|
||||
AffineFormatBarWidget,
|
||||
CommunityCanvasTextFonts,
|
||||
@@ -19,7 +15,7 @@ import {
|
||||
toolbarDefaultConfig,
|
||||
} from '@blocksuite/blocks';
|
||||
import { AffineEditorContainer, CommentPanel } from '@blocksuite/presets';
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import type { ExtensionType, Workspace } from '@blocksuite/store';
|
||||
|
||||
import { AttachmentViewerPanel } from '../../_common/components/attachment-viewer-panel.js';
|
||||
import { CustomFramePanel } from '../../_common/components/custom-frame-panel.js';
|
||||
@@ -47,7 +43,7 @@ function configureFormatBar(formatBar: AffineFormatBarWidget) {
|
||||
toolbarDefaultConfig(formatBar);
|
||||
}
|
||||
|
||||
export async function mountDefaultDocEditor(collection: DocCollection) {
|
||||
export async function mountDefaultDocEditor(collection: Workspace) {
|
||||
const app = document.getElementById('app');
|
||||
if (!app) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user