Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@blocksuite/store

Package Overview
Dependencies
Maintainers
0
Versions
1252
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blocksuite/store - npm Package Compare versions

Comparing version 0.0.0-canary-20240906001315 to 0.0.0-canary-20240907001248

15

dist/adapter/base.d.ts
import type { Doc } from '../store/index.js';
import type { AssetsManager } from '../transformer/assets.js';
import type { Slice } from '../transformer/index.js';
import type { DraftModel, Job } from '../transformer/index.js';
import type { DraftModel, Job, Slice } from '../transformer/index.js';
import type { BlockSnapshot, DocSnapshot, SliceSnapshot } from '../transformer/type.js';

@@ -45,15 +44,15 @@ import { ASTWalkerContext } from './context.js';

job: Job;
get configs(): Map<string, string>;
constructor(job: Job);
fromBlock(mode: DraftModel): Promise<FromBlockSnapshotResult<AdapterTarget> | undefined>;
abstract fromBlockSnapshot(payload: FromBlockSnapshotPayload): Promise<FromBlockSnapshotResult<AdapterTarget>> | FromBlockSnapshotResult<AdapterTarget>;
fromDoc(doc: Doc): Promise<FromDocSnapshotResult<AdapterTarget> | undefined>;
abstract fromDocSnapshot(payload: FromDocSnapshotPayload): Promise<FromDocSnapshotResult<AdapterTarget>> | FromDocSnapshotResult<AdapterTarget>;
fromSlice(slice: Slice): Promise<FromSliceSnapshotResult<AdapterTarget> | undefined>;
abstract fromSliceSnapshot(payload: FromSliceSnapshotPayload): Promise<FromSliceSnapshotResult<AdapterTarget>> | FromSliceSnapshotResult<AdapterTarget>;
toBlock(payload: ToBlockSnapshotPayload<AdapterTarget>, doc: Doc, parent?: string, index?: number): Promise<import("../index.js").BlockModel<object, object & {}> | undefined>;
abstract toBlockSnapshot(payload: ToBlockSnapshotPayload<AdapterTarget>): Promise<BlockSnapshot> | BlockSnapshot;
toDoc(payload: ToDocSnapshotPayload<AdapterTarget>): Promise<Doc | undefined>;
abstract toDocSnapshot(payload: ToDocSnapshotPayload<AdapterTarget>): Promise<DocSnapshot> | DocSnapshot;
toSlice(payload: ToSliceSnapshotPayload<AdapterTarget>, doc: Doc, parent?: string, index?: number): Promise<Slice | undefined>;
get configs(): Map<string, string>;
abstract fromBlockSnapshot(payload: FromBlockSnapshotPayload): Promise<FromBlockSnapshotResult<AdapterTarget>> | FromBlockSnapshotResult<AdapterTarget>;
abstract fromDocSnapshot(payload: FromDocSnapshotPayload): Promise<FromDocSnapshotResult<AdapterTarget>> | FromDocSnapshotResult<AdapterTarget>;
abstract fromSliceSnapshot(payload: FromSliceSnapshotPayload): Promise<FromSliceSnapshotResult<AdapterTarget>> | FromSliceSnapshotResult<AdapterTarget>;
abstract toBlockSnapshot(payload: ToBlockSnapshotPayload<AdapterTarget>): Promise<BlockSnapshot> | BlockSnapshot;
abstract toDocSnapshot(payload: ToDocSnapshotPayload<AdapterTarget>): Promise<DocSnapshot> | DocSnapshot;
abstract toSliceSnapshot(payload: ToSliceSnapshotPayload<AdapterTarget>): Promise<SliceSnapshot | null> | SliceSnapshot | null;

@@ -60,0 +59,0 @@ }

import { assertEquals } from '@blocksuite/global/utils';
import { ASTWalkerContext } from './context.js';
export class BaseAdapter {
get configs() {
return this.job.adapterConfigs;
}
constructor(job) {

@@ -94,5 +97,2 @@ this.job = job;

}
get configs() {
return this.job.adapterConfigs;
}
}

@@ -99,0 +99,0 @@ // Ported from https://github.com/Rich-Harris/estree-walker MIT License

@@ -5,6 +5,11 @@ type Keyof<T> = T extends unknown ? keyof T : never;

private _globalContext;
private _stack;
_skip: boolean;
_skipChildrenNum: number;
private _stack;
setDefaultProp: (parentProp: Keyof<TNode>) => void;
get stack(): {
node: TNode;
prop: Keyof<TNode>;
context: Record<string, unknown>;
}[];
private current;

@@ -25,9 +30,4 @@ closeNode(): this;

skipChildren(num?: number): void;
get stack(): {
node: TNode;
prop: Keyof<TNode>;
context: Record<string, unknown>;
}[];
}
export {};
//# sourceMappingURL=context.d.ts.map

@@ -5,5 +5,5 @@ export class ASTWalkerContext {

this._globalContext = Object.create(null);
this._stack = [];
this._skip = false;
this._skipChildrenNum = 0;
this._stack = [];
this.setDefaultProp = (parentProp) => {

@@ -13,2 +13,5 @@ this._defaultProp = parentProp;

}
get stack() {
return this._stack;
}
current() {

@@ -90,6 +93,3 @@ return this._stack[this._stack.length - 1];

}
get stack() {
return this._stack;
}
}
//# sourceMappingURL=context.js.map

@@ -9,3 +9,3 @@ /// <reference types="@blocksuite/global" preserve="true" />

export * from './transformer/index.js';
export { type IdGenerator, createAutoIncrementIdGenerator, createAutoIncrementIdGeneratorByClientId, nanoid, uuidv4, } from './utils/id-generator.js';
export { createAutoIncrementIdGenerator, createAutoIncrementIdGeneratorByClientId, type IdGenerator, nanoid, uuidv4, } from './utils/id-generator.js';
export * as Utils from './utils/utils.js';

@@ -12,0 +12,0 @@ export * from './yjs/index.js';

import * as Y from 'yjs';
export type OnBoxedChange = (data: unknown) => void;
export declare class Boxed<T = unknown> {
static from: <T_1>(map: Y.Map<T_1>, onChange?: OnBoxedChange) => Boxed<T_1>;
static is: (value: unknown) => value is Boxed;
private readonly _map;
private _onChange?;
static from: <T_1>(map: Y.Map<T_1>, onChange?: OnBoxedChange) => Boxed<T_1>;
static is: (value: unknown) => value is Boxed;
getValue: () => T | undefined;
setValue: (value: T) => T;
get yMap(): Y.Map<T>;
constructor(value: T, onChange?: OnBoxedChange);
bind(onChange: OnBoxedChange): void;
get yMap(): Y.Map<T>;
}
//# sourceMappingURL=boxed.d.ts.map

@@ -10,2 +10,5 @@ import * as Y from 'yjs';

}; }
get yMap() {
return this._map;
}
constructor(value, onChange) {

@@ -35,6 +38,3 @@ this.getValue = () => {

}
get yMap() {
return this._map;
}
}
//# sourceMappingURL=boxed.js.map

@@ -11,4 +11,4 @@ import { Array as YArray, Map as YMap } from 'yjs';

protected readonly _options: ProxyOptions<unknown[]>;
private _observer;
protected _getProxy: () => unknown[];
private _observer;
protected readonly _proxy: unknown[];

@@ -23,4 +23,4 @@ constructor(_source: unknown[], _ySource: YArray<unknown>, _options: ProxyOptions<unknown[]>);

protected readonly _options: ProxyOptions<UnRecord>;
private _observer;
protected _getProxy: () => UnRecord;
private _observer;
protected readonly _proxy: UnRecord;

@@ -27,0 +27,0 @@ constructor(_source: UnRecord, _ySource: YMap<unknown>, _options: ProxyOptions<UnRecord>);

@@ -14,2 +14,27 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';

