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

@blocksuite/block-std

Package Overview
Dependencies
Maintainers
5
Versions
880
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blocksuite/block-std - npm Package Compare versions

Comparing version 0.0.0-20230724154746-ae3fee14-nightly to 0.0.0-20230725102342-7fa145e5-nightly

4

dist/event/state.d.ts

@@ -14,3 +14,3 @@ import { UIEventState } from './base.js';

export declare class PointerEventState extends UIEventState {
type: string;
readonly type = "pointerState";
raw: PointerEvent;

@@ -36,3 +36,3 @@ point: Point;

export declare class KeyboardEventState extends UIEventState {
type: string;
readonly type = "keyboardState";
raw: KeyboardEvent;

@@ -39,0 +39,0 @@ constructor({ event }: KeyboardEventStateOptions);

export * from './event/index.js';
export * from './selection/index.js';
export * from './service/index.js';

@@ -4,0 +3,0 @@ export * from './spec/index.js';

export * from './event/index.js';
export * from './selection/index.js';
export * from './service/index.js';

@@ -4,0 +3,0 @@ export * from './spec/index.js';

@@ -5,4 +5,2 @@ export declare abstract class BaseSelection {

constructor(blockId: string);
is<T extends BlockSuiteSelectionType>(type: T): this is BlockSuiteSelectionInstance[T];
get type(): BlockSuiteSelectionType;
abstract equals(other: BaseSelection): boolean;

@@ -9,0 +7,0 @@ abstract toJSON(): Record<string, unknown>;

@@ -5,9 +5,2 @@ export class BaseSelection {

}
is(type) {
return this.type === type;
}
get type() {
return this.constructor
.type;
}
static fromJSON(_) {

@@ -14,0 +7,0 @@ throw new Error('You must override this method');

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

import type { Page, Workspace } from '@blocksuite/store';
import type { Workspace } from '@blocksuite/store';
import { DisposableGroup, Slot } from '@blocksuite/store';

@@ -10,24 +10,17 @@ import type { BaseSelection } from './base.js';

export declare class SelectionManager {
root: HTMLElement;
workspace: Workspace;
private _workspace;
disposables: DisposableGroup;
private _selectionConstructors;
private _oldSelections;
_selectionConstructors: Record<string, SelectionConstructor>;
slots: {
changed: Slot<BaseSelection[]>;
};
constructor(root: HTMLElement, workspace: Workspace);
register(ctor: SelectionConstructor | SelectionConstructor[]): this;
constructor(workspace: Workspace);
register(ctor: SelectionConstructor): void;
private get _store();
private _setupDefaultSelections;
getInstance<T extends BlockSuiteSelectionType>(type: T, ...args: ConstructorParameters<BlockSuiteSelection[T]>): BlockSuiteSelectionInstance[T];
get selections(): BaseSelection[];
set(selections: BaseSelection[]): void;
update(fn: (currentSelections: BaseSelection[]) => BaseSelection[]): void;
clear(): void;
setSelections(selections: BaseSelection[]): void;
get remoteSelections(): {
[k: string]: Record<string, unknown>[];
};
mount(page: Page): void;
unmount(): void;
dispose(): void;

@@ -34,0 +27,0 @@ }

import { DisposableGroup, Slot } from '@blocksuite/store';
import { BlockSelection, TextSelection } from './variants/index.js';
export class SelectionManager {
constructor(root, workspace) {
this.root = root;
this.workspace = workspace;
constructor(workspace) {
this.disposables = new DisposableGroup();
this._selectionConstructors = {};
this._oldSelections = [];
this.slots = {
changed: new Slot(),
};
this._setupDefaultSelections();
this._workspace = workspace;
}
register(ctor) {
[ctor].flat().forEach(ctor => {
this._selectionConstructors[ctor.type] = ctor;
});
return this;
this._selectionConstructors[ctor.type] = ctor;
}
get _store() {
return this.workspace.awarenessStore;
return this._workspace.awarenessStore;
}
_setupDefaultSelections() {
this.register([TextSelection, BlockSelection]);
}
getInstance(type, ...args) {

@@ -43,14 +33,6 @@ const ctor = this._selectionConstructors[type];

}
set(selections) {
this._oldSelections = this.selections;
setSelections(selections) {
this._store.setLocalSelection(selections.map(s => s.toJSON()));
this.slots.changed.emit(selections);
}
update(fn) {
const selections = fn(this.selections);
this.set(selections);
}
clear() {
this.set([]);
}
get remoteSelections() {

@@ -61,21 +43,2 @@ return Object.fromEntries(Array.from(this._store.getStates().entries())

}
mount(page) {
if (this.disposables.disposed) {
this.disposables = new DisposableGroup();
}
page.history.on('stack-item-added', (event) => {
event.stackItem.meta.set('selection-state', this._oldSelections);
});
page.history.on('stack-item-popped', (event) => {
const selection = event.stackItem.meta.get('selection-state');
if (selection) {
this.set(selection);
}
});
}
unmount() {
this.clear();
this.slots.changed.dispose();
this.disposables.dispose();
}
dispose() {

@@ -82,0 +45,0 @@ Object.values(this.slots).forEach(slot => slot.dispose());

import { BaseSelection } from '../base.js';
export declare class BlockSelection extends BaseSelection {
static type: string;
static readonly type = "block";
equals(other: BaseSelection): boolean;

@@ -5,0 +5,0 @@ toJSON(): Record<string, unknown>;

import { BaseSelection } from '../base.js';
type TextSelectionProps = {
blockId: string;
index: number;
length: number;
};
export declare class TextSelection extends BaseSelection {
static type: string;
index: number;
length: number;
constructor({ blockId, index, length }: TextSelectionProps);
static readonly type = "text";
from: number;
to: number;
constructor(blockId: string, from: number, to: number);
empty(): boolean;

@@ -22,3 +17,2 @@ equals(other: BaseSelection): boolean;

}
export {};
//# sourceMappingURL=text.d.ts.map
import { BaseSelection } from '../base.js';
export class TextSelection extends BaseSelection {
constructor({ blockId, index, length }) {
constructor(blockId, from, to) {
super(blockId);
this.index = index;
this.length = length;
this.from = from;
this.to = to;
}
empty() {
return this.length === 0;
return this.from === this.to;
}

@@ -14,4 +14,4 @@ equals(other) {

return (other.blockId === this.blockId &&
other.index === this.index &&
other.length === this.length);
other.from === this.from &&
other.to === this.to);
}

@@ -24,12 +24,8 @@ return false;

blockId: this.blockId,
index: this.index,
length: this.length,
from: this.from,
to: this.to,
};
}
static fromJSON(json) {
return new TextSelection({
blockId: json.blockId,
index: json.index,
length: json.length,
});
return new TextSelection(json.blockId, json.from, json.to);
}

@@ -36,0 +32,0 @@ }

import type { BaseBlockModel } from '@blocksuite/store';
import { DisposableGroup } from '@blocksuite/store';
import type { UIEventDispatcher } from '../event/index.js';
import type { EventName, UIEventHandler } from '../event/index.js';
import type { BlockStore } from '../store/index.js';
export interface BlockServiceOptions {
store: BlockStore;
uiEventDispatcher: UIEventDispatcher;
}
export declare class BlockService<Model extends BaseBlockModel = BaseBlockModel> {
readonly store: BlockStore;
readonly disposables: DisposableGroup;
disposables: DisposableGroup;
uiEventDispatcher: UIEventDispatcher;
constructor(options: BlockServiceOptions);
get workspace(): import("@blocksuite/store").Workspace;
get page(): import("@blocksuite/store").Page;
get selectionManager(): import("../index.js").SelectionManager;
get uiEventDispatcher(): import("../event/dispatcher.js").UIEventDispatcher;
dispose(): void;

@@ -17,0 +13,0 @@ mounted(): void;

@@ -5,16 +5,4 @@ import { DisposableGroup } from '@blocksuite/store';

this.disposables = new DisposableGroup();
this.store = options.store;
this.uiEventDispatcher = options.uiEventDispatcher;
}
get workspace() {
return this.store.workspace;
}
get page() {
return this.store.page;
}
get selectionManager() {
return this.store.selectionManager;
}
get uiEventDispatcher() {
return this.store.uiEventDispatcher;
}
// life cycle start

@@ -21,0 +9,0 @@ dispose() {

import type { BlockSchemaType } from '@blocksuite/store';
import type { BlockServiceConstructor } from '../service/index.js';
export interface BlockView<ComponentType = unknown, WidgetNames extends string = string> {
export interface BlockView<ComponentType = unknown> {
component: ComponentType;
widgets?: Record<WidgetNames, ComponentType>;
widgets?: ComponentType[];
}
export interface BlockSpec<ComponentType = unknown, WidgetNames extends string = string> {
export interface BlockSpec<ComponentType = unknown> {
schema: BlockSchemaType;
service?: BlockServiceConstructor;
view: BlockView<ComponentType, WidgetNames>;
view: BlockView<ComponentType>;
}
//# sourceMappingURL=index.d.ts.map

@@ -1,4 +0,2 @@

import type { Page, Workspace } from '@blocksuite/store';
import type { UIEventDispatcher } from '../event/index.js';
import type { SelectionManager } from '../selection/index.js';
import type { BlockService } from '../service/index.js';

@@ -8,18 +6,12 @@ import type { BlockSpec } from '../spec/index.js';

uiEventDispatcher: UIEventDispatcher;
selectionManager: SelectionManager;
workspace: Workspace;
page: Page;
}
export declare class BlockStore<ComponentType = unknown> {
page: Page;
readonly workspace: Workspace;
readonly uiEventDispatcher: UIEventDispatcher;
readonly selectionManager: SelectionManager;
private _specs;
private _services;
private readonly _uiEventDispatcher;
constructor(options: BlockStoreOptions);
applySpecs(specs: Array<BlockSpec<ComponentType>>): void;
dispose(): void;
getView(flavour: string): import("../spec/index.js").BlockView<ComponentType, string> | null;
getService(flavour: string): BlockService<import("@blocksuite/store").BaseBlockModel<object>> | undefined;
getView(flavour: string): import("../spec/index.js").BlockView<ComponentType> | null;
getService(flavour: string): BlockService<import("@blocksuite/store/base.js").BaseBlockModel<object>> | undefined;
private _diffServices;

@@ -26,0 +18,0 @@ private get _serviceOptions();

@@ -5,6 +5,3 @@ export class BlockStore {

this._services = new Map();
this.workspace = options.workspace;
this.page = options.page;
this.uiEventDispatcher = options.uiEventDispatcher;
this.selectionManager = options.selectionManager;
this._uiEventDispatcher = options.uiEventDispatcher;
}

@@ -61,3 +58,3 @@ applySpecs(specs) {

return {
store: this,
uiEventDispatcher: this._uiEventDispatcher,
};

@@ -64,0 +61,0 @@ }

{
"name": "@blocksuite/block-std",
"version": "0.0.0-20230724154746-ae3fee14-nightly",
"version": "0.0.0-20230725102342-7fa145e5-nightly",
"description": "Std for blocksuite blocks",

@@ -12,9 +12,9 @@ "main": "dist/index.js",

"peerDependencies": {
"@blocksuite/store": "0.0.0-20230724154746-ae3fee14-nightly"
"@blocksuite/store": "0.0.0-20230725102342-7fa145e5-nightly"
},
"dependencies": {
"@blocksuite/global": "0.0.0-20230724154746-ae3fee14-nightly"
"@blocksuite/global": "0.0.0-20230725102342-7fa145e5-nightly"
},
"devDependencies": {
"@blocksuite/store": "0.0.0-20230724154746-ae3fee14-nightly"
"@blocksuite/store": "0.0.0-20230725102342-7fa145e5-nightly"
},

@@ -21,0 +21,0 @@ "exports": {

@@ -14,3 +14,3 @@ import { UIEventState } from './base.js';

export class PointerEventState extends UIEventState {
override type = 'pointerState';
override readonly type = 'pointerState';

@@ -66,3 +66,3 @@ raw: PointerEvent;

export class KeyboardEventState extends UIEventState {
override type = 'keyboardState';
override readonly type = 'keyboardState';

@@ -69,0 +69,0 @@ raw: KeyboardEvent;

export * from './event/index.js';
export * from './selection/index.js';
export * from './service/index.js';
export * from './spec/index.js';
export * from './store/index.js';

@@ -1,6 +0,1 @@

type SelectionConstructor<T = unknown> = {
new (...args: unknown[]): T;
type: string;
};
export abstract class BaseSelection {

@@ -13,13 +8,2 @@ static readonly type: string;

is<T extends BlockSuiteSelectionType>(
type: T
): this is BlockSuiteSelectionInstance[T] {
return this.type === type;
}
get type(): BlockSuiteSelectionType {
return (this.constructor as SelectionConstructor)
.type as BlockSuiteSelectionType;
}
abstract equals(other: BaseSelection): boolean;

@@ -26,0 +10,0 @@

@@ -1,6 +0,5 @@

import type { Page, StackItem, Workspace } from '@blocksuite/store';
import type { Workspace } from '@blocksuite/store';
import { DisposableGroup, Slot } from '@blocksuite/store';
import type { BaseSelection } from './base.js';
import { BlockSelection, TextSelection } from './variants/index.js';

@@ -16,5 +15,6 @@ interface SelectionConstructor {

export class SelectionManager {
private _workspace: Workspace;
disposables = new DisposableGroup();
private _selectionConstructors: Record<string, SelectionConstructor> = {};
private _oldSelections: BaseSelection[] = [];
_selectionConstructors: Record<string, SelectionConstructor> = {};

@@ -25,21 +25,14 @@ slots = {

constructor(public root: HTMLElement, public workspace: Workspace) {
this._setupDefaultSelections();
constructor(workspace: Workspace) {
this._workspace = workspace;
}
register(ctor: SelectionConstructor | SelectionConstructor[]) {
[ctor].flat().forEach(ctor => {
this._selectionConstructors[ctor.type] = ctor;
});
return this;
register(ctor: SelectionConstructor) {
this._selectionConstructors[ctor.type] = ctor;
}
private get _store() {
return this.workspace.awarenessStore;
return this._workspace.awarenessStore;
}
private _setupDefaultSelections() {
this.register([TextSelection, BlockSelection]);
}
getInstance<T extends BlockSuiteSelectionType>(

@@ -66,4 +59,3 @@ type: T,

set(selections: BaseSelection[]) {
this._oldSelections = this.selections;
setSelections(selections: BaseSelection[]) {
this._store.setLocalSelection(selections.map(s => s.toJSON()));

@@ -73,11 +65,2 @@ this.slots.changed.emit(selections);

update(fn: (currentSelections: BaseSelection[]) => BaseSelection[]) {
const selections = fn(this.selections);
this.set(selections);
}
clear() {
this.set([]);
}
get remoteSelections() {

@@ -91,23 +74,2 @@ return Object.fromEntries(

mount(page: Page) {
if (this.disposables.disposed) {
this.disposables = new DisposableGroup();
}
page.history.on('stack-item-added', (event: { stackItem: StackItem }) => {
event.stackItem.meta.set('selection-state', this._oldSelections);
});
page.history.on('stack-item-popped', (event: { stackItem: StackItem }) => {
const selection = event.stackItem.meta.get('selection-state');
if (selection) {
this.set(selection as BaseSelection[]);
}
});
}
unmount() {
this.clear();
this.slots.changed.dispose();
this.disposables.dispose();
}
dispose() {

@@ -114,0 +76,0 @@ Object.values(this.slots).forEach(slot => slot.dispose());

import { BaseSelection } from '../base.js';
export class BlockSelection extends BaseSelection {
static override type = 'block';
static override readonly type = 'block';

@@ -6,0 +6,0 @@ override equals(other: BaseSelection): boolean {

import { BaseSelection } from '../base.js';
type TextSelectionProps = {
blockId: string;
index: number;
length: number;
};
export class TextSelection extends BaseSelection {
static override type = 'text';
static override readonly type = 'text';
index: number;
from: number;
length: number;
to: number;
constructor({ blockId, index, length }: TextSelectionProps) {
constructor(blockId: string, from: number, to: number) {
super(blockId);
this.index = index;
this.length = length;
this.from = from;
this.to = to;
}
empty(): boolean {
return this.length === 0;
return this.from === this.to;
}

@@ -30,4 +24,4 @@

other.blockId === this.blockId &&
other.index === this.index &&
other.length === this.length
other.from === this.from &&
other.to === this.to
);

@@ -37,2 +31,3 @@ }

}
override toJSON(): Record<string, unknown> {

@@ -42,4 +37,4 @@ return {

blockId: this.blockId,
index: this.index,
length: this.length,
from: this.from,
to: this.to,
};

@@ -49,7 +44,7 @@ }

static override fromJSON(json: Record<string, unknown>): TextSelection {
return new TextSelection({
blockId: json.blockId as string,
index: json.index as number,
length: json.length as number,
});
return new TextSelection(
json.blockId as string,
json.from as number,
json.to as number
);
}

@@ -56,0 +51,0 @@ }

import type { BaseBlockModel } from '@blocksuite/store';
import { DisposableGroup } from '@blocksuite/store';
import type { UIEventDispatcher } from '../event/index.js';
import type { EventName, UIEventHandler } from '../event/index.js';
import type { BlockStore } from '../store/index.js';
export interface BlockServiceOptions {
// TODO: add these
// selectionManager;
// transformer;
store: BlockStore;
uiEventDispatcher: UIEventDispatcher;
}
export class BlockService<Model extends BaseBlockModel = BaseBlockModel> {
readonly store: BlockStore;
readonly disposables = new DisposableGroup();
disposables = new DisposableGroup();
uiEventDispatcher: UIEventDispatcher;
constructor(options: BlockServiceOptions) {
this.store = options.store;
this.uiEventDispatcher = options.uiEventDispatcher;
}
get workspace() {
return this.store.workspace;
}
get page() {
return this.store.page;
}
get selectionManager() {
return this.store.selectionManager;
}
get uiEventDispatcher() {
return this.store.uiEventDispatcher;
}
// life cycle start

@@ -39,0 +24,0 @@ dispose() {

@@ -5,17 +5,11 @@ import type { BlockSchemaType } from '@blocksuite/store';

export interface BlockView<
ComponentType = unknown,
WidgetNames extends string = string
> {
export interface BlockView<ComponentType = unknown> {
component: ComponentType;
widgets?: Record<WidgetNames, ComponentType>;
widgets?: ComponentType[];
}
export interface BlockSpec<
ComponentType = unknown,
WidgetNames extends string = string
> {
export interface BlockSpec<ComponentType = unknown> {
schema: BlockSchemaType;
service?: BlockServiceConstructor;
view: BlockView<ComponentType, WidgetNames>;
view: BlockView<ComponentType>;
}

@@ -1,5 +0,2 @@

import type { Page, Workspace } from '@blocksuite/store';
import type { UIEventDispatcher } from '../event/index.js';
import type { SelectionManager } from '../selection/index.js';
import type { BlockService, BlockServiceOptions } from '../service/index.js';

@@ -10,20 +7,10 @@ import type { BlockSpec } from '../spec/index.js';

uiEventDispatcher: UIEventDispatcher;
selectionManager: SelectionManager;
workspace: Workspace;
page: Page;
}
export class BlockStore<ComponentType = unknown> {
page: Page;
readonly workspace: Workspace;
readonly uiEventDispatcher: UIEventDispatcher;
readonly selectionManager: SelectionManager;
private _specs: Map<string, BlockSpec<ComponentType>> = new Map();
private _services: Map<string, BlockService> = new Map();
private readonly _uiEventDispatcher: UIEventDispatcher;
constructor(options: BlockStoreOptions) {
this.workspace = options.workspace;
this.page = options.page;
this.uiEventDispatcher = options.uiEventDispatcher;
this.selectionManager = options.selectionManager;
this._uiEventDispatcher = options.uiEventDispatcher;
}

@@ -95,3 +82,3 @@

return {
store: this,
uiEventDispatcher: this._uiEventDispatcher,
};

@@ -98,0 +85,0 @@ }

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