snapshot of https://github.com/toeverything/AFFiNE.git (canary, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Build & Test / Analyze (javascript, blocksuite) (push) Failing after 3s
Build & Test / Rust test filter (push) Failing after 3s
Build & Test / E2E BlockSuite Test (2) (push) Failing after 3s
Build & Test / E2E BlockSuite Test (3) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (4) (push) Failing after 3s
Build & Test / E2E BlockSuite Cross Browser Test (push) Failing after 3s
Build & Test / E2E Mobile Test (1) (push) Failing after 3s
Build & Test / E2E Mobile Test (2) (push) Failing after 3s
Build & Test / Build AFFiNE native (x86_64-unknown-linux-gnu) (push) Failing after 4s
Build & Test / Unit Test (1) (push) Has been skipped
Build & Test / Unit Test (2) (push) Has been skipped
Build & Test / Unit Test (3) (push) Has been skipped
Build & Test / Build Server native (push) Failing after 3s
Build & Test / Check Git Status (push) Has been skipped
Build & Test / Server Test (0, 4) (push) Has been skipped
Build & Test / Server Test (1, 4) (push) Has been skipped
Build & Test / Analyze (javascript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, blocksuite) (push) Failing after 3s
Build & Test / Mobile native build filter (push) Failing after 3s
Build & Test / Check yarn binary (push) Failing after 3s
Build & Test / E2E BlockSuite Test (1) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (5) (push) Failing after 3s
Build & Test / Unit Test (4) (push) Has been skipped
Build & Test / Unit Test (5) (push) Has been skipped
Build & Test / Native Unit Test (push) Has been skipped
Build & Test / Server Test (2, 4) (push) Has been skipped
Build & Test / Server Test (3, 4) (push) Has been skipped
Build & Test / Server Test with Elasticsearch (push) Has been skipped
Build & Test / Server Test with Embedded Search (push) Has been skipped
Build & Test / Server Test with Manticore Search (push) Has been skipped
Build & Test / Server E2E Test (push) Has been skipped
Build & Test / Cloud Desktop E2E Test (push) Has been skipped
Build & Test / Cloud E2E Test 1/2 (push) Has been skipped
Build & Test / Cloud E2E Test 2/2 (push) Has been skipped
Build & Test / Build @affine/electron renderer (push) Failing after 3s
Build & Test / Copilot test filter (push) Failing after 4s
Build & Test / Lint Rust (push) Has been skipped
Build & Test / Build Android app (push) Has been skipped
Build & Test / Test Android app (push) Has been skipped
Build & Test / Run native tests (push) Has been skipped
Build & Test / Server Copilot Api Test (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (3, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (4, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (1, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (2, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (5, 5) (push) Has been skipped
Build & Test / Desktop Test (ubuntu-latest, linux, x64, x86_64-unknown-linux-gnu, true) (push) Has been cancelled
Build & Test / Desktop Test (windows-latest, windows, x64, x86_64-pc-windows-msvc, true) (push) Has been cancelled
Build & Test / 3, 2, 1 Launch (push) Has been cancelled
Build & Test / Lint (push) Has been cancelled
Build & Test / Typecheck (push) Has been cancelled
Build & Test / Build iOS app (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-apple-darwin) (push) Has been cancelled
Build & Test / E2E Test (1) (push) Has been cancelled
Build & Test / E2E Test (2) (push) Has been cancelled
Build & Test / E2E Test (3) (push) Has been cancelled
Build & Test / E2E Test (4) (push) Has been cancelled
Build & Test / E2E Test (5) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-apple-darwin) (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, arm64, aarch64-apple-darwin, true) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, x64, x86_64-apple-darwin, false) (push) Has been cancelled
Some checks failed
Build & Test / Analyze (javascript, blocksuite) (push) Failing after 3s
Build & Test / Rust test filter (push) Failing after 3s
Build & Test / E2E BlockSuite Test (2) (push) Failing after 3s
Build & Test / E2E BlockSuite Test (3) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (4) (push) Failing after 3s
Build & Test / E2E BlockSuite Cross Browser Test (push) Failing after 3s
Build & Test / E2E Mobile Test (1) (push) Failing after 3s
Build & Test / E2E Mobile Test (2) (push) Failing after 3s
Build & Test / Build AFFiNE native (x86_64-unknown-linux-gnu) (push) Failing after 4s
Build & Test / Unit Test (1) (push) Has been skipped
Build & Test / Unit Test (2) (push) Has been skipped
Build & Test / Unit Test (3) (push) Has been skipped
Build & Test / Build Server native (push) Failing after 3s
Build & Test / Check Git Status (push) Has been skipped
Build & Test / Server Test (0, 4) (push) Has been skipped
Build & Test / Server Test (1, 4) (push) Has been skipped
Build & Test / Analyze (javascript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, blocksuite) (push) Failing after 3s
Build & Test / Mobile native build filter (push) Failing after 3s
Build & Test / Check yarn binary (push) Failing after 3s
Build & Test / E2E BlockSuite Test (1) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (5) (push) Failing after 3s
Build & Test / Unit Test (4) (push) Has been skipped
Build & Test / Unit Test (5) (push) Has been skipped
Build & Test / Native Unit Test (push) Has been skipped
Build & Test / Server Test (2, 4) (push) Has been skipped
Build & Test / Server Test (3, 4) (push) Has been skipped
Build & Test / Server Test with Elasticsearch (push) Has been skipped
Build & Test / Server Test with Embedded Search (push) Has been skipped
Build & Test / Server Test with Manticore Search (push) Has been skipped
Build & Test / Server E2E Test (push) Has been skipped
Build & Test / Cloud Desktop E2E Test (push) Has been skipped
Build & Test / Cloud E2E Test 1/2 (push) Has been skipped
Build & Test / Cloud E2E Test 2/2 (push) Has been skipped
Build & Test / Build @affine/electron renderer (push) Failing after 3s
Build & Test / Copilot test filter (push) Failing after 4s
Build & Test / Lint Rust (push) Has been skipped
Build & Test / Build Android app (push) Has been skipped
Build & Test / Test Android app (push) Has been skipped
Build & Test / Run native tests (push) Has been skipped
Build & Test / Server Copilot Api Test (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (3, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (4, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (1, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (2, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (5, 5) (push) Has been skipped
Build & Test / Desktop Test (ubuntu-latest, linux, x64, x86_64-unknown-linux-gnu, true) (push) Has been cancelled
Build & Test / Desktop Test (windows-latest, windows, x64, x86_64-pc-windows-msvc, true) (push) Has been cancelled
Build & Test / 3, 2, 1 Launch (push) Has been cancelled
Build & Test / Lint (push) Has been cancelled
Build & Test / Typecheck (push) Has been cancelled
Build & Test / Build iOS app (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-apple-darwin) (push) Has been cancelled
Build & Test / E2E Test (1) (push) Has been cancelled
Build & Test / E2E Test (2) (push) Has been cancelled
Build & Test / E2E Test (3) (push) Has been cancelled
Build & Test / E2E Test (4) (push) Has been cancelled
Build & Test / E2E Test (5) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-apple-darwin) (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, arm64, aarch64-apple-darwin, true) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, x64, x86_64-apple-darwin, false) (push) Has been cancelled
This commit is contained in:
12
blocksuite/docs/api/@blocksuite/std/README.md
Normal file
12
blocksuite/docs/api/@blocksuite/std/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
[**BlockSuite API Documentation**](../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../README.md) / @blocksuite/std
|
||||
|
||||
# @blocksuite/std
|
||||
|
||||
## Modules
|
||||
|
||||
- [gfx](gfx/README.md)
|
||||
- [index](index/README.md)
|
||||
50
blocksuite/docs/api/@blocksuite/std/gfx/README.md
Normal file
50
blocksuite/docs/api/@blocksuite/std/gfx/README.md
Normal file
@@ -0,0 +1,50 @@
|
||||
[**BlockSuite API Documentation**](../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../README.md) / [@blocksuite/std](../README.md) / gfx
|
||||
|
||||
# gfx
|
||||
|
||||
## Classes
|
||||
|
||||
- [GfxBlockElementModel](classes/GfxBlockElementModel.md)
|
||||
- [GfxSelectionManager](classes/GfxSelectionManager.md)
|
||||
|
||||
## Interfaces
|
||||
|
||||
- [GfxCompatibleInterface](interfaces/GfxCompatibleInterface.md)
|
||||
- [GfxElementGeometry](interfaces/GfxElementGeometry.md)
|
||||
- [GfxGroupCompatibleInterface](interfaces/GfxGroupCompatibleInterface.md)
|
||||
- [PointTestOptions](interfaces/PointTestOptions.md)
|
||||
|
||||
## Type Aliases
|
||||
|
||||
- [GfxCommonBlockProps](type-aliases/GfxCommonBlockProps.md)
|
||||
- [GfxCompatibleProps](type-aliases/GfxCompatibleProps.md)
|
||||
|
||||
## Variables
|
||||
|
||||
- [gfxGroupCompatibleSymbol](variables/gfxGroupCompatibleSymbol.md)
|
||||
- [SURFACE\_TEXT\_UNIQ\_IDENTIFIER](variables/SURFACE_TEXT_UNIQ_IDENTIFIER.md)
|
||||
- [SURFACE\_YMAP\_UNIQ\_IDENTIFIER](variables/SURFACE_YMAP_UNIQ_IDENTIFIER.md)
|
||||
- [viewportRuntimeConfig](variables/viewportRuntimeConfig.md)
|
||||
|
||||
## Functions
|
||||
|
||||
- [canSafeAddToContainer](functions/canSafeAddToContainer.md)
|
||||
- [compareLayer](functions/compareLayer.md)
|
||||
- [convert](functions/convert.md)
|
||||
- [createRafCoalescer](functions/createRafCoalescer.md)
|
||||
- [derive](functions/derive.md)
|
||||
- [generateKeyBetween](functions/generateKeyBetween.md)
|
||||
- [generateKeyBetweenV2](functions/generateKeyBetweenV2.md)
|
||||
- [generateNKeysBetween](functions/generateNKeysBetween.md)
|
||||
- [getEffectiveDpr](functions/getEffectiveDpr.md)
|
||||
- [getTopElements](functions/getTopElements.md)
|
||||
- [GfxCompatible](functions/GfxCompatible.md)
|
||||
- [isGfxGroupCompatibleModel](functions/isGfxGroupCompatibleModel.md)
|
||||
- [local](functions/local.md)
|
||||
- [measureOperation](functions/measureOperation.md)
|
||||
- [observe](functions/observe.md)
|
||||
- [watch](functions/watch.md)
|
||||
@@ -0,0 +1,147 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / GfxBlockElementModel
|
||||
|
||||
# Class: GfxBlockElementModel\<Props\>
|
||||
|
||||
The graphic block model that can be rendered in the graphics mode.
|
||||
All the graphic block model should extend this class.
|
||||
You can use `GfxCompatibleBlockModel` to convert a BlockModel to a subclass that extends it.
|
||||
|
||||
## Extends
|
||||
|
||||
- `BlockModel`\<`Props`\>
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### Props
|
||||
|
||||
`Props` *extends* [`GfxCompatibleProps`](../type-aliases/GfxCompatibleProps.md) = [`GfxCompatibleProps`](../type-aliases/GfxCompatibleProps.md)
|
||||
|
||||
## Implements
|
||||
|
||||
- [`GfxCompatibleInterface`](../interfaces/GfxCompatibleInterface.md)
|
||||
|
||||
## Properties
|
||||
|
||||
### responseExtension
|
||||
|
||||
> **responseExtension**: \[`number`, `number`\]
|
||||
|
||||
Defines the extension of the response area beyond the element's bounding box.
|
||||
This tuple specifies the horizontal and vertical margins to be added to the element's [x, y, width, height].
|
||||
|
||||
The first value represents the horizontal extension (added to both left and right sides),
|
||||
and the second value represents the vertical extension (added to both top and bottom sides).
|
||||
|
||||
The response area is computed as:
|
||||
`[x - horizontal, y - vertical, width + 2 * horizontal, height + 2 * vertical]`.
|
||||
|
||||
Example:
|
||||
- Bounding box: `[0, 0, 100, 100]`, `responseExtension: [10, 20]`
|
||||
Resulting response area: `[-10, -20, 120, 140]`.
|
||||
- `responseExtension: [0, 0]` keeps the response area equal to the bounding box.
|
||||
|
||||
#### Implementation of
|
||||
|
||||
[`GfxCompatibleInterface`](../interfaces/GfxCompatibleInterface.md).[`responseExtension`](../interfaces/GfxCompatibleInterface.md#responseextension)
|
||||
|
||||
## Accessors
|
||||
|
||||
### elementBound
|
||||
|
||||
#### Get Signature
|
||||
|
||||
> **get** **elementBound**(): `Bound`
|
||||
|
||||
The bound of the element without considering the response extension.
|
||||
|
||||
##### Returns
|
||||
|
||||
`Bound`
|
||||
|
||||
The bound of the element without considering the response extension.
|
||||
|
||||
#### Implementation of
|
||||
|
||||
[`GfxCompatibleInterface`](../interfaces/GfxCompatibleInterface.md).[`elementBound`](../interfaces/GfxCompatibleInterface.md#elementbound)
|
||||
|
||||
***
|
||||
|
||||
### lockedBySelf
|
||||
|
||||
#### Get Signature
|
||||
|
||||
> **get** **lockedBySelf**(): `boolean` \| `undefined`
|
||||
|
||||
Indicates whether the current block is explicitly locked by self.
|
||||
For checking the lock status of the element, use `isLocked` instead.
|
||||
For (un)locking the element, use `(un)lock` instead.
|
||||
|
||||
##### Returns
|
||||
|
||||
`boolean` \| `undefined`
|
||||
|
||||
#### Set Signature
|
||||
|
||||
> **set** **lockedBySelf**(`lockedBySelf`): `void`
|
||||
|
||||
Indicates whether the current block is explicitly locked by self.
|
||||
For checking the lock status of the element, use `isLocked` instead.
|
||||
For (un)locking the element, use `(un)lock` instead.
|
||||
|
||||
##### Parameters
|
||||
|
||||
###### lockedBySelf
|
||||
|
||||
`boolean` \| `undefined`
|
||||
|
||||
##### Returns
|
||||
|
||||
`void`
|
||||
|
||||
Indicates whether the current block is explicitly locked by self.
|
||||
For checking the lock status of the element, use `isLocked` instead.
|
||||
For (un)locking the element, use `(un)lock` instead.
|
||||
|
||||
#### Implementation of
|
||||
|
||||
[`GfxCompatibleInterface`](../interfaces/GfxCompatibleInterface.md).[`lockedBySelf`](../interfaces/GfxCompatibleInterface.md#lockedbyself)
|
||||
|
||||
***
|
||||
|
||||
### responseBound
|
||||
|
||||
#### Get Signature
|
||||
|
||||
> **get** **responseBound**(): `Bound`
|
||||
|
||||
The bound of the element considering the response extension.
|
||||
|
||||
##### Returns
|
||||
|
||||
`Bound`
|
||||
|
||||
The bound of the element considering the response extension.
|
||||
|
||||
#### Implementation of
|
||||
|
||||
[`GfxCompatibleInterface`](../interfaces/GfxCompatibleInterface.md).[`responseBound`](../interfaces/GfxCompatibleInterface.md#responsebound)
|
||||
|
||||
## Methods
|
||||
|
||||
### isLocked()
|
||||
|
||||
> **isLocked**(): `boolean`
|
||||
|
||||
Check if the element is locked. It will check the lock status of the element and its ancestors.
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
#### Implementation of
|
||||
|
||||
[`GfxCompatibleInterface`](../interfaces/GfxCompatibleInterface.md).[`isLocked`](../interfaces/GfxCompatibleInterface.md#islocked)
|
||||
@@ -0,0 +1,64 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / GfxSelectionManager
|
||||
|
||||
# Class: GfxSelectionManager
|
||||
|
||||
GfxSelectionManager is just a wrapper of std selection providing
|
||||
convenient method and states in gfx
|
||||
|
||||
## Methods
|
||||
|
||||
### has()
|
||||
|
||||
> **has**(`element`): `boolean`
|
||||
|
||||
check if the element is selected in local
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### element
|
||||
|
||||
`string`
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
***
|
||||
|
||||
### hasRemote()
|
||||
|
||||
> **hasRemote**(`element`): `boolean`
|
||||
|
||||
check if element is selected by remote peers
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### element
|
||||
|
||||
`string`
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
***
|
||||
|
||||
### toggle()
|
||||
|
||||
> **toggle**(`element`): `void`
|
||||
|
||||
Toggle the selection state of single element
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### element
|
||||
|
||||
`string` \| `GfxModel`
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
@@ -0,0 +1,35 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / GfxCompatible
|
||||
|
||||
# Function: GfxCompatible()
|
||||
|
||||
> **GfxCompatible**\<`Props`, `T`\>(`BlockModelSuperClass`): *typeof* [`GfxBlockElementModel`](../classes/GfxBlockElementModel.md)
|
||||
|
||||
Convert a BlockModel to a GfxBlockElementModel.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### Props
|
||||
|
||||
`Props` *extends* [`GfxCompatibleProps`](../type-aliases/GfxCompatibleProps.md)
|
||||
|
||||
### T
|
||||
|
||||
`T` *extends* `Constructor`\<`BlockModel`\<`Props`\>\> = `Constructor`\<`BlockModel`\<`Props`\>\>
|
||||
|
||||
## Parameters
|
||||
|
||||
### BlockModelSuperClass
|
||||
|
||||
`T`
|
||||
|
||||
The BlockModel class to be converted.
|
||||
|
||||
## Returns
|
||||
|
||||
*typeof* [`GfxBlockElementModel`](../classes/GfxBlockElementModel.md)
|
||||
|
||||
The returned class is a subclass of the GfxBlockElementModel class and the given BlockModelSuperClass.
|
||||
@@ -0,0 +1,25 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / canSafeAddToContainer
|
||||
|
||||
# Function: canSafeAddToContainer()
|
||||
|
||||
> **canSafeAddToContainer**(`container`, `element`): `boolean`
|
||||
|
||||
This checker is used to prevent circular reference, when adding a child element to a container.
|
||||
|
||||
## Parameters
|
||||
|
||||
### container
|
||||
|
||||
`GfxGroupModel`
|
||||
|
||||
### element
|
||||
|
||||
[`GfxCompatibleInterface`](../interfaces/GfxCompatibleInterface.md)
|
||||
|
||||
## Returns
|
||||
|
||||
`boolean`
|
||||
@@ -0,0 +1,26 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / compareLayer
|
||||
|
||||
# Function: compareLayer()
|
||||
|
||||
> **compareLayer**(`a`, `b`): `SortOrder`
|
||||
|
||||
A comparator function for sorting elements in the surface.
|
||||
SortOrder.AFTER means a should be rendered after b and so on.
|
||||
|
||||
## Parameters
|
||||
|
||||
### a
|
||||
|
||||
`GfxModel` \| `GfxLocalElementModel`
|
||||
|
||||
### b
|
||||
|
||||
`GfxModel` \| `GfxLocalElementModel`
|
||||
|
||||
## Returns
|
||||
|
||||
`SortOrder`
|
||||
35
blocksuite/docs/api/@blocksuite/std/gfx/functions/convert.md
Normal file
35
blocksuite/docs/api/@blocksuite/std/gfx/functions/convert.md
Normal file
@@ -0,0 +1,35 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / convert
|
||||
|
||||
# Function: convert()
|
||||
|
||||
> **convert**\<`V`, `T`\>(`fn`): (`_`, `context`) => `ClassAccessorDecoratorResult`\<`T`, `V`\>
|
||||
|
||||
The convert decorator is used to convert the property value before it's
|
||||
set to the Y map.
|
||||
|
||||
Note:
|
||||
1. This decorator function will not execute in model initialization.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### V
|
||||
|
||||
`V`
|
||||
|
||||
### T
|
||||
|
||||
`T` *extends* `GfxPrimitiveElementModel`\<`BaseElementProps`\>
|
||||
|
||||
## Parameters
|
||||
|
||||
### fn
|
||||
|
||||
(`propValue`, `instance`) => `unknown`
|
||||
|
||||
## Returns
|
||||
|
||||
(`_`, `context`) => `ClassAccessorDecoratorResult`\<`T`, `V`\>
|
||||
@@ -0,0 +1,27 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / createRafCoalescer
|
||||
|
||||
# Function: createRafCoalescer()
|
||||
|
||||
> **createRafCoalescer**\<`T`\>(`apply`): `RafCoalescer`\<`T`\>
|
||||
|
||||
Coalesce high-frequency updates and only process the latest payload in one frame.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### T
|
||||
|
||||
`T`
|
||||
|
||||
## Parameters
|
||||
|
||||
### apply
|
||||
|
||||
(`payload`) => `void`
|
||||
|
||||
## Returns
|
||||
|
||||
`RafCoalescer`\<`T`\>
|
||||
40
blocksuite/docs/api/@blocksuite/std/gfx/functions/derive.md
Normal file
40
blocksuite/docs/api/@blocksuite/std/gfx/functions/derive.md
Normal file
@@ -0,0 +1,40 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / derive
|
||||
|
||||
# Function: derive()
|
||||
|
||||
> **derive**\<`V`, `T`\>(`fn`): (`_`, `context`) => `ClassAccessorDecoratorResult`\<`GfxPrimitiveElementModel`\<`BaseElementProps`\>, `V`\>
|
||||
|
||||
The derive decorator is used to derive other properties' update when the
|
||||
decorated property is updated through assignment in the local.
|
||||
|
||||
Note:
|
||||
1. The first argument of the function is the new value of the decorated property
|
||||
before the `convert` decorator is called.
|
||||
2. The decorator function will execute after the decorated property has been updated.
|
||||
3. The decorator function will not execute during model creation.
|
||||
4. The decorator function will not execute if the decorated property is updated through
|
||||
the Y map. That is to say, if other peers update the property will not trigger this decorator
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### V
|
||||
|
||||
`V`
|
||||
|
||||
### T
|
||||
|
||||
`T` *extends* `GfxPrimitiveElementModel`\<`BaseElementProps`\>
|
||||
|
||||
## Parameters
|
||||
|
||||
### fn
|
||||
|
||||
(`propValue`, `instance`) => `Record`\<`string`, `unknown`\>
|
||||
|
||||
## Returns
|
||||
|
||||
(`_`, `context`) => `ClassAccessorDecoratorResult`\<`GfxPrimitiveElementModel`\<`BaseElementProps`\>, `V`\>
|
||||
@@ -0,0 +1,27 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / generateKeyBetween
|
||||
|
||||
# Function: generateKeyBetween()
|
||||
|
||||
> **generateKeyBetween**(`a`, `b`, `digits?`): `string`
|
||||
|
||||
## Parameters
|
||||
|
||||
### a
|
||||
|
||||
`string` \| `null` \| `undefined`
|
||||
|
||||
### b
|
||||
|
||||
`string` \| `null` \| `undefined`
|
||||
|
||||
### digits?
|
||||
|
||||
`string`
|
||||
|
||||
## Returns
|
||||
|
||||
`string`
|
||||
@@ -0,0 +1,28 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / generateKeyBetweenV2
|
||||
|
||||
# Function: generateKeyBetweenV2()
|
||||
|
||||
> **generateKeyBetweenV2**(`a`, `b`): `string`
|
||||
|
||||
generate a key between a and b, the result key is always satisfied with a < result < b.
|
||||
the key always has a random suffix, so there is no need to worry about collision.
|
||||
|
||||
make sure a and b are generated by this function.
|
||||
|
||||
## Parameters
|
||||
|
||||
### a
|
||||
|
||||
`string` \| `null`
|
||||
|
||||
### b
|
||||
|
||||
`string` \| `null`
|
||||
|
||||
## Returns
|
||||
|
||||
`string`
|
||||
@@ -0,0 +1,39 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / generateNKeysBetween
|
||||
|
||||
# Function: generateNKeysBetween()
|
||||
|
||||
> **generateNKeysBetween**(`a`, `b`, `n`, `digits?`): `string`[]
|
||||
|
||||
same preconditions as generateKeysBetween.
|
||||
n >= 0.
|
||||
Returns an array of n distinct keys in sorted order.
|
||||
If a and b are both null, returns [a0, a1, ...]
|
||||
If one or the other is null, returns consecutive "integer"
|
||||
keys. Otherwise, returns relatively short keys between
|
||||
a and b.
|
||||
|
||||
## Parameters
|
||||
|
||||
### a
|
||||
|
||||
`string` \| `null` \| `undefined`
|
||||
|
||||
### b
|
||||
|
||||
`string` \| `null` \| `undefined`
|
||||
|
||||
### n
|
||||
|
||||
`number`
|
||||
|
||||
### digits?
|
||||
|
||||
`string`
|
||||
|
||||
## Returns
|
||||
|
||||
`string`[]
|
||||
@@ -0,0 +1,28 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / getEffectiveDpr
|
||||
|
||||
# Function: getEffectiveDpr()
|
||||
|
||||
> **getEffectiveDpr**(`zoom`, `rawDpr?`): `number`
|
||||
|
||||
Resolves the effective device-pixel-ratio for canvas backing stores at the
|
||||
given zoom, honoring [viewportRuntimeConfig.CANVAS\_DPR\_CAP\_BY\_ZOOM](../variables/viewportRuntimeConfig.md#canvas_dpr_cap_by_zoom).
|
||||
|
||||
Returns the raw `window.devicePixelRatio` when no cap applies.
|
||||
|
||||
## Parameters
|
||||
|
||||
### zoom
|
||||
|
||||
`number`
|
||||
|
||||
### rawDpr?
|
||||
|
||||
`number` = `window.devicePixelRatio`
|
||||
|
||||
## Returns
|
||||
|
||||
`number`
|
||||
@@ -0,0 +1,36 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / getTopElements
|
||||
|
||||
# Function: getTopElements()
|
||||
|
||||
> **getTopElements**(`elements`): `GfxModel`[]
|
||||
|
||||
Get the top elements from the list of elements, which are in some tree structures.
|
||||
|
||||
For example: a list `[G1, E1, G2, E2, E3, E4, G4, E5, E6]`,
|
||||
and they are in the elements tree like:
|
||||
```
|
||||
G1 G4 E6
|
||||
/ \ |
|
||||
E1 G2 E5
|
||||
/ \
|
||||
E2 G3*
|
||||
/ \
|
||||
E3 E4
|
||||
```
|
||||
where the star symbol `*` denote it is not in the list.
|
||||
|
||||
The result should be `[G1, G4, E6]`
|
||||
|
||||
## Parameters
|
||||
|
||||
### elements
|
||||
|
||||
`GfxModel`[]
|
||||
|
||||
## Returns
|
||||
|
||||
`GfxModel`[]
|
||||
@@ -0,0 +1,21 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / isGfxGroupCompatibleModel
|
||||
|
||||
# Function: isGfxGroupCompatibleModel()
|
||||
|
||||
> **isGfxGroupCompatibleModel**(`elm`): `elm is GfxGroupModel`
|
||||
|
||||
Check if the element is a container element.
|
||||
|
||||
## Parameters
|
||||
|
||||
### elm
|
||||
|
||||
`unknown`
|
||||
|
||||
## Returns
|
||||
|
||||
`elm is GfxGroupModel`
|
||||
28
blocksuite/docs/api/@blocksuite/std/gfx/functions/local.md
Normal file
28
blocksuite/docs/api/@blocksuite/std/gfx/functions/local.md
Normal file
@@ -0,0 +1,28 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / local
|
||||
|
||||
# Function: local()
|
||||
|
||||
> **local**\<`V`, `T`\>(): (`_target`, `context`) => `ClassAccessorDecoratorResult`\<`T`, `V`\>
|
||||
|
||||
A decorator to mark the property as a local property.
|
||||
|
||||
The local property act like it is a field property, but it's not synced to the Y map.
|
||||
Updating local property will also trigger the `elementUpdated` slot of the surface model
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### V
|
||||
|
||||
`V`
|
||||
|
||||
### T
|
||||
|
||||
`T` *extends* `GfxPrimitiveElementModel`\<`BaseElementProps`\>
|
||||
|
||||
## Returns
|
||||
|
||||
(`_target`, `context`) => `ClassAccessorDecoratorResult`\<`T`, `V`\>
|
||||
@@ -0,0 +1,34 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / measureOperation
|
||||
|
||||
# Function: measureOperation()
|
||||
|
||||
> **measureOperation**\<`T`\>(`name`, `fn`): `T`
|
||||
|
||||
Measure operation cost via Performance API when available.
|
||||
|
||||
Marks are always cleared, while measure entries are intentionally retained
|
||||
so callers can inspect them from Performance tools.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### T
|
||||
|
||||
`T`
|
||||
|
||||
## Parameters
|
||||
|
||||
### name
|
||||
|
||||
`string`
|
||||
|
||||
### fn
|
||||
|
||||
() => `T`
|
||||
|
||||
## Returns
|
||||
|
||||
`T`
|
||||
39
blocksuite/docs/api/@blocksuite/std/gfx/functions/observe.md
Normal file
39
blocksuite/docs/api/@blocksuite/std/gfx/functions/observe.md
Normal file
@@ -0,0 +1,39 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / observe
|
||||
|
||||
# Function: observe()
|
||||
|
||||
> **observe**\<`V`, `E`, `T`\>(`fn`): (`_`, `context`) => `ClassAccessorDecoratorResult`\<`GfxPrimitiveElementModel`\<`BaseElementProps`\>, `V`\>
|
||||
|
||||
A decorator to observe the y type property.
|
||||
You can think of it is just a decorator version of 'observe' method of Y.Array and Y.Map.
|
||||
|
||||
The observer function start to observe the property when the model is mounted. And it will
|
||||
re-observe the property automatically when the value is altered.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### V
|
||||
|
||||
`V`
|
||||
|
||||
### E
|
||||
|
||||
`E` *extends* `YEvent`\<`any`\>
|
||||
|
||||
### T
|
||||
|
||||
`T` *extends* `GfxPrimitiveElementModel`\<`BaseElementProps`\>
|
||||
|
||||
## Parameters
|
||||
|
||||
### fn
|
||||
|
||||
`ObserveFn`\<`E`, `T`\>
|
||||
|
||||
## Returns
|
||||
|
||||
(`_`, `context`) => `ClassAccessorDecoratorResult`\<`GfxPrimitiveElementModel`\<`BaseElementProps`\>, `V`\>
|
||||
32
blocksuite/docs/api/@blocksuite/std/gfx/functions/watch.md
Normal file
32
blocksuite/docs/api/@blocksuite/std/gfx/functions/watch.md
Normal file
@@ -0,0 +1,32 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / watch
|
||||
|
||||
# Function: watch()
|
||||
|
||||
> **watch**\<`V`, `T`\>(`fn`): (`_`, `context`) => `ClassAccessorDecoratorResult`\<`GfxPrimitiveElementModel`\<`BaseElementProps`\>, `V`\>
|
||||
|
||||
The watch decorator is used to watch the property change of the element.
|
||||
You can thinks of it as a decorator version of `elementUpdated` slot of the surface model.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### V
|
||||
|
||||
`V`
|
||||
|
||||
### T
|
||||
|
||||
`T` *extends* `GfxPrimitiveElementModel`\<`BaseElementProps`\>
|
||||
|
||||
## Parameters
|
||||
|
||||
### fn
|
||||
|
||||
`WatchFn`\<`T`\>
|
||||
|
||||
## Returns
|
||||
|
||||
(`_`, `context`) => `ClassAccessorDecoratorResult`\<`GfxPrimitiveElementModel`\<`BaseElementProps`\>, `V`\>
|
||||
@@ -0,0 +1,84 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / GfxCompatibleInterface
|
||||
|
||||
# Interface: GfxCompatibleInterface
|
||||
|
||||
All the model that can be rendered in graphics mode should implement this interface.
|
||||
|
||||
## Extends
|
||||
|
||||
- `IBound`.[`GfxElementGeometry`](GfxElementGeometry.md)
|
||||
|
||||
## Extended by
|
||||
|
||||
- [`GfxGroupCompatibleInterface`](GfxGroupCompatibleInterface.md)
|
||||
|
||||
## Properties
|
||||
|
||||
### elementBound
|
||||
|
||||
> `readonly` **elementBound**: `Bound`
|
||||
|
||||
The bound of the element without considering the response extension.
|
||||
|
||||
***
|
||||
|
||||
### forceFullRender?
|
||||
|
||||
> `optional` **forceFullRender?**: `boolean`
|
||||
|
||||
Whether to disable fallback rendering for this element, e.g., during zooming.
|
||||
Defaults to false (fallback to placeholder rendering is enabled).
|
||||
|
||||
***
|
||||
|
||||
### lockedBySelf?
|
||||
|
||||
> `optional` **lockedBySelf?**: `boolean`
|
||||
|
||||
Indicates whether the current block is explicitly locked by self.
|
||||
For checking the lock status of the element, use `isLocked` instead.
|
||||
For (un)locking the element, use `(un)lock` instead.
|
||||
|
||||
***
|
||||
|
||||
### responseBound
|
||||
|
||||
> `readonly` **responseBound**: `Bound`
|
||||
|
||||
The bound of the element considering the response extension.
|
||||
|
||||
***
|
||||
|
||||
### responseExtension
|
||||
|
||||
> **responseExtension**: \[`number`, `number`\]
|
||||
|
||||
Defines the extension of the response area beyond the element's bounding box.
|
||||
This tuple specifies the horizontal and vertical margins to be added to the element's bound.
|
||||
|
||||
The first value represents the horizontal extension (added to both left and right sides),
|
||||
and the second value represents the vertical extension (added to both top and bottom sides).
|
||||
|
||||
The response area is computed as:
|
||||
`[x - horizontal, y - vertical, w + 2 * horizontal, h + 2 * vertical]`.
|
||||
|
||||
Example:
|
||||
- xywh: `[0, 0, 100, 100]`, `responseExtension: [10, 20]`
|
||||
Resulting response area: `[-10, -20, 120, 140]`.
|
||||
- `responseExtension: [0, 0]` keeps the response area equal to the bounding box.
|
||||
|
||||
## Methods
|
||||
|
||||
### isLocked()
|
||||
|
||||
> **isLocked**(): `boolean`
|
||||
|
||||
Check if the element is locked. It will check the lock status of the element and its ancestors.
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
@@ -0,0 +1,14 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / GfxElementGeometry
|
||||
|
||||
# Interface: GfxElementGeometry
|
||||
|
||||
The methods that a graphic element should implement.
|
||||
It is already included in the `GfxCompatibleInterface` interface.
|
||||
|
||||
## Extended by
|
||||
|
||||
- [`GfxCompatibleInterface`](GfxCompatibleInterface.md)
|
||||
@@ -0,0 +1,123 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / GfxGroupCompatibleInterface
|
||||
|
||||
# Interface: GfxGroupCompatibleInterface
|
||||
|
||||
GfxGroupCompatibleElement is a model that can contain other models.
|
||||
It just like a group that in common graphic software.
|
||||
|
||||
## Extends
|
||||
|
||||
- [`GfxCompatibleInterface`](GfxCompatibleInterface.md)
|
||||
|
||||
## Properties
|
||||
|
||||
### childElements
|
||||
|
||||
> **childElements**: `GfxModel`[]
|
||||
|
||||
All child element models of this container.
|
||||
Note that the `childElements` may not contains all the children in `childIds`,
|
||||
because some children may not be loaded.
|
||||
|
||||
***
|
||||
|
||||
### childIds
|
||||
|
||||
> **childIds**: `string`[]
|
||||
|
||||
All child ids of this container.
|
||||
|
||||
***
|
||||
|
||||
### elementBound
|
||||
|
||||
> `readonly` **elementBound**: `Bound`
|
||||
|
||||
The bound of the element without considering the response extension.
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`GfxCompatibleInterface`](GfxCompatibleInterface.md).[`elementBound`](GfxCompatibleInterface.md#elementbound)
|
||||
|
||||
***
|
||||
|
||||
### forceFullRender?
|
||||
|
||||
> `optional` **forceFullRender?**: `boolean`
|
||||
|
||||
Whether to disable fallback rendering for this element, e.g., during zooming.
|
||||
Defaults to false (fallback to placeholder rendering is enabled).
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`GfxCompatibleInterface`](GfxCompatibleInterface.md).[`forceFullRender`](GfxCompatibleInterface.md#forcefullrender)
|
||||
|
||||
***
|
||||
|
||||
### lockedBySelf?
|
||||
|
||||
> `optional` **lockedBySelf?**: `boolean`
|
||||
|
||||
Indicates whether the current block is explicitly locked by self.
|
||||
For checking the lock status of the element, use `isLocked` instead.
|
||||
For (un)locking the element, use `(un)lock` instead.
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`GfxCompatibleInterface`](GfxCompatibleInterface.md).[`lockedBySelf`](GfxCompatibleInterface.md#lockedbyself)
|
||||
|
||||
***
|
||||
|
||||
### responseBound
|
||||
|
||||
> `readonly` **responseBound**: `Bound`
|
||||
|
||||
The bound of the element considering the response extension.
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`GfxCompatibleInterface`](GfxCompatibleInterface.md).[`responseBound`](GfxCompatibleInterface.md#responsebound)
|
||||
|
||||
***
|
||||
|
||||
### responseExtension
|
||||
|
||||
> **responseExtension**: \[`number`, `number`\]
|
||||
|
||||
Defines the extension of the response area beyond the element's bounding box.
|
||||
This tuple specifies the horizontal and vertical margins to be added to the element's bound.
|
||||
|
||||
The first value represents the horizontal extension (added to both left and right sides),
|
||||
and the second value represents the vertical extension (added to both top and bottom sides).
|
||||
|
||||
The response area is computed as:
|
||||
`[x - horizontal, y - vertical, w + 2 * horizontal, h + 2 * vertical]`.
|
||||
|
||||
Example:
|
||||
- xywh: `[0, 0, 100, 100]`, `responseExtension: [10, 20]`
|
||||
Resulting response area: `[-10, -20, 120, 140]`.
|
||||
- `responseExtension: [0, 0]` keeps the response area equal to the bounding box.
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`GfxCompatibleInterface`](GfxCompatibleInterface.md).[`responseExtension`](GfxCompatibleInterface.md#responseextension)
|
||||
|
||||
## Methods
|
||||
|
||||
### isLocked()
|
||||
|
||||
> **isLocked**(): `boolean`
|
||||
|
||||
Check if the element is locked. It will check the lock status of the element and its ancestors.
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
#### Inherited from
|
||||
|
||||
[`GfxCompatibleInterface`](GfxCompatibleInterface.md).[`isLocked`](GfxCompatibleInterface.md#islocked)
|
||||
@@ -0,0 +1,54 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / PointTestOptions
|
||||
|
||||
# Interface: PointTestOptions
|
||||
|
||||
The options for the hit testing of a point.
|
||||
|
||||
## Properties
|
||||
|
||||
### hitThreshold?
|
||||
|
||||
> `optional` **hitThreshold?**: `number`
|
||||
|
||||
The threshold of the hit test. The unit is pixel.
|
||||
|
||||
***
|
||||
|
||||
### ignoreTransparent?
|
||||
|
||||
> `optional` **ignoreTransparent?**: `boolean`
|
||||
|
||||
If true, the transparent area of the element will be ignored during the point inclusion test.
|
||||
Otherwise, the transparent area will be considered as filled area.
|
||||
|
||||
Default is true.
|
||||
|
||||
***
|
||||
|
||||
### responsePadding?
|
||||
|
||||
> `optional` **responsePadding?**: \[`number`, `number`\]
|
||||
|
||||
The padding of the response area for each element when do the hit testing. The unit is pixel.
|
||||
The first value is the padding for the x-axis, and the second value is the padding for the y-axis.
|
||||
|
||||
***
|
||||
|
||||
### useElementBound?
|
||||
|
||||
> `optional` **useElementBound?**: `boolean`
|
||||
|
||||
If true, the element bound will be used for the hit testing.
|
||||
By default, the response bound will be used.
|
||||
|
||||
***
|
||||
|
||||
### zoom?
|
||||
|
||||
> `optional` **zoom?**: `number`
|
||||
|
||||
The zoom level of current view when do the hit testing.
|
||||
@@ -0,0 +1,22 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / GfxCommonBlockProps
|
||||
|
||||
# Type Alias: GfxCommonBlockProps
|
||||
|
||||
> **GfxCommonBlockProps** = [`GfxCompatibleProps`](GfxCompatibleProps.md) & `object`
|
||||
|
||||
This type include the common props for the graphic block model.
|
||||
You can use this type with Omit to define the props of a graphic block model.
|
||||
|
||||
## Type Declaration
|
||||
|
||||
### rotate
|
||||
|
||||
> **rotate**: `number`
|
||||
|
||||
### scale
|
||||
|
||||
> **scale**: `number`
|
||||
@@ -0,0 +1,11 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / GfxCompatibleProps
|
||||
|
||||
# Type Alias: GfxCompatibleProps
|
||||
|
||||
> **GfxCompatibleProps** = `object`
|
||||
|
||||
The props that a graphics block model should have.
|
||||
@@ -0,0 +1,11 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / SURFACE\_TEXT\_UNIQ\_IDENTIFIER
|
||||
|
||||
# Variable: SURFACE\_TEXT\_UNIQ\_IDENTIFIER
|
||||
|
||||
> `const` **SURFACE\_TEXT\_UNIQ\_IDENTIFIER**: `"affine:surface:text"` = `'affine:surface:text'`
|
||||
|
||||
Used for text field
|
||||
@@ -0,0 +1,11 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / SURFACE\_YMAP\_UNIQ\_IDENTIFIER
|
||||
|
||||
# Variable: SURFACE\_YMAP\_UNIQ\_IDENTIFIER
|
||||
|
||||
> `const` **SURFACE\_YMAP\_UNIQ\_IDENTIFIER**: `"affine:surface:ymap"` = `'affine:surface:ymap'`
|
||||
|
||||
Used for field that use Y.Map. E.g. group children field
|
||||
@@ -0,0 +1,11 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / gfxGroupCompatibleSymbol
|
||||
|
||||
# Variable: gfxGroupCompatibleSymbol
|
||||
|
||||
> `const` **gfxGroupCompatibleSymbol**: *typeof* `gfxGroupCompatibleSymbol`
|
||||
|
||||
The symbol to mark a model as a container.
|
||||
@@ -0,0 +1,117 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [gfx](../README.md) / viewportRuntimeConfig
|
||||
|
||||
# Variable: viewportRuntimeConfig
|
||||
|
||||
> `const` **viewportRuntimeConfig**: `object`
|
||||
|
||||
Process-wide defaults applied to every Viewport at construction.
|
||||
|
||||
Platforms that need different behavior (e.g. mobile/iOS, which must clamp the
|
||||
zoom floor and defer DOM mutations during gestures to avoid WKWebView process
|
||||
termination) override these once at startup, before any editor mounts. This
|
||||
guarantees both the editor and the readonly preview viewports are born with
|
||||
the same limits — avoiding the race and wrong-instance problems of patching a
|
||||
single Viewport asynchronously after it has already mounted.
|
||||
|
||||
Desktop leaves these untouched, so its behavior is unchanged.
|
||||
|
||||
## Type Declaration
|
||||
|
||||
### CANVAS\_DPR\_CAP\_BY\_ZOOM
|
||||
|
||||
> **CANVAS\_DPR\_CAP\_BY\_ZOOM**: \[`number`, `number`\][]
|
||||
|
||||
Caps the canvas backing-store device-pixel-ratio at low zoom.
|
||||
|
||||
Each entry is `[zoomThreshold, dprCap]`, sorted ascending by threshold.
|
||||
When the live zoom is below a threshold, the corresponding cap bounds the
|
||||
effective dpr used to size canvases. Far-out zoom makes content tiny on
|
||||
screen, so a full retina backing store is wasted memory — on iOS that waste
|
||||
is what pushes WKWebView past its compositing budget and crashes the web
|
||||
content process during pan/zoom.
|
||||
|
||||
Empty (the desktop default) means no cap: canvases always use the raw
|
||||
`window.devicePixelRatio`, so desktop behavior is unchanged.
|
||||
|
||||
### LOW\_ZOOM\_GESTURE\_ACTIVE\_BLOCK\_LIMIT
|
||||
|
||||
> **LOW\_ZOOM\_GESTURE\_ACTIVE\_BLOCK\_LIMIT**: `number` = `0`
|
||||
|
||||
During low-zoom gesture survival mode, keep only a tiny subset of DOM blocks
|
||||
as real active DOM (selected + a few nearby blocks). `0` keeps the legacy
|
||||
behavior where every viewport block remains visually mounted as `survival`.
|
||||
|
||||
### LOW\_ZOOM\_GESTURE\_ACTIVE\_DISTANCE\_RATIO
|
||||
|
||||
> **LOW\_ZOOM\_GESTURE\_ACTIVE\_DISTANCE\_RATIO**: `number` = `0.35`
|
||||
|
||||
Distance threshold (as a fraction of the viewport's shorter side) used to
|
||||
decide whether an unselected viewport block counts as "nearby" to the
|
||||
current selection during low-zoom gesture survival mode.
|
||||
|
||||
### OVERSCAN\_RATIO
|
||||
|
||||
> **OVERSCAN\_RATIO**: `number` = `0`
|
||||
|
||||
Fraction by which the *render/activation* viewport bound is enlarged on
|
||||
every side (see Viewport.overscanViewportBounds). Pre-painting a
|
||||
margin around the visible area means moderate pan/zoom gestures move into
|
||||
content that is already mounted and rasterized, so it does not blank out
|
||||
and wait for the post-gesture refresh.
|
||||
|
||||
Memory grows by roughly `(1 + 2 * ratio) ** 2`, so this must stay modest
|
||||
and be paired with a zoom floor + dpr cap on mobile. `0` (desktop default)
|
||||
makes Viewport.overscanViewportBounds identical to
|
||||
Viewport.viewportBounds, leaving desktop behavior unchanged.
|
||||
|
||||
This governs the *canvas* render bound only (see
|
||||
Viewport.overscanViewportBounds). It enlarges the canvas backing
|
||||
stores, so memory grows with the overscan area. Keep it modest and pair it
|
||||
with the mobile zoom floor + dpr cap so connectors/elements stay painted
|
||||
through a gesture without pushing WKWebView over budget.
|
||||
|
||||
### OVERSCAN\_RATIO\_BLOCK
|
||||
|
||||
> **OVERSCAN\_RATIO\_BLOCK**: `number` = `0`
|
||||
|
||||
Like [OVERSCAN\_RATIO](#overscan_ratio) but for the *DOM block mounting* bound (see
|
||||
Viewport.overscanBlockBounds). This one is expensive: every
|
||||
mounted block becomes its own composited layer subtree in the WebContent
|
||||
process, so enlarging it multiplies resident memory and is what pushes the
|
||||
process toward an iOS jetsam kill. Keep this small (or `0`) even when
|
||||
[OVERSCAN\_RATIO](#overscan_ratio) is generous. `0` (desktop default) leaves block
|
||||
mounting on the exact visible bound, unchanged from upstream.
|
||||
|
||||
### POST\_GESTURE\_REFRESH\_DELAY
|
||||
|
||||
> **POST\_GESTURE\_REFRESH\_DELAY**: `number` = `800`
|
||||
|
||||
Delay (ms) before the post-gesture refresh repaints canvases and reactivates
|
||||
blocks, used only when [SKIP\_REFRESH\_DURING\_GESTURE](#skip_refresh_during_gesture) is true. The same
|
||||
value drives both the canvas and block refresh timers so they fire together
|
||||
(avoiding the "blocks appear, then connectors" staggered reveal). Desktop
|
||||
never enters that code path, so this is mobile-only.
|
||||
|
||||
### SKIP\_REFRESH\_DURING\_GESTURE
|
||||
|
||||
> **SKIP\_REFRESH\_DURING\_GESTURE**: `boolean` = `false`
|
||||
|
||||
### VIEWPORT\_REFRESH\_MAX\_INTERVAL
|
||||
|
||||
> **VIEWPORT\_REFRESH\_MAX\_INTERVAL**: `number` = `120`
|
||||
|
||||
### VIEWPORT\_REFRESH\_PIXEL\_THRESHOLD
|
||||
|
||||
> **VIEWPORT\_REFRESH\_PIXEL\_THRESHOLD**: `number` = `18`
|
||||
|
||||
### ZOOM\_MAX
|
||||
|
||||
> **ZOOM\_MAX**: `number`
|
||||
|
||||
### ZOOM\_MIN
|
||||
|
||||
> **ZOOM\_MIN**: `number`
|
||||
21
blocksuite/docs/api/@blocksuite/std/index/README.md
Normal file
21
blocksuite/docs/api/@blocksuite/std/index/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
[**BlockSuite API Documentation**](../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../README.md) / [@blocksuite/std](../README.md) / index
|
||||
|
||||
# index
|
||||
|
||||
## Classes
|
||||
|
||||
- [~~BlockService~~](classes/BlockService.md)
|
||||
- [CommandManager](classes/CommandManager.md)
|
||||
- [LifeCycleWatcher](classes/LifeCycleWatcher.md)
|
||||
|
||||
## Functions
|
||||
|
||||
- [BlockViewExtension](functions/BlockViewExtension.md)
|
||||
- [ConfigExtensionFactory](functions/ConfigExtensionFactory.md)
|
||||
- [FlavourExtension](functions/FlavourExtension.md)
|
||||
- [KeymapExtension](functions/KeymapExtension.md)
|
||||
- [WidgetViewExtension](functions/WidgetViewExtension.md)
|
||||
@@ -0,0 +1,19 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [index](../README.md) / BlockService
|
||||
|
||||
# ~~Abstract Class: 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 API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/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,81 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [index](../README.md) / LifeCycleWatcher
|
||||
|
||||
# Abstract Class: 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)
|
||||
|
||||
## 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,42 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [index](../README.md) / BlockViewExtension
|
||||
|
||||
# Function: BlockViewExtension()
|
||||
|
||||
> **BlockViewExtension**(`flavour`, `view`): `ExtensionType`
|
||||
|
||||
Create a block view extension.
|
||||
|
||||
## Parameters
|
||||
|
||||
### flavour
|
||||
|
||||
`string`
|
||||
|
||||
The flavour of the block that the view is for.
|
||||
|
||||
### view
|
||||
|
||||
`BlockViewType`
|
||||
|
||||
Lit literal template for the view. Example: `my-list-block`
|
||||
|
||||
The view is a lit template that is used to render the block.
|
||||
|
||||
## Returns
|
||||
|
||||
`ExtensionType`
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { BlockViewExtension } from '@blocksuite/std';
|
||||
|
||||
const MyListBlockViewExtension = BlockViewExtension(
|
||||
'affine:list',
|
||||
literal`my-list-block`
|
||||
);
|
||||
```
|
||||
@@ -0,0 +1,45 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [index](../README.md) / ConfigExtensionFactory
|
||||
|
||||
# Function: ConfigExtensionFactory()
|
||||
|
||||
> **ConfigExtensionFactory**\<`Config`\>(`configId`): `ConfigFactory`\<`Config`\>
|
||||
|
||||
Create a config extension.
|
||||
A config extension provides a configuration object for a block flavour.
|
||||
The configuration object can be used like:
|
||||
```ts
|
||||
const config = std.provider.getOptional(ConfigIdentifier('my-flavour'));
|
||||
```
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### Config
|
||||
|
||||
`Config` *extends* `Record`\<`string`, `any`\>
|
||||
|
||||
## Parameters
|
||||
|
||||
### configId
|
||||
|
||||
`string`
|
||||
|
||||
The id of the config. Should be unique for each config.
|
||||
|
||||
## Returns
|
||||
|
||||
`ConfigFactory`\<`Config`\>
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { ConfigExtensionFactory } from '@blocksuite/std';
|
||||
const MyConfigExtensionFactory = ConfigExtensionFactory<ConfigType>('my-flavour');
|
||||
const MyConfigExtension = MyConfigExtensionFactory({
|
||||
option1: 'value1',
|
||||
option2: 'value2',
|
||||
});
|
||||
```
|
||||
@@ -0,0 +1,31 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [index](../README.md) / FlavourExtension
|
||||
|
||||
# Function: FlavourExtension()
|
||||
|
||||
> **FlavourExtension**(`flavour`): `ExtensionType`
|
||||
|
||||
Create a flavour extension.
|
||||
|
||||
## Parameters
|
||||
|
||||
### flavour
|
||||
|
||||
`string`
|
||||
|
||||
The flavour of the block that the extension is for.
|
||||
|
||||
## Returns
|
||||
|
||||
`ExtensionType`
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { FlavourExtension } from '@blocksuite/std';
|
||||
|
||||
const MyFlavourExtension = FlavourExtension('my-flavour');
|
||||
```
|
||||
@@ -0,0 +1,49 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [index](../README.md) / KeymapExtension
|
||||
|
||||
# Function: KeymapExtension()
|
||||
|
||||
> **KeymapExtension**(`keymapFactory`, `options?`): `ExtensionType`
|
||||
|
||||
Create a keymap extension.
|
||||
|
||||
## Parameters
|
||||
|
||||
### keymapFactory
|
||||
|
||||
(`std`) => `Record`\<`string`, `UIEventHandler`\>
|
||||
|
||||
Create keymap of the extension.
|
||||
It should return an object with `keymap` and `options`.
|
||||
|
||||
`keymap` is a record of keymap.
|
||||
|
||||
### options?
|
||||
|
||||
`EventOptions`
|
||||
|
||||
`options` is an optional object that restricts the event to be handled.
|
||||
|
||||
## Returns
|
||||
|
||||
`ExtensionType`
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { KeymapExtension } from '@blocksuite/std';
|
||||
|
||||
const MyKeymapExtension = KeymapExtension(std => {
|
||||
return {
|
||||
keymap: {
|
||||
'mod-a': SelectAll
|
||||
}
|
||||
options: {
|
||||
flavour: 'affine:paragraph'
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
@@ -0,0 +1,45 @@
|
||||
[**BlockSuite API Documentation**](../../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../../README.md) / [@blocksuite/std](../../README.md) / [index](../README.md) / WidgetViewExtension
|
||||
|
||||
# Function: WidgetViewExtension()
|
||||
|
||||
> **WidgetViewExtension**(`flavour`, `id`, `view`): `ExtensionType`
|
||||
|
||||
Create a widget view extension.
|
||||
|
||||
## Parameters
|
||||
|
||||
### flavour
|
||||
|
||||
`string`
|
||||
|
||||
The flavour of the block that the widget view is for.
|
||||
|
||||
### id
|
||||
|
||||
`string`
|
||||
|
||||
The id of the widget view.
|
||||
|
||||
### view
|
||||
|
||||
`StaticValue`
|
||||
|
||||
The widget view lit literal.
|
||||
|
||||
A widget view is to provide a widget view for a block.
|
||||
For every target block, it's view will be rendered with the widget view.
|
||||
|
||||
## Returns
|
||||
|
||||
`ExtensionType`
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
import { WidgetViewExtension } from '@blocksuite/std';
|
||||
|
||||
const MyWidgetViewExtension = WidgetViewExtension('my-flavour', 'my-widget', literal`my-widget-view`);
|
||||
26
blocksuite/docs/api/@blocksuite/store/README.md
Normal file
26
blocksuite/docs/api/@blocksuite/store/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
[**BlockSuite API Documentation**](../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../README.md) / @blocksuite/store
|
||||
|
||||
# @blocksuite/store
|
||||
|
||||
## Extension
|
||||
|
||||
- [Extension](classes/Extension.md)
|
||||
- [StoreExtension](classes/StoreExtension.md)
|
||||
|
||||
## Reactive
|
||||
|
||||
- [Boxed](classes/Boxed.md)
|
||||
- [Text](classes/Text.md)
|
||||
|
||||
## Store
|
||||
|
||||
- [Store](classes/Store.md)
|
||||
- [StoreSlots](interfaces/StoreSlots.md)
|
||||
|
||||
## Other
|
||||
|
||||
- [Schema](classes/Schema.md)
|
||||
141
blocksuite/docs/api/@blocksuite/store/classes/Boxed.md
Normal file
141
blocksuite/docs/api/@blocksuite/store/classes/Boxed.md
Normal file
@@ -0,0 +1,141 @@
|
||||
[**BlockSuite API Documentation**](../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../README.md) / [@blocksuite/store](../README.md) / Boxed
|
||||
|
||||
# Class: Boxed\<Value\>
|
||||
|
||||
Boxed is to store raw data in Yjs.
|
||||
By default, store will try to convert a object to a Y.Map.
|
||||
If you want to store a raw object for you want to manipulate the Y.Map directly, you can use Boxed.
|
||||
|
||||
> [!NOTE]
|
||||
> Please notice that the data will be stored in Y.Map anyway so it can not hold data structure like function.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
const boxedObject = new Boxed({ a: 1, b: 2 });
|
||||
const boxedYMap = new Boxed(new Y.Map());
|
||||
boxedObject.getValue().a; // 1
|
||||
boxedYMap.getValue().set('a', 1);
|
||||
boxedObject.setValue({ foo: 'bar' });
|
||||
```
|
||||
|
||||
## Type Param
|
||||
|
||||
**T**
|
||||
|
||||
The type of the value stored in the Boxed.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### Value
|
||||
|
||||
`Value` = `unknown`
|
||||
|
||||
## Methods
|
||||
|
||||
### getValue()
|
||||
|
||||
> **getValue**(): `Value` \| `undefined`
|
||||
|
||||
Get the current value of the Boxed.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Value` \| `undefined`
|
||||
|
||||
***
|
||||
|
||||
### setValue()
|
||||
|
||||
> **setValue**(`value`): `Value`
|
||||
|
||||
Replace the current value of the Boxed.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### value
|
||||
|
||||
`Value`
|
||||
|
||||
The new value to set.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Value`
|
||||
|
||||
***
|
||||
|
||||
### from()
|
||||
|
||||
> `static` **from**\<`Value`\>(`map`): `Boxed`\<`Value`\>
|
||||
|
||||
Create a Boxed from a Y.Map.
|
||||
It is useful when you sync a Y.Map from remote.
|
||||
|
||||
#### Type Parameters
|
||||
|
||||
##### Value
|
||||
|
||||
`Value`
|
||||
|
||||
The type of the value.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### map
|
||||
|
||||
`YMap`\<`unknown`\>
|
||||
|
||||
#### Returns
|
||||
|
||||
`Boxed`\<`Value`\>
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const doc1 = new Y.Doc();
|
||||
const doc2 = new Y.Doc();
|
||||
keepSynced(doc1, doc2);
|
||||
|
||||
const data1 = doc1.getMap('data');
|
||||
const boxed1 = new Boxed({ a: 1, b: 2 });
|
||||
data1.set('boxed', boxed1.yMap);
|
||||
|
||||
const data2 = doc2.getMap('data');
|
||||
const boxed2 = Boxed.from<{ a: number; b: number }>(data2.get('boxed'));
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### is()
|
||||
|
||||
> `static` **is**(`value`): `value is Boxed<unknown>`
|
||||
|
||||
Check if a value is a Boxed.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### value
|
||||
|
||||
`unknown`
|
||||
|
||||
#### Returns
|
||||
|
||||
`value is Boxed<unknown>`
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const doc = new Y.Doc();
|
||||
|
||||
const data = doc.getMap('data');
|
||||
const boxed = new Boxed({ a: 1, b: 2 });
|
||||
Boxed.is(boxed); // true
|
||||
|
||||
data.set('boxed', boxed.yMap);
|
||||
Boxed.is(data.get('boxed)); // true
|
||||
```
|
||||
133
blocksuite/docs/api/@blocksuite/store/classes/Extension.md
Normal file
133
blocksuite/docs/api/@blocksuite/store/classes/Extension.md
Normal file
@@ -0,0 +1,133 @@
|
||||
[**BlockSuite API Documentation**](../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../README.md) / [@blocksuite/store](../README.md) / Extension
|
||||
|
||||
# Abstract Class: Extension
|
||||
|
||||
# Understanding Extensions
|
||||
|
||||
Extensions provide a way to extend the functionality of a system using dependency injection.
|
||||
They allow you to register services, implementations, and factories in the DI container,
|
||||
which can then be retrieved and used by different parts of the application.
|
||||
|
||||
Extensions are particularly useful for:
|
||||
- Registering different implementations for different types
|
||||
- Creating pluggable architecture where components can be added or removed
|
||||
- Managing dependencies between different parts of the application
|
||||
|
||||
# Usage Example: Fruit Processing System
|
||||
|
||||
Let's consider a fruit processing system where different types of fruits need
|
||||
different processing methods. We'll show how to implement this using extensions.
|
||||
|
||||
## Step 1: Define the interfaces
|
||||
|
||||
```ts
|
||||
interface FruitProcessor {
|
||||
process(fruit: Fruit): void;
|
||||
}
|
||||
|
||||
interface Fruit {
|
||||
type: string;
|
||||
// other properties
|
||||
}
|
||||
```
|
||||
|
||||
## Step 2: Create a service identifier
|
||||
|
||||
```ts
|
||||
import { createIdentifier } from '@blocksuite/global/di';
|
||||
|
||||
const FruitProcessorProvider = createIdentifier<FruitProcessor>('fruit-processor-provider');
|
||||
```
|
||||
|
||||
## Step 3: Create implementations
|
||||
|
||||
```ts
|
||||
class AppleProcessor implements FruitProcessor {
|
||||
process(fruit: Fruit): void {
|
||||
console.log('Slicing apple');
|
||||
// Apple-specific processing
|
||||
}
|
||||
}
|
||||
|
||||
class BananaProcessor implements FruitProcessor {
|
||||
process(fruit: Fruit): void {
|
||||
console.log('Peeling banana');
|
||||
// Banana-specific processing
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Step 4: Create an extension factory
|
||||
|
||||
```ts
|
||||
const FruitProcessorExtension = (
|
||||
fruitType: string,
|
||||
implementation: new () => FruitProcessor
|
||||
): ExtensionType => {
|
||||
return {
|
||||
setup: di => {
|
||||
di.addImpl(FruitProcessorProvider(fruitType), implementation);
|
||||
}
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
## Step 5: Create concrete extensions
|
||||
|
||||
```ts
|
||||
export const AppleProcessorExtension = FruitProcessorExtension('apple', AppleProcessor);
|
||||
export const BananaProcessorExtension = FruitProcessorExtension('banana', BananaProcessor);
|
||||
```
|
||||
|
||||
## Step 6: Use the extensions
|
||||
|
||||
```ts
|
||||
import { Container } from '@blocksuite/global/di';
|
||||
|
||||
class FruitProcessingSystem {
|
||||
provider: ServiceProvider;
|
||||
|
||||
constructor(extensions: ExtensionType[]) {
|
||||
const container = new Container();
|
||||
|
||||
// Set up all extensions
|
||||
extensions.forEach(ext => ext.setup(container));
|
||||
|
||||
// Create a provider from the container
|
||||
this.provider = container.provider();
|
||||
}
|
||||
|
||||
processFruit(fruit: Fruit) {
|
||||
// Get the appropriate processor based on fruit type
|
||||
const processor = this.provider.get(FruitProcessorProvider(fruit.type));
|
||||
|
||||
// Process the fruit
|
||||
processor.process(fruit);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the system with extensions
|
||||
const system = new FruitProcessingSystem([
|
||||
AppleProcessorExtension,
|
||||
BananaProcessorExtension
|
||||
]);
|
||||
|
||||
// Use the system
|
||||
system.processFruit({ type: 'apple' }); // Output: Slicing apple
|
||||
system.processFruit({ type: 'banana' }); // Output: Peeling banana
|
||||
```
|
||||
|
||||
Note: We deliberately used a non-block specific example here. In BlockSuite, the extension
|
||||
pattern can be applied to any entity that can be configured by third parties, not just blocks.
|
||||
This includes different tools in the whiteboard, different column types in database blocks,
|
||||
and many other extensible components. The pattern remains the same regardless of what you're extending.
|
||||
|
||||
## Extended by
|
||||
|
||||
- [`StoreExtension`](StoreExtension.md)
|
||||
- [`BlockService`](../../std/index/classes/BlockService.md)
|
||||
- [`LifeCycleWatcher`](../../std/index/classes/LifeCycleWatcher.md)
|
||||
297
blocksuite/docs/api/@blocksuite/store/classes/Schema.md
Normal file
297
blocksuite/docs/api/@blocksuite/store/classes/Schema.md
Normal file
@@ -0,0 +1,297 @@
|
||||
[**BlockSuite API Documentation**](../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../README.md) / [@blocksuite/store](../README.md) / Schema
|
||||
|
||||
# Class: Schema
|
||||
|
||||
Represents a schema manager for block flavours and their relationships.
|
||||
Provides methods to register, validate, and query block schemas.
|
||||
|
||||
## Properties
|
||||
|
||||
### flavourSchemaMap
|
||||
|
||||
> `readonly` **flavourSchemaMap**: `Map`\<`string`, \{ `model`: \{ `children?`: `string`[]; `flavour`: `string`; `isFlatData?`: `boolean`; `parent?`: `string`[]; `props?`: (...`args`) => `Record`\<`string`, `any`\>; `role`: `string`; `toModel?`: (...`args`) => `BlockModel`\<`object`\>; \}; `transformer?`: (...`args`) => `BaseBlockTransformer`\<`object`\>; `version`: `number`; \}\>
|
||||
|
||||
A map storing block flavour names to their corresponding schema definitions.
|
||||
|
||||
## Accessors
|
||||
|
||||
### versions
|
||||
|
||||
#### Get Signature
|
||||
|
||||
> **get** **versions**(): `object`
|
||||
|
||||
Returns an object mapping each registered flavour to its version number.
|
||||
|
||||
##### Returns
|
||||
|
||||
`object`
|
||||
|
||||
## Methods
|
||||
|
||||
### get()
|
||||
|
||||
> **get**(`flavour`): \{ `model`: \{ `children?`: `string`[]; `flavour`: `string`; `isFlatData?`: `boolean`; `parent?`: `string`[]; `props?`: (...`args`) => `Record`\<`string`, `any`\>; `role`: `string`; `toModel?`: (...`args`) => `BlockModel`\<`object`\>; \}; `transformer?`: (...`args`) => `BaseBlockTransformer`\<`object`\>; `version`: `number`; \} \| `undefined`
|
||||
|
||||
Retrieves the schema for a given block flavour.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### flavour
|
||||
|
||||
`string`
|
||||
|
||||
The block flavour name.
|
||||
|
||||
#### Returns
|
||||
|
||||
\{ `model`: \{ `children?`: `string`[]; `flavour`: `string`; `isFlatData?`: `boolean`; `parent?`: `string`[]; `props?`: (...`args`) => `Record`\<`string`, `any`\>; `role`: `string`; `toModel?`: (...`args`) => `BlockModel`\<`object`\>; \}; `transformer?`: (...`args`) => `BaseBlockTransformer`\<`object`\>; `version`: `number`; \} \| `undefined`
|
||||
|
||||
The corresponding BlockSchemaType or undefined if not found.
|
||||
|
||||
***
|
||||
|
||||
### isValid()
|
||||
|
||||
> **isValid**(`child`, `parent`): `boolean`
|
||||
|
||||
Checks if the child flavour is valid under the parent flavour.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### child
|
||||
|
||||
`string`
|
||||
|
||||
The child block flavour name.
|
||||
|
||||
##### parent
|
||||
|
||||
`string`
|
||||
|
||||
The parent block flavour name.
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
True if the relationship is valid, false otherwise.
|
||||
|
||||
***
|
||||
|
||||
### register()
|
||||
|
||||
> **register**(`blockSchema`): `Schema`
|
||||
|
||||
Registers an array of block schemas into the schema manager.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### blockSchema
|
||||
|
||||
`object`[]
|
||||
|
||||
An array of block schema definitions to register.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Schema`
|
||||
|
||||
The Schema instance (for chaining).
|
||||
|
||||
***
|
||||
|
||||
### safeValidate()
|
||||
|
||||
> **safeValidate**(`flavour`, `parentFlavour?`, `childFlavours?`): `boolean`
|
||||
|
||||
Safely validates the schema relationship for a given flavour, parent, and children.
|
||||
Returns true if valid, false otherwise (does not throw).
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### flavour
|
||||
|
||||
`string`
|
||||
|
||||
The block flavour to validate.
|
||||
|
||||
##### parentFlavour?
|
||||
|
||||
`string`
|
||||
|
||||
The parent block flavour (optional).
|
||||
|
||||
##### childFlavours?
|
||||
|
||||
`string`[]
|
||||
|
||||
The child block flavours (optional).
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
True if the schema relationship is valid, false otherwise.
|
||||
|
||||
***
|
||||
|
||||
### toJSON()
|
||||
|
||||
> **toJSON**(): `object`
|
||||
|
||||
Serializes the schema map to a plain object for JSON output.
|
||||
|
||||
#### Returns
|
||||
|
||||
`object`
|
||||
|
||||
An object mapping each flavour to its role, parent, and children.
|
||||
|
||||
***
|
||||
|
||||
### validate()
|
||||
|
||||
> **validate**(`flavour`, `parentFlavour?`, `childFlavours?`): `void`
|
||||
|
||||
Validates the schema relationship for a given flavour, parent, and children.
|
||||
Throws SchemaValidateError if invalid.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### flavour
|
||||
|
||||
`string`
|
||||
|
||||
The block flavour to validate.
|
||||
|
||||
##### parentFlavour?
|
||||
|
||||
`string`
|
||||
|
||||
The parent block flavour (optional).
|
||||
|
||||
##### childFlavours?
|
||||
|
||||
`string`[]
|
||||
|
||||
The child block flavours (optional).
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Throws
|
||||
|
||||
If the schema relationship is invalid.
|
||||
|
||||
***
|
||||
|
||||
### validateSchema()
|
||||
|
||||
> **validateSchema**(`child`, `parent`): `void`
|
||||
|
||||
Validates the relationship between a child and parent schema.
|
||||
Throws if the relationship is invalid.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### child
|
||||
|
||||
The child block schema.
|
||||
|
||||
###### model
|
||||
|
||||
\{ `children?`: `string`[]; `flavour`: `string`; `isFlatData?`: `boolean`; `parent?`: `string`[]; `props?`: (...`args`) => `Record`\<`string`, `any`\>; `role`: `string`; `toModel?`: (...`args`) => `BlockModel`\<`object`\>; \} = `...`
|
||||
|
||||
###### model.children?
|
||||
|
||||
`string`[] = `ContentSchema`
|
||||
|
||||
###### model.flavour
|
||||
|
||||
`string` = `FlavourSchema`
|
||||
|
||||
###### model.isFlatData?
|
||||
|
||||
`boolean` = `...`
|
||||
|
||||
###### model.parent?
|
||||
|
||||
`string`[] = `ParentSchema`
|
||||
|
||||
###### model.props?
|
||||
|
||||
(...`args`) => `Record`\<`string`, `any`\> = `...`
|
||||
|
||||
###### model.role
|
||||
|
||||
`string` = `RoleSchema`
|
||||
|
||||
###### model.toModel?
|
||||
|
||||
(...`args`) => `BlockModel`\<`object`\> = `...`
|
||||
|
||||
###### transformer?
|
||||
|
||||
(...`args`) => `BaseBlockTransformer`\<`object`\> = `...`
|
||||
|
||||
###### version
|
||||
|
||||
`number` = `...`
|
||||
|
||||
##### parent
|
||||
|
||||
The parent block schema.
|
||||
|
||||
###### model
|
||||
|
||||
\{ `children?`: `string`[]; `flavour`: `string`; `isFlatData?`: `boolean`; `parent?`: `string`[]; `props?`: (...`args`) => `Record`\<`string`, `any`\>; `role`: `string`; `toModel?`: (...`args`) => `BlockModel`\<`object`\>; \} = `...`
|
||||
|
||||
###### model.children?
|
||||
|
||||
`string`[] = `ContentSchema`
|
||||
|
||||
###### model.flavour
|
||||
|
||||
`string` = `FlavourSchema`
|
||||
|
||||
###### model.isFlatData?
|
||||
|
||||
`boolean` = `...`
|
||||
|
||||
###### model.parent?
|
||||
|
||||
`string`[] = `ParentSchema`
|
||||
|
||||
###### model.props?
|
||||
|
||||
(...`args`) => `Record`\<`string`, `any`\> = `...`
|
||||
|
||||
###### model.role
|
||||
|
||||
`string` = `RoleSchema`
|
||||
|
||||
###### model.toModel?
|
||||
|
||||
(...`args`) => `BlockModel`\<`object`\> = `...`
|
||||
|
||||
###### transformer?
|
||||
|
||||
(...`args`) => `BaseBlockTransformer`\<`object`\> = `...`
|
||||
|
||||
###### version
|
||||
|
||||
`number` = `...`
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Throws
|
||||
|
||||
If the relationship is invalid.
|
||||
1018
blocksuite/docs/api/@blocksuite/store/classes/Store.md
Normal file
1018
blocksuite/docs/api/@blocksuite/store/classes/Store.md
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,47 @@
|
||||
[**BlockSuite API Documentation**](../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../README.md) / [@blocksuite/store](../README.md) / StoreExtension
|
||||
|
||||
# Class: StoreExtension
|
||||
|
||||
Store extensions are used to extend the store.
|
||||
They should be registered to the store. And they should be able to run in a none-dom environment.
|
||||
|
||||
## Extends
|
||||
|
||||
- [`Extension`](Extension.md)
|
||||
|
||||
## Properties
|
||||
|
||||
### key
|
||||
|
||||
> `readonly` `static` **key**: `string`
|
||||
|
||||
The key of the store extension.
|
||||
**You must override this property with a unique string.**
|
||||
|
||||
## Methods
|
||||
|
||||
### disposed()
|
||||
|
||||
> **disposed**(): `void`
|
||||
|
||||
Lifecycle hook when the yjs document is disposed.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
***
|
||||
|
||||
### loaded()
|
||||
|
||||
> **loaded**(): `void`
|
||||
|
||||
Lifecycle hook when the yjs document is loaded.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
398
blocksuite/docs/api/@blocksuite/store/classes/Text.md
Normal file
398
blocksuite/docs/api/@blocksuite/store/classes/Text.md
Normal file
@@ -0,0 +1,398 @@
|
||||
[**BlockSuite API Documentation**](../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../README.md) / [@blocksuite/store](../README.md) / Text
|
||||
|
||||
# Class: Text\<TextAttributes\>
|
||||
|
||||
Text is an abstraction of Y.Text.
|
||||
It provides useful methods to manipulate the text content.
|
||||
|
||||
## Example
|
||||
|
||||
```ts
|
||||
const text = new Text('Hello, world!');
|
||||
text.insert(' blocksuite', 7);
|
||||
text.delete(7, 1);
|
||||
text.format(7, 1, { bold: true });
|
||||
text.join(new Text(' blocksuite'));
|
||||
text.split(7, 1);
|
||||
```
|
||||
|
||||
Text [delta](https://docs.yjs.dev/api/delta-format) is a format from Y.js.
|
||||
|
||||
## Type Parameters
|
||||
|
||||
### TextAttributes
|
||||
|
||||
`TextAttributes` *extends* `BaseTextAttributes` = `BaseTextAttributes`
|
||||
|
||||
## Constructors
|
||||
|
||||
### Constructor
|
||||
|
||||
> **new Text**\<`TextAttributes`\>(`input?`): `Text`\<`TextAttributes`\>
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### input?
|
||||
|
||||
`string` \| `YText` \| `DeltaInsert`\<`TextAttributes`\>[]
|
||||
|
||||
The input can be a string, a Y.Text instance, or an array of DeltaInsert.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Text`\<`TextAttributes`\>
|
||||
|
||||
## Accessors
|
||||
|
||||
### deltas$
|
||||
|
||||
#### Get Signature
|
||||
|
||||
> **get** **deltas$**(): `Signal`\<`DeltaOperation`[]\>
|
||||
|
||||
Get the text delta as a signal.
|
||||
|
||||
##### Returns
|
||||
|
||||
`Signal`\<`DeltaOperation`[]\>
|
||||
|
||||
## Methods
|
||||
|
||||
### applyDelta()
|
||||
|
||||
> **applyDelta**(`delta`): `void`
|
||||
|
||||
Apply a delta to the text.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### delta
|
||||
|
||||
`DeltaOperation`[]
|
||||
|
||||
The delta to apply.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const text = new Text('Hello, world!');
|
||||
text.applyDelta([{insert: ' blocksuite', attributes: { bold: true }}]);
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### clear()
|
||||
|
||||
> **clear**(): `void`
|
||||
|
||||
Clear the text content.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
***
|
||||
|
||||
### clone()
|
||||
|
||||
> **clone**(): `Text`\<\{ `bold?`: `true` \| `null`; `code?`: `true` \| `null`; `italic?`: `true` \| `null`; `link?`: `string` \| `null`; `strike?`: `true` \| `null`; `underline?`: `true` \| `null`; \}\>
|
||||
|
||||
Clone the text to a new Text instance.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Text`\<\{ `bold?`: `true` \| `null`; `code?`: `true` \| `null`; `italic?`: `true` \| `null`; `link?`: `string` \| `null`; `strike?`: `true` \| `null`; `underline?`: `true` \| `null`; \}\>
|
||||
|
||||
A new Text instance.
|
||||
|
||||
***
|
||||
|
||||
### delete()
|
||||
|
||||
> **delete**(`index`, `length`): `void`
|
||||
|
||||
Delete the text content.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### index
|
||||
|
||||
`number`
|
||||
|
||||
The index to delete.
|
||||
|
||||
##### length
|
||||
|
||||
`number`
|
||||
|
||||
The length to delete.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
***
|
||||
|
||||
### format()
|
||||
|
||||
> **format**(`index`, `length`, `format`): `void`
|
||||
|
||||
Format the text content.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### index
|
||||
|
||||
`number`
|
||||
|
||||
The index to format.
|
||||
|
||||
##### length
|
||||
|
||||
`number`
|
||||
|
||||
The length to format.
|
||||
|
||||
##### format
|
||||
|
||||
`Record`\<`string`, `unknown`\>
|
||||
|
||||
The format to apply.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const text = new Text('Hello, world!');
|
||||
text.format(7, 1, { bold: true });
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### insert()
|
||||
|
||||
> **insert**(`content`, `index`, `attributes?`): `void`
|
||||
|
||||
Insert content at the specified index.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### content
|
||||
|
||||
`string`
|
||||
|
||||
The content to insert.
|
||||
|
||||
##### index
|
||||
|
||||
`number`
|
||||
|
||||
The index to insert.
|
||||
|
||||
##### attributes?
|
||||
|
||||
`Record`\<`string`, `unknown`\>
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const text = new Text('Hello, world!');
|
||||
text.insert(' blocksuite', 7);
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### join()
|
||||
|
||||
> **join**(`other`): `void`
|
||||
|
||||
Join current text with another text.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### other
|
||||
|
||||
`Text`
|
||||
|
||||
The other text to join.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const text = new Text('Hello, world!');
|
||||
const other = new Text(' blocksuite');
|
||||
text.join(other);
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### replace()
|
||||
|
||||
> **replace**(`index`, `length`, `content`, `attributes?`): `void`
|
||||
|
||||
Replace the text content with a new content.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### index
|
||||
|
||||
`number`
|
||||
|
||||
The index to replace.
|
||||
|
||||
##### length
|
||||
|
||||
`number`
|
||||
|
||||
The length to replace.
|
||||
|
||||
##### content
|
||||
|
||||
`string`
|
||||
|
||||
The content to replace.
|
||||
|
||||
##### attributes?
|
||||
|
||||
`Record`\<`string`, `unknown`\>
|
||||
|
||||
The attributes to replace.
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const text = new Text('Hello, world!');
|
||||
text.replace(7, 1, ' blocksuite');
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### sliceToDelta()
|
||||
|
||||
> **sliceToDelta**(`begin`, `end?`): `DeltaOperation`[]
|
||||
|
||||
Slice the text to a delta.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### begin
|
||||
|
||||
`number`
|
||||
|
||||
The begin index.
|
||||
|
||||
##### end?
|
||||
|
||||
`number`
|
||||
|
||||
The end index.
|
||||
|
||||
#### Returns
|
||||
|
||||
`DeltaOperation`[]
|
||||
|
||||
The delta of the sliced text.
|
||||
|
||||
***
|
||||
|
||||
### split()
|
||||
|
||||
> **split**(`index`, `length?`): `Text`
|
||||
|
||||
Split the text into another Text.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### index
|
||||
|
||||
`number`
|
||||
|
||||
The index to split.
|
||||
|
||||
##### length?
|
||||
|
||||
`number` = `0`
|
||||
|
||||
The length to split.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Text`
|
||||
|
||||
The right part of the text.
|
||||
|
||||
#### Example
|
||||
|
||||
```ts
|
||||
const text = new Text('Hello, world!');
|
||||
text.split(7, 1);
|
||||
```
|
||||
|
||||
NOTE: The string included in [index, index + length) will be deleted.
|
||||
|
||||
Here are three cases for point position(index + length):
|
||||
|
||||
```
|
||||
[{insert: 'abc', ...}, {insert: 'def', ...}, {insert: 'ghi', ...}]
|
||||
1. abc|de|fghi
|
||||
left: [{insert: 'abc', ...}]
|
||||
right: [{insert: 'f', ...}, {insert: 'ghi', ...}]
|
||||
2. abc|def|ghi
|
||||
left: [{insert: 'abc', ...}]
|
||||
right: [{insert: 'ghi', ...}]
|
||||
3. abc|defg|hi
|
||||
left: [{insert: 'abc', ...}]
|
||||
right: [{insert: 'hi', ...}]
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
### toDelta()
|
||||
|
||||
> **toDelta**(): `DeltaOperation`[]
|
||||
|
||||
Get the text delta.
|
||||
|
||||
#### Returns
|
||||
|
||||
`DeltaOperation`[]
|
||||
|
||||
The delta of the text.
|
||||
|
||||
***
|
||||
|
||||
### toString()
|
||||
|
||||
> **toString**(): `string`
|
||||
|
||||
Get the text content as a string.
|
||||
In most cases, you should not use this method. It will lose the delta attributes information.
|
||||
|
||||
#### Returns
|
||||
|
||||
`string`
|
||||
|
||||
The text content.
|
||||
@@ -0,0 +1,59 @@
|
||||
[**BlockSuite API Documentation**](../../../README.md)
|
||||
|
||||
***
|
||||
|
||||
[BlockSuite API Documentation](../../../README.md) / [@blocksuite/store](../README.md) / StoreSlots
|
||||
|
||||
# Interface: StoreSlots
|
||||
|
||||
Slots for receiving events from the store.
|
||||
All events are rxjs Subjects, you can subscribe to them like this:
|
||||
|
||||
```ts
|
||||
store.slots.ready.subscribe(() => {
|
||||
console.log('store is ready');
|
||||
});
|
||||
```
|
||||
|
||||
You can also use rxjs operators to handle the events.
|
||||
|
||||
## Properties
|
||||
|
||||
### blockUpdated
|
||||
|
||||
> **blockUpdated**: `Subject`\<`StoreBlockUpdatedPayloads`\>
|
||||
|
||||
This fires when a block is updated via API call or has just been updated from existing ydoc.
|
||||
|
||||
The payload can have three types:
|
||||
- add: When a new block is added
|
||||
- delete: When a block is removed
|
||||
- update: When a block's properties are modified
|
||||
|
||||
***
|
||||
|
||||
### ready
|
||||
|
||||
> **ready**: `Subject`\<`void`\>
|
||||
|
||||
This fires after `doc.load` is called.
|
||||
The Y.Doc is fully loaded and ready to use.
|
||||
|
||||
***
|
||||
|
||||
### rootAdded
|
||||
|
||||
> **rootAdded**: `Subject`\<`string`\>
|
||||
|
||||
This fires when the root block is added via API call or has just been initialized from existing ydoc.
|
||||
useful for internal block UI components to start subscribing following up events.
|
||||
Note that at this moment, the whole block tree may not be fully initialized yet.
|
||||
|
||||
***
|
||||
|
||||
### rootDeleted
|
||||
|
||||
> **rootDeleted**: `Subject`\<`string`\>
|
||||
|
||||
This fires when the root block is deleted via API call or has just been removed from existing ydoc.
|
||||
In most cases, you don't need to subscribe to this event.
|
||||
Reference in New Issue
Block a user