mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
refactor(editor): store should not rely on inline (#11017)
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
internalPrimitives,
|
||||
} from '../model/block/index.js';
|
||||
import type { YBlock } from '../model/block/types.js';
|
||||
import type { Text } from '../reactive/text.js';
|
||||
import type { Text } from '../reactive/text/index.js';
|
||||
import { createAutoIncrementIdGenerator } from '../test/index.js';
|
||||
import { TestWorkspace } from '../test/test-workspace.js';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { assert, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { applyUpdate, type Doc, encodeStateAsUpdate } from 'yjs';
|
||||
|
||||
import type { BlockModel, DocMeta, Store } from '../index.js';
|
||||
import { Text } from '../reactive/text.js';
|
||||
import { Text } from '../reactive/text/index.js';
|
||||
import { createAutoIncrementIdGenerator } from '../test/index.js';
|
||||
import { TestWorkspace } from '../test/test-workspace.js';
|
||||
import {
|
||||
|
||||
@@ -4,5 +4,5 @@ export * from './is-pure-object.js';
|
||||
export * from './native-y.js';
|
||||
export * from './proxy.js';
|
||||
export * from './stash-pop.js';
|
||||
export * from './text.js';
|
||||
export * from './text/index.js';
|
||||
export * from './types.js';
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Array as YArray, Map as YMap, Text as YText } from 'yjs';
|
||||
|
||||
import { Boxed } from './boxed.js';
|
||||
import { isPureObject } from './is-pure-object.js';
|
||||
import { Text } from './text.js';
|
||||
import { Text } from './text/index.js';
|
||||
import type { Native2Y, TransformOptions } from './types.js';
|
||||
|
||||
export function native2Y<T>(
|
||||
|
||||
@@ -6,7 +6,7 @@ import { BaseReactiveYData } from './base-reactive-data.js';
|
||||
import { Boxed, type OnBoxedChange } from './boxed.js';
|
||||
import { proxies } from './memory.js';
|
||||
import { native2Y, y2Native } from './native-y.js';
|
||||
import { type OnTextChange, Text } from './text.js';
|
||||
import { type OnTextChange, Text } from './text/index.js';
|
||||
import type { ProxyOptions, TransformOptions, UnRecord } from './types.js';
|
||||
|
||||
export class ReactiveYArray extends BaseReactiveYData<
|
||||
|
||||
12
blocksuite/framework/store/src/reactive/text/attributes.ts
Normal file
12
blocksuite/framework/store/src/reactive/text/attributes.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const baseTextAttributes = z.object({
|
||||
bold: z.literal(true).optional().nullable().catch(undefined),
|
||||
italic: z.literal(true).optional().nullable().catch(undefined),
|
||||
underline: z.literal(true).optional().nullable().catch(undefined),
|
||||
strike: z.literal(true).optional().nullable().catch(undefined),
|
||||
code: z.literal(true).optional().nullable().catch(undefined),
|
||||
link: z.string().optional().nullable().catch(undefined),
|
||||
});
|
||||
|
||||
export type BaseTextAttributes = z.infer<typeof baseTextAttributes>;
|
||||
3
blocksuite/framework/store/src/reactive/text/index.ts
Normal file
3
blocksuite/framework/store/src/reactive/text/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './attributes';
|
||||
export * from './text';
|
||||
export * from './types';
|
||||
@@ -1,19 +1,8 @@
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import type { DeltaInsert } from '@blocksuite/inline';
|
||||
import { type Signal, signal } from '@preact/signals-core';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
export interface OptionalAttributes {
|
||||
attributes?: Record<string, any>;
|
||||
}
|
||||
|
||||
export type DeltaOperation = {
|
||||
insert?: string;
|
||||
delete?: number;
|
||||
retain?: number;
|
||||
} & OptionalAttributes;
|
||||
|
||||
export type OnTextChange = (data: Y.Text, isLocal: boolean) => void;
|
||||
import type { DeltaInsert, DeltaOperation, OnTextChange } from './types';
|
||||
|
||||
/**
|
||||
* Text is an abstraction of Y.Text.
|
||||
22
blocksuite/framework/store/src/reactive/text/types.ts
Normal file
22
blocksuite/framework/store/src/reactive/text/types.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
import type { BaseTextAttributes } from './attributes';
|
||||
|
||||
export interface OptionalAttributes {
|
||||
attributes?: Record<string, any>;
|
||||
}
|
||||
|
||||
export type DeltaOperation = {
|
||||
insert?: string;
|
||||
delete?: number;
|
||||
retain?: number;
|
||||
} & OptionalAttributes;
|
||||
|
||||
export type OnTextChange = (data: Y.Text, isLocal: boolean) => void;
|
||||
|
||||
export type DeltaInsert<
|
||||
TextAttributes extends BaseTextAttributes = BaseTextAttributes,
|
||||
> = {
|
||||
insert: string;
|
||||
attributes?: TextAttributes;
|
||||
};
|
||||
Reference in New Issue
Block a user