@blocksuite/block-std
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -20,6 +20,6 @@ import { UIEventStateContext } from './base.js'; | ||
listen() { | ||
this._dispatcher.disposables.addFromEvent(document, 'keydown', this._down); | ||
this._dispatcher.disposables.addFromEvent(document, 'keyup', this._up); | ||
this._dispatcher.disposables.addFromEvent(this._dispatcher.root, 'keydown', this._down); | ||
this._dispatcher.disposables.addFromEvent(this._dispatcher.root, 'keyup', this._up); | ||
} | ||
} | ||
//# sourceMappingURL=keyboard.js.map |
@@ -15,2 +15,3 @@ import type { UIEventDispatcher } from './dispatcher.js'; | ||
private _reset; | ||
private _createContext; | ||
private _down; | ||
@@ -17,0 +18,0 @@ private _up; |
import { assertExists } from '@blocksuite/global/utils'; | ||
import { UIEventStateContext } from './base.js'; | ||
import { UIEventState, UIEventStateContext } from './base.js'; | ||
import { PointerEventState } from './state.js'; | ||
@@ -42,3 +42,3 @@ import { isFarEnough } from './utils.js'; | ||
this._lastPointerDownEvent = event; | ||
this._dispatcher.run('pointerDown', UIEventStateContext.from(pointerEventState)); | ||
this._dispatcher.run('pointerDown', this._createContext(event, pointerEventState)); | ||
this._dispatcher.disposables.addFromEvent(document, 'pointermove', this._move); | ||
@@ -55,3 +55,3 @@ this._dispatcher.disposables.addFromEvent(document, 'pointerup', this._up); | ||
}); | ||
const context = UIEventStateContext.from(pointerEventState); | ||
const context = this._createContext(event, pointerEventState); | ||
const run = () => { | ||
@@ -89,6 +89,6 @@ if (this._dragging) { | ||
this._dragging = true; | ||
this._dispatcher.run('dragStart', UIEventStateContext.from(this._startDragState)); | ||
this._dispatcher.run('dragStart', this._createContext(event, this._startDragState)); | ||
} | ||
if (this._dragging) { | ||
this._dispatcher.run('dragMove', UIEventStateContext.from(state)); | ||
this._dispatcher.run('dragMove', this._createContext(event, state)); | ||
} | ||
@@ -104,3 +104,3 @@ }; | ||
}); | ||
this._dispatcher.run('pointerMove', UIEventStateContext.from(state)); | ||
this._dispatcher.run('pointerMove', this._createContext(event, state)); | ||
}; | ||
@@ -115,3 +115,3 @@ this._out = (event) => { | ||
}); | ||
this._dispatcher.run('pointerOut', UIEventStateContext.from(state)); | ||
this._dispatcher.run('pointerOut', this._createContext(event, state)); | ||
}; | ||
@@ -127,3 +127,6 @@ } | ||
} | ||
_createContext(event, pointerState) { | ||
return UIEventStateContext.from(new UIEventState(event), pointerState); | ||
} | ||
} | ||
//# sourceMappingURL=pointer.js.map |
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'; | ||
export interface BlockServiceOptions { | ||
@@ -12,4 +13,7 @@ uiEventDispatcher: UIEventDispatcher; | ||
dispose(): void; | ||
mounted(): void; | ||
unmounted(): void; | ||
handleEvent(name: EventName, fn: UIEventHandler): void; | ||
} | ||
export type BlockServiceConstructor = new (options: BlockServiceOptions) => BlockService; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -7,6 +7,18 @@ import { DisposableGroup } from '@blocksuite/store'; | ||
} | ||
// life cycle start | ||
dispose() { | ||
this.disposables.dispose(); | ||
} | ||
mounted() { | ||
// do nothing | ||
} | ||
unmounted() { | ||
// do nothing | ||
} | ||
// life cycle end | ||
// event handlers start | ||
handleEvent(name, fn) { | ||
this.disposables.add(this.uiEventDispatcher.add(name, fn)); | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
import type { UIEventDispatcher } from '../event/index.js'; | ||
import type { BlockService } from '../service/index.js'; | ||
import type { BlockSpec } from '../spec/index.js'; | ||
@@ -14,2 +15,3 @@ export interface BlockStoreOptions { | ||
getView(flavour: string): import("../spec/index.js").BlockView<ComponentType> | null; | ||
getService(flavour: string): BlockService<import("@blocksuite/store/base.js").BaseBlockModel<object>> | undefined; | ||
private _diffServices; | ||
@@ -16,0 +18,0 @@ private get _serviceOptions(); |
@@ -16,2 +16,3 @@ export class BlockStore { | ||
service.dispose(); | ||
service.unmounted(); | ||
}); | ||
@@ -27,19 +28,28 @@ this._services.clear(); | ||
} | ||
getService(flavour) { | ||
return this._services.get(flavour); | ||
} | ||
_diffServices(oldSpecs, newSpecs) { | ||
oldSpecs.forEach((oldSpec, flavour) => { | ||
if (newSpecs.has(flavour)) { | ||
if (newSpecs.has(flavour) && | ||
newSpecs.get(flavour)?.service === oldSpec.service) { | ||
return; | ||
} | ||
const service = this._services.get(oldSpec.schema.model.flavour); | ||
const service = this._services.get(flavour); | ||
if (service) { | ||
service.dispose(); | ||
service.unmounted(); | ||
} | ||
this._services.delete(oldSpec.schema.model.flavour); | ||
this._services.delete(flavour); | ||
}); | ||
newSpecs.forEach((newSpec, flavour) => { | ||
if (oldSpecs.has(flavour) || !newSpec.service) { | ||
if (this._services.has(flavour)) { | ||
return; | ||
} | ||
if (!newSpec.service) { | ||
return; | ||
} | ||
const service = new newSpec.service(this._serviceOptions); | ||
this._services.set(flavour, service); | ||
service.mounted(); | ||
}); | ||
@@ -46,0 +56,0 @@ } |
{ | ||
"name": "@blocksuite/block-std", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "Std for blocksuite blocks", | ||
@@ -12,9 +12,9 @@ "main": "dist/index.js", | ||
"peerDependencies": { | ||
"@blocksuite/store": "0.6.0" | ||
"@blocksuite/store": "0.7.0" | ||
}, | ||
"dependencies": { | ||
"@blocksuite/global": "0.6.0" | ||
"@blocksuite/global": "0.7.0" | ||
}, | ||
"devDependencies": { | ||
"@blocksuite/store": "0.6.0" | ||
"@blocksuite/store": "0.7.0" | ||
}, | ||
@@ -21,0 +21,0 @@ "exports": { |
@@ -9,4 +9,12 @@ import { UIEventStateContext } from './base.js'; | ||
listen() { | ||
this._dispatcher.disposables.addFromEvent(document, 'keydown', this._down); | ||
this._dispatcher.disposables.addFromEvent(document, 'keyup', this._up); | ||
this._dispatcher.disposables.addFromEvent( | ||
this._dispatcher.root, | ||
'keydown', | ||
this._down | ||
); | ||
this._dispatcher.disposables.addFromEvent( | ||
this._dispatcher.root, | ||
'keyup', | ||
this._up | ||
); | ||
} | ||
@@ -13,0 +21,0 @@ |
import { assertExists } from '@blocksuite/global/utils'; | ||
import { UIEventStateContext } from './base.js'; | ||
import { UIEventState, UIEventStateContext } from './base.js'; | ||
import type { UIEventDispatcher } from './dispatcher.js'; | ||
@@ -48,2 +48,6 @@ import { PointerEventState } from './state.js'; | ||
private _createContext(event: Event, pointerState: PointerEventState) { | ||
return UIEventStateContext.from(new UIEventState(event), pointerState); | ||
} | ||
private _down = (event: PointerEvent) => { | ||
@@ -76,3 +80,3 @@ if ( | ||
'pointerDown', | ||
UIEventStateContext.from(pointerEventState) | ||
this._createContext(event, pointerEventState) | ||
); | ||
@@ -96,3 +100,3 @@ | ||
}); | ||
const context = UIEventStateContext.from(pointerEventState); | ||
const context = this._createContext(event, pointerEventState); | ||
@@ -138,3 +142,3 @@ const run = () => { | ||
'dragStart', | ||
UIEventStateContext.from(this._startDragState) | ||
this._createContext(event, this._startDragState) | ||
); | ||
@@ -144,3 +148,3 @@ } | ||
if (this._dragging) { | ||
this._dispatcher.run('dragMove', UIEventStateContext.from(state)); | ||
this._dispatcher.run('dragMove', this._createContext(event, state)); | ||
} | ||
@@ -158,3 +162,3 @@ }; | ||
this._dispatcher.run('pointerMove', UIEventStateContext.from(state)); | ||
this._dispatcher.run('pointerMove', this._createContext(event, state)); | ||
}; | ||
@@ -171,4 +175,4 @@ | ||
this._dispatcher.run('pointerOut', UIEventStateContext.from(state)); | ||
this._dispatcher.run('pointerOut', this._createContext(event, state)); | ||
}; | ||
} |
@@ -38,3 +38,3 @@ import { UIEventState } from './base.js'; | ||
constructor({ event, rect, startX, startY, last }: PointerEventStateOptions) { | ||
super(event as Event); | ||
super(event); | ||
@@ -71,3 +71,3 @@ const offsetX = event.clientX - rect.left; | ||
constructor({ event }: KeyboardEventStateOptions) { | ||
super(event as Event); | ||
super(event); | ||
@@ -74,0 +74,0 @@ this.raw = event; |
@@ -5,2 +5,3 @@ import type { BaseBlockModel } from '@blocksuite/store'; | ||
import type { UIEventDispatcher } from '../event/index.js'; | ||
import type { EventName, UIEventHandler } from '../event/index.js'; | ||
@@ -23,2 +24,3 @@ export interface BlockServiceOptions { | ||
// life cycle start | ||
dispose() { | ||
@@ -28,3 +30,16 @@ this.disposables.dispose(); | ||
// TODO: life cycle methods | ||
mounted() { | ||
// do nothing | ||
} | ||
unmounted() { | ||
// do nothing | ||
} | ||
// life cycle end | ||
// event handlers start | ||
handleEvent(name: EventName, fn: UIEventHandler) { | ||
this.disposables.add(this.uiEventDispatcher.add(name, fn)); | ||
} | ||
// event handlers end | ||
} | ||
@@ -31,0 +46,0 @@ |
@@ -27,2 +27,3 @@ import type { UIEventDispatcher } from '../event/index.js'; | ||
service.dispose(); | ||
service.unmounted(); | ||
}); | ||
@@ -41,2 +42,6 @@ this._services.clear(); | ||
getService(flavour: string) { | ||
return this._services.get(flavour); | ||
} | ||
private _diffServices( | ||
@@ -47,19 +52,28 @@ oldSpecs: Map<string, BlockSpec<ComponentType>>, | ||
oldSpecs.forEach((oldSpec, flavour) => { | ||
if (newSpecs.has(flavour)) { | ||
if ( | ||
newSpecs.has(flavour) && | ||
newSpecs.get(flavour)?.service === oldSpec.service | ||
) { | ||
return; | ||
} | ||
const service = this._services.get(oldSpec.schema.model.flavour); | ||
const service = this._services.get(flavour); | ||
if (service) { | ||
service.dispose(); | ||
service.unmounted(); | ||
} | ||
this._services.delete(oldSpec.schema.model.flavour); | ||
this._services.delete(flavour); | ||
}); | ||
newSpecs.forEach((newSpec, flavour) => { | ||
if (oldSpecs.has(flavour) || !newSpec.service) { | ||
if (this._services.has(flavour)) { | ||
return; | ||
} | ||
if (!newSpec.service) { | ||
return; | ||
} | ||
const service = new newSpec.service(this._serviceOptions); | ||
this._services.set(flavour, service); | ||
service.mounted(); | ||
}); | ||
@@ -66,0 +80,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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
265790
89
1457
0
+ Added@blocksuite/global@0.7.0(transitive)
+ Added@blocksuite/store@0.7.0(transitive)
+ Added@blocksuite/virgo@0.7.0(transitive)
+ Addedasync-call-rpc@6.4.2(transitive)
- Removed@blocksuite/global@0.6.0(transitive)
- Removed@blocksuite/store@0.6.0(transitive)
- Removed@blocksuite/virgo@0.6.0(transitive)
- Removeddebug@4.4.0(transitive)
- Removederr-code@3.0.1(transitive)
- Removedget-browser-rtc@1.1.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedms@2.1.3(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedrandombytes@2.1.0(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsimple-peer@9.11.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedws@8.18.0(transitive)
- Removedy-webrtc@10.3.0(transitive)
Updated@blocksuite/global@0.7.0