Skip to content

Commit f29caba

Browse files
authored
fix: multi block handle (#1731)
* fix: should not support blockquote in list * fix: multi block handle instance
1 parent 95ff9cf commit f29caba

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

Diff for: packages/plugins/plugin-block/src/block-plugin.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,38 @@ import { $ctx, $prose } from '@milkdown/utils'
44

55
import { BlockService } from './block-service'
66
import { withMeta } from './__internal__/with-meta'
7-
import { blockConfig } from './block-config'
87

98
/// @internal
10-
export const blockService = $ctx(new BlockService(), 'blockService')
9+
export const blockService = $ctx(() => new BlockService(), 'blockService')
1110

12-
withMeta(blockConfig, {
11+
/// @internal
12+
export const blockServiceInstance = $ctx(
13+
{} as BlockService,
14+
'blockServiceInstance'
15+
)
16+
17+
withMeta(blockService, {
1318
displayName: 'Ctx<blockService>',
1419
})
1520

21+
withMeta(blockServiceInstance, {
22+
displayName: 'Ctx<blockServiceInstance>',
23+
})
24+
1625
/// A slice contains a factory that will return a plugin spec.
1726
/// Users can use this slice to customize the plugin.
1827
export const blockSpec = $ctx<PluginSpec<any>, 'blockSpec'>({}, 'blockSpec')
1928

20-
withMeta(blockConfig, {
29+
withMeta(blockSpec, {
2130
displayName: 'Ctx<blockSpec>',
2231
})
2332

2433
/// The block prosemirror plugin.
2534
export const blockPlugin = $prose((ctx) => {
2635
const milkdownPluginBlockKey = new PluginKey('MILKDOWN_BLOCK')
27-
const service = ctx.get(blockService.key)
36+
const getService = ctx.get(blockService.key)
37+
const service = getService()
38+
ctx.set(blockServiceInstance.key, service)
2839
const spec = ctx.get(blockSpec.key)
2940

3041
return new Plugin({

Diff for: packages/plugins/plugin-block/src/block-provider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { computePosition, flip, offset } from '@floating-ui/dom'
1212

1313
import { editorViewCtx } from '@milkdown/core'
1414
import type { BlockService } from './block-service'
15-
import { blockService } from './block-plugin'
15+
import { blockServiceInstance } from './block-plugin'
1616
import type { ActiveNode } from './types'
1717

1818
/// The context of the block provider.
@@ -117,7 +117,7 @@ export class BlockProvider {
117117
const root = this.#root ?? view.dom.parentElement ?? document.body
118118
root.appendChild(this.#element)
119119

120-
const service = this.#ctx.get(blockService.key)
120+
const service = this.#ctx.get(blockServiceInstance.key)
121121
service.bind(this.#ctx, (message) => {
122122
if (message.type === 'hide') {
123123
this.hide()

Diff for: packages/plugins/plugin-block/src/index.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import type { PluginSpec } from '@milkdown/prose/state'
33
import type { $Ctx, $Prose } from '@milkdown/utils'
44
import type { FilterNodes } from './block-config'
55
import { blockConfig } from './block-config'
6-
import { blockPlugin, blockService, blockSpec } from './block-plugin'
6+
import {
7+
blockPlugin,
8+
blockService,
9+
blockServiceInstance,
10+
blockSpec,
11+
} from './block-plugin'
712
import type { BlockService } from './block-service'
813

914
export * from './block-plugin'
@@ -16,7 +21,8 @@ export * from './types'
1621
export type BlockPlugin = [
1722
$Ctx<PluginSpec<any>, 'blockSpec'>,
1823
$Ctx<{ filterNodes: FilterNodes }, 'blockConfig'>,
19-
$Ctx<BlockService, 'blockService'>,
24+
$Ctx<() => BlockService, 'blockService'>,
25+
$Ctx<BlockService, 'blockServiceInstance'>,
2026
$Prose,
2127
] & {
2228
key: SliceType<PluginSpec<any>, 'blockSpec'>
@@ -28,6 +34,7 @@ export const block = [
2834
blockSpec,
2935
blockConfig,
3036
blockService,
37+
blockServiceInstance,
3138
blockPlugin,
3239
] as BlockPlugin
3340
block.key = blockSpec.key

0 commit comments

Comments
 (0)