mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 06:16:59 +08:00
refactor(editor): reduce dependency to doc collection (#9492)
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
"date-fns": "^4.0.0",
|
||||
"lit": "^3.2.0",
|
||||
"minimatch": "^10.0.1",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
@@ -66,7 +66,7 @@ export class NoteRenderer
|
||||
},
|
||||
} satisfies AffineTextAttributes as BaseTextAttributes
|
||||
);
|
||||
collection.setDocMeta(note.id, { title: rowContent });
|
||||
collection.meta.setDocMeta(note.id, { title: rowContent });
|
||||
if (note.root) {
|
||||
(note.root as RootBlockModel).title.insert(rowContent ?? '', 0);
|
||||
note.root.children
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
"@toeverything/theme": "^1.1.3",
|
||||
"lit": "^3.2.0",
|
||||
"minimatch": "^10.0.1",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
@@ -22,13 +22,13 @@ import {
|
||||
referenceToNode,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { Bound, throttle } from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import { computed } from '@preact/signals-core';
|
||||
import { html, nothing } from 'lit';
|
||||
import { property, queryAsync, state } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
import { when } from 'lit/directives/when.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { EmbedBlockComponent } from '../common/embed-block-element.js';
|
||||
import {
|
||||
@@ -163,7 +163,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
}
|
||||
const index = parent.children.indexOf(this.model);
|
||||
|
||||
const yText = new DocCollection.Y.Text();
|
||||
const yText = new Y.Text();
|
||||
yText.insert(0, REFERENCE_NODE);
|
||||
yText.format(0, REFERENCE_NODE.length, {
|
||||
reference: {
|
||||
|
||||
@@ -27,7 +27,6 @@ import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||
import { assertExists, Bound, getCommonBound } from '@blocksuite/global/utils';
|
||||
import {
|
||||
BlockViewType,
|
||||
DocCollection,
|
||||
type GetDocOptions,
|
||||
type Query,
|
||||
} from '@blocksuite/store';
|
||||
@@ -38,6 +37,7 @@ import { choose } from 'lit/directives/choose.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import { guard } from 'lit/directives/guard.js';
|
||||
import { type StyleInfo, styleMap } from 'lit/directives/style-map.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { EmbedBlockComponent } from '../common/embed-block-element.js';
|
||||
import { isEmptyDoc } from '../common/render-linked-doc.js';
|
||||
@@ -272,7 +272,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
assertExists(parent);
|
||||
const index = parent.children.indexOf(this.model);
|
||||
|
||||
const yText = new DocCollection.Y.Text();
|
||||
const yText = new Y.Text();
|
||||
yText.insert(0, REFERENCE_NODE);
|
||||
yText.format(0, REFERENCE_NODE.length, {
|
||||
reference: {
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"lit": "^3.2.0",
|
||||
"lodash.chunk": "^4.2.0",
|
||||
"nanoid": "^5.0.7",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
rotatePoints,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { deltaInsertsToChunks } from '@blocksuite/inline';
|
||||
import type { Y } from '@blocksuite/store';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
import {
|
||||
getFontFacesByFontFamily,
|
||||
|
||||
@@ -2,7 +2,8 @@ import type { ConnectorElementModel } from '@blocksuite/affine-model';
|
||||
import type { SurfaceBlockProps } from '@blocksuite/block-std/gfx';
|
||||
import { SurfaceBlockModel as BaseSurfaceModel } from '@blocksuite/block-std/gfx';
|
||||
import { DisposableGroup } from '@blocksuite/global/utils';
|
||||
import { defineBlockSchema, DocCollection } from '@blocksuite/store';
|
||||
import { defineBlockSchema } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { elementsCtorMap } from './element-model/index.js';
|
||||
import { SurfaceBlockTransformer } from './surface-transformer.js';
|
||||
@@ -12,7 +13,7 @@ import { groupRelationWatcher } from './watchers/group.js';
|
||||
export const SurfaceBlockSchema = defineBlockSchema({
|
||||
flavour: 'affine:surface',
|
||||
props: (internalPrimitives): SurfaceBlockProps => ({
|
||||
elements: internalPrimitives.Boxed(new DocCollection.Y.Map()),
|
||||
elements: internalPrimitives.Boxed(new Y.Map()),
|
||||
}),
|
||||
metadata: {
|
||||
version: 5,
|
||||
|
||||
@@ -3,9 +3,9 @@ import type {
|
||||
FromSnapshotPayload,
|
||||
SnapshotNode,
|
||||
ToSnapshotPayload,
|
||||
Y,
|
||||
} from '@blocksuite/store';
|
||||
import { BaseBlockTransformer, DocCollection } from '@blocksuite/store';
|
||||
import { BaseBlockTransformer } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
const SURFACE_TEXT_UNIQ_IDENTIFIER = 'affine:surface:text';
|
||||
// Used for group children field
|
||||
@@ -24,11 +24,11 @@ export class SurfaceBlockTransformer extends BaseBlockTransformer<SurfaceBlockPr
|
||||
private _fromJSON(value: unknown): unknown {
|
||||
if (value instanceof Object) {
|
||||
if (Reflect.has(value, SURFACE_TEXT_UNIQ_IDENTIFIER)) {
|
||||
const yText = new DocCollection.Y.Text();
|
||||
const yText = new Y.Text();
|
||||
yText.applyDelta(Reflect.get(value, 'delta'));
|
||||
return yText;
|
||||
} else if (Reflect.has(value, SURFACE_YMAP_UNIQ_IDENTIFIER)) {
|
||||
const yMap = new DocCollection.Y.Map();
|
||||
const yMap = new Y.Map();
|
||||
const json = Reflect.get(value, 'json') as Record<string, unknown>;
|
||||
Object.entries(json).forEach(([key, value]) => {
|
||||
yMap.set(key, value);
|
||||
@@ -40,12 +40,12 @@ export class SurfaceBlockTransformer extends BaseBlockTransformer<SurfaceBlockPr
|
||||
}
|
||||
|
||||
private _toJSON(value: unknown): unknown {
|
||||
if (value instanceof DocCollection.Y.Text) {
|
||||
if (value instanceof Y.Text) {
|
||||
return {
|
||||
[SURFACE_TEXT_UNIQ_IDENTIFIER]: true,
|
||||
delta: value.toDelta(),
|
||||
};
|
||||
} else if (value instanceof DocCollection.Y.Map) {
|
||||
} else if (value instanceof Y.Map) {
|
||||
return {
|
||||
[SURFACE_YMAP_UNIQ_IDENTIFIER]: true,
|
||||
json: value.toJSON(),
|
||||
@@ -55,7 +55,7 @@ export class SurfaceBlockTransformer extends BaseBlockTransformer<SurfaceBlockPr
|
||||
}
|
||||
|
||||
elementFromJSON(element: Record<string, unknown>) {
|
||||
const yMap = new DocCollection.Y.Map();
|
||||
const yMap = new Y.Map();
|
||||
Object.entries(element).forEach(([key, value]) => {
|
||||
yMap.set(key, this._fromJSON(value));
|
||||
});
|
||||
@@ -71,7 +71,7 @@ export class SurfaceBlockTransformer extends BaseBlockTransformer<SurfaceBlockPr
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
const yMap = new DocCollection.Y.Map<Y.Map<unknown>>();
|
||||
const yMap = new Y.Map<Y.Map<unknown>>();
|
||||
|
||||
Object.entries(elementsJSON).forEach(([key, value]) => {
|
||||
const element = this.elementFromJSON(value as Record<string, unknown>);
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
type SurfaceBlockModel,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import { assertType, isEqual, type IVec, last } from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { fitContent } from '../../renderer/elements/shape/utils.js';
|
||||
import { layout } from './layout.js';
|
||||
@@ -360,7 +360,7 @@ export function createFromTree(
|
||||
layoutType: LayoutType,
|
||||
surface: SurfaceBlockModel
|
||||
) {
|
||||
const children = new DocCollection.Y.Map();
|
||||
const children = new Y.Map();
|
||||
const traverse = (subtree: MindmapNode, parent?: string) => {
|
||||
const value: NodeDetail = {
|
||||
...subtree.detail,
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
"lit-html": "^3.2.1",
|
||||
"lodash.clonedeep": "^4.5.0",
|
||||
"shiki": "^1.12.0",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
KEYBOARD_ALLOW_DEFAULT,
|
||||
type KeyboardBindingContext,
|
||||
} from '@blocksuite/inline';
|
||||
import type { Y } from '@blocksuite/store';
|
||||
import type * as Y from 'yjs';
|
||||
import { z, type ZodObject, type ZodTypeAny } from 'zod';
|
||||
|
||||
import { MarkdownMatcherIdentifier } from './markdown-matcher.js';
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
InlineRange,
|
||||
KeyboardBindingHandler,
|
||||
} from '@blocksuite/inline';
|
||||
import type { Y } from '@blocksuite/store';
|
||||
import type * as Y from 'yjs';
|
||||
import type { ZodTypeAny } from 'zod';
|
||||
|
||||
export type InlineSpecs<
|
||||
|
||||
@@ -4,12 +4,11 @@ import { unsafeCSSVar } from '@blocksuite/affine-shared/theme';
|
||||
import { type BlockStdScope, ShadowlessElement } from '@blocksuite/block-std';
|
||||
import { noop, SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
||||
import { DoneIcon } from '@blocksuite/icons/lit';
|
||||
import type { Y } from '@blocksuite/store';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import { effect, type Signal, signal } from '@preact/signals-core';
|
||||
import { css, html } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
import { codeToTokensBase, type ThemedToken } from 'shiki';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { InlineManagerExtension } from '../../../../extension/index.js';
|
||||
import { LatexEditorUnitSpecExtension } from '../../affine-inline-specs.js';
|
||||
@@ -111,7 +110,7 @@ export class LatexEditorMenu extends SignalWatcher(
|
||||
override connectedCallback(): void {
|
||||
super.connectedCallback();
|
||||
|
||||
const doc = new DocCollection.Y.Doc();
|
||||
const doc = new Y.Doc();
|
||||
this.yText = doc.getText('latex');
|
||||
this.yText.insert(0, this.latexSignal.value);
|
||||
|
||||
|
||||
@@ -11,12 +11,12 @@ import {
|
||||
type KeyboardBindingContext,
|
||||
type VLine,
|
||||
} from '@blocksuite/inline';
|
||||
import type { Y } from '@blocksuite/store';
|
||||
import { DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text } from '@blocksuite/store';
|
||||
import { effect } from '@preact/signals-core';
|
||||
import { css, html, type TemplateResult } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
import { classMap } from 'lit/directives/class-map.js';
|
||||
import * as Y from 'yjs';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { onVBeforeinput, onVCompositionEnd } from './hooks.js';
|
||||
@@ -289,7 +289,7 @@ export class RichText extends WithDisposable(ShadowlessElement) {
|
||||
}
|
||||
|
||||
if (!this.undoManager) {
|
||||
this.undoManager = new DocCollection.Y.UndoManager(this._yText, {
|
||||
this.undoManager = new Y.UndoManager(this._yText, {
|
||||
trackedOrigins: new Set([this._yText.doc.clientID]),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
"@toeverything/theme": "^1.1.3",
|
||||
"date-fns": "^4.0.0",
|
||||
"lit": "^3.2.0",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { ShadowlessElement } from '@blocksuite/block-std';
|
||||
import { assertEquals } from '@blocksuite/global/utils';
|
||||
import { DocCollection, type Text } from '@blocksuite/store';
|
||||
import { type Text } from '@blocksuite/store';
|
||||
import { css, html } from 'lit';
|
||||
import { state } from 'lit/decorators.js';
|
||||
import { createRef, ref } from 'lit/directives/ref.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { t } from '../../../../core/index.js';
|
||||
import type { TableAreaSelection } from '../../types.js';
|
||||
@@ -98,7 +99,7 @@ export function fillSelectionWithFocusCellData(
|
||||
curCellText.clear();
|
||||
curCellText.applyDelta(delta);
|
||||
} else {
|
||||
const newText = new DocCollection.Y.Text();
|
||||
const newText = new Y.Text();
|
||||
newText.applyDelta(delta);
|
||||
curCell.valueSet(newText);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"@blocksuite/inline": "workspace:*",
|
||||
"@blocksuite/store": "workspace:*",
|
||||
"fractional-indexing": "^3.2.0",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
@@ -14,7 +14,7 @@ export class RootBlockModel extends BlockModel<RootBlockProps> {
|
||||
if (model instanceof RootBlockModel) {
|
||||
const newDocMeta = this.doc.collection.meta.getDocMeta(model.doc.id);
|
||||
if (!newDocMeta || newDocMeta.title !== model.title.toString()) {
|
||||
this.doc.collection.setDocMeta(model.doc.id, {
|
||||
this.doc.collection.meta.setDocMeta(model.doc.id, {
|
||||
title: model.title.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
polyLineNearestPoint,
|
||||
Vec,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { DocCollection, type Y } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import {
|
||||
CONNECTOR_LABEL_MAX_WIDTH,
|
||||
@@ -126,8 +126,8 @@ export class ConnectorElementModel extends GfxPrimitiveElementModel<ConnectorEle
|
||||
}
|
||||
|
||||
static override propsToY(props: ConnectorElementProps) {
|
||||
if (props.text && !(props.text instanceof DocCollection.Y.Text)) {
|
||||
props.text = new DocCollection.Y.Text(props.text);
|
||||
if (props.text && !(props.text instanceof Y.Text)) {
|
||||
props.text = new Y.Text(props.text);
|
||||
}
|
||||
|
||||
return props;
|
||||
|
||||
@@ -12,8 +12,7 @@ import {
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import type { IVec, PointLocation } from '@blocksuite/global/utils';
|
||||
import { Bound, keys, linePolygonIntersects } from '@blocksuite/global/utils';
|
||||
import type { Y } from '@blocksuite/store';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
type GroupElementProps = BaseElementProps & {
|
||||
children: Y.Map<boolean>;
|
||||
@@ -37,12 +36,12 @@ export class GroupElementModel extends GfxGroupLikeElementModel<GroupElementProp
|
||||
}
|
||||
|
||||
static override propsToY(props: Record<string, unknown>) {
|
||||
if ('title' in props && !(props.title instanceof DocCollection.Y.Text)) {
|
||||
props.title = new DocCollection.Y.Text(props.title as string);
|
||||
if ('title' in props && !(props.title instanceof Y.Text)) {
|
||||
props.title = new Y.Text(props.title as string);
|
||||
}
|
||||
|
||||
if (props.children && !(props.children instanceof DocCollection.Y.Map)) {
|
||||
const children = new DocCollection.Y.Map() as Y.Map<boolean>;
|
||||
if (props.children && !(props.children instanceof Y.Map)) {
|
||||
const children = new Y.Map() as Y.Map<boolean>;
|
||||
|
||||
keys(props.children).forEach(key => {
|
||||
children.set(key as string, true);
|
||||
@@ -112,13 +111,13 @@ export class GroupElementModel extends GfxGroupLikeElementModel<GroupElementProp
|
||||
}
|
||||
)
|
||||
@field()
|
||||
accessor children: Y.Map<boolean> = new DocCollection.Y.Map<boolean>();
|
||||
accessor children: Y.Map<boolean> = new Y.Map<boolean>();
|
||||
|
||||
@local()
|
||||
accessor showTitle: boolean = true;
|
||||
|
||||
@field()
|
||||
accessor title: Y.Text = new DocCollection.Y.Text();
|
||||
accessor title: Y.Text = new Y.Text();
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -20,8 +20,8 @@ import {
|
||||
noop,
|
||||
pick,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { DocCollection, type Y } from '@blocksuite/store';
|
||||
import { generateKeyBetween } from 'fractional-indexing';
|
||||
import * as Y from 'yjs';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ConnectorMode } from '../../consts/connector.js';
|
||||
@@ -183,9 +183,9 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
if (
|
||||
props.children &&
|
||||
!isNodeType(props.children as Record<string, unknown>) &&
|
||||
!(props.children instanceof DocCollection.Y.Map)
|
||||
!(props.children instanceof Y.Map)
|
||||
) {
|
||||
const children: Y.Map<NodeDetail> = new DocCollection.Y.Map();
|
||||
const children: Y.Map<NodeDetail> = new Y.Map();
|
||||
|
||||
keys(props.children).forEach(key => {
|
||||
const detail = pick<Record<string, unknown>, keyof NodeDetail>(
|
||||
@@ -284,9 +284,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
throw new Error(`Parent node ${parent} not found`);
|
||||
}
|
||||
|
||||
props['text'] = new DocCollection.Y.Text(
|
||||
(props['text'] as string) ?? 'New node'
|
||||
);
|
||||
props['text'] = new Y.Text((props['text'] as string) ?? 'New node');
|
||||
|
||||
const type = (props.type as string) ?? 'shape';
|
||||
let id: string;
|
||||
@@ -919,12 +917,12 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
}
|
||||
|
||||
@convert((initialValue, instance) => {
|
||||
if (!(initialValue instanceof DocCollection.Y.Map)) {
|
||||
if (!(initialValue instanceof Y.Map)) {
|
||||
nodeSchema.parse(initialValue);
|
||||
|
||||
assertType<NodeType>(initialValue);
|
||||
|
||||
const map: Y.Map<NodeDetail> = new DocCollection.Y.Map();
|
||||
const map: Y.Map<NodeDetail> = new Y.Map();
|
||||
const surface = instance.surface;
|
||||
const doc = surface.doc;
|
||||
const recursive = (
|
||||
@@ -967,7 +965,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
// since this model package is imported by playwright
|
||||
@observe(observeChildren)
|
||||
@field()
|
||||
accessor children: Y.Map<NodeDetail> = new DocCollection.Y.Map();
|
||||
accessor children: Y.Map<NodeDetail> = new Y.Map();
|
||||
|
||||
@watch(watchLayoutType)
|
||||
@field()
|
||||
|
||||
@@ -16,7 +16,7 @@ import type {
|
||||
PointLocation,
|
||||
SerializedXYWH,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { DocCollection, type Y } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import {
|
||||
DEFAULT_ROUGHNESS,
|
||||
@@ -68,8 +68,8 @@ export class ShapeElementModel extends GfxPrimitiveElementModel<ShapeProps> {
|
||||
}
|
||||
|
||||
static override propsToY(props: ShapeProps) {
|
||||
if (props.text && !(props.text instanceof DocCollection.Y.Text)) {
|
||||
props.text = new DocCollection.Y.Text(props.text);
|
||||
if (props.text && !(props.text instanceof Y.Text)) {
|
||||
props.text = new Y.Text(props.text);
|
||||
}
|
||||
|
||||
return props;
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
pointInPolygon,
|
||||
polygonNearestPoint,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { DocCollection, type Y } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import {
|
||||
FontFamily,
|
||||
@@ -31,8 +31,8 @@ export class TextElementModel extends GfxPrimitiveElementModel<TextElementProps>
|
||||
}
|
||||
|
||||
static override propsToY(props: Record<string, unknown>) {
|
||||
if (props.text && !(props.text instanceof DocCollection.Y.Text)) {
|
||||
props.text = new DocCollection.Y.Text(props.text as string);
|
||||
if (props.text && !(props.text instanceof Y.Text)) {
|
||||
props.text = new Y.Text(props.text as string);
|
||||
}
|
||||
|
||||
return props;
|
||||
@@ -82,7 +82,7 @@ export class TextElementModel extends GfxPrimitiveElementModel<TextElementProps>
|
||||
accessor rotate: number = 0;
|
||||
|
||||
@field()
|
||||
accessor text: Y.Text = new DocCollection.Y.Text();
|
||||
accessor text: Y.Text = new Y.Text();
|
||||
|
||||
@field()
|
||||
accessor textAlign: TextAlign = TextAlign.Center;
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
"remark-parse": "^11.0.0",
|
||||
"remark-stringify": "^11.0.0",
|
||||
"unified": "^11.0.5",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
@@ -17,12 +17,12 @@ import {
|
||||
type BlockModel,
|
||||
type BlockSnapshot,
|
||||
type DeltaOperation,
|
||||
DocCollection,
|
||||
fromJSON,
|
||||
type JobMiddleware,
|
||||
type SliceSnapshot,
|
||||
type Text,
|
||||
} from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { REFERENCE_NODE } from '../../consts';
|
||||
import {
|
||||
@@ -357,7 +357,7 @@ class PasteTr {
|
||||
!matchFlavours(this.pointState.model, ['affine:code'])
|
||||
) {
|
||||
const text = fromJSON(this.lastSnapshot.props.text) as Text;
|
||||
const doc = new DocCollection.Y.Doc();
|
||||
const doc = new Y.Doc();
|
||||
const temp = doc.getMap('temp');
|
||||
temp.set('text', text.yText);
|
||||
this.lastIndex = text.length;
|
||||
|
||||
@@ -6,10 +6,10 @@ import {
|
||||
DisposableGroup,
|
||||
Slot,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import { computed, type Signal, signal } from '@preact/signals-core';
|
||||
import clonedeep from 'lodash.clonedeep';
|
||||
import mergeWith from 'lodash.mergewith';
|
||||
import * as Y from 'yjs';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { makeDeepOptional, NodePropsSchema } from '../utils/index.js';
|
||||
@@ -63,9 +63,9 @@ function isSessionProp(key: string): key is keyof SessionProps {
|
||||
function customizer(_target: unknown, source: unknown) {
|
||||
if (
|
||||
ColorSchema.safeParse(source).success ||
|
||||
source instanceof DocCollection.Y.Text ||
|
||||
source instanceof DocCollection.Y.Array ||
|
||||
source instanceof DocCollection.Y.Map
|
||||
source instanceof Y.Text ||
|
||||
source instanceof Y.Array ||
|
||||
source instanceof Y.Map
|
||||
) {
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export function createDefaultDoc(
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(title),
|
||||
});
|
||||
collection.setDocMeta(doc.id, {
|
||||
collection.meta.setDocMeta(doc.id, {
|
||||
title,
|
||||
});
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
"shiki": "^1.14.1",
|
||||
"simple-xml-to-json": "^1.2.2",
|
||||
"unified": "^11.0.5",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
@@ -57,12 +57,12 @@ import {
|
||||
import {
|
||||
type BlockSnapshot,
|
||||
BlockSnapshotSchema,
|
||||
DocCollection,
|
||||
fromJSON,
|
||||
Job,
|
||||
type SliceSnapshot,
|
||||
} from '@blocksuite/store';
|
||||
import DOMPurify from 'dompurify';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { ExportManager } from '../../../_common/export-manager/export-manager.js';
|
||||
import { getRootByEditorHost } from '../../../_common/utils/query.js';
|
||||
@@ -522,7 +522,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
||||
newXYWH: SerializedXYWH
|
||||
) {
|
||||
if (clipboardData.type === GROUP) {
|
||||
const yMap = new DocCollection.Y.Map();
|
||||
const yMap = new Y.Map();
|
||||
const children = clipboardData.children ?? {};
|
||||
|
||||
for (const [key, value] of Object.entries(children)) {
|
||||
@@ -536,7 +536,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
||||
clipboardData.children = yMap;
|
||||
clipboardData.xywh = newXYWH;
|
||||
} else if (clipboardData.type === MINDMAP) {
|
||||
const yMap = new DocCollection.Y.Map();
|
||||
const yMap = new Y.Map();
|
||||
const children = clipboardData.children ?? {};
|
||||
|
||||
for (const [oldKey, oldValue] of Object.entries(children)) {
|
||||
@@ -1112,7 +1112,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
||||
TextUtils.splitIntoLines(content).forEach((line, idx) => {
|
||||
this.crud.addBlock(
|
||||
'affine:paragraph',
|
||||
{ text: new DocCollection.Y.Text(line) },
|
||||
{ text: new Y.Text(line) },
|
||||
noteId,
|
||||
idx
|
||||
);
|
||||
|
||||
@@ -40,13 +40,13 @@ import {
|
||||
Vec,
|
||||
WithDisposable,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import { consume } from '@lit/context';
|
||||
import { baseTheme } from '@toeverything/theme';
|
||||
import { css, html, LitElement, nothing, unsafeCSS } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js';
|
||||
import {
|
||||
@@ -157,7 +157,7 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
|
||||
const id = this.crud.addBlock(
|
||||
'affine:frame',
|
||||
{
|
||||
title: new DocCollection.Y.Text(`Frame ${frameIndex}`),
|
||||
title: new Y.Text(`Frame ${frameIndex}`),
|
||||
xywh: serializeXYWH(...xywh),
|
||||
presentationIndex: frameMgr.generatePresentationIndex(),
|
||||
},
|
||||
@@ -275,7 +275,7 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
|
||||
} else {
|
||||
const textId = this.crud.addElement(CanvasElementType.TEXT, {
|
||||
xywh: bound.serialize(),
|
||||
text: new DocCollection.Y.Text(),
|
||||
text: new Y.Text(),
|
||||
textAlign: 'left',
|
||||
fontSize: 24,
|
||||
fontFamily: FontFamily.Inter,
|
||||
|
||||
@@ -18,7 +18,7 @@ import type { GfxController, GfxModel } from '@blocksuite/block-std/gfx';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import type { XYWH } from '@blocksuite/global/utils';
|
||||
import { assertType, Bound } from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js';
|
||||
import { type Shape, ShapeFactory } from '../../utils/tool-overlay.js';
|
||||
@@ -284,7 +284,7 @@ export function createEdgelessElement(
|
||||
if (isShape(current)) {
|
||||
id = crud.addElement(current.type, {
|
||||
...current.serialize(),
|
||||
text: new DocCollection.Y.Text(),
|
||||
text: new Y.Text(),
|
||||
xywh: bound.serialize(),
|
||||
});
|
||||
if (!id) return null;
|
||||
@@ -340,7 +340,7 @@ export function createShapeElement(
|
||||
const id = crud.addElement('shape', {
|
||||
shapeType: getShapeType(targetType),
|
||||
radius: getShapeRadius(targetType),
|
||||
text: new DocCollection.Y.Text(),
|
||||
text: new Y.Text(),
|
||||
});
|
||||
if (!id) return null;
|
||||
const element = crud.getElementById(id);
|
||||
|
||||
@@ -16,10 +16,10 @@ import {
|
||||
Vec,
|
||||
WithDisposable,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import { css, html, nothing } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js';
|
||||
|
||||
@@ -187,7 +187,7 @@ export class EdgelessConnectorLabelEditor extends WithDisposable(
|
||||
} else if (len < text.length) {
|
||||
this.crud.updateElement(connector.id, {
|
||||
// @TODO: trim in Y.Text?
|
||||
text: new DocCollection.Y.Text(trimed),
|
||||
text: new Y.Text(trimed),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ import {
|
||||
Vec,
|
||||
WithDisposable,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import { html, nothing } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js';
|
||||
|
||||
@@ -110,7 +110,7 @@ export class EdgelessShapeTextEditor extends WithDisposable(ShadowlessElement) {
|
||||
if (len === 0) {
|
||||
this.element.text = undefined;
|
||||
} else if (len < text.length) {
|
||||
this.element.text = new DocCollection.Y.Text(trimed);
|
||||
this.element.text = new Y.Text(trimed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ import { CanvasElementType } from '@blocksuite/affine-block-surface';
|
||||
import { type MindmapStyle, TextElementModel } from '@blocksuite/affine-model';
|
||||
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
||||
import { assertInstanceOf, Bound } from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import type { TemplateResult } from 'lit';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { EdgelessRootBlockComponent } from '../../../edgeless-root-block.js';
|
||||
import type { EdgelessRootService } from '../../../edgeless-root-service.js';
|
||||
@@ -114,7 +114,7 @@ export const textRender: DraggableTool['render'] = (
|
||||
} else {
|
||||
id = service.crud.addElement(CanvasElementType.TEXT, {
|
||||
xywh: new Bound(bound.x, vCenter - h / 2, w, h).serialize(),
|
||||
text: new DocCollection.Y.Text(),
|
||||
text: new Y.Text(),
|
||||
}) as string;
|
||||
|
||||
edgeless.doc.captureSync();
|
||||
|
||||
@@ -20,7 +20,8 @@ import {
|
||||
type SerializedXYWH,
|
||||
} from '@blocksuite/global/utils';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import { DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { FrameBlockModel, NoteBlockModel } from '../../index.js';
|
||||
import { areSetsEqual } from './utils/misc.js';
|
||||
@@ -196,9 +197,7 @@ export class EdgelessFrameManager extends GfxExtension {
|
||||
const id = this.gfx.doc.addBlock(
|
||||
'affine:frame',
|
||||
{
|
||||
title: new Text(
|
||||
new DocCollection.Y.Text(`Frame ${this.frames.length + 1}`)
|
||||
),
|
||||
title: new Text(new Y.Text(`Frame ${this.frames.length + 1}`)),
|
||||
xywh: bound.serialize(),
|
||||
index: this.gfx.layer.generateIndex(true),
|
||||
presentationIndex: this.generatePresentationIndex(),
|
||||
|
||||
@@ -9,7 +9,8 @@ import {
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import type { IPoint, IVec } from '@blocksuite/global/utils';
|
||||
import { Bound, Vec } from '@blocksuite/global/utils';
|
||||
import { DocCollection, Text } from '@blocksuite/store';
|
||||
import { Text } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { EdgelessFrameManager, FrameOverlay } from '../frame-manager.js';
|
||||
|
||||
@@ -72,9 +73,7 @@ export class FrameTool extends BaseTool {
|
||||
const id = this.doc.addBlock(
|
||||
'affine:frame',
|
||||
{
|
||||
title: new Text(
|
||||
new DocCollection.Y.Text(`Frame ${frames.length + 1}`)
|
||||
),
|
||||
title: new Text(new Y.Text(`Frame ${frames.length + 1}`)),
|
||||
xywh: Bound.fromPoints([this._startPoint, currentPoint]).serialize(),
|
||||
index: this.gfx.layer.generateIndex(true),
|
||||
presentationIndex: this.frameManager.generatePresentationIndex(),
|
||||
|
||||
@@ -3,7 +3,7 @@ import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
||||
import type { PointerEventState } from '@blocksuite/block-std';
|
||||
import { BaseTool, type GfxController } from '@blocksuite/block-std/gfx';
|
||||
import { Bound } from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { EdgelessRootBlockComponent } from '../edgeless-root-block.js';
|
||||
import { mountTextElementEditor } from '../utils/text.js';
|
||||
@@ -22,7 +22,7 @@ export function addText(gfx: GfxController, event: PointerEventState) {
|
||||
const id = gfx.surface.addElement({
|
||||
type: 'text',
|
||||
xywh: new Bound(modelX, modelY, 32, 32).serialize(),
|
||||
text: new DocCollection.Y.Text(),
|
||||
text: new Y.Text(),
|
||||
});
|
||||
gfx.doc.captureSync();
|
||||
const textElement = gfx.getElementById(id) as TextElementModel;
|
||||
|
||||
@@ -17,9 +17,8 @@ import {
|
||||
DocSnapshotSchema,
|
||||
Job,
|
||||
type SnapshotNode,
|
||||
type Y,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import type * as Y from 'yjs';
|
||||
/**
|
||||
* Those block contains other block's id
|
||||
* should defer the loading
|
||||
|
||||
@@ -14,7 +14,7 @@ import type { PointerEventState } from '@blocksuite/block-std';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import type { IVec } from '@blocksuite/global/utils';
|
||||
import { assertInstanceOf, Bound } from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { EdgelessConnectorLabelEditor } from '../components/text/edgeless-connector-label-editor.js';
|
||||
import { EdgelessFrameTitleEditor } from '../components/text/edgeless-frame-title-editor.js';
|
||||
@@ -73,7 +73,7 @@ export function mountShapeTextEditor(
|
||||
}
|
||||
|
||||
if (!shapeElement.text) {
|
||||
const text = new DocCollection.Y.Text();
|
||||
const text = new Y.Text();
|
||||
edgeless.std
|
||||
.get(EdgelessCRUDIdentifier)
|
||||
.updateElement(shapeElement.id, { text });
|
||||
@@ -167,7 +167,7 @@ export function addText(
|
||||
.get(EdgelessCRUDIdentifier)
|
||||
.addElement(CanvasElementType.TEXT, {
|
||||
xywh: new Bound(modelX, modelY, 32, 32).serialize(),
|
||||
text: new DocCollection.Y.Text(),
|
||||
text: new Y.Text(),
|
||||
});
|
||||
if (!id) return;
|
||||
edgeless.doc.captureSync();
|
||||
@@ -192,7 +192,7 @@ export function mountConnectorLabelEditor(
|
||||
}
|
||||
|
||||
if (!connector.text) {
|
||||
const text = new DocCollection.Y.Text();
|
||||
const text = new Y.Text();
|
||||
const labelOffset = connector.labelOffset;
|
||||
let labelXYWH = connector.labelXYWH ?? [0, 0, 16, 16];
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ import {
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import { getHostName, referenceToNode } from '@blocksuite/affine-shared/utils';
|
||||
import { type BlockStdScope, WidgetComponent } from '@blocksuite/block-std';
|
||||
import { type BlockModel, DocCollection } from '@blocksuite/store';
|
||||
import { type BlockModel } from '@blocksuite/store';
|
||||
import { autoUpdate, computePosition, flip, offset } from '@floating-ui/dom';
|
||||
import { html, nothing, type TemplateResult } from 'lit';
|
||||
import { query, state } from 'lit/decorators.js';
|
||||
@@ -61,6 +61,7 @@ import { classMap } from 'lit/directives/class-map.js';
|
||||
import { ifDefined } from 'lit/directives/if-defined.js';
|
||||
import { join } from 'lit/directives/join.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import {
|
||||
isBookmarkBlock,
|
||||
@@ -614,7 +615,7 @@ export class EmbedCardToolbar extends WidgetComponent<
|
||||
const parent = doc.getParent(targetModel);
|
||||
const index = parent?.children.indexOf(targetModel);
|
||||
|
||||
const yText = new DocCollection.Y.Text();
|
||||
const yText = new Y.Text();
|
||||
const insert = title || caption || url;
|
||||
yText.insert(0, insert);
|
||||
yText.format(0, insert.length, { link: url });
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
"rehype-parse": "^9.0.0",
|
||||
"unified": "^11.0.5",
|
||||
"w3c-keyname": "^2.2.8",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Y } from '@blocksuite/store';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
import type { GfxPrimitiveElementModel } from '../element-model.js';
|
||||
import { getObjectPropMeta, setObjectPropMeta } from './common.js';
|
||||
|
||||
@@ -16,8 +16,8 @@ import {
|
||||
Slot,
|
||||
type XYWH,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { DocCollection, type Y } from '@blocksuite/store';
|
||||
import { createMutex } from 'lib0/mutex';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import {
|
||||
descendantElementsImpl,
|
||||
@@ -538,7 +538,7 @@ export function syncElementFromY(
|
||||
if (type.action === 'update' || type.action === 'add') {
|
||||
const value = model.yMap.get(key);
|
||||
|
||||
if (value instanceof DocCollection.Y.Text) {
|
||||
if (value instanceof Y.Text) {
|
||||
disposables[key]?.();
|
||||
disposables[key] = watchText(key, value, callback);
|
||||
}
|
||||
@@ -560,7 +560,7 @@ export function syncElementFromY(
|
||||
};
|
||||
|
||||
Array.from(model.yMap.entries()).forEach(([key, value]) => {
|
||||
if (value instanceof DocCollection.Y.Text) {
|
||||
if (value instanceof Y.Text) {
|
||||
disposables[key] = watchText(key, value, callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { assertType, type Constructor, Slot } from '@blocksuite/global/utils';
|
||||
import type { Boxed, Y } from '@blocksuite/store';
|
||||
import { BlockModel, DocCollection, nanoid } from '@blocksuite/store';
|
||||
import type { Boxed } from '@blocksuite/store';
|
||||
import { BlockModel, nanoid } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import {
|
||||
type GfxGroupCompatibleInterface,
|
||||
@@ -124,7 +125,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
throw new Error('Cannot find id in props');
|
||||
}
|
||||
|
||||
const yMap = new DocCollection.Y.Map();
|
||||
const yMap = new Y.Map();
|
||||
const elementModel = this._createElementFromYMap(
|
||||
type as string,
|
||||
id as string,
|
||||
|
||||
@@ -18,14 +18,6 @@
|
||||
],
|
||||
"author": "toeverything",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"lit": "^3.2.0",
|
||||
"yjs": "^13.6.21"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"lit": "^3.2.0",
|
||||
"yjs": "*"
|
||||
},
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./consts": "./src/consts.ts",
|
||||
@@ -35,6 +27,8 @@
|
||||
"dependencies": {
|
||||
"@blocksuite/global": "workspace:*",
|
||||
"@preact/signals-core": "^1.8.0",
|
||||
"lit": "^3.2.0",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"version": "0.19.0"
|
||||
|
||||
@@ -18,10 +18,8 @@
|
||||
"@blocksuite/inline": "workspace:*",
|
||||
"@blocksuite/sync": "workspace:*",
|
||||
"@preact/signals-core": "^1.8.0",
|
||||
"@types/flexsearch": "^0.7.6",
|
||||
"@types/lodash.ismatch": "^4.4.9",
|
||||
"file-type": "^19.5.0",
|
||||
"flexsearch": "0.7.43",
|
||||
"lib0": "^0.2.97",
|
||||
"lodash.clonedeep": "^4.5.0",
|
||||
"lodash.ismatch": "^4.4.0",
|
||||
@@ -29,16 +27,12 @@
|
||||
"minimatch": "^10.0.1",
|
||||
"nanoid": "^5.0.7",
|
||||
"y-protocols": "^1.0.6",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash.clonedeep": "^4.5.9",
|
||||
"@types/lodash.merge": "^4.6.9",
|
||||
"lit": "^3.2.0",
|
||||
"yjs": "^13.6.21"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"yjs": "*"
|
||||
"@types/lodash.merge": "^4.6.9"
|
||||
},
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
|
||||
@@ -436,7 +436,7 @@ describe('addBlock', () => {
|
||||
called = true;
|
||||
});
|
||||
|
||||
collection.setDocMeta('doc:home', { favorite: true });
|
||||
collection.meta.setDocMeta('doc:home', { favorite: true });
|
||||
assert.deepEqual(
|
||||
collection.meta.docMetas.map(({ id, title, favorite }) => ({
|
||||
id,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// oxlint-disable-next-line @typescript-eslint/triple-slash-reference
|
||||
/// <reference path="../shim.d.ts" />
|
||||
|
||||
export type { Y };
|
||||
export * from './adapter/index.js';
|
||||
export * from './reactive/index.js';
|
||||
export * from './schema/index.js';
|
||||
@@ -11,8 +10,6 @@ export { type IdGenerator, nanoid, uuidv4 } from './utils/id-generator.js';
|
||||
export * as Utils from './utils/utils.js';
|
||||
export * from './yjs/index.js';
|
||||
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
const env =
|
||||
typeof globalThis !== 'undefined'
|
||||
? globalThis
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
import clonedeep from 'lodash.clonedeep';
|
||||
import merge from 'lodash.merge';
|
||||
import { Awareness } from 'y-protocols/awareness.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { Schema } from '../schema/index.js';
|
||||
import type { IdGenerator } from '../utils/id-generator.js';
|
||||
@@ -27,7 +26,7 @@ import { BlockCollection, type GetDocOptions } from './doc/block-collection.js';
|
||||
import type { Doc, Query } from './doc/index.js';
|
||||
import type { IdGeneratorType } from './id.js';
|
||||
import { pickIdGenerator } from './id.js';
|
||||
import { DocCollectionMeta, type DocMeta } from './meta.js';
|
||||
import { DocCollectionMeta } from './meta.js';
|
||||
|
||||
export type DocCollectionOptions = {
|
||||
schema: Schema;
|
||||
@@ -71,8 +70,6 @@ export interface StackItem {
|
||||
}
|
||||
|
||||
export class DocCollection {
|
||||
static Y = Y;
|
||||
|
||||
protected readonly _schema: Schema;
|
||||
|
||||
readonly awarenessStore: AwarenessStore;
|
||||
@@ -252,15 +249,6 @@ export class DocCollection {
|
||||
this.blockCollections.delete(docId);
|
||||
}
|
||||
|
||||
/** Update doc meta state. Note that this intentionally does not mutate doc state. */
|
||||
setDocMeta(
|
||||
docId: string,
|
||||
// You should not update subDocIds directly.
|
||||
props: Partial<DocMeta>
|
||||
) {
|
||||
this.meta.setDocMeta(docId, props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the data sync process
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
IndexedDBBlobSource,
|
||||
IndexedDBDocSource,
|
||||
} from '@blocksuite/sync';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { WebSocketAwarenessSource } from '../../_common/sync/websocket/awareness';
|
||||
import { WebSocketDocSource } from '../../_common/sync/websocket/doc';
|
||||
@@ -93,7 +94,7 @@ export async function createDefaultDocCollection() {
|
||||
delete: (id: string) => collection.removeDoc(id),
|
||||
},
|
||||
});
|
||||
window.Y = DocCollection.Y;
|
||||
window.Y = Y;
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
3
blocksuite/playground/apps/env.d.ts
vendored
3
blocksuite/playground/apps/env.d.ts
vendored
@@ -3,6 +3,7 @@ import type { TestUtils } from '@blocksuite/blocks';
|
||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import type { BlockSchema, Doc, DocCollection, Job } from '@blocksuite/store';
|
||||
import type { z } from 'zod';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
declare global {
|
||||
type HTMLTemplate = [
|
||||
@@ -17,7 +18,7 @@ declare global {
|
||||
collection: DocCollection;
|
||||
blockSchemas: z.infer<typeof BlockSchema>[];
|
||||
job: Job;
|
||||
Y: typeof DocCollection.Y;
|
||||
Y: typeof Y;
|
||||
std: typeof std;
|
||||
testUtils: TestUtils;
|
||||
host: EditorHost;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DocCollection, Text } from '@blocksuite/store';
|
||||
import { type DocCollection, Text } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
@@ -13,10 +14,10 @@ export const pendingStructs: InitFn = (
|
||||
const rootId = tempDoc.addBlock('affine:page', {
|
||||
title: new Text('Pending Structs'),
|
||||
});
|
||||
const vec = DocCollection.Y.encodeStateVector(tempDoc.spaceDoc);
|
||||
const vec = Y.encodeStateVector(tempDoc.spaceDoc);
|
||||
|
||||
// To avoid pending structs, uncomment the following line
|
||||
// const update = DocCollection.Y.encodeStateAsUpdate(tempDoc.spaceDoc);
|
||||
// const update = Y.encodeStateAsUpdate(tempDoc.spaceDoc);
|
||||
|
||||
tempDoc.addBlock('affine:surface', {}, rootId);
|
||||
// Add note block inside root block
|
||||
@@ -28,11 +29,11 @@ export const pendingStructs: InitFn = (
|
||||
},
|
||||
noteId
|
||||
);
|
||||
const diff = DocCollection.Y.encodeStateAsUpdate(tempDoc.spaceDoc, vec);
|
||||
const diff = Y.encodeStateAsUpdate(tempDoc.spaceDoc, vec);
|
||||
// To avoid pending structs, uncomment the following line
|
||||
// DocCollection.Y.applyUpdate(doc.spaceDoc, update);
|
||||
// Y.applyUpdate(doc.spaceDoc, update);
|
||||
|
||||
DocCollection.Y.applyUpdate(doc.spaceDoc, diff);
|
||||
Y.applyUpdate(doc.spaceDoc, diff);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Y } from '@blocksuite/store';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
@@ -24,9 +24,9 @@ export const versionMismatch: InitFn = (
|
||||
const paragraph = blocks.get(paragraphId) as Y.Map<unknown>;
|
||||
paragraph.set('sys:version', (paragraph.get('sys:version') as number) + 1);
|
||||
|
||||
const update = DocCollection.Y.encodeStateAsUpdate(tempDoc.spaceDoc);
|
||||
const update = Y.encodeStateAsUpdate(tempDoc.spaceDoc);
|
||||
|
||||
DocCollection.Y.applyUpdate(doc.spaceDoc, update);
|
||||
Y.applyUpdate(doc.spaceDoc, update);
|
||||
doc.addBlock('affine:paragraph', {}, noteId);
|
||||
});
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
IndexedDBBlobSource,
|
||||
MemoryBlobSource,
|
||||
} from '@blocksuite/sync';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { MockServerBlobSource } from '../../_common/sync/blob/mock-server.js';
|
||||
import type { InitFn } from '../data/utils.js';
|
||||
@@ -92,7 +93,7 @@ export function createStarterDocCollection() {
|
||||
delete: (id: string) => collection.removeDoc(id),
|
||||
},
|
||||
});
|
||||
window.Y = DocCollection.Y;
|
||||
window.Y = Y;
|
||||
window.testUtils = new TestUtils();
|
||||
|
||||
return collection;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
"@preact/signals-core": "^1.8.0",
|
||||
"@toeverything/theme": "^1.1.3",
|
||||
"lit": "^3.2.0",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
@@ -6,8 +6,8 @@ import {
|
||||
NoteDisplayMode,
|
||||
} from '@blocksuite/blocks';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import { beforeEach, describe, expect, test } from 'vitest';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { wait } from '../utils/common.js';
|
||||
import { addNote, getDocRootBlock } from '../utils/edgeless.js';
|
||||
@@ -24,7 +24,7 @@ describe('group', () => {
|
||||
});
|
||||
|
||||
test('group with no children will be removed automatically', () => {
|
||||
const map = new DocCollection.Y.Map<boolean>();
|
||||
const map = new Y.Map<boolean>();
|
||||
const ids = Array.from({ length: 2 })
|
||||
.map(() => {
|
||||
const id = service.crud.addElement('shape', {
|
||||
@@ -62,7 +62,7 @@ describe('group', () => {
|
||||
});
|
||||
|
||||
test('remove group should remove its children at the same time', () => {
|
||||
const map = new DocCollection.Y.Map<boolean>();
|
||||
const map = new Y.Map<boolean>();
|
||||
const doc = service.doc;
|
||||
const noteId = addNote(doc);
|
||||
const shapeId = service.crud.addElement('shape', {
|
||||
@@ -112,7 +112,7 @@ describe('group', () => {
|
||||
collapsedHeight: 100,
|
||||
},
|
||||
});
|
||||
const children = new DocCollection.Y.Map<boolean>();
|
||||
const children = new Y.Map<boolean>();
|
||||
|
||||
children.set(shape1, true);
|
||||
children.set(shape2, true);
|
||||
@@ -187,7 +187,7 @@ describe('group', () => {
|
||||
});
|
||||
|
||||
test('empty group should have all zero xywh', () => {
|
||||
const map = new DocCollection.Y.Map<boolean>();
|
||||
const map = new Y.Map<boolean>();
|
||||
const groupId = service.crud.addElement('group', { children: map });
|
||||
assertExists(groupId);
|
||||
const group = service.crud.getElementById(groupId) as GroupElementModel;
|
||||
@@ -201,7 +201,7 @@ describe('group', () => {
|
||||
test('descendant of group should not contain itself', () => {
|
||||
const groupIds = [1, 2, 3].map(_ => {
|
||||
return service.crud.addElement('group', {
|
||||
children: new DocCollection.Y.Map<boolean>(),
|
||||
children: new Y.Map<boolean>(),
|
||||
}) as string;
|
||||
});
|
||||
const groups = groupIds.map(
|
||||
|
||||
@@ -5,8 +5,9 @@ import type {
|
||||
GroupElementModel,
|
||||
NoteBlockModel,
|
||||
} from '@blocksuite/blocks';
|
||||
import { type BlockModel, type Doc, DocCollection } from '@blocksuite/store';
|
||||
import { type BlockModel, type Doc } from '@blocksuite/store';
|
||||
import { beforeEach, describe, expect, test } from 'vitest';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { wait } from '../utils/common.js';
|
||||
import {
|
||||
@@ -409,7 +410,7 @@ describe('group related functionality', () => {
|
||||
service: EdgelessRootBlockComponent['service'],
|
||||
childIds: string[]
|
||||
) => {
|
||||
const children = new DocCollection.Y.Map<boolean>();
|
||||
const children = new Y.Map<boolean>();
|
||||
childIds.forEach(id => children.set(id, true));
|
||||
|
||||
return service.crud.addElement('group', {
|
||||
@@ -574,7 +575,7 @@ describe('compare function', () => {
|
||||
childIds: string[]
|
||||
// eslint-disable-next-line sonarjs/no-identical-functions
|
||||
) => {
|
||||
const children = new DocCollection.Y.Map<boolean>();
|
||||
const children = new Y.Map<boolean>();
|
||||
childIds.forEach(id => children.set(id, true));
|
||||
|
||||
return service.crud.addElement('group', {
|
||||
|
||||
@@ -2,9 +2,9 @@ import type { TextSelection } from '@blocksuite/block-std';
|
||||
import { ShadowlessElement } from '@blocksuite/block-std';
|
||||
import type { RichText } from '@blocksuite/blocks';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import { css, html, nothing } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { Comment, CommentManager } from './comment-manager.js';
|
||||
|
||||
@@ -52,7 +52,7 @@ export class CommentInput extends WithDisposable(ShadowlessElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
const yText = new DocCollection.Y.Text();
|
||||
const yText = new Y.Text();
|
||||
yText.applyDelta(deltas);
|
||||
const comment = this.manager.addComment(textSelection, {
|
||||
author: 'Anonymous',
|
||||
@@ -82,7 +82,7 @@ export class CommentInput extends WithDisposable(ShadowlessElement) {
|
||||
|
||||
const { quote } = parseResult;
|
||||
|
||||
const tmpYDoc = new DocCollection.Y.Doc();
|
||||
const tmpYDoc = new Y.Doc();
|
||||
const tmpYText = tmpYDoc.getText('comment');
|
||||
|
||||
return html`<div class="comment-input-container">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { EditorHost, TextSelection } from '@blocksuite/block-std';
|
||||
import { DocCollection, type Y } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
export interface CommentMeta {
|
||||
id: string;
|
||||
@@ -53,10 +53,7 @@ export class CommentManager {
|
||||
quote,
|
||||
...payload,
|
||||
};
|
||||
this.commentsMap.set(
|
||||
id,
|
||||
new DocCollection.Y.Map<unknown>(Object.entries(comment))
|
||||
);
|
||||
this.commentsMap.set(id, new Y.Map<unknown>(Object.entries(comment)));
|
||||
return comment;
|
||||
}
|
||||
|
||||
@@ -66,17 +63,15 @@ export class CommentManager {
|
||||
const start = comment.get('start') as Comment['start'];
|
||||
const end = comment.get('end') as Comment['end'];
|
||||
|
||||
const startIndex =
|
||||
DocCollection.Y.createAbsolutePositionFromRelativePosition(
|
||||
start.index,
|
||||
this.host.doc.spaceDoc
|
||||
);
|
||||
const startIndex = Y.createAbsolutePositionFromRelativePosition(
|
||||
start.index,
|
||||
this.host.doc.spaceDoc
|
||||
);
|
||||
const startBlock = this.host.view.getBlock(start.id);
|
||||
const endIndex =
|
||||
DocCollection.Y.createAbsolutePositionFromRelativePosition(
|
||||
end.index,
|
||||
this.host.doc.spaceDoc
|
||||
);
|
||||
const endIndex = Y.createAbsolutePositionFromRelativePosition(
|
||||
end.index,
|
||||
this.host.doc.spaceDoc
|
||||
);
|
||||
const endBlock = this.host.view.getBlock(end.id);
|
||||
|
||||
if (!startIndex || !startBlock || !endIndex || !endBlock) {
|
||||
@@ -122,11 +117,11 @@ export class CommentManager {
|
||||
const toBlockId = toBlock.model.id;
|
||||
if (!fromBlockText || !toBlockText) return null;
|
||||
|
||||
const startIndex = DocCollection.Y.createRelativePositionFromTypeIndex(
|
||||
const startIndex = Y.createRelativePositionFromTypeIndex(
|
||||
fromBlockText.yText,
|
||||
from.index
|
||||
);
|
||||
const endIndex = DocCollection.Y.createRelativePositionFromTypeIndex(
|
||||
const endIndex = Y.createRelativePositionFromTypeIndex(
|
||||
toBlockText.yText,
|
||||
to ? to.index + to.length : from.index + from.length
|
||||
);
|
||||
|
||||
@@ -84,7 +84,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
|
||||
};
|
||||
|
||||
private readonly _updateTitleInMeta = () => {
|
||||
this.doc.collection.setDocMeta(this.doc.id, {
|
||||
this.doc.collection.meta.setDocMeta(this.doc.id, {
|
||||
title: this._rootModel.title.toString(),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { ShadowlessElement } from '@blocksuite/block-std';
|
||||
import type { FrameBlockModel } from '@blocksuite/blocks';
|
||||
import { DisposableGroup, WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { Y } from '@blocksuite/store';
|
||||
import { css, html, type PropertyValues } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
import { FrameCardTitleEditor } from './frame-card-title-editor.js';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user