refactor(editor): store should not rely on inline (#11017)

This commit is contained in:
Saul-Mirone
2025-03-20 01:33:29 +00:00
parent ee337a16af
commit 258c70cf07
82 changed files with 140 additions and 141 deletions

View File

@@ -23,6 +23,7 @@
},
"dependencies": {
"@blocksuite/global": "workspace:*",
"@blocksuite/store": "workspace:*",
"@preact/signals-core": "^1.8.0",
"lit": "^3.2.0",
"rxjs": "^7.8.1",

View File

@@ -1,6 +1,7 @@
import type { DeltaInsert } from '@blocksuite/store';
import { expect, type Page } from '@playwright/test';
import type { DeltaInsert, InlineEditor, InlineRange } from '../index.js';
import type { InlineEditor, InlineRange } from '../index.js';
const defaultPlaygroundURL = new URL(
`http://localhost:${process.env.CI ? 4173 : 5173}/`

View File

@@ -1,6 +1,7 @@
import { DisposableGroup } from '@blocksuite/global/disposable';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { SignalWatcher } from '@blocksuite/global/lit';
import type { BaseTextAttributes, DeltaInsert } from '@blocksuite/store';
import { effect, signal } from '@preact/signals-core';
import { html, LitElement } from 'lit';
import { property } from 'lit/decorators.js';
@@ -8,8 +9,6 @@ import { styleMap } from 'lit/directives/style-map.js';
import { ZERO_WIDTH_SPACE } from '../consts.js';
import type { InlineEditor } from '../inline-editor.js';
import type { DeltaInsert } from '../types.js';
import type { BaseTextAttributes } from '../utils/base-attributes.js';
import { isInlineRangeIntersect } from '../utils/inline-range.js';
export class VElement<

View File

@@ -1,11 +1,11 @@
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { DeltaInsert } from '@blocksuite/store';
import { html, LitElement, type TemplateResult } from 'lit';
import { property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { INLINE_ROOT_ATTR, ZERO_WIDTH_SPACE } from '../consts.js';
import type { InlineRootElement } from '../inline-editor.js';
import type { DeltaInsert } from '../types.js';
import { EmbedGap } from './embed-gap.js';
export class VLine extends LitElement {

View File

@@ -1,5 +1,6 @@
import { DisposableGroup } from '@blocksuite/global/disposable';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { BaseTextAttributes, DeltaInsert } from '@blocksuite/store';
import { type Signal, signal } from '@preact/signals-core';
import { nothing, render, type TemplateResult } from 'lit';
import { Subject } from 'rxjs';
@@ -16,12 +17,8 @@ import {
} from './services/index.js';
import { RenderService } from './services/render.js';
import { InlineTextService } from './services/text.js';
import type { DeltaInsert, InlineRange } from './types.js';
import {
type BaseTextAttributes,
nativePointToTextPoint,
textPointToDomPoint,
} from './utils/index.js';
import type { InlineRange } from './types.js';
import { nativePointToTextPoint, textPointToDomPoint } from './utils/index.js';
import { getTextNodesFromElement } from './utils/text.js';
export type InlineRootElement<

View File

@@ -1,19 +1,16 @@
import { type BaseTextAttributes, baseTextAttributes } from '@blocksuite/store';
import type { z, ZodTypeDef } from 'zod';
import type { InlineEditor } from '../inline-editor.js';
import type { AttributeRenderer, InlineRange } from '../types.js';
import type { BaseTextAttributes } from '../utils/index.js';
import {
baseTextAttributes,
getDefaultAttributeRenderer,
} from '../utils/index.js';
import { getDefaultAttributeRenderer } from '../utils/index.js';
export class AttributeService<TextAttributes extends BaseTextAttributes> {
private _attributeRenderer: AttributeRenderer<TextAttributes> =
getDefaultAttributeRenderer<TextAttributes>();
private _attributeSchema: z.ZodSchema<TextAttributes, ZodTypeDef, unknown> =
baseTextAttributes as z.ZodSchema<TextAttributes, ZodTypeDef, unknown>;
baseTextAttributes as never;
private _marks: TextAttributes | null = null;

View File

@@ -1,6 +1,7 @@
import type { BaseTextAttributes, DeltaInsert } from '@blocksuite/store';
import type { InlineEditor } from '../inline-editor.js';
import type { DeltaEntry, DeltaInsert, InlineRange } from '../types.js';
import type { BaseTextAttributes } from '../utils/index.js';
import type { DeltaEntry, InlineRange } from '../types.js';
import { transformDeltasToEmbedDeltas } from '../utils/index.js';
export class DeltaService<TextAttributes extends BaseTextAttributes> {

View File

@@ -1,7 +1,8 @@
import type { BaseTextAttributes } from '@blocksuite/store';
import type { InlineEditor } from '../inline-editor.js';
import type { InlineRange } from '../types.js';
import {
type BaseTextAttributes,
isInEmbedElement,
isInEmbedGap,
isInEmptyLine,
@@ -115,7 +116,7 @@ export class EventService<TextAttributes extends BaseTextAttributes> {
ctx.data,
ctx.attributes,
ctx.inlineRange,
this.editor as InlineEditor
this.editor as never
);
this.editor.slots.inputting.next();

View File

@@ -1,6 +1,7 @@
import type { BaseTextAttributes } from '@blocksuite/store';
import type { InlineEditor } from '../inline-editor.js';
import type { InlineRange } from '../types.js';
import type { BaseTextAttributes } from '../utils/base-attributes.js';
export interface BeforeinputHookCtx<TextAttributes extends BaseTextAttributes> {
inlineEditor: InlineEditor<TextAttributes>;

View File

@@ -1,10 +1,10 @@
import type { BaseTextAttributes } from '@blocksuite/store';
import { effect } from '@preact/signals-core';
import * as Y from 'yjs';
import type { VLine } from '../components/v-line.js';
import type { InlineEditor } from '../inline-editor.js';
import type { InlineRange, TextPoint } from '../types.js';
import type { BaseTextAttributes } from '../utils/base-attributes.js';
import { isInEmbedGap } from '../utils/embed.js';
import { isMaybeInlineRangeEqual } from '../utils/inline-range.js';
import {

View File

@@ -1,4 +1,5 @@
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { BaseTextAttributes } from '@blocksuite/store';
import { html, render } from 'lit';
import { repeat } from 'lit/directives/repeat.js';
import * as Y from 'yjs';
@@ -6,7 +7,6 @@ import * as Y from 'yjs';
import type { VLine } from '../components/v-line.js';
import type { InlineEditor } from '../inline-editor.js';
import type { InlineRange } from '../types.js';
import type { BaseTextAttributes } from '../utils/base-attributes.js';
import { deltaInsertsToChunks } from '../utils/delta-convert.js';
export class RenderService<TextAttributes extends BaseTextAttributes> {

View File

@@ -1,6 +1,7 @@
import type { BaseTextAttributes, DeltaInsert } from '@blocksuite/store';
import type { InlineEditor } from '../inline-editor.js';
import type { DeltaInsert, InlineRange } from '../types.js';
import type { BaseTextAttributes } from '../utils/base-attributes.js';
import type { InlineRange } from '../types.js';
import { intersectInlineRange } from '../utils/inline-range.js';
export class InlineTextService<TextAttributes extends BaseTextAttributes> {

View File

@@ -1,14 +1,7 @@
import type { BaseTextAttributes, DeltaInsert } from '@blocksuite/store';
import type { TemplateResult } from 'lit';
import type { InlineEditor } from './inline-editor.js';
import type { BaseTextAttributes } from './utils/index.js';
export type DeltaInsert<
TextAttributes extends BaseTextAttributes = BaseTextAttributes,
> = {
insert: string;
attributes?: TextAttributes;
};
export type AttributeRenderer<
TextAttributes extends BaseTextAttributes = BaseTextAttributes,

View File

@@ -1,8 +1,8 @@
import type { BaseTextAttributes } from '@blocksuite/store';
import { html } from 'lit';
import { styleMap } from 'lit/directives/style-map.js';
import type { AttributeRenderer } from '../types.js';
import type { BaseTextAttributes } from './base-attributes.js';
function inlineTextStyles(
props: BaseTextAttributes

View File

@@ -1,12 +0,0 @@
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>;

View File

@@ -1,5 +1,4 @@
import type { DeltaInsert } from '../types.js';
import type { BaseTextAttributes } from './base-attributes.js';
import type { BaseTextAttributes, DeltaInsert } from '@blocksuite/store';
export function transformDelta<TextAttributes extends BaseTextAttributes>(
delta: DeltaInsert<TextAttributes>

View File

@@ -1,7 +1,7 @@
import type { BaseTextAttributes, DeltaInsert } from '@blocksuite/store';
import { VElement } from '../components/v-element.js';
import type { InlineEditor } from '../inline-editor.js';
import type { DeltaInsert } from '../types.js';
import type { BaseTextAttributes } from './base-attributes.js';
export function isInEmbedElement(node: Node): boolean {
if (node instanceof Element) {

View File

@@ -1,5 +1,4 @@
export * from './attribute-renderer.js';
export * from './base-attributes.js';
export * from './delta-convert.js';
export * from './embed.js';
export * from './guard.js';

View File

@@ -1,8 +1,6 @@
import type { BaseTextAttributes, DeltaInsert } from '@blocksuite/store';
import { html, type TemplateResult } from 'lit';
import type { DeltaInsert } from '../types.js';
import type { BaseTextAttributes } from './base-attributes.js';
export function renderElement<TextAttributes extends BaseTextAttributes>(
delta: DeltaInsert<TextAttributes>,
parseAttributes: (

View File

@@ -1,6 +1,7 @@
import type { BaseTextAttributes } from '@blocksuite/store';
import type { InlineEditor } from '../inline-editor.js';
import type { InlineRange } from '../types.js';
import type { BaseTextAttributes } from './base-attributes.js';
function handleInsertText<TextAttributes extends BaseTextAttributes>(
inlineRange: InlineRange,

View File

@@ -6,5 +6,5 @@
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo"
},
"include": ["./src"],
"references": [{ "path": "../global" }]
"references": [{ "path": "../global" }, { "path": "../store" }]
}