this._options = _options;
this._observer = (event) => {
this._onObserve(event, () => {
let retain = 0;
event.changes.delta.forEach(change => {
if (change.retain) {
retain += change.retain;
return;
}
if (change.delete) {
this._updateWithSkip(() => {
this._source.splice(retain, change.delete);
});
return;
}
if (change.insert) {
const _arr = [change.insert].flat();
const proxyList = _arr.map(value => createYProxy(value));
this._updateWithSkip(() => {
this._source.splice(retain, 0, ...proxyList);
});
retain += change.insert.length;
}
});
});
};
this._getProxy = () => {

@@ -77,27 +102,2 @@ return new Proxy(this._source, {

};
this._observer = (event) => {
this._onObserve(event, () => {
let retain = 0;
event.changes.delta.forEach(change => {
if (change.retain) {
retain += change.retain;
return;
}
if (change.delete) {
this._updateWithSkip(() => {
this._source.splice(retain, change.delete);
});
return;
}
if (change.insert) {
const _arr = [change.insert].flat();
const proxyList = _arr.map(value => createYProxy(value));
this._updateWithSkip(() => {
this._source.splice(retain, 0, ...proxyList);
});
retain += change.insert.length;
}
});
});
};
this._proxy = this._getProxy();

@@ -122,2 +122,25 @@ proxies.set(_ySource, this);

this._options = _options;
this._observer = (event) => {
this._onObserve(event, () => {
event.keysChanged.forEach(key => {
const type = event.changes.keys.get(key);
if (!type) {
return;
}
if (type.action === 'delete') {
this._updateWithSkip(() => {
delete this._source[key];
});
}
else if (type.action === 'add' || type.action === 'update') {
const current = this._ySource.get(key);
this._updateWithSkip(() => {
this._source[key] = proxies.has(current)
? proxies.get(current)
: createYProxy(current, this._options);
});
}
});
});
};
this._getProxy = () => {

@@ -180,25 +203,2 @@ return new Proxy(this._source, {

};
this._observer = (event) => {
this._onObserve(event, () => {
event.keysChanged.forEach(key => {
const type = event.changes.keys.get(key);
if (!type) {
return;
}
if (type.action === 'delete') {
this._updateWithSkip(() => {
delete this._source[key];
});
}
else if (type.action === 'add' || type.action === 'update') {
const current = this._ySource.get(key);
this._updateWithSkip(() => {
this._source[key] = proxies.has(current)
? proxies.get(current)
: createYProxy(current, this._options);
});
}
});
});
};
this._proxy = this._getProxy();

@@ -205,0 +205,0 @@ proxies.set(_ySource, this);

@@ -18,2 +18,5 @@ import type { BaseTextAttributes, DeltaInsert } from '@blocksuite/inline';

private readonly _yText;
get deltas$(): Signal<DeltaOperation[]>;
get length(): number;
get yText(): Y.Text;
constructor(input?: Y.Text | string | DeltaInsert[], onChange?: OnTextChange);

@@ -54,6 +57,3 @@ /**

toString(): string;
get deltas$(): Signal<DeltaOperation[]>;
get length(): number;
get yText(): Y.Text;
}
//# sourceMappingURL=text.d.ts.map

@@ -5,2 +5,11 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';

export class Text {
get deltas$() {
return this._deltas$;
}
get length() {
return this._length$.value;
}
get yText() {
return this._yText;
}
constructor(input, onChange) {

@@ -260,12 +269,3 @@ this._onChange = onChange;

}
get deltas$() {
return this._deltas$;
}
get length() {
return this._length$.value;
}
get yText() {
return this._yText;
}
}
//# sourceMappingURL=text.js.map

@@ -20,12 +20,12 @@ import type { Doc as YDoc, YEvent } from 'yjs';

protected _onObserve: (event: YEvent<any>, handler: () => void) => void;
protected abstract readonly _options: ProxyOptions<T>;
protected abstract readonly _proxy: T;
protected _skipNext: boolean;
protected abstract readonly _source: T;
protected readonly _stashed: Set<string | number>;
protected _transact: (doc: YDoc, fn: () => void) => void;
protected _updateWithSkip: (fn: () => void) => void;
protected abstract readonly _ySource: Y;
get proxy(): T;
protected abstract _getProxy(): T;
protected abstract readonly _options: ProxyOptions<T>;
protected abstract readonly _proxy: T;
protected abstract readonly _source: T;
protected abstract readonly _ySource: Y;
abstract pop(prop: string | number): void;

@@ -32,0 +32,0 @@ abstract stash(prop: string | number): void;

@@ -130,13 +130,13 @@ import type { Signal } from '@preact/signals-core';

yBlock: YBlock;
get children(): BlockModel<object, SignaledProps<object>>[];
get doc(): Doc;
set doc(doc: Doc);
get parent(): BlockModel<object, SignaledProps<object>> | null;
constructor();
[Symbol.dispose](): void;
dispose(): void;
firstChild(): BlockModel | null;
lastChild(): BlockModel | null;
get children(): BlockModel<object, SignaledProps<object>>[];
get doc(): Doc;
set doc(doc: Doc);
get parent(): BlockModel<object, SignaledProps<object>> | null;
[Symbol.dispose](): void;
}
export {};
//# sourceMappingURL=base.d.ts.map

@@ -76,2 +76,14 @@ var _a;

export class BlockModel extends MagicProps() {
get children() {
return this._childModels.value;
}
get doc() {
return this.page;
}
set doc(doc) {
this.page = doc;
}
get parent() {
return this.doc.getParent(this);
}
constructor() {

@@ -117,6 +129,2 @@ super();

}
[(_a = modelLabel, Symbol.dispose)]() {
this._onCreated.dispose();
this._onDeleted.dispose();
}
dispose() {

@@ -136,15 +144,7 @@ this.created.dispose();

}
get children() {
return this._childModels.value;
[(_a = modelLabel, Symbol.dispose)]() {
this._onCreated.dispose();
this._onDeleted.dispose();
}
get doc() {
return this.page;
}
set doc(doc) {
this.page = doc;
}
get parent() {
return this.doc.getParent(this);
}
}
//# sourceMappingURL=base.js.map

@@ -22,2 +22,5 @@ import type * as Y from 'yjs';

validate: (flavour: string, parentFlavour?: string, childFlavours?: string[]) => void;
get versions(): {
[k: string]: number;
};
private _matchFlavour;

@@ -32,6 +35,3 @@ private _validateParent;

validateSchema(child: BlockSchemaType, parent: BlockSchemaType): void;
get versions(): {
[k: string]: number;
};
}
//# sourceMappingURL=schema.d.ts.map

@@ -111,2 +111,5 @@ import { minimatch } from 'minimatch';

}
get versions() {
return Object.fromEntries(Array.from(this.flavourSchemaMap.values()).map((schema) => [schema.model.flavour, schema.version]));
}
_matchFlavour(childFlavour, parentFlavour) {

@@ -190,6 +193,3 @@ return (minimatch(childFlavour, parentFlavour) ||

}
get versions() {
return Object.fromEntries(Array.from(this.flavourSchemaMap.values()).map((schema) => [schema.model.flavour, schema.version]));
}
}
//# sourceMappingURL=schema.js.map

@@ -1,3 +0,2 @@

import type { DocCollection } from '../collection.js';
import type { DocCollectionOptions } from '../collection.js';
import type { DocCollection, DocCollectionOptions } from '../collection.js';
type DocCollectionConstructor<Keys extends string> = {

@@ -4,0 +3,0 @@ new (storeOptions: DocCollectionOptions): Omit<DocCollection, Keys>;

@@ -32,4 +32,4 @@ import { type Logger, Slot } from '@blocksuite/global/utils';

export declare class DocCollection extends DocCollectionAddonType {
static Y: typeof Y;
protected readonly _schema: Schema;
static Y: typeof Y;
readonly awarenessStore: AwarenessStore;

@@ -50,2 +50,5 @@ readonly awarenessSync: AwarenessEngine;

};
get docs(): Map<string, BlockCollection>;
get isEmpty(): boolean;
get schema(): Schema;
constructor({ id, schema, idGenerator, defaultFlags, awarenessSources, docSources, blobSources, logger, }: DocCollectionOptions);

@@ -87,6 +90,3 @@ private _bindDocMetaEvents;

waitForSynced(): Promise<unknown>;
get docs(): Map<string, BlockCollection>;
get isEmpty(): boolean;
get schema(): Schema;
}
//# sourceMappingURL=collection.d.ts.map

@@ -53,3 +53,2 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {

enable_legacy_validation: true,
enable_expand_database_block: false,
enable_block_query: false,

@@ -78,2 +77,21 @@ enable_lasso_tool: false,

static { this.Y = Y; }
get docs() {
return this.blockCollections;
}
get isEmpty() {
if (this.doc.store.clients.size === 0)
return true;
let flag = false;
if (this.doc.store.clients.size === 1) {
const items = Array.from(this.doc.store.clients.values())[0];
// workspaceVersion and pageVersion were set when the collection is initialized
if (items.length <= 2) {
flag = true;
}
}
return flag;
}
get schema() {
return this._schema;
}
constructor({ id, schema, idGenerator, defaultFlags, awarenessSources = [], docSources = {

@@ -206,21 +224,2 @@ main: new NoopDocSource(),

}
get docs() {
return this.blockCollections;
}
get isEmpty() {
if (this.doc.store.clients.size === 0)
return true;
let flag = false;
if (this.doc.store.clients.size === 1) {
const items = Array.from(this.doc.store.clients.values())[0];
// workspaceVersion and pageVersion were set when the collection is initialized
if (items.length <= 2) {
flag = true;
}
}
return flag;
}
get schema() {
return this._schema;
}
static {

@@ -227,0 +226,0 @@ __runInitializers(_classThis, _classExtraInitializers);

@@ -65,2 +65,19 @@ import { Slot } from '@blocksuite/global/utils';

};
get awarenessSync(): import("@blocksuite/sync").AwarenessEngine;
get blobSync(): import("@blocksuite/sync").BlobEngine;
get canRedo(): boolean;
get canUndo(): boolean;
get collection(): DocCollection;
get crud(): DocCRUD;
get docSync(): import("@blocksuite/sync").DocEngine;
get history(): Y.UndoManager;
get isEmpty(): boolean;
get loaded(): boolean;
get meta(): import("../meta.js").DocMeta | undefined;
get readonly(): boolean;
get ready(): boolean;
get schema(): import("../../index.js").Schema;
get spaceDoc(): Y.Doc;
get Text(): typeof Text;
get yBlocks(): Y.Map<YBlock>;
constructor({ id, collection, doc, awarenessStore, idGenerator, }: DocOptions);

@@ -91,19 +108,2 @@ private _getReadonlyKey;

withoutTransact(callback: () => void): void;
get Text(): typeof Text;
get awarenessSync(): import("@blocksuite/sync").AwarenessEngine;
get blobSync(): import("@blocksuite/sync").BlobEngine;
get canRedo(): boolean;
get canUndo(): boolean;
get collection(): DocCollection;
get crud(): DocCRUD;
get docSync(): import("@blocksuite/sync").DocEngine;
get history(): Y.UndoManager;
get isEmpty(): boolean;
get loaded(): boolean;
get meta(): import("../meta.js").DocMeta | undefined;
get readonly(): boolean;
get ready(): boolean;
get schema(): import("../../index.js").Schema;
get spaceDoc(): Y.Doc;
get yBlocks(): Y.Map<YBlock>;
}

@@ -110,0 +110,0 @@ declare global {

@@ -8,2 +8,60 @@ import { Slot } from '@blocksuite/global/utils';

export class BlockCollection {
// So, we apply a listener at the top level for the flat structure of the current
get awarenessSync() {
return this.collection.awarenessSync;
}
get blobSync() {
return this.collection.blobSync;
}
get canRedo() {
if (this.readonly) {
return false;
}
return this._history.canRedo();
}
get canUndo() {
if (this.readonly) {
return false;
}
return this._history.canUndo();
}
get collection() {
return this._collection;
}
get crud() {
return this._docCRUD;
}
get docSync() {
return this.collection.docSync;
}
get history() {
return this._history;
}
get isEmpty() {
return this._yBlocks.size === 0;
}
get loaded() {
return this._loaded;
}
get meta() {
return this.collection.meta.getDocMeta(this.id);
}
get readonly() {
return this.awarenessStore.isReadonly(this);
}
get ready() {
return this._ready;
}
get schema() {
return this.collection.schema;
}
get spaceDoc() {
return this._ySpaceDoc;
}
get Text() {
return Text;
}
get yBlocks() {
return this._yBlocks;
}
constructor({ id, collection, doc, awarenessStore, idGenerator = uuidv4, }) {

@@ -217,61 +275,3 @@ this._docMap = {

}
get Text() {
return Text;
}
// So, we apply a listener at the top level for the flat structure of the current
get awarenessSync() {
return this.collection.awarenessSync;
}
get blobSync() {
return this.collection.blobSync;
}
get canRedo() {
if (this.readonly) {
return false;
}
return this._history.canRedo();
}
get canUndo() {
if (this.readonly) {
return false;
}
return this._history.canUndo();
}
get collection() {
return this._collection;
}
get crud() {
return this._docCRUD;
}
get docSync() {
return this.collection.docSync;
}
get history() {
return this._history;
}
get isEmpty() {
return this._yBlocks.size === 0;
}
get loaded() {
return this._loaded;
}
get meta() {
return this.collection.meta.getDocMeta(this.id);
}
get readonly() {
return this.awarenessStore.isReadonly(this);
}
get ready() {
return this._ready;
}
get schema() {
return this.collection.schema;
}
get spaceDoc() {
return this._ySpaceDoc;
}
get yBlocks() {
return this._yBlocks;
}
}
//# sourceMappingURL=block-collection.js.map

@@ -13,3 +13,2 @@ import type { Schema } from '../../../schema/index.js';

blockViewType: BlockViewType;
constructor(schema: Schema, yBlock: YBlock, doc?: Doc | undefined, options?: BlockOptions);
get flavour(): string;

@@ -21,3 +20,4 @@ get id(): string;

get version(): number;
constructor(schema: Schema, yBlock: YBlock, doc?: Doc | undefined, options?: BlockOptions);
}
//# sourceMappingURL=index.d.ts.map

@@ -5,15 +5,2 @@ import { BlockViewType } from '../consts.js';

export class Block {
constructor(schema, yBlock, doc, options = {}) {
this.schema = schema;
this.yBlock = yBlock;
this.doc = doc;
this.options = options;
this.blockViewType = BlockViewType.Display;
const onChange = !options.onChange
? undefined
: (key, value) => {
options.onChange?.(this, key, value);
};
this._syncController = new SyncController(schema, yBlock, doc, onChange);
}
get flavour() {

@@ -37,3 +24,16 @@ return this._syncController.flavour;

}
constructor(schema, yBlock, doc, options = {}) {
this.schema = schema;
this.yBlock = yBlock;
this.doc = doc;
this.options = options;
this.blockViewType = BlockViewType.Display;
const onChange = !options.onChange
? undefined
: (key, value) => {
options.onChange?.(this, key, value);
};
this._syncController = new SyncController(schema, yBlock, doc, onChange);
}
}
//# sourceMappingURL=index.js.map

@@ -7,2 +7,3 @@ import * as Y from 'yjs';

private readonly _schema;
get root(): string | null;
constructor(_yBlocks: Y.Map<YBlock>, _schema: Schema);

@@ -20,4 +21,3 @@ private _getSiblings;

updateBlockChildren(id: string, children: string[]): void;
get root(): string | null;
}
//# sourceMappingURL=crud.d.ts.map
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import * as Y from 'yjs';
import { native2Y } from '../../reactive/index.js';
import { internalPrimitives } from '../../schema/index.js';
import { internalPrimitives, } from '../../schema/index.js';
export class DocCRUD {
get root() {
let rootId = null;
this._yBlocks.forEach(yBlock => {
const flavour = yBlock.get('sys:flavour');
const schema = this._schema.flavourSchemaMap.get(flavour);
if (!schema)
return;
if (schema.model.role === 'root') {
rootId = yBlock.get('sys:id');
}
});
return rootId;
}
constructor(_yBlocks, _schema) {

@@ -234,16 +247,3 @@ this._yBlocks = _yBlocks;

}
get root() {
let rootId = null;
this._yBlocks.forEach(yBlock => {
const flavour = yBlock.get('sys:flavour');
const schema = this._schema.flavourSchemaMap.get(flavour);
if (!schema)
return;
if (schema.model.role === 'root') {
rootId = yBlock.get('sys:id');
}
});
return rootId;
}
}
//# sourceMappingURL=crud.js.map

@@ -15,2 +15,3 @@ import { type Disposable, Slot } from '@blocksuite/global/utils';

export declare class Doc {
private _runQuery;
protected readonly _blockCollection: BlockCollection;

@@ -22,3 +23,2 @@ protected readonly _blocks: import("@preact/signals-core").Signal<Record<string, Block>>;

protected readonly _readonly?: boolean;
private _runQuery;
protected readonly _schema: Schema;

@@ -56,2 +56,33 @@ readonly slots: BlockCollection['slots'] & {

};
private get _yBlocks();
get awarenessStore(): import("../../index.js").AwarenessStore<BlockSuiteFlags>;
get awarenessSync(): import("@blocksuite/sync").AwarenessEngine;
get blobSync(): import("@blocksuite/sync").BlobEngine;
get blockCollection(): BlockCollection;
get blocks(): import("@preact/signals-core").Signal<Record<string, Block>>;
get blockSize(): number;
get canRedo(): boolean;
get canUndo(): boolean;
get captureSync(): () => void;
get clear(): () => void;
get collection(): import("../collection.js").DocCollection;
get docSync(): import("@blocksuite/sync").DocEngine;
get generateBlockId(): () => string;
get history(): import("yjs").UndoManager;
get id(): string;
get isEmpty(): boolean;
get loaded(): boolean;
get meta(): import("../meta.js").DocMeta | undefined;
get readonly(): boolean;
get ready(): boolean;
get redo(): () => void;
get resetHistory(): () => void;
get root(): BlockModel<object, object & {}> | null;
get rootDoc(): import("../../index.js").BlockSuiteDoc;
get schema(): Schema;
get spaceDoc(): import("yjs").Doc;
get Text(): typeof import("../../index.js").Text;
get transact(): (fn: () => void, shouldTransact?: boolean) => void;
get undo(): () => void;
get withoutTransact(): (callback: () => void) => void;
constructor({ schema, blockCollection, crud, readonly, query }: DocOptions);

@@ -61,3 +92,2 @@ private _getSiblings;

private _onBlockRemoved;
private get _yBlocks();
addBlock<Key extends BlockSuite.Flavour>(flavour: Key, blockProps?: BlockSuite.ModelProps<BlockSuite.BlockModels[Key]>, parent?: BlockModel | string | null, parentIndex?: number): string;

@@ -117,34 +147,4 @@ addBlock(flavour: never, blockProps?: Partial<BlockProps & Omit<BlockProps, 'flavour'>>, parent?: BlockModel | string | null, parentIndex?: number): string;

updateBlock(model: BlockModel, callback: () => void): void;
get Text(): typeof import("../../index.js").Text;
get awarenessStore(): import("../../index.js").AwarenessStore<BlockSuiteFlags>;
get awarenessSync(): import("@blocksuite/sync").AwarenessEngine;
get blobSync(): import("@blocksuite/sync").BlobEngine;
get blockCollection(): BlockCollection;
get blockSize(): number;
get blocks(): import("@preact/signals-core").Signal<Record<string, Block>>;
get canRedo(): boolean;
get canUndo(): boolean;
get captureSync(): () => void;
get clear(): () => void;
get collection(): import("../collection.js").DocCollection;
get docSync(): import("@blocksuite/sync").DocEngine;
get generateBlockId(): () => string;
get history(): import("yjs").UndoManager;
get id(): string;
get isEmpty(): boolean;
get loaded(): boolean;
get meta(): import("../meta.js").DocMeta | undefined;
get readonly(): boolean;
get ready(): boolean;
get redo(): () => void;
get resetHistory(): () => void;
get root(): BlockModel<object, object & {}> | null;
get rootDoc(): import("../../index.js").BlockSuiteDoc;
get schema(): Schema;
get spaceDoc(): import("yjs").Doc;
get transact(): (fn: () => void, shouldTransact?: boolean) => void;
get undo(): () => void;
get withoutTransact(): (callback: () => void) => void;
}
export {};
//# sourceMappingURL=doc.d.ts.map

@@ -8,3 +8,105 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';

export class Doc {
get _yBlocks() {
return this._blockCollection.yBlocks;
}
get awarenessStore() {
return this._blockCollection.awarenessStore;
}
get awarenessSync() {
return this.collection.awarenessSync;
}
get blobSync() {
return this.collection.blobSync;
}
get blockCollection() {
return this._blockCollection;
}
get blocks() {
return this._blocks;
}
get blockSize() {
return Object.values(this._blocks.peek()).length;
}
get canRedo() {
return this._blockCollection.canRedo;
}
get canUndo() {
return this._blockCollection.canUndo;
}
get captureSync() {
return this._blockCollection.captureSync.bind(this._blockCollection);
}
get clear() {
return this._blockCollection.clear.bind(this._blockCollection);
}
get collection() {
return this._blockCollection.collection;
}
get docSync() {
return this.collection.docSync;
}
get generateBlockId() {
return this._blockCollection.generateBlockId.bind(this._blockCollection);
}
get history() {
return this._blockCollection.history;
}
get id() {
return this._blockCollection.id;
}
get isEmpty() {
return Object.values(this._blocks.peek()).length === 0;
}
get loaded() {
return this._blockCollection.loaded;
}
get meta() {
return this._blockCollection.meta;
}
get readonly() {
if (this._blockCollection.readonly) {
return true;
}
return this._readonly === true;
}
get ready() {
return this._blockCollection.ready;
}
get redo() {
return this._blockCollection.redo.bind(this._blockCollection);
}
get resetHistory() {
return this._blockCollection.resetHistory.bind(this._blockCollection);
}
get root() {
const rootId = this._crud.root;
if (!rootId)
return null;
return this.getBlock(rootId)?.model ?? null;
}
get rootDoc() {
return this._blockCollection.rootDoc;
}
get schema() {
return this._schema;
}
get spaceDoc() {
return this._blockCollection.spaceDoc;
}
get Text() {
return this._blockCollection.Text;
}
get transact() {
return this._blockCollection.transact.bind(this._blockCollection);
}
get undo() {
return this._blockCollection.undo.bind(this._blockCollection);
}
get withoutTransact() {
return this._blockCollection.withoutTransact.bind(this._blockCollection);
}
constructor({ schema, blockCollection, crud, readonly, query }) {
this._runQuery = (block) => {
runQuery(this._query, block);
};
this._blocks = signal({});

@@ -15,5 +117,2 @@ this._query = {

};
this._runQuery = (block) => {
runQuery(this._query, block);
};
this._blockCollection = blockCollection;

@@ -136,5 +235,2 @@ this.slots = {

}
get _yBlocks() {
return this._blockCollection.yBlocks;
}
addBlock(flavour, blockProps = {}, parent, parentIndex) {

@@ -318,99 +414,3 @@ if (this.readonly) {

}
get Text() {
return this._blockCollection.Text;
}
get awarenessStore() {
return this._blockCollection.awarenessStore;
}
get awarenessSync() {
return this.collection.awarenessSync;
}
get blobSync() {
return this.collection.blobSync;
}
get blockCollection() {
return this._blockCollection;
}
get blockSize() {
return Object.values(this._blocks.peek()).length;
}
get blocks() {
return this._blocks;
}
get canRedo() {
return this._blockCollection.canRedo;
}
get canUndo() {
return this._blockCollection.canUndo;
}
get captureSync() {
return this._blockCollection.captureSync.bind(this._blockCollection);
}
get clear() {
return this._blockCollection.clear.bind(this._blockCollection);
}
get collection() {
return this._blockCollection.collection;
}
get docSync() {
return this.collection.docSync;
}
get generateBlockId() {
return this._blockCollection.generateBlockId.bind(this._blockCollection);
}
get history() {
return this._blockCollection.history;
}
get id() {
return this._blockCollection.id;
}
get isEmpty() {
return Object.values(this._blocks.peek()).length === 0;
}
get loaded() {
return this._blockCollection.loaded;
}
get meta() {
return this._blockCollection.meta;
}
get readonly() {
if (this._blockCollection.readonly) {
return true;
}
return this._readonly === true;
}
get ready() {
return this._blockCollection.ready;
}
get redo() {
return this._blockCollection.redo.bind(this._blockCollection);
}
get resetHistory() {
return this._blockCollection.resetHistory.bind(this._blockCollection);
}
get root() {
const rootId = this._crud.root;
if (!rootId)
return null;
return this.getBlock(rootId)?.model ?? null;
}
get rootDoc() {
return this._blockCollection.rootDoc;
}
get schema() {
return this._schema;
}
get spaceDoc() {
return this._blockCollection.spaceDoc;
}
get transact() {
return this._blockCollection.transact.bind(this._blockCollection);
}
get undo() {
return this._blockCollection.undo.bind(this._blockCollection);
}
get withoutTransact() {
return this._blockCollection.withoutTransact.bind(this._blockCollection);
}
}
//# sourceMappingURL=doc.js.map

@@ -42,2 +42,12 @@ import type * as Y from 'yjs';

readonly id: string;
get avatar(): string | undefined;
get blockVersions(): Record<string, number> | undefined;
get docMetas(): DocMeta[];
get docs(): unknown[] | undefined;
get hasVersion(): boolean;
get name(): string | undefined;
get pageVersion(): number | undefined;
get properties(): DocsPropertiesMeta;
get workspaceVersion(): number | undefined;
get yDocs(): Y.Array<unknown>;
constructor(doc: BlockSuiteDoc);

@@ -63,13 +73,3 @@ private _handleCommonFieldsEvent;

writeVersion(collection: DocCollection): void;
get avatar(): string | undefined;
get blockVersions(): Record<string, number> | undefined;
get docMetas(): DocMeta[];
get docs(): unknown[] | undefined;
get hasVersion(): boolean;
get name(): string | undefined;
get pageVersion(): number | undefined;
get properties(): DocsPropertiesMeta;
get workspaceVersion(): number | undefined;
get yDocs(): Y.Array<unknown>;
}
//# sourceMappingURL=meta.d.ts.map

@@ -5,2 +5,46 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';

export class DocCollectionMeta {
get avatar() {
return this._proxy.avatar;
}
get blockVersions() {
return this._proxy.blockVersions;
}
get docMetas() {
if (!this._proxy.pages) {
return [];
}
return this._proxy.pages;
}
get docs() {
return this._proxy.pages;
}
get hasVersion() {
if (!this.blockVersions || !this.pageVersion || !this.workspaceVersion) {
return false;
}
return Object.keys(this.blockVersions).length > 0;
}
get name() {
return this._proxy.name;
}
get pageVersion() {
return this._proxy.pageVersion;
}
get properties() {
const meta = this._proxy.properties;
if (!meta) {
return {
tags: {
options: [],
},
};
}
return meta;
}
get workspaceVersion() {
return this._proxy.workspaceVersion;
}
get yDocs() {
return this._yMap.get('pages');
}
constructor(doc) {

@@ -197,47 +241,3 @@ this._handleDocCollectionMetaEvents = (events) => {

}
get avatar() {
return this._proxy.avatar;
}
get blockVersions() {
return this._proxy.blockVersions;
}
get docMetas() {
if (!this._proxy.pages) {
return [];
}
return this._proxy.pages;
}
get docs() {
return this._proxy.pages;
}
get hasVersion() {
if (!this.blockVersions || !this.pageVersion || !this.workspaceVersion) {
return false;
}
return Object.keys(this.blockVersions).length > 0;
}
get name() {
return this._proxy.name;
}
get pageVersion() {
return this._proxy.pageVersion;
}
get properties() {
const meta = this._proxy.properties;
if (!meta) {
return {
tags: {
options: [],
},
};
}
return meta;
}
get workspaceVersion() {
return this._proxy.workspaceVersion;
}
get yDocs() {
return this._yMap.get('pages');
}
}
//# sourceMappingURL=meta.js.map

@@ -29,2 +29,6 @@ import type { BlockModel } from '../schema/index.js';

walk: (snapshot: DocSnapshot, callback: (block: BlockSnapshot) => void) => void;
get adapterConfigs(): Map<string, string>;
get assets(): Map<string, Blob>;
get assetsManager(): AssetsManager;
get collection(): DocCollection;
constructor({ collection, middlewares }: JobConfig);

@@ -39,7 +43,3 @@ private _batchSnapshotToBlock;

reset(): void;
get adapterConfigs(): Map<string, string>;
get assets(): Map<string, Blob>;
get assetsManager(): AssetsManager;
get collection(): DocCollection;
}
//# sourceMappingURL=job.d.ts.map

@@ -9,2 +9,14 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';

export class Job {
get adapterConfigs() {
return this._adapterConfigs;
}
get assets() {
return this._assetsManager.getAssets();
}
get assetsManager() {
return this._assetsManager;
}
get collection() {
return this._collection;
}
constructor({ collection, middlewares = [] }) {

@@ -386,15 +398,3 @@ this._adapterConfigs = new Map();

}
get adapterConfigs() {
return this._adapterConfigs;
}
get assets() {
return this._assetsManager.getAssets();
}
get assetsManager() {
return this._assetsManager;
}
get collection() {
return this._collection;
}
}
//# sourceMappingURL=job.js.map

@@ -12,4 +12,2 @@ import type { Doc } from '../store/index.js';

readonly data: SliceData;
constructor(data: SliceData);
static fromModels(doc: Doc, models: DraftModel[]): Slice;
get content(): DraftModel[];

@@ -20,4 +18,6 @@ get docId(): string;

get workspaceVersion(): number;
constructor(data: SliceData);
static fromModels(doc: Doc, models: DraftModel[]): Slice;
}
export {};
//# sourceMappingURL=slice.d.ts.map
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
export class Slice {
get content() {
return this.data.content;
}
get docId() {
return this.data.pageId;
}
get pageVersion() {
return this.data.pageVersion;
}
get workspaceId() {
return this.data.workspaceId;
}
get workspaceVersion() {
return this.data.workspaceVersion;
}
constructor(data) {

@@ -20,18 +35,3 @@ this.data = data;

}
get content() {
return this.data.content;
}
get docId() {
return this.data.pageId;
}
get pageVersion() {
return this.data.pageVersion;
}
get workspaceId() {
return this.data.workspaceId;
}
get workspaceVersion() {
return this.data.workspaceVersion;
}
}
//# sourceMappingURL=slice.js.map
import type { z } from 'zod';
import type { BlockModel } from '../schema/base.js';
import type { BlockSchema } from '../schema/base.js';
import type { BlockModel, BlockSchema } from '../schema/base.js';
import type { YBlock } from '../store/doc/block/index.js';

@@ -5,0 +4,0 @@ import type { BlockProps } from '../store/doc/block-collection.js';

@@ -7,2 +7,3 @@ import type { Transaction } from 'yjs';

private _spaces;
get spaces(): Y.Map<Y.Doc>;
getArrayProxy<Key extends keyof BlockSuiteDocData & string, Value extends unknown[] = BlockSuiteDocData[Key] extends unknown[] ? BlockSuiteDocData[Key] : never>(key: Key): Value;

@@ -12,4 +13,3 @@ getMapProxy<Key extends keyof BlockSuiteDocData & string, Value extends Record<string, unknown> = BlockSuiteDocData[Key] extends Record<string, unknown> ? BlockSuiteDocData[Key] : never>(key: Key): Value;

transact<T>(f: (arg0: Transaction) => T, origin?: number | string): T;
get spaces(): Y.Map<Y.Doc>;
}
//# sourceMappingURL=doc.d.ts.map

@@ -8,2 +8,5 @@ import * as Y from 'yjs';

}
get spaces() {
return this._spaces;
}
getArrayProxy(key) {

@@ -33,6 +36,3 @@ const array = super.getArray(key);

}
get spaces() {
return this._spaces;
}
}
//# sourceMappingURL=doc.js.map
{
"name": "@blocksuite/store",
"version": "0.0.0-canary-20240906001315",
"version": "0.0.0-canary-20240907001248",
"description": "BlockSuite data store built for general purpose state management.",

@@ -23,5 +23,5 @@ "type": "module",

"zod": "^3.23.8",
"@blocksuite/global": "0.0.0-canary-20240906001315",
"@blocksuite/inline": "0.0.0-canary-20240906001315",
"@blocksuite/sync": "0.0.0-canary-20240906001315"
"@blocksuite/global": "0.0.0-canary-20240907001248",
"@blocksuite/inline": "0.0.0-canary-20240907001248",
"@blocksuite/sync": "0.0.0-canary-20240907001248"
},

@@ -28,0 +28,0 @@ "devDependencies": {

@@ -5,4 +5,3 @@ import { assertEquals } from '@blocksuite/global/utils';

import type { AssetsManager } from '../transformer/assets.js';
import type { Slice } from '../transformer/index.js';
import type { DraftModel, Job } from '../transformer/index.js';
import type { DraftModel, Job, Slice } from '../transformer/index.js';
import type {

@@ -56,2 +55,6 @@ BlockSnapshot,

get configs() {
return this.job.adapterConfigs;
}
constructor(job: Job) {

@@ -76,2 +79,8 @@ this.job = job;

abstract fromBlockSnapshot(
payload: FromBlockSnapshotPayload
):
| Promise<FromBlockSnapshotResult<AdapterTarget>>
| FromBlockSnapshotResult<AdapterTarget>;
async fromDoc(doc: Doc) {

@@ -92,2 +101,8 @@ try {

abstract fromDocSnapshot(
payload: FromDocSnapshotPayload
):
| Promise<FromDocSnapshotResult<AdapterTarget>>
| FromDocSnapshotResult<AdapterTarget>;
async fromSlice(slice: Slice) {

@@ -108,2 +123,8 @@ try {

abstract fromSliceSnapshot(
payload: FromSliceSnapshotPayload
):
| Promise<FromSliceSnapshotResult<AdapterTarget>>
| FromSliceSnapshotResult<AdapterTarget>;
async toBlock(

@@ -126,2 +147,6 @@ payload: ToBlockSnapshotPayload<AdapterTarget>,

abstract toBlockSnapshot(
payload: ToBlockSnapshotPayload<AdapterTarget>
): Promise<BlockSnapshot> | BlockSnapshot;
async toDoc(payload: ToDocSnapshotPayload<AdapterTarget>) {

@@ -139,2 +164,6 @@ try {

abstract toDocSnapshot(
payload: ToDocSnapshotPayload<AdapterTarget>
): Promise<DocSnapshot> | DocSnapshot;
async toSlice(

@@ -157,32 +186,2 @@ payload: ToSliceSnapshotPayload<AdapterTarget>,

get configs() {
return this.job.adapterConfigs;
}
abstract fromBlockSnapshot(
payload: FromBlockSnapshotPayload
):
| Promise<FromBlockSnapshotResult<AdapterTarget>>
| FromBlockSnapshotResult<AdapterTarget>;
abstract fromDocSnapshot(
payload: FromDocSnapshotPayload
):
| Promise<FromDocSnapshotResult<AdapterTarget>>
| FromDocSnapshotResult<AdapterTarget>;
abstract fromSliceSnapshot(
payload: FromSliceSnapshotPayload
):
| Promise<FromSliceSnapshotResult<AdapterTarget>>
| FromSliceSnapshotResult<AdapterTarget>;
abstract toBlockSnapshot(
payload: ToBlockSnapshotPayload<AdapterTarget>
): Promise<BlockSnapshot> | BlockSnapshot;
abstract toDocSnapshot(
payload: ToDocSnapshotPayload<AdapterTarget>
): Promise<DocSnapshot> | DocSnapshot;
abstract toSliceSnapshot(

@@ -189,0 +188,0 @@ payload: ToSliceSnapshotPayload<AdapterTarget>

@@ -8,6 +8,2 @@ type Keyof<T> = T extends unknown ? keyof T : never;

_skip = false;
_skipChildrenNum = 0;
private _stack: {

@@ -19,2 +15,6 @@ node: TNode;

_skip = false;
_skipChildrenNum = 0;
setDefaultProp = (parentProp: Keyof<TNode>) => {

@@ -24,2 +24,6 @@ this._defaultProp = parentProp;

get stack() {
return this._stack;
}
private current() {

@@ -112,6 +116,2 @@ return this._stack[this._stack.length - 1];

}
get stack() {
return this._stack;
}
}

@@ -13,5 +13,5 @@ /// <reference types="@blocksuite/global" preserve="true" />

export {
type IdGenerator,
createAutoIncrementIdGenerator,
createAutoIncrementIdGeneratorByClientId,
type IdGenerator,
nanoid,

@@ -18,0 +18,0 @@ uuidv4,

@@ -8,6 +8,2 @@ import * as Y from 'yjs';

export class Boxed<T = unknown> {
private readonly _map: Y.Map<T>;
private _onChange?: OnBoxedChange;
static from = <T>(map: Y.Map<T>, onChange?: OnBoxedChange): Boxed<T> => {

@@ -23,2 +19,6 @@ return new Boxed<T>(map.get('value') as T, onChange);

private readonly _map: Y.Map<T>;
private _onChange?: OnBoxedChange;
getValue = () => {

@@ -32,2 +32,6 @@ return this._map.get('value');

get yMap() {
return this._map;
}
constructor(value: T, onChange?: OnBoxedChange) {

@@ -53,6 +57,2 @@ this._onChange = onChange;

}
get yMap() {
return this._map;
}
}

@@ -23,2 +23,31 @@ import type { YArrayEvent, YMapEvent } from 'yjs';

> {
private _observer = (event: YArrayEvent<unknown>) => {
this._onObserve(event, () => {
let retain = 0;
event.changes.delta.forEach(change => {
if (change.retain) {
retain += change.retain;
return;
}
if (change.delete) {
this._updateWithSkip(() => {
this._source.splice(retain, change.delete);
});
return;
}
if (change.insert) {
const _arr = [change.insert].flat();
const proxyList = _arr.map(value => createYProxy(value));
this._updateWithSkip(() => {
this._source.splice(retain, 0, ...proxyList);
});
retain += change.insert.length;
}
});
});
};
protected _getProxy = () => {

@@ -112,31 +141,2 @@ return new Proxy(this._source, {

private _observer = (event: YArrayEvent<unknown>) => {
this._onObserve(event, () => {
let retain = 0;
event.changes.delta.forEach(change => {
if (change.retain) {
retain += change.retain;
return;
}
if (change.delete) {
this._updateWithSkip(() => {
this._source.splice(retain, change.delete);
});
return;
}
if (change.insert) {
const _arr = [change.insert].flat();
const proxyList = _arr.map(value => createYProxy(value));
this._updateWithSkip(() => {
this._source.splice(retain, 0, ...proxyList);
});
retain += change.insert.length;
}
});
});
};
protected readonly _proxy: unknown[];

@@ -167,2 +167,25 @@

export class ReactiveYMap extends BaseReactiveYData<UnRecord, YMap<unknown>> {
private _observer = (event: YMapEvent<unknown>) => {
this._onObserve(event, () => {
event.keysChanged.forEach(key => {
const type = event.changes.keys.get(key);
if (!type) {
return;
}
if (type.action === 'delete') {
this._updateWithSkip(() => {
delete this._source[key];
});
} else if (type.action === 'add' || type.action === 'update') {
const current = this._ySource.get(key);
this._updateWithSkip(() => {
this._source[key] = proxies.has(current)
? proxies.get(current)
: createYProxy(current, this._options);
});
}
});
});
};
protected _getProxy = () => {

@@ -250,25 +273,2 @@ return new Proxy(this._source, {

private _observer = (event: YMapEvent<unknown>) => {
this._onObserve(event, () => {
event.keysChanged.forEach(key => {
const type = event.changes.keys.get(key);
if (!type) {
return;
}
if (type.action === 'delete') {
this._updateWithSkip(() => {
delete this._source[key];
});
} else if (type.action === 'add' || type.action === 'update') {
const current = this._ySource.get(key);
this._updateWithSkip(() => {
this._source[key] = proxies.has(current)
? proxies.get(current)
: createYProxy(current, this._options);
});
}
});
});
};
protected readonly _proxy: UnRecord;

@@ -275,0 +275,0 @@

@@ -28,2 +28,14 @@ import type { BaseTextAttributes, DeltaInsert } from '@blocksuite/inline';

get deltas$() {
return this._deltas$;
}
get length() {
return this._length$.value;
}
get yText() {
return this._yText;
}
constructor(

@@ -334,14 +346,2 @@ input?: Y.Text | string | DeltaInsert[],

}
get deltas$() {
return this._deltas$;
}
get length() {
return this._length$.value;
}
get yText() {
return this._yText;
}
}

@@ -130,4 +130,10 @@ import type { Doc as YDoc, YEvent } from 'yjs';

protected abstract readonly _options: ProxyOptions<T>;
protected abstract readonly _proxy: T;
protected _skipNext = false;
protected abstract readonly _source: T;
protected readonly _stashed = new Set<string | number>();

@@ -145,2 +151,4 @@

protected abstract readonly _ySource: Y;
get proxy() {

@@ -152,12 +160,4 @@ return this._proxy;

protected abstract readonly _options: ProxyOptions<T>;
protected abstract readonly _proxy: T;
protected abstract readonly _source: T;
protected abstract readonly _ySource: Y;
abstract pop(prop: string | number): void;
abstract stash(prop: string | number): void;
}

@@ -243,2 +243,18 @@ import type { Signal } from '@preact/signals-core';

get children() {
return this._childModels.value;
}
get doc() {
return this.page;
}
set doc(doc: Doc) {
this.page = doc;
}
get parent() {
return this.doc.getParent(this);
}
constructor() {

@@ -262,7 +278,2 @@ super();

[Symbol.dispose]() {
this._onCreated.dispose();
this._onDeleted.dispose();
}
dispose() {

@@ -285,17 +296,6 @@ this.created.dispose();

get children() {
return this._childModels.value;
[Symbol.dispose]() {
this._onCreated.dispose();
this._onDeleted.dispose();
}
get doc() {
return this.page;
}
set doc(doc: Doc) {
this.page = doc;
}
get parent() {
return this.doc.getParent(this);
}
}

@@ -147,2 +147,10 @@ import type * as Y from 'yjs';

get versions() {
return Object.fromEntries(
Array.from(this.flavourSchemaMap.values()).map(
(schema): [string, number] => [schema.model.flavour, schema.version]
)
);
}
private _matchFlavour(childFlavour: string, parentFlavour: string) {

@@ -264,10 +272,2 @@ return (

}
get versions() {
return Object.fromEntries(
Array.from(this.flavourSchemaMap.values()).map(
(schema): [string, number] => [schema.model.flavour, schema.version]
)
);
}
}

@@ -1,3 +0,2 @@

import type { DocCollection } from '../collection.js';
import type { DocCollectionOptions } from '../collection.js';
import type { DocCollection, DocCollectionOptions } from '../collection.js';

@@ -4,0 +3,0 @@ type DocCollectionConstructor<Keys extends string> = {

@@ -56,3 +56,2 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';

enable_legacy_validation: true,
enable_expand_database_block: false,
enable_block_query: false,

@@ -73,6 +72,6 @@ enable_lasso_tool: false,

export class DocCollection extends DocCollectionAddonType {
static Y = Y;
protected readonly _schema: Schema;
static Y = Y;
readonly awarenessStore: AwarenessStore;

@@ -103,2 +102,24 @@

get docs() {
return this.blockCollections;
}
get isEmpty() {
if (this.doc.store.clients.size === 0) return true;
let flag = false;
if (this.doc.store.clients.size === 1) {
const items = Array.from(this.doc.store.clients.values())[0];
// workspaceVersion and pageVersion were set when the collection is initialized
if (items.length <= 2) {
flag = true;
}
}
return flag;
}
get schema() {
return this._schema;
}
constructor({

@@ -275,24 +296,2 @@ id,

}
get docs() {
return this.blockCollections;
}
get isEmpty() {
if (this.doc.store.clients.size === 0) return true;
let flag = false;
if (this.doc.store.clients.size === 1) {
const items = Array.from(this.doc.store.clients.values())[0];
// workspaceVersion and pageVersion were set when the collection is initialized
if (items.length <= 2) {
flag = true;
}
}
return flag;
}
get schema() {
return this._schema;
}
}

@@ -129,2 +129,77 @@ import { Slot } from '@blocksuite/global/utils';

// So, we apply a listener at the top level for the flat structure of the current
get awarenessSync() {
return this.collection.awarenessSync;
}
get blobSync() {
return this.collection.blobSync;
}
get canRedo() {
if (this.readonly) {
return false;
}
return this._history.canRedo();
}
get canUndo() {
if (this.readonly) {
return false;
}
return this._history.canUndo();
}
get collection() {
return this._collection;
}
get crud() {
return this._docCRUD;
}
get docSync() {
return this.collection.docSync;
}
get history() {
return this._history;
}
get isEmpty() {
return this._yBlocks.size === 0;
}
get loaded() {
return this._loaded;
}
get meta() {
return this.collection.meta.getDocMeta(this.id);
}
get readonly() {
return this.awarenessStore.isReadonly(this);
}
get ready() {
return this._ready;
}
get schema() {
return this.collection.schema;
}
get spaceDoc() {
return this._ySpaceDoc;
}
get Text() {
return Text;
}
get yBlocks() {
return this._yBlocks;
}
constructor({

@@ -338,77 +413,2 @@ id,

}
get Text() {
return Text;
}
// So, we apply a listener at the top level for the flat structure of the current
get awarenessSync() {
return this.collection.awarenessSync;
}
get blobSync() {
return this.collection.blobSync;
}
get canRedo() {
if (this.readonly) {
return false;
}
return this._history.canRedo();
}
get canUndo() {
if (this.readonly) {
return false;
}
return this._history.canUndo();
}
get collection() {
return this._collection;
}
get crud() {
return this._docCRUD;
}
get docSync() {
return this.collection.docSync;
}
get history() {
return this._history;
}
get isEmpty() {
return this._yBlocks.size === 0;
}
get loaded() {
return this._loaded;
}
get meta() {
return this.collection.meta.getDocMeta(this.id);
}
get readonly() {
return this.awarenessStore.isReadonly(this);
}
get ready() {
return this._ready;
}
get schema() {
return this.collection.schema;
}
get spaceDoc() {
return this._ySpaceDoc;
}
get yBlocks() {
return this._yBlocks;
}
}

@@ -415,0 +415,0 @@

@@ -15,16 +15,2 @@ import type { Schema } from '../../../schema/index.js';

constructor(
readonly schema: Schema,
readonly yBlock: YBlock,
readonly doc?: Doc,
readonly options: BlockOptions = {}
) {
const onChange = !options.onChange
? undefined
: (key: string, value: unknown) => {
options.onChange?.(this, key, value);
};
this._syncController = new SyncController(schema, yBlock, doc, onChange);
}
get flavour() {

@@ -53,2 +39,16 @@ return this._syncController.flavour;

}
constructor(
readonly schema: Schema,
readonly yBlock: YBlock,
readonly doc?: Doc,
readonly options: BlockOptions = {}
) {
const onChange = !options.onChange
? undefined
: (key: string, value: unknown) => {
options.onChange?.(this, key, value);
};
this._syncController = new SyncController(schema, yBlock, doc, onChange);
}
}

@@ -12,5 +12,5 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';

Boxed,
type UnRecord,
createYProxy,
native2Y,
type UnRecord,
y2Native,

@@ -17,0 +17,0 @@ } from '../../../reactive/index.js';

import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import * as Y from 'yjs';
import type { BlockModel } from '../../schema/index.js';
import type { YBlock } from './index.js';
import { native2Y } from '../../reactive/index.js';
import { type Schema, internalPrimitives } from '../../schema/index.js';
import {
type BlockModel,
internalPrimitives,
type Schema,
} from '../../schema/index.js';
export class DocCRUD {
get root(): string | null {
let rootId: string | null = null;
this._yBlocks.forEach(yBlock => {
const flavour = yBlock.get('sys:flavour');
const schema = this._schema.flavourSchemaMap.get(flavour);
if (!schema) return;
if (schema.model.role === 'root') {
rootId = yBlock.get('sys:id');
}
});
return rootId;
}
constructor(

@@ -329,16 +346,2 @@ private readonly _yBlocks: Y.Map<YBlock>,

}
get root(): string | null {
let rootId: string | null = null;
this._yBlocks.forEach(yBlock => {
const flavour = yBlock.get('sys:flavour');
const schema = this._schema.flavourSchemaMap.get(flavour);
if (!schema) return;
if (schema.model.role === 'root') {
rootId = yBlock.get('sys:id');
}
});
return rootId;
}
}

@@ -23,2 +23,6 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';

export class Doc {
private _runQuery = (block: Block) => {
runQuery(this._query, block);
};
protected readonly _blockCollection: BlockCollection;

@@ -39,6 +43,2 @@

private _runQuery = (block: Block) => {
runQuery(this._query, block);
};
protected readonly _schema: Schema;

@@ -80,2 +80,131 @@

private get _yBlocks() {
return this._blockCollection.yBlocks;
}
get awarenessStore() {
return this._blockCollection.awarenessStore;
}
get awarenessSync() {
return this.collection.awarenessSync;
}
get blobSync() {
return this.collection.blobSync;
}
get blockCollection() {
return this._blockCollection;
}
get blocks() {
return this._blocks;
}
get blockSize() {
return Object.values(this._blocks.peek()).length;
}
get canRedo() {
return this._blockCollection.canRedo;
}
get canUndo() {
return this._blockCollection.canUndo;
}
get captureSync() {
return this._blockCollection.captureSync.bind(this._blockCollection);
}
get clear() {
return this._blockCollection.clear.bind(this._blockCollection);
}
get collection() {
return this._blockCollection.collection;
}
get docSync() {
return this.collection.docSync;
}
get generateBlockId() {
return this._blockCollection.generateBlockId.bind(this._blockCollection);
}
get history() {
return this._blockCollection.history;
}
get id() {
return this._blockCollection.id;
}
get isEmpty() {
return Object.values(this._blocks.peek()).length === 0;
}
get loaded() {
return this._blockCollection.loaded;
}
get meta() {
return this._blockCollection.meta;
}
get readonly() {
if (this._blockCollection.readonly) {
return true;
}
return this._readonly === true;
}
get ready() {
return this._blockCollection.ready;
}
get redo() {
return this._blockCollection.redo.bind(this._blockCollection);
}
get resetHistory() {
return this._blockCollection.resetHistory.bind(this._blockCollection);
}
get root() {
const rootId = this._crud.root;
if (!rootId) return null;
return this.getBlock(rootId)?.model ?? null;
}
get rootDoc() {
return this._blockCollection.rootDoc;
}
get schema() {
return this._schema;
}
get spaceDoc() {
return this._blockCollection.spaceDoc;
}
get Text() {
return this._blockCollection.Text;
}
get transact() {
return this._blockCollection.transact.bind(this._blockCollection);
}
get undo() {
return this._blockCollection.undo.bind(this._blockCollection);
}
get withoutTransact() {
return this._blockCollection.withoutTransact.bind(this._blockCollection);
}
constructor({ schema, blockCollection, crud, readonly, query }: DocOptions) {

@@ -220,6 +349,2 @@ this._blockCollection = blockCollection;

private get _yBlocks() {
return this._blockCollection.yBlocks;
}
addBlock<Key extends BlockSuite.Flavour>(

@@ -550,127 +675,2 @@ flavour: Key,

}
get Text() {
return this._blockCollection.Text;
}
get awarenessStore() {
return this._blockCollection.awarenessStore;
}
get awarenessSync() {
return this.collection.awarenessSync;
}
get blobSync() {
return this.collection.blobSync;
}
get blockCollection() {
return this._blockCollection;
}
get blockSize() {
return Object.values(this._blocks.peek()).length;
}
get blocks() {
return this._blocks;
}
get canRedo() {
return this._blockCollection.canRedo;
}
get canUndo() {
return this._blockCollection.canUndo;
}
get captureSync() {
return this._blockCollection.captureSync.bind(this._blockCollection);
}
get clear() {
return this._blockCollection.clear.bind(this._blockCollection);
}
get collection() {
return this._blockCollection.collection;
}
get docSync() {
return this.collection.docSync;
}
get generateBlockId() {
return this._blockCollection.generateBlockId.bind(this._blockCollection);
}
get history() {
return this._blockCollection.history;
}
get id() {
return this._blockCollection.id;
}
get isEmpty() {
return Object.values(this._blocks.peek()).length === 0;
}
get loaded() {
return this._blockCollection.loaded;
}
get meta() {
return this._blockCollection.meta;
}
get readonly() {
if (this._blockCollection.readonly) {
return true;
}
return this._readonly === true;
}
get ready() {
return this._blockCollection.ready;
}
get redo() {
return this._blockCollection.redo.bind(this._blockCollection);
}
get resetHistory() {
return this._blockCollection.resetHistory.bind(this._blockCollection);
}
get root() {
const rootId = this._crud.root;
if (!rootId) return null;
return this.getBlock(rootId)?.model ?? null;
}
get rootDoc() {
return this._blockCollection.rootDoc;
}
get schema() {
return this._schema;
}
get spaceDoc() {
return this._blockCollection.spaceDoc;
}
get transact() {
return this._blockCollection.transact.bind(this._blockCollection);
}
get undo() {
return this._blockCollection.undo.bind(this._blockCollection);
}
get withoutTransact() {
return this._blockCollection.withoutTransact.bind(this._blockCollection);
}
}
import {
type IdGenerator,
createAutoIncrementIdGenerator,
createAutoIncrementIdGeneratorByClientId,
type IdGenerator,
nanoid,

@@ -6,0 +6,0 @@ uuidv4,

@@ -82,2 +82,56 @@ import type * as Y from 'yjs';

get avatar() {
return this._proxy.avatar;
}
get blockVersions() {
return this._proxy.blockVersions;
}
get docMetas() {
if (!this._proxy.pages) {
return [] as DocMeta[];
}
return this._proxy.pages as DocMeta[];
}
get docs() {
return this._proxy.pages;
}
get hasVersion() {
if (!this.blockVersions || !this.pageVersion || !this.workspaceVersion) {
return false;
}
return Object.keys(this.blockVersions).length > 0;
}
get name() {
return this._proxy.name;
}
get pageVersion() {
return this._proxy.pageVersion;
}
get properties(): DocsPropertiesMeta {
const meta = this._proxy.properties;
if (!meta) {
return {
tags: {
options: [],
},
};
}
return meta;
}
get workspaceVersion() {
return this._proxy.workspaceVersion;
}
get yDocs() {
return this._yMap.get('pages') as unknown as Y.Array<unknown>;
}
constructor(doc: BlockSuiteDoc) {

@@ -305,56 +359,2 @@ this.doc = doc;

}
get avatar() {
return this._proxy.avatar;
}
get blockVersions() {
return this._proxy.blockVersions;
}
get docMetas() {
if (!this._proxy.pages) {
return [] as DocMeta[];
}
return this._proxy.pages as DocMeta[];
}
get docs() {
return this._proxy.pages;
}
get hasVersion() {
if (!this.blockVersions || !this.pageVersion || !this.workspaceVersion) {
return false;
}
return Object.keys(this.blockVersions).length > 0;
}
get name() {
return this._proxy.name;
}
get pageVersion() {
return this._proxy.pageVersion;
}
get properties(): DocsPropertiesMeta {
const meta = this._proxy.properties;
if (!meta) {
return {
tags: {
options: [],
},
};
}
return meta;
}
get workspaceVersion() {
return this._proxy.workspaceVersion;
}
get yDocs() {
return this._yMap.get('pages') as unknown as Y.Array<unknown>;
}
}

@@ -306,2 +306,18 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';

get adapterConfigs() {
return this._adapterConfigs;
}
get assets() {
return this._assetsManager.getAssets();
}
get assetsManager() {
return this._assetsManager;
}
get collection() {
return this._collection;
}
constructor({ collection, middlewares = [] }: JobConfig) {

@@ -511,18 +527,2 @@ this._collection = collection;

}
get adapterConfigs() {
return this._adapterConfigs;
}
get assets() {
return this._assetsManager.getAssets();
}
get assetsManager() {
return this._assetsManager;
}
get collection() {
return this._collection;
}
}

@@ -15,2 +15,22 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';

export class Slice {
get content() {
return this.data.content;
}
get docId() {
return this.data.pageId;
}
get pageVersion() {
return this.data.pageVersion;
}
get workspaceId() {
return this.data.workspaceId;
}
get workspaceVersion() {
return this.data.workspaceVersion;
}
constructor(readonly data: SliceData) {}

@@ -35,22 +55,2 @@

}
get content() {
return this.data.content;
}
get docId() {
return this.data.pageId;
}
get pageVersion() {
return this.data.pageVersion;
}
get workspaceId() {
return this.data.workspaceId;
}
get workspaceVersion() {
return this.data.workspaceVersion;
}
}
import type { z } from 'zod';
import type { BlockModel } from '../schema/base.js';
import type { BlockSchema } from '../schema/base.js';
import type { BlockModel, BlockSchema } from '../schema/base.js';
import type { YBlock } from '../store/doc/block/index.js';

@@ -6,0 +5,0 @@ import type { BlockProps } from '../store/doc/block-collection.js';

@@ -16,2 +16,6 @@ import type { Transaction } from 'yjs';

get spaces() {
return this._spaces;
}
getArrayProxy<

@@ -57,6 +61,2 @@ Key extends keyof BlockSuiteDocData & string,

}
get spaces() {
return this._spaces;
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc