forked from toeverything/blocksuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 0614-support-DnD-images-from-outside-into-…
…editor * master: (62 commits) fix: image resize after switch page mode (toeverything#3238) feat(edgeless): add index for other notes when selecting a note (toeverything#3235) feat: support import notion database (toeverything#3170) style: adjust checkbox style (toeverything#3240) fix: the incorrect import path (toeverything#3234) fix: console error exporting PNG/PDF in playground (toeverything#3205) feat(blocks): add page block service (toeverything#3232) refactor(edgeless): rename children container (toeverything#3231) fix: edgeless text error when importing from snapshot (toeverything#3229) refactor(blocks): split code (toeverything#3228) fix(store): handle resource load error when importing snapshot (toeverything#3227) feat: use human-readable name in code block (toeverything#3225) fix(store): snapshot import and export (toeverything#3223) fix(phasor): curveFitting should be enabled on ellipse (toeverything#3224) feat: support for adding tags to pages (toeverything#3203) fix(store): broadcast channel not defined (toeverything#3222) fix(store): bring back remove page for subdoc (toeverything#3221) fix(phasor): bound should be calculated using expand (toeverything#3220) refactor: migrate image resize manager to block level (toeverything#3218) feat(edgeless): support select element below the hollow shape (toeverything#3212) ...
- Loading branch information
Showing
347 changed files
with
12,084 additions
and
9,049 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,9 @@ | |
"slash-menu", | ||
"drag-handle", | ||
"format-bar", | ||
"connector" | ||
"connector", | ||
"lit", | ||
"block-std" | ||
] | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "@blocksuite/block-std", | ||
"version": "0.6.0", | ||
"description": "Std for blocksuite blocks", | ||
"main": "src/index.ts", | ||
"type": "module", | ||
"repository": "toeverything/blocksuite", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "toeverything", | ||
"license": "MPL-2.0", | ||
"peerDependencies": { | ||
"@blocksuite/store": "workspace:*" | ||
}, | ||
"dependencies": { | ||
"@blocksuite/global": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@blocksuite/store": "workspace:*" | ||
}, | ||
"exports": { | ||
".": "./src/index.ts" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"module": "./dist/index.js", | ||
"import": "./dist/index.js" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
] | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './event/index.js'; | ||
export * from './service/index.js'; | ||
export * from './spec/index.js'; | ||
export * from './store/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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 { | ||
// TODO: add these | ||
// selectionManager; | ||
// transformer; | ||
|
||
uiEventDispatcher: UIEventDispatcher; | ||
} | ||
|
||
export class BlockService<Model extends BaseBlockModel = BaseBlockModel> { | ||
disposables = new DisposableGroup(); | ||
uiEventDispatcher: UIEventDispatcher; | ||
|
||
constructor(options: BlockServiceOptions) { | ||
this.uiEventDispatcher = options.uiEventDispatcher; | ||
} | ||
|
||
// life cycle start | ||
dispose() { | ||
this.disposables.dispose(); | ||
} | ||
|
||
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 | ||
} | ||
|
||
export type BlockServiceConstructor = new ( | ||
options: BlockServiceOptions | ||
) => BlockService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { BlockSchemaType } from '@blocksuite/store'; | ||
|
||
import type { BlockServiceConstructor } from '../service/index.js'; | ||
|
||
export interface BlockView<ComponentType = unknown> { | ||
component: ComponentType; | ||
widgets?: ComponentType[]; | ||
} | ||
|
||
export interface BlockSpec<ComponentType = unknown> { | ||
schema: BlockSchemaType; | ||
service?: BlockServiceConstructor; | ||
view: BlockView<ComponentType>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import type { UIEventDispatcher } from '../event/index.js'; | ||
import type { BlockService, BlockServiceOptions } from '../service/index.js'; | ||
import type { BlockSpec } from '../spec/index.js'; | ||
|
||
export interface BlockStoreOptions { | ||
uiEventDispatcher: UIEventDispatcher; | ||
} | ||
|
||
export class BlockStore<ComponentType = unknown> { | ||
private _specs: Map<string, BlockSpec<ComponentType>> = new Map(); | ||
private _services: Map<string, BlockService> = new Map(); | ||
private readonly _uiEventDispatcher: UIEventDispatcher; | ||
constructor(options: BlockStoreOptions) { | ||
this._uiEventDispatcher = options.uiEventDispatcher; | ||
} | ||
|
||
applySpecs(specs: Array<BlockSpec<ComponentType>>) { | ||
const oldSpecs = this._specs; | ||
const newSpecs = this._buildSpecMap(specs); | ||
this._diffServices(oldSpecs, newSpecs); | ||
this._specs = newSpecs; | ||
} | ||
|
||
dispose() { | ||
this._services.forEach(service => { | ||
service.dispose(); | ||
service.unmounted(); | ||
}); | ||
this._services.clear(); | ||
} | ||
|
||
getView(flavour: string) { | ||
const spec = this._specs.get(flavour); | ||
if (!spec) { | ||
return null; | ||
} | ||
|
||
return spec.view; | ||
} | ||
|
||
getService(flavour: string) { | ||
return this._services.get(flavour); | ||
} | ||
|
||
private _diffServices( | ||
oldSpecs: Map<string, BlockSpec<ComponentType>>, | ||
newSpecs: Map<string, BlockSpec<ComponentType>> | ||
) { | ||
oldSpecs.forEach((oldSpec, flavour) => { | ||
if ( | ||
newSpecs.has(flavour) && | ||
newSpecs.get(flavour)?.service === oldSpec.service | ||
) { | ||
return; | ||
} | ||
|
||
const service = this._services.get(flavour); | ||
if (service) { | ||
service.dispose(); | ||
service.unmounted(); | ||
} | ||
this._services.delete(flavour); | ||
}); | ||
newSpecs.forEach((newSpec, flavour) => { | ||
if (this._services.has(flavour)) { | ||
return; | ||
} | ||
|
||
if (!newSpec.service) { | ||
return; | ||
} | ||
|
||
const service = new newSpec.service(this._serviceOptions); | ||
this._services.set(flavour, service); | ||
service.mounted(); | ||
}); | ||
} | ||
|
||
private get _serviceOptions(): BlockServiceOptions { | ||
return { | ||
uiEventDispatcher: this._uiEventDispatcher, | ||
}; | ||
} | ||
|
||
private _buildSpecMap(specs: Array<BlockSpec<ComponentType>>) { | ||
const specMap = new Map<string, BlockSpec<ComponentType>>(); | ||
specs.forEach(spec => { | ||
specMap.set(spec.schema.model.flavour, spec); | ||
}); | ||
return specMap; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src/", | ||
"outDir": "./dist/", | ||
"noEmit": false | ||
}, | ||
"include": ["./src"], | ||
"references": [] | ||
} |
Oops, something went wrong.