Skip to content

Commit 18c4156

Browse files
authored
feat: 🎸 add root option for tooltip,slash,block (#1681)
Closes: #1635
1 parent 851ea61 commit 18c4156

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export interface BlockProviderOptions {
4747
middleware?: Middleware[]
4848
/// Options for floating ui. If you pass `middleware` or `placement`, it will override the internal settings.
4949
floatingUIOptions?: Partial<ComputePositionConfig>
50+
/// The root element that the block will be appended to.
51+
root?: HTMLElement
5052
}
5153

5254
/// A provider for creating block.
@@ -63,6 +65,9 @@ export class BlockProvider {
6365
/// @internal
6466
#activeNode: ActiveNode | null = null
6567

68+
/// @internal
69+
readonly #root?: HTMLElement
70+
6671
/// @internal
6772
#initialized = false
6873

@@ -102,13 +107,15 @@ export class BlockProvider {
102107
this.#getPlacement = options.getPlacement
103108
this.#middleware = options.middleware ?? []
104109
this.#floatingUIOptions = options.floatingUIOptions ?? {}
110+
this.#root = options.root
105111
this.hide()
106112
}
107113

108114
/// @internal
109115
#init() {
110116
const view = this.#ctx.get(editorViewCtx)
111-
view.dom.parentElement?.appendChild(this.#element)
117+
const root = this.#root ?? view.dom.parentElement ?? document.body
118+
root.appendChild(this.#element)
112119

113120
const service = this.#ctx.get(blockService.key)
114121
service.bind(this.#ctx, (message) => {

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export interface SlashProviderOptions {
3333
middleware?: Middleware[]
3434
/// Options for floating ui. If you pass `middleware` or `placement`, it will override the internal settings.
3535
floatingUIOptions?: Partial<ComputePositionConfig>
36+
/// The root element that the slash will be appended to.
37+
root?: HTMLElement
3638
}
3739

3840
/// A provider for creating slash.
@@ -49,6 +51,9 @@ export class SlashProvider {
4951
/// @internal
5052
readonly #floatingUIOptions: Partial<ComputePositionConfig>
5153

54+
/// @internal
55+
readonly #root?: HTMLElement
56+
5257
/// @internal
5358
readonly #debounce: number
5459

@@ -81,6 +86,7 @@ export class SlashProvider {
8186
this.#offset = options.offset
8287
this.#middleware = options.middleware ?? []
8388
this.#floatingUIOptions = options.floatingUIOptions ?? {}
89+
this.#root = options.root
8490
}
8591

8692
/// @internal
@@ -94,7 +100,8 @@ export class SlashProvider {
94100
prevState && prevState.doc.eq(doc) && prevState.selection.eq(selection)
95101

96102
if (!this.#initialized) {
97-
view.dom.parentElement?.appendChild(this.element)
103+
const root = this.#root ?? view.dom.parentElement ?? document.body
104+
root.appendChild(this.element)
98105
this.#initialized = true
99106
}
100107

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export interface TooltipProviderOptions {
3030
middleware?: Middleware[]
3131
/// Options for floating ui. If you pass `middleware` or `placement`, it will override the internal settings.
3232
floatingUIOptions?: Partial<ComputePositionConfig>
33+
/// The root element that the tooltip will be appended to.
34+
root?: HTMLElement
3335
}
3436

3537
/// A provider for creating tooltip.
@@ -46,6 +48,9 @@ export class TooltipProvider {
4648
/// @internal
4749
readonly #floatingUIOptions: Partial<ComputePositionConfig>
4850

51+
/// @internal
52+
readonly #root?: HTMLElement
53+
4954
/// @internal
5055
#initialized = false
5156

@@ -74,6 +79,7 @@ export class TooltipProvider {
7479
this.#offset = options.offset
7580
this.#middleware = options.middleware ?? []
7681
this.#floatingUIOptions = options.floatingUIOptions ?? {}
82+
this.#root = options.root
7783
this.element.dataset.show = 'false'
7884
}
7985

@@ -88,7 +94,8 @@ export class TooltipProvider {
8894
prevState && prevState.doc.eq(doc) && prevState.selection.eq(selection)
8995

9096
if (!this.#initialized) {
91-
view.dom.parentElement?.appendChild(this.element)
97+
const root = this.#root ?? view.dom.parentElement ?? document.body
98+
root.appendChild(this.element)
9299
this.#initialized = true
93100
}
94101

0 commit comments

Comments
 (0)