mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
docs(editor): scaffolding docs generator (#10925)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
[**@blocksuite/block-std**](../../../../@blocksuite/block-std/README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/block-std](../../README.md) / [index](../README.md) / BlockService
|
||||
|
||||
# Class: ~~`abstract` BlockService~~
|
||||
|
||||
## Deprecated
|
||||
|
||||
BlockService is deprecated. You should reconsider where to put your feature.
|
||||
|
||||
BlockService is a legacy extension that is used to provide services to the block.
|
||||
In the previous version of BlockSuite, block service provides a way to extend the block.
|
||||
However, in the new version, we recommend using the new extension system.
|
||||
|
||||
## Extends
|
||||
|
||||
- [`Extension`](../../../store/classes/Extension.md)
|
||||
@@ -0,0 +1,186 @@
|
||||
[**@blocksuite/block-std**](../../../../@blocksuite/block-std/README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/block-std](../../README.md) / [index](../README.md) / CommandManager
|
||||
|
||||
# Class: CommandManager
|
||||
|
||||
Command manager to manage all commands
|
||||
|
||||
Commands are functions that take a context and a next function as arguments
|
||||
|
||||
```ts
|
||||
const myCommand: Command<input, output> = (ctx, next) => {
|
||||
const count = ctx.count || 0;
|
||||
|
||||
const success = someOperation();
|
||||
if (success) {
|
||||
return next({ count: count + 1 });
|
||||
}
|
||||
// if the command is not successful, you can return without calling next
|
||||
return;
|
||||
```
|
||||
|
||||
Command input and output data can be defined in the `Command` type
|
||||
|
||||
```ts
|
||||
// input: ctx.firstName, ctx.lastName
|
||||
// output: ctx.fullName
|
||||
const myCommand: Command<{ firstName: string; lastName: string }, { fullName: string }> = (ctx, next) => {
|
||||
const { firstName, lastName } = ctx;
|
||||
const fullName = `${firstName} ${lastName}`;
|
||||
return next({ fullName });
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Commands can be run in two ways:
|
||||
|
||||
1. Using `exec` method
|
||||
`exec` is used to run a single command
|
||||
```ts
|
||||
const [result, data] = commandManager.exec(myCommand, payload);
|
||||
```
|
||||
|
||||
2. Using `chain` method
|
||||
`chain` is used to run a series of commands
|
||||
```ts
|
||||
const chain = commandManager.chain();
|
||||
const [result, data] = chain
|
||||
.pipe(myCommand1)
|
||||
.pipe(myCommand2, payload)
|
||||
.run();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Command chains will stop running if a command is not successful
|
||||
|
||||
```ts
|
||||
const chain = commandManager.chain();
|
||||
const [result, data] = chain
|
||||
.chain(myCommand1) <-- if this fail
|
||||
.chain(myCommand2, payload) <- this won't run
|
||||
.run();
|
||||
|
||||
result <- result will be `false`
|
||||
```
|
||||
|
||||
You can use `try` to run a series of commands and if one of them is successful, it will continue to the next command
|
||||
```ts
|
||||
const chain = commandManager.chain();
|
||||
const [result, data] = chain
|
||||
.try(chain => [
|
||||
chain.pipe(myCommand1), <- if this fail
|
||||
chain.pipe(myCommand2, payload), <- this will run, if this success
|
||||
chain.pipe(myCommand3), <- this won't run
|
||||
])
|
||||
.run();
|
||||
```
|
||||
|
||||
The `tryAll` method is similar to `try`, but it will run all commands even if one of them is successful
|
||||
```ts
|
||||
const chain = commandManager.chain();
|
||||
const [result, data] = chain
|
||||
.try(chain => [
|
||||
chain.pipe(myCommand1), <- if this success
|
||||
chain.pipe(myCommand2), <- this will also run
|
||||
chain.pipe(myCommand3), <- so will this
|
||||
])
|
||||
.run();
|
||||
```
|
||||
|
||||
## Extends
|
||||
|
||||
- [`LifeCycleWatcher`](LifeCycleWatcher.md)
|
||||
|
||||
## Methods
|
||||
|
||||
### chain()
|
||||
|
||||
> **chain**(): `Chain`\<`InitCommandCtx`\>
|
||||
|
||||
Create a chain to run a series of commands
|
||||
```ts
|
||||
const chain = commandManager.chain();
|
||||
const [result, data] = chain
|
||||
.myCommand1()
|
||||
.myCommand2(payload)
|
||||
.run();
|
||||
```
|
||||
|
||||
#### Returns
|
||||
|
||||
`Chain`\<`InitCommandCtx`\>
|
||||
|
||||
[success, data] - success is a boolean to indicate if the chain is successful,
|
||||
data is the final context after running the chain
|
||||
|
||||
***
|
||||
|
||||
### created()
|
||||
|
||||
> **created**(): `void`
|
||||
|
||||
Called when std is created.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LifeCycleWatcher`](LifeCycleWatcher.md).[`created`](LifeCycleWatcher.md#created)
|
||||
|
||||
***
|
||||
|
||||
### mounted()
|
||||
|
||||
> **mounted**(): `void`
|
||||
|
||||
Called when editor host is mounted.
|
||||
Which means the editor host emit the `connectedCallback` lifecycle event.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LifeCycleWatcher`](LifeCycleWatcher.md).[`mounted`](LifeCycleWatcher.md#mounted)
|
||||
|
||||
***
|
||||
|
||||
### rendered()
|
||||
|
||||
> **rendered**(): `void`
|
||||
|
||||
Called when `std.render` is called.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LifeCycleWatcher`](LifeCycleWatcher.md).[`rendered`](LifeCycleWatcher.md#rendered)
|
||||
|
||||
***
|
||||
|
||||
### unmounted()
|
||||
|
||||
> **unmounted**(): `void`
|
||||
|
||||
Called when editor host is unmounted.
|
||||
Which means the editor host emit the `disconnectedCallback` lifecycle event.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LifeCycleWatcher`](LifeCycleWatcher.md).[`unmounted`](LifeCycleWatcher.md#unmounted)
|
||||
@@ -0,0 +1,82 @@
|
||||
[**@blocksuite/block-std**](../../../../@blocksuite/block-std/README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/block-std](../../README.md) / [index](../README.md) / LifeCycleWatcher
|
||||
|
||||
# Class: `abstract` LifeCycleWatcher
|
||||
|
||||
A life cycle watcher is an extension that watches the life cycle of the editor.
|
||||
It is used to perform actions when the editor is created, mounted, rendered, or unmounted.
|
||||
|
||||
When creating a life cycle watcher, you must define a key that is unique to the watcher.
|
||||
The key is used to identify the watcher in the dependency injection container.
|
||||
```ts
|
||||
class MyLifeCycleWatcher extends LifeCycleWatcher {
|
||||
static override readonly key = 'my-life-cycle-watcher';
|
||||
```
|
||||
|
||||
In the life cycle watcher, the methods will be called in the following order:
|
||||
1. `created`: Called when the std is created.
|
||||
2. `rendered`: Called when `std.render` is called.
|
||||
3. `mounted`: Called when the editor host is mounted.
|
||||
4. `unmounted`: Called when the editor host is unmounted.
|
||||
|
||||
## Extends
|
||||
|
||||
- [`Extension`](../../../store/classes/Extension.md)
|
||||
|
||||
## Extended by
|
||||
|
||||
- [`CommandManager`](CommandManager.md)
|
||||
- [`RangeManager`](RangeManager.md)
|
||||
|
||||
## Methods
|
||||
|
||||
### created()
|
||||
|
||||
> **created**(): `void`
|
||||
|
||||
Called when std is created.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
***
|
||||
|
||||
### mounted()
|
||||
|
||||
> **mounted**(): `void`
|
||||
|
||||
Called when editor host is mounted.
|
||||
Which means the editor host emit the `connectedCallback` lifecycle event.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
***
|
||||
|
||||
### rendered()
|
||||
|
||||
> **rendered**(): `void`
|
||||
|
||||
Called when `std.render` is called.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
***
|
||||
|
||||
### unmounted()
|
||||
|
||||
> **unmounted**(): `void`
|
||||
|
||||
Called when editor host is unmounted.
|
||||
Which means the editor host emit the `disconnectedCallback` lifecycle event.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
@@ -0,0 +1,9 @@
|
||||
[**@blocksuite/block-std**](../../../../@blocksuite/block-std/README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/block-std](../../README.md) / [index](../README.md) / RangeBinding
|
||||
|
||||
# Class: RangeBinding
|
||||
|
||||
Two-way binding between native range and text selection
|
||||
@@ -0,0 +1,121 @@
|
||||
[**@blocksuite/block-std**](../../../../@blocksuite/block-std/README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/block-std](../../README.md) / [index](../README.md) / RangeManager
|
||||
|
||||
# Class: RangeManager
|
||||
|
||||
CRUD for Range and TextSelection
|
||||
|
||||
## Extends
|
||||
|
||||
- [`LifeCycleWatcher`](LifeCycleWatcher.md)
|
||||
|
||||
## Methods
|
||||
|
||||
### created()
|
||||
|
||||
> **created**(): `void`
|
||||
|
||||
Called when std is created.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LifeCycleWatcher`](LifeCycleWatcher.md).[`created`](LifeCycleWatcher.md#created)
|
||||
|
||||
***
|
||||
|
||||
### getSelectedBlockComponentsByRange()
|
||||
|
||||
> **getSelectedBlockComponentsByRange**(`range`, `options`): `BlockComponent`\<`BlockModel`\<`object`\>, [`BlockService`](BlockService.md), `string`\>[]
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### range
|
||||
|
||||
`Range`
|
||||
|
||||
##### options
|
||||
|
||||
###### match?
|
||||
|
||||
(`el`) => `boolean`
|
||||
|
||||
###### mode?
|
||||
|
||||
`"flat"` \| `"all"` \| `"highest"`
|
||||
|
||||
#### Returns
|
||||
|
||||
`BlockComponent`\<`BlockModel`\<`object`\>, [`BlockService`](BlockService.md), `string`\>[]
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
aaa
|
||||
b[bb
|
||||
ccc
|
||||
ddd
|
||||
ee]e
|
||||
|
||||
all mode: [aaa, bbb, ccc, ddd, eee]
|
||||
flat mode: [bbb, ccc, ddd, eee]
|
||||
highest mode: [bbb, ddd]
|
||||
|
||||
match function will be evaluated before filtering using mode
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### mounted()
|
||||
|
||||
> **mounted**(): `void`
|
||||
|
||||
Called when editor host is mounted.
|
||||
Which means the editor host emit the `connectedCallback` lifecycle event.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Overrides
|
||||
|
||||
[`LifeCycleWatcher`](LifeCycleWatcher.md).[`mounted`](LifeCycleWatcher.md#mounted)
|
||||
|
||||
***
|
||||
|
||||
### rendered()
|
||||
|
||||
> **rendered**(): `void`
|
||||
|
||||
Called when `std.render` is called.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LifeCycleWatcher`](LifeCycleWatcher.md).[`rendered`](LifeCycleWatcher.md#rendered)
|
||||
|
||||
***
|
||||
|
||||
### unmounted()
|
||||
|
||||
> **unmounted**(): `void`
|
||||
|
||||
Called when editor host is unmounted.
|
||||
Which means the editor host emit the `disconnectedCallback` lifecycle event.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`LifeCycleWatcher`](LifeCycleWatcher.md).[`unmounted`](LifeCycleWatcher.md#unmounted)
|
||||
Reference in New Issue
Block a user