@blocksuite/block-std
Advanced tools
Comparing version 0.0.0-20230724154746-52953d6c-nightly to 0.0.0-20230724154746-ae3fee14-nightly
import { DisposableGroup } from '@blocksuite/global/utils'; | ||
import type { UIEventHandler } from './base.js'; | ||
import { UIEventStateContext } from './base.js'; | ||
declare const eventNames: readonly ["click", "doubleClick", "tripleClick", "pointerDown", "pointerMove", "pointerUp", "pointerOut", "dragStart", "dragMove", "dragEnd", "keyDown", "keyUp", "beforeInput", "compositionStart", "compositionUpdate", "compositionEnd", "paste", "copy", "blur", "focus", "drop", "contextMenu", "wheel", "selectionChange"]; | ||
declare const eventNames: readonly ["click", "doubleClick", "tripleClick", "pointerDown", "pointerMove", "pointerUp", "pointerOut", "dragStart", "dragMove", "dragEnd", "keyDown", "keyUp", "beforeInput", "compositionStart", "compositionUpdate", "compositionEnd", "paste", "copy", "blur", "focus", "drop", "contextMenu", "wheel", "selectionChange", "virgo-vrange-updated"]; | ||
export type EventName = (typeof eventNames)[number]; | ||
@@ -17,3 +17,2 @@ export declare class UIEventDispatcher { | ||
add(name: EventName, handler: UIEventHandler): () => void; | ||
bindHotkey(keymap: Record<string, UIEventHandler>): () => void; | ||
private _bindEvents; | ||
@@ -20,0 +19,0 @@ } |
@@ -5,3 +5,2 @@ import { DisposableGroup } from '@blocksuite/global/utils'; | ||
import { KeyboardControl } from './keyboard.js'; | ||
import { bindKeymap } from './keymap.js'; | ||
import { PointerControl } from './pointer.js'; | ||
@@ -22,3 +21,3 @@ import { toLowerCase } from './utils.js'; | ||
]; | ||
const globalEventNames = ['selectionChange']; | ||
const globalEventNames = ['selectionChange', 'virgo-vrange-updated']; | ||
const eventNames = [ | ||
@@ -76,5 +75,2 @@ 'click', | ||
} | ||
bindHotkey(keymap) { | ||
return this.add('keyDown', bindKeymap(keymap)); | ||
} | ||
_bindEvents() { | ||
@@ -81,0 +77,0 @@ bypassEventNames.forEach(eventName => { |
@@ -23,3 +23,3 @@ import type { Page, Workspace } from '@blocksuite/store'; | ||
getInstance<T extends BlockSuiteSelectionType>(type: T, ...args: ConstructorParameters<BlockSuiteSelection[T]>): BlockSuiteSelectionInstance[T]; | ||
get value(): BaseSelection[]; | ||
get selections(): BaseSelection[]; | ||
set(selections: BaseSelection[]): void; | ||
@@ -26,0 +26,0 @@ update(fn: (currentSelections: BaseSelection[]) => BaseSelection[]): void; |
@@ -34,3 +34,3 @@ import { DisposableGroup, Slot } from '@blocksuite/store'; | ||
} | ||
get value() { | ||
get selections() { | ||
return this._store.getLocalSelection().map(json => { | ||
@@ -45,3 +45,3 @@ const ctor = this._selectionConstructors[json.type]; | ||
set(selections) { | ||
this._oldSelections = this.value; | ||
this._oldSelections = this.selections; | ||
this._store.setLocalSelection(selections.map(s => s.toJSON())); | ||
@@ -51,3 +51,3 @@ this.slots.changed.emit(selections); | ||
update(fn) { | ||
const selections = fn(this.value); | ||
const selections = fn(this.selections); | ||
this.set(selections); | ||
@@ -54,0 +54,0 @@ } |
import { BaseSelection } from '../base.js'; | ||
export type TextRangePoint = { | ||
type TextSelectionProps = { | ||
blockId: string; | ||
path: string[]; | ||
index: number; | ||
length: number; | ||
}; | ||
export type TextSelectionProps = { | ||
from: TextRangePoint; | ||
to: TextRangePoint | null; | ||
}; | ||
export declare class TextSelection extends BaseSelection { | ||
static type: string; | ||
from: TextRangePoint; | ||
to: TextRangePoint | null; | ||
constructor({ from, to }: TextSelectionProps); | ||
index: number; | ||
length: number; | ||
constructor({ blockId, index, length }: TextSelectionProps); | ||
empty(): boolean; | ||
private _equalPoint; | ||
equals(other: BaseSelection): boolean; | ||
@@ -28,2 +22,3 @@ toJSON(): Record<string, unknown>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=text.d.ts.map |
import { BaseSelection } from '../base.js'; | ||
export class TextSelection extends BaseSelection { | ||
constructor({ from, to }) { | ||
super(from.blockId); | ||
this.from = from; | ||
this.to = to; | ||
constructor({ blockId, index, length }) { | ||
super(blockId); | ||
this.index = index; | ||
this.length = length; | ||
} | ||
empty() { | ||
return !!this.to; | ||
return this.length === 0; | ||
} | ||
_equalPoint(a, b) { | ||
if (a && b) { | ||
return (a.blockId === b.blockId && a.index === b.index && a.length === b.length); | ||
} | ||
return a === b; | ||
} | ||
equals(other) { | ||
if (other instanceof TextSelection) { | ||
return (other.blockId === this.blockId && | ||
this._equalPoint(other.from, this.from) && | ||
this._equalPoint(other.to, this.to)); | ||
other.index === this.index && | ||
other.length === this.length); | ||
} | ||
@@ -28,4 +22,5 @@ return false; | ||
type: 'text', | ||
from: this.from, | ||
to: this.to, | ||
blockId: this.blockId, | ||
index: this.index, | ||
length: this.length, | ||
}; | ||
@@ -35,4 +30,5 @@ } | ||
return new TextSelection({ | ||
from: json.from, | ||
to: json.to, | ||
blockId: json.blockId, | ||
index: json.index, | ||
length: json.length, | ||
}); | ||
@@ -39,0 +35,0 @@ } |
@@ -7,3 +7,2 @@ import type { Page, Workspace } from '@blocksuite/store'; | ||
export interface BlockStoreOptions { | ||
root: HTMLElement; | ||
uiEventDispatcher: UIEventDispatcher; | ||
@@ -19,3 +18,2 @@ selectionManager: SelectionManager; | ||
readonly selectionManager: SelectionManager; | ||
readonly root: HTMLElement; | ||
private _specs; | ||
@@ -22,0 +20,0 @@ private _services; |
@@ -5,3 +5,2 @@ export class BlockStore { | ||
this._services = new Map(); | ||
this.root = options.root; | ||
this.workspace = options.workspace; | ||
@@ -8,0 +7,0 @@ this.page = options.page; |
{ | ||
"name": "@blocksuite/block-std", | ||
"version": "0.0.0-20230724154746-52953d6c-nightly", | ||
"version": "0.0.0-20230724154746-ae3fee14-nightly", | ||
"description": "Std for blocksuite blocks", | ||
@@ -12,10 +12,9 @@ "main": "dist/index.js", | ||
"peerDependencies": { | ||
"@blocksuite/store": "0.0.0-20230724154746-52953d6c-nightly" | ||
"@blocksuite/store": "0.0.0-20230724154746-ae3fee14-nightly" | ||
}, | ||
"dependencies": { | ||
"w3c-keyname": "^2.2.8", | ||
"@blocksuite/global": "0.0.0-20230724154746-52953d6c-nightly" | ||
"@blocksuite/global": "0.0.0-20230724154746-ae3fee14-nightly" | ||
}, | ||
"devDependencies": { | ||
"@blocksuite/store": "0.0.0-20230724154746-52953d6c-nightly" | ||
"@blocksuite/store": "0.0.0-20230724154746-ae3fee14-nightly" | ||
}, | ||
@@ -22,0 +21,0 @@ "exports": { |
@@ -7,3 +7,2 @@ import { DisposableGroup } from '@blocksuite/global/utils'; | ||
import { KeyboardControl } from './keyboard.js'; | ||
import { bindKeymap } from './keymap.js'; | ||
import { PointerControl } from './pointer.js'; | ||
@@ -27,3 +26,3 @@ import { toLowerCase } from './utils.js'; | ||
const globalEventNames = ['selectionChange'] as const; | ||
const globalEventNames = ['selectionChange', 'virgo-vrange-updated'] as const; | ||
@@ -102,6 +101,2 @@ const eventNames = [ | ||
bindHotkey(keymap: Record<string, UIEventHandler>) { | ||
return this.add('keyDown', bindKeymap(keymap)); | ||
} | ||
private _bindEvents() { | ||
@@ -108,0 +103,0 @@ bypassEventNames.forEach(eventName => { |
@@ -54,3 +54,3 @@ import type { Page, StackItem, Workspace } from '@blocksuite/store'; | ||
get value() { | ||
get selections() { | ||
return this._store.getLocalSelection().map(json => { | ||
@@ -66,3 +66,3 @@ const ctor = this._selectionConstructors[json.type as string]; | ||
set(selections: BaseSelection[]) { | ||
this._oldSelections = this.value; | ||
this._oldSelections = this.selections; | ||
this._store.setLocalSelection(selections.map(s => s.toJSON())); | ||
@@ -73,3 +73,3 @@ this.slots.changed.emit(selections); | ||
update(fn: (currentSelections: BaseSelection[]) => BaseSelection[]) { | ||
const selections = fn(this.value); | ||
const selections = fn(this.selections); | ||
this.set(selections); | ||
@@ -76,0 +76,0 @@ } |
import { BaseSelection } from '../base.js'; | ||
export type TextRangePoint = { | ||
type TextSelectionProps = { | ||
blockId: string; | ||
path: string[]; | ||
index: number; | ||
@@ -10,37 +9,19 @@ length: number; | ||
export type TextSelectionProps = { | ||
from: TextRangePoint; | ||
to: TextRangePoint | null; | ||
}; | ||
export class TextSelection extends BaseSelection { | ||
static override type = 'text'; | ||
from: TextRangePoint; | ||
index: number; | ||
to: TextRangePoint | null; | ||
length: number; | ||
constructor({ from, to }: TextSelectionProps) { | ||
super(from.blockId); | ||
this.from = from; | ||
this.to = to; | ||
constructor({ blockId, index, length }: TextSelectionProps) { | ||
super(blockId); | ||
this.index = index; | ||
this.length = length; | ||
} | ||
empty(): boolean { | ||
return !!this.to; | ||
return this.length === 0; | ||
} | ||
private _equalPoint( | ||
a: TextRangePoint | null, | ||
b: TextRangePoint | null | ||
): boolean { | ||
if (a && b) { | ||
return ( | ||
a.blockId === b.blockId && a.index === b.index && a.length === b.length | ||
); | ||
} | ||
return a === b; | ||
} | ||
override equals(other: BaseSelection): boolean { | ||
@@ -50,4 +31,4 @@ if (other instanceof TextSelection) { | ||
other.blockId === this.blockId && | ||
this._equalPoint(other.from, this.from) && | ||
this._equalPoint(other.to, this.to) | ||
other.index === this.index && | ||
other.length === this.length | ||
); | ||
@@ -60,4 +41,5 @@ } | ||
type: 'text', | ||
from: this.from, | ||
to: this.to, | ||
blockId: this.blockId, | ||
index: this.index, | ||
length: this.length, | ||
}; | ||
@@ -68,4 +50,5 @@ } | ||
return new TextSelection({ | ||
from: json.from as TextRangePoint, | ||
to: json.to as TextRangePoint | null, | ||
blockId: json.blockId as string, | ||
index: json.index as number, | ||
length: json.length as number, | ||
}); | ||
@@ -72,0 +55,0 @@ } |
@@ -8,2 +8,5 @@ import type { BaseBlockModel } from '@blocksuite/store'; | ||
export interface BlockServiceOptions { | ||
// TODO: add these | ||
// transformer; | ||
store: BlockStore; | ||
@@ -10,0 +13,0 @@ } |
@@ -9,3 +9,2 @@ import type { Page, Workspace } from '@blocksuite/store'; | ||
export interface BlockStoreOptions { | ||
root: HTMLElement; | ||
uiEventDispatcher: UIEventDispatcher; | ||
@@ -22,3 +21,2 @@ selectionManager: SelectionManager; | ||
readonly selectionManager: SelectionManager; | ||
readonly root: HTMLElement; | ||
@@ -28,3 +26,2 @@ private _specs: Map<string, BlockSpec<ComponentType>> = new Map(); | ||
constructor(options: BlockStoreOptions) { | ||
this.root = options.root; | ||
this.workspace = options.workspace; | ||
@@ -31,0 +28,0 @@ this.page = options.page; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
278517
89
1630
- Removedw3c-keyname@^2.2.8
- Removed@blocksuite/global@0.0.0-20230724154746-52953d6c-nightly(transitive)
- Removed@blocksuite/store@0.0.0-20230724154746-52953d6c-nightly(transitive)
- Removed@blocksuite/virgo@0.0.0-20230724154746-52953d6c-nightly(transitive)
- Removed@lit-labs/ssr-dom-shim@1.2.1(transitive)
- Removed@lit/reactive-element@1.6.3(transitive)
- Removed@types/flexsearch@0.7.6(transitive)
- Removed@types/trusted-types@2.0.7(transitive)
- Removedansi-colors@4.1.3(transitive)
- Removedasync-call-rpc@6.4.2(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbrace-expansion@2.0.1(transitive)
- Removedbuffer@6.0.3(transitive)
- Removedflexsearch@0.7.21(transitive)
- Removedidb-keyval@6.2.1(transitive)
- Removedieee754@1.2.1(transitive)
- Removedisomorphic.js@0.2.5(transitive)
- Removedky@0.33.3(transitive)
- Removedlib0@0.2.99(transitive)
- Removedlit@2.8.0(transitive)
- Removedlit-element@3.3.3(transitive)
- Removedlit-html@2.8.0(transitive)
- Removedmerge@2.1.1(transitive)
- Removedminimatch@9.0.5(transitive)
- Removednanoid@4.0.2(transitive)
- Removedw3c-keyname@2.2.8(transitive)
- Removedy-protocols@1.0.6(transitive)
- Removedyjs@13.6.20(transitive)
- Removedzod@3.24.1(transitive)
Updated@blocksuite/global@0.0.0-20230724154746-ae3fee14-nightly