@prosekit/web 0.8.0-beta.0 → 0.8.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/prosekit-web-autocomplete.d.ts +112 -90
- package/dist/prosekit-web-autocomplete.d.ts.map +1 -1
- package/dist/prosekit-web-autocomplete.js +292 -217
- package/dist/prosekit-web-autocomplete.js.map +1 -1
- package/dist/prosekit-web-block-handle.d.ts +95 -62
- package/dist/prosekit-web-block-handle.d.ts.map +1 -1
- package/dist/prosekit-web-block-handle.js +219 -114
- package/dist/prosekit-web-block-handle.js.map +1 -1
- package/dist/prosekit-web-drop-indicator.d.ts +13 -15
- package/dist/prosekit-web-drop-indicator.d.ts.map +1 -1
- package/dist/prosekit-web-drop-indicator.js +34 -30
- package/dist/prosekit-web-drop-indicator.js.map +1 -1
- package/dist/prosekit-web-inline-popover.d.ts +94 -53
- package/dist/prosekit-web-inline-popover.d.ts.map +1 -1
- package/dist/prosekit-web-inline-popover.js +134 -79
- package/dist/prosekit-web-inline-popover.js.map +1 -1
- package/dist/prosekit-web-menu.d.ts +13 -0
- package/dist/prosekit-web-menu.d.ts.map +1 -0
- package/dist/prosekit-web-menu.js +53 -0
- package/dist/prosekit-web-menu.js.map +1 -0
- package/dist/prosekit-web-popover.d.ts +7 -26
- package/dist/prosekit-web-popover.d.ts.map +1 -1
- package/dist/prosekit-web-popover.js +31 -29
- package/dist/prosekit-web-popover.js.map +1 -1
- package/dist/prosekit-web-resizable.d.ts +92 -51
- package/dist/prosekit-web-resizable.d.ts.map +1 -1
- package/dist/prosekit-web-resizable.js +139 -131
- package/dist/prosekit-web-resizable.js.map +1 -1
- package/dist/prosekit-web-table-handle.d.ts +166 -199
- package/dist/prosekit-web-table-handle.d.ts.map +1 -1
- package/dist/prosekit-web-table-handle.js +495 -496
- package/dist/prosekit-web-table-handle.js.map +1 -1
- package/dist/prosekit-web-tooltip.d.ts +7 -26
- package/dist/prosekit-web-tooltip.d.ts.map +1 -1
- package/dist/prosekit-web-tooltip.js +31 -29
- package/dist/prosekit-web-tooltip.js.map +1 -1
- package/dist/use-editor-extension.js +2 -2
- package/dist/use-editor-extension.js.map +1 -1
- package/dist/use-scrolling.js +17 -8
- package/dist/use-scrolling.js.map +1 -1
- package/package.json +26 -21
- package/src/components/autocomplete/autocomplete-empty.ts +45 -0
- package/src/components/autocomplete/autocomplete-item.ts +65 -0
- package/src/components/autocomplete/autocomplete-popup.ts +95 -0
- package/src/components/autocomplete/autocomplete-positioner.ts +98 -0
- package/src/components/autocomplete/autocomplete-root.ts +280 -0
- package/src/components/autocomplete/context.ts +16 -14
- package/src/components/autocomplete/index.ts +65 -0
- package/src/components/block-handle/block-handle-add.ts +71 -0
- package/src/components/block-handle/block-handle-draggable.ts +158 -0
- package/src/components/block-handle/block-handle-popup.ts +43 -0
- package/src/components/block-handle/block-handle-positioner.ts +89 -0
- package/src/components/block-handle/block-handle-root.ts +116 -0
- package/src/components/block-handle/context.ts +9 -18
- package/src/components/block-handle/hover-state.ts +16 -0
- package/src/components/block-handle/index.ts +59 -0
- package/src/components/block-handle/{block-handle-popover/pointer-move.ts → pointer-move.ts} +8 -7
- package/src/components/block-handle/{block-handle-draggable/set-drag-preview.ts → set-drag-preview.ts} +4 -4
- package/src/components/block-handle/use-hover-extension.ts +65 -0
- package/src/components/drop-indicator/drop-indicator.ts +128 -0
- package/src/components/drop-indicator/index.ts +18 -0
- package/src/components/inline-popover/index.ts +41 -0
- package/src/components/inline-popover/inline-popover-popup.ts +52 -0
- package/src/components/inline-popover/inline-popover-positioner.ts +118 -0
- package/src/components/inline-popover/inline-popover-root.ts +122 -0
- package/src/components/inline-popover/store.ts +6 -0
- package/src/components/menu/index.ts +92 -0
- package/src/components/popover/index.ts +53 -0
- package/src/components/resizable/{resizable-handle/calc-resize.ts → calc-resize.ts} +1 -1
- package/src/components/resizable/context.ts +3 -6
- package/src/components/resizable/index.ts +32 -0
- package/src/components/resizable/resizable-handle.ts +134 -0
- package/src/components/resizable/resizable-root.ts +184 -0
- package/src/components/table-handle/dnd.ts +16 -27
- package/src/components/table-handle/index.ts +125 -0
- package/src/components/table-handle/{table-handle-drag-preview/render-preview.ts → render-preview.ts} +5 -5
- package/src/components/table-handle/shared.ts +61 -0
- package/src/components/table-handle/store.ts +117 -0
- package/src/components/table-handle/table-handle-column-menu-root.ts +51 -0
- package/src/components/table-handle/table-handle-column-menu-trigger.ts +107 -0
- package/src/components/table-handle/table-handle-column-popup.ts +44 -0
- package/src/components/table-handle/table-handle-column-positioner.ts +67 -0
- package/src/components/table-handle/table-handle-drag-preview.ts +169 -0
- package/src/components/table-handle/table-handle-drop-indicator.ts +166 -0
- package/src/components/table-handle/table-handle-root.ts +103 -0
- package/src/components/table-handle/table-handle-row-menu-root.ts +51 -0
- package/src/components/table-handle/table-handle-row-menu-trigger.ts +107 -0
- package/src/components/table-handle/table-handle-row-popup.ts +42 -0
- package/src/components/table-handle/table-handle-row-positioner.ts +67 -0
- package/src/components/table-handle/use-drop.ts +74 -0
- package/src/components/table-handle/{hooks/use-empty-image.ts → use-empty-image.ts} +2 -3
- package/src/components/table-handle/utils.ts +0 -11
- package/src/components/tooltip/index.ts +52 -0
- package/src/hooks/use-editor-extension.ts +4 -4
- package/src/hooks/use-editor-focus-event.ts +4 -4
- package/src/hooks/use-editor-typing.ts +12 -16
- package/src/hooks/use-editor-update-event.ts +4 -4
- package/src/hooks/use-keymap.ts +4 -4
- package/src/hooks/use-scrolling.ts +11 -10
- package/src/hooks/use-selecting.ts +8 -15
- package/src/utils/event.ts +28 -0
- package/src/utils/lazy-signal.spec.ts +68 -0
- package/src/utils/lazy-signal.ts +17 -0
- package/src/utils/prefers-reduced-motion.ts +6 -0
- package/src/utils/prevent-default.ts +3 -0
- package/src/utils/use-html-element-at.ts +17 -0
- package/src/utils/use-no-focus.ts +7 -0
- package/dist/get-default-state.js +0 -11
- package/dist/get-default-state.js.map +0 -1
- package/src/components/autocomplete/autocomplete-empty/element.gen.ts +0 -18
- package/src/components/autocomplete/autocomplete-empty/setup.ts +0 -6
- package/src/components/autocomplete/autocomplete-empty/types.ts +0 -13
- package/src/components/autocomplete/autocomplete-item/element.gen.ts +0 -18
- package/src/components/autocomplete/autocomplete-item/setup.ts +0 -30
- package/src/components/autocomplete/autocomplete-item/types.ts +0 -25
- package/src/components/autocomplete/autocomplete-list/element.gen.ts +0 -18
- package/src/components/autocomplete/autocomplete-list/setup.ts +0 -125
- package/src/components/autocomplete/autocomplete-list/types.ts +0 -22
- package/src/components/autocomplete/autocomplete-popover/element.gen.ts +0 -18
- package/src/components/autocomplete/autocomplete-popover/setup.ts +0 -169
- package/src/components/autocomplete/autocomplete-popover/types.ts +0 -100
- package/src/components/autocomplete/index.gen.ts +0 -17
- package/src/components/block-handle/block-handle-add/element.gen.ts +0 -18
- package/src/components/block-handle/block-handle-add/setup.ts +0 -33
- package/src/components/block-handle/block-handle-add/types.ts +0 -23
- package/src/components/block-handle/block-handle-draggable/element.gen.ts +0 -18
- package/src/components/block-handle/block-handle-draggable/setup.ts +0 -113
- package/src/components/block-handle/block-handle-draggable/types.ts +0 -23
- package/src/components/block-handle/block-handle-popover/element.gen.ts +0 -18
- package/src/components/block-handle/block-handle-popover/setup.ts +0 -68
- package/src/components/block-handle/block-handle-popover/types.ts +0 -81
- package/src/components/block-handle/index.gen.ts +0 -13
- package/src/components/drop-indicator/drop-indicator/element.gen.ts +0 -18
- package/src/components/drop-indicator/drop-indicator/setup.ts +0 -75
- package/src/components/drop-indicator/drop-indicator/types.ts +0 -31
- package/src/components/drop-indicator/index.gen.ts +0 -5
- package/src/components/inline-popover/index.gen.ts +0 -5
- package/src/components/inline-popover/inline-popover/element.gen.ts +0 -18
- package/src/components/inline-popover/inline-popover/setup.ts +0 -111
- package/src/components/inline-popover/inline-popover/types.ts +0 -112
- package/src/components/popover/index.gen.ts +0 -13
- package/src/components/popover/popover-content/element.gen.ts +0 -18
- package/src/components/popover/popover-content/setup.ts +0 -1
- package/src/components/popover/popover-content/types.ts +0 -6
- package/src/components/popover/popover-root/element.gen.ts +0 -18
- package/src/components/popover/popover-root/setup.ts +0 -1
- package/src/components/popover/popover-root/types.ts +0 -6
- package/src/components/popover/popover-trigger/element.gen.ts +0 -18
- package/src/components/popover/popover-trigger/setup.ts +0 -1
- package/src/components/popover/popover-trigger/types.ts +0 -6
- package/src/components/resizable/index.gen.ts +0 -9
- package/src/components/resizable/resizable-handle/element.gen.ts +0 -18
- package/src/components/resizable/resizable-handle/setup.ts +0 -106
- package/src/components/resizable/resizable-handle/types.ts +0 -29
- package/src/components/resizable/resizable-root/element.gen.ts +0 -18
- package/src/components/resizable/resizable-root/setup.ts +0 -84
- package/src/components/resizable/resizable-root/types.ts +0 -59
- package/src/components/table-handle/context.ts +0 -43
- package/src/components/table-handle/hooks/use-drop.ts +0 -85
- package/src/components/table-handle/index.gen.ts +0 -37
- package/src/components/table-handle/table-handle-column-root/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-column-root/setup.ts +0 -60
- package/src/components/table-handle/table-handle-column-root/types.ts +0 -73
- package/src/components/table-handle/table-handle-column-trigger/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-column-trigger/setup.ts +0 -64
- package/src/components/table-handle/table-handle-column-trigger/types.ts +0 -20
- package/src/components/table-handle/table-handle-drag-preview/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-drag-preview/setup.ts +0 -57
- package/src/components/table-handle/table-handle-drag-preview/types.ts +0 -14
- package/src/components/table-handle/table-handle-drag-preview/updater.ts +0 -90
- package/src/components/table-handle/table-handle-drop-indicator/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-drop-indicator/setup.ts +0 -52
- package/src/components/table-handle/table-handle-drop-indicator/types.ts +0 -15
- package/src/components/table-handle/table-handle-drop-indicator/updater.ts +0 -96
- package/src/components/table-handle/table-handle-popover-content/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-popover-content/setup.ts +0 -83
- package/src/components/table-handle/table-handle-popover-content/types.ts +0 -32
- package/src/components/table-handle/table-handle-popover-item/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-popover-item/setup.ts +0 -17
- package/src/components/table-handle/table-handle-popover-item/types.ts +0 -16
- package/src/components/table-handle/table-handle-root/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-root/setup.ts +0 -86
- package/src/components/table-handle/table-handle-root/types.ts +0 -23
- package/src/components/table-handle/table-handle-row-root/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-row-root/setup.ts +0 -70
- package/src/components/table-handle/table-handle-row-root/types.ts +0 -68
- package/src/components/table-handle/table-handle-row-trigger/element.gen.ts +0 -18
- package/src/components/table-handle/table-handle-row-trigger/setup.ts +0 -63
- package/src/components/table-handle/table-handle-row-trigger/types.ts +0 -23
- package/src/components/tooltip/index.gen.ts +0 -13
- package/src/components/tooltip/tooltip-content/element.gen.ts +0 -18
- package/src/components/tooltip/tooltip-content/setup.ts +0 -1
- package/src/components/tooltip/tooltip-content/types.ts +0 -6
- package/src/components/tooltip/tooltip-root/element.gen.ts +0 -18
- package/src/components/tooltip/tooltip-root/setup.ts +0 -1
- package/src/components/tooltip/tooltip-root/types.ts +0 -6
- package/src/components/tooltip/tooltip-trigger/element.gen.ts +0 -18
- package/src/components/tooltip/tooltip-trigger/setup.ts +0 -1
- package/src/components/tooltip/tooltip-trigger/types.ts +0 -6
- package/src/hooks/use-first-rendering.ts +0 -15
- package/src/utils/get-default-state.spec.ts +0 -42
- package/src/utils/get-default-state.ts +0 -18
- /package/src/components/autocomplete/{autocomplete-popover/helpers.spec.ts → helpers.spec.ts} +0 -0
- /package/src/components/autocomplete/{autocomplete-popover/helpers.ts → helpers.ts} +0 -0
- /package/src/components/inline-popover/{inline-popover/virtual-selection-element.ts → virtual-selection-element.ts} +0 -0
- /package/src/components/resizable/{resizable-handle/calc-resize.spec.ts → calc-resize.spec.ts} +0 -0
- /package/src/components/table-handle/{table-handle-drop-indicator/calc-drag-over.ts → calc-drag-over.ts} +0 -0
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { useAttribute, useEffect, useEventListener, type ConnectableElement, type ReadonlySignal, type SignalState } from '@aria-ui/core'
|
|
2
|
-
import { isHTMLElement } from '@ocavue/utils'
|
|
3
|
-
import type { Editor } from '@prosekit/core'
|
|
4
|
-
import type { ViewDragging } from '@prosekit/extensions/drop-indicator'
|
|
5
|
-
import { Fragment, Slice } from '@prosekit/pm/model'
|
|
6
|
-
import { NodeSelection } from '@prosekit/pm/state'
|
|
7
|
-
import type { EditorView } from '@prosekit/pm/view'
|
|
8
|
-
|
|
9
|
-
import { DRAGGING_CLASS_NAME } from '../../../constants.ts'
|
|
10
|
-
import { getSafeEditorView } from '../../../utils/get-safe-editor-view.ts'
|
|
11
|
-
import { blockPopoverContext, draggingContext, type BlockPopoverContext, type HoverState } from '../context.ts'
|
|
12
|
-
|
|
13
|
-
import { setDragPreview } from './set-drag-preview.ts'
|
|
14
|
-
import type { BlockHandleDraggableProps } from './types.ts'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export function useBlockHandleDraggable(
|
|
20
|
-
host: ConnectableElement,
|
|
21
|
-
{ state }: { state: SignalState<BlockHandleDraggableProps> },
|
|
22
|
-
): void {
|
|
23
|
-
const context = blockPopoverContext.consume(host)
|
|
24
|
-
const dragging = draggingContext.consume(host)
|
|
25
|
-
|
|
26
|
-
useEffect(host, () => {
|
|
27
|
-
host.draggable = true
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
usePointerDownHandler(host, context, state.editor)
|
|
31
|
-
|
|
32
|
-
useEventListener(host, 'dragstart', (event) => {
|
|
33
|
-
dragging.set(true)
|
|
34
|
-
|
|
35
|
-
const view = getSafeEditorView(state.editor.get())
|
|
36
|
-
const hoverState = context.get()
|
|
37
|
-
|
|
38
|
-
if (view && hoverState) {
|
|
39
|
-
view.dom.classList.add(DRAGGING_CLASS_NAME)
|
|
40
|
-
createDraggingPreview(view, hoverState, event)
|
|
41
|
-
setViewDragging(view, hoverState)
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
useEventListener(host, 'dragend', () => {
|
|
46
|
-
dragging.set(false)
|
|
47
|
-
|
|
48
|
-
const view = getSafeEditorView(state.editor.get())
|
|
49
|
-
if (view) {
|
|
50
|
-
view.dom.classList.remove(DRAGGING_CLASS_NAME)
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
useAttribute(host, 'data-dragging', () => (dragging.get() ? '' : undefined))
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function usePointerDownHandler(
|
|
58
|
-
host: ConnectableElement,
|
|
59
|
-
context: ReadonlySignal<BlockPopoverContext>,
|
|
60
|
-
editor: ReadonlySignal<Editor | null>,
|
|
61
|
-
) {
|
|
62
|
-
useEventListener(host, 'pointerdown', () => {
|
|
63
|
-
const { pos } = context.get() ?? {}
|
|
64
|
-
const { view } = editor.get() ?? {}
|
|
65
|
-
|
|
66
|
-
if (pos == null || view == null) {
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
view.dispatch(
|
|
71
|
-
view.state.tr.setSelection(NodeSelection.create(view.state.doc, pos)),
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
// Clicking the handle will blur the editor, so we need to focus it again.
|
|
75
|
-
// We cannot call `event.preventDefault()` here to prevent the blur
|
|
76
|
-
// because it will prevent the drag event from firing.
|
|
77
|
-
requestAnimationFrame(() => {
|
|
78
|
-
view.focus()
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function createDraggingPreview(view: EditorView, hoverState: HoverState, event: DragEvent): void {
|
|
84
|
-
if (!event.dataTransfer) {
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const { pos } = hoverState
|
|
89
|
-
|
|
90
|
-
const element = view.nodeDOM(pos)
|
|
91
|
-
if (!element || !isHTMLElement(element)) {
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
event.dataTransfer.clearData()
|
|
96
|
-
event.dataTransfer.setData('text/html', element.outerHTML)
|
|
97
|
-
event.dataTransfer.effectAllowed = 'copyMove'
|
|
98
|
-
setDragPreview(event, element)
|
|
99
|
-
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function setViewDragging(view: EditorView, hoverState: HoverState): void {
|
|
104
|
-
const { node, pos } = hoverState
|
|
105
|
-
|
|
106
|
-
const dragging: ViewDragging = {
|
|
107
|
-
slice: new Slice(Fragment.from(node), 0, 0),
|
|
108
|
-
move: true,
|
|
109
|
-
node: NodeSelection.create(view.state.doc, pos),
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
view.dragging = dragging
|
|
113
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { EventDeclarations, PropDeclarations } from '@aria-ui/core'
|
|
2
|
-
import type { Editor } from '@prosekit/core'
|
|
3
|
-
|
|
4
|
-
export interface BlockHandleDraggableProps {
|
|
5
|
-
/**
|
|
6
|
-
* The ProseKit editor instance.
|
|
7
|
-
*
|
|
8
|
-
* @default null
|
|
9
|
-
* @hidden
|
|
10
|
-
*/
|
|
11
|
-
editor: Editor | null
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** @internal */
|
|
15
|
-
export const blockHandleDraggableProps: PropDeclarations<BlockHandleDraggableProps> = {
|
|
16
|
-
editor: { default: null },
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** @internal */
|
|
20
|
-
export interface BlockHandleDraggableEvents {}
|
|
21
|
-
|
|
22
|
-
/** @internal */
|
|
23
|
-
export const blockHandleDraggableEvents: EventDeclarations<BlockHandleDraggableEvents> = {}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from "@aria-ui/core"
|
|
2
|
-
|
|
3
|
-
import { useBlockHandlePopover } from "./setup.ts"
|
|
4
|
-
import { blockHandlePopoverEvents, blockHandlePopoverProps, type BlockHandlePopoverEvents, type BlockHandlePopoverProps } from "./types.ts"
|
|
5
|
-
|
|
6
|
-
const BlockHandlePopoverElementBase: BaseElementConstructor<BlockHandlePopoverProps> = defineCustomElement<
|
|
7
|
-
BlockHandlePopoverProps,
|
|
8
|
-
BlockHandlePopoverEvents
|
|
9
|
-
>({
|
|
10
|
-
props: blockHandlePopoverProps,
|
|
11
|
-
events: blockHandlePopoverEvents,
|
|
12
|
-
setup: useBlockHandlePopover,
|
|
13
|
-
})
|
|
14
|
-
class BlockHandlePopoverElement extends BlockHandlePopoverElementBase {}
|
|
15
|
-
|
|
16
|
-
registerCustomElement('prosekit-block-handle-popover', BlockHandlePopoverElement)
|
|
17
|
-
|
|
18
|
-
export { BlockHandlePopoverElement }
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { createComputed, createSignal, useAttribute, type ConnectableElement, type ReadonlySignal, type SetupOptions } from '@aria-ui/core'
|
|
2
|
-
import { useOverlayPositionerState } from '@aria-ui/overlay/elements'
|
|
3
|
-
import { usePresence } from '@aria-ui/presence'
|
|
4
|
-
import type { VirtualElement } from '@floating-ui/dom'
|
|
5
|
-
import type { Editor } from '@prosekit/core'
|
|
6
|
-
|
|
7
|
-
import { useEditorExtension } from '../../../hooks/use-editor-extension.ts'
|
|
8
|
-
import { useScrolling } from '../../../hooks/use-scrolling.ts'
|
|
9
|
-
import { blockPopoverContext, draggingContext, type BlockPopoverContext, type HoverState } from '../context.ts'
|
|
10
|
-
|
|
11
|
-
import { defineElementHoverHandler, type ElementHoverHandler } from './pointer-move.ts'
|
|
12
|
-
import type { BlockHandlePopoverEvents, BlockHandlePopoverProps } from './types.ts'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export function useBlockHandlePopover(
|
|
18
|
-
host: ConnectableElement,
|
|
19
|
-
{ state, emit }: SetupOptions<BlockHandlePopoverProps, BlockHandlePopoverEvents>,
|
|
20
|
-
): void {
|
|
21
|
-
const { editor, ...overlayState } = state
|
|
22
|
-
const reference = createSignal<VirtualElement | null>(null)
|
|
23
|
-
useOverlayPositionerState(host, overlayState, { reference })
|
|
24
|
-
|
|
25
|
-
const context = createSignal<BlockPopoverContext>(null)
|
|
26
|
-
blockPopoverContext.provide(host, context)
|
|
27
|
-
|
|
28
|
-
const dragging = createSignal(false)
|
|
29
|
-
draggingContext.provide(host, dragging)
|
|
30
|
-
|
|
31
|
-
const scrolling = useScrolling(host)
|
|
32
|
-
const open = createComputed(() => {
|
|
33
|
-
return !!context.get() && !scrolling.get()
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
useHoverExtension(host, editor, (referenceValue, hoverState) => {
|
|
37
|
-
reference.set(referenceValue)
|
|
38
|
-
context.set(hoverState)
|
|
39
|
-
const stateChangeDetails = hoverState ? { node: hoverState.node, pos: hoverState.pos } : null
|
|
40
|
-
emit('stateChange', stateChangeDetails)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
useAttribute(host, 'data-state', () => (open.get() ? 'open' : 'closed'))
|
|
44
|
-
usePresence(host, open)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function useHoverExtension(
|
|
48
|
-
host: ConnectableElement,
|
|
49
|
-
editor: ReadonlySignal<Editor | null>,
|
|
50
|
-
handler: ElementHoverHandler,
|
|
51
|
-
) {
|
|
52
|
-
let prevHoverState: HoverState | null = null
|
|
53
|
-
|
|
54
|
-
const extension = defineElementHoverHandler((reference, hoverState) => {
|
|
55
|
-
if (isHoverStateEqual(prevHoverState, hoverState)) {
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
prevHoverState = hoverState
|
|
60
|
-
handler(reference, hoverState)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
useEditorExtension(host, editor, extension)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function isHoverStateEqual(a: HoverState | null, b: HoverState | null) {
|
|
67
|
-
return (!a && !b) || (a && b && a.pos === b.pos && a.node.eq(b.node))
|
|
68
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { EventDeclarations, PropDeclarations } from '@aria-ui/core'
|
|
2
|
-
import {
|
|
3
|
-
overlayPositionerEvents,
|
|
4
|
-
overlayPositionerProps,
|
|
5
|
-
type OverlayPositionerEvents,
|
|
6
|
-
type OverlayPositionerProps,
|
|
7
|
-
} from '@aria-ui/overlay/elements'
|
|
8
|
-
import type { Placement } from '@floating-ui/dom'
|
|
9
|
-
import type { Editor } from '@prosekit/core'
|
|
10
|
-
import type { ProseMirrorNode } from '@prosekit/pm/model'
|
|
11
|
-
|
|
12
|
-
export interface BlockHandlePopoverProps extends Omit<OverlayPositionerProps, 'placement' | 'hoist' | 'flip' | 'shift' | 'hide'> {
|
|
13
|
-
/**
|
|
14
|
-
* The ProseKit editor instance.
|
|
15
|
-
*
|
|
16
|
-
* @default null
|
|
17
|
-
* @hidden
|
|
18
|
-
*/
|
|
19
|
-
editor: Editor | null
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The placement of the popover, relative to the hovered block.
|
|
23
|
-
*
|
|
24
|
-
* @default "left"
|
|
25
|
-
*/
|
|
26
|
-
placement: Placement
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Whether to use the browser [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API)
|
|
30
|
-
* to place the floating element on top of other page content.
|
|
31
|
-
*
|
|
32
|
-
* @default false
|
|
33
|
-
*/
|
|
34
|
-
hoist: boolean
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @default false
|
|
38
|
-
* @hidden
|
|
39
|
-
*/
|
|
40
|
-
flip: boolean
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @default false
|
|
44
|
-
* @hidden
|
|
45
|
-
*/
|
|
46
|
-
shift: boolean
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @default true
|
|
50
|
-
* @hidden
|
|
51
|
-
*/
|
|
52
|
-
hide: boolean
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** @internal */
|
|
56
|
-
export const blockHandlePopoverProps: PropDeclarations<BlockHandlePopoverProps> = {
|
|
57
|
-
...overlayPositionerProps,
|
|
58
|
-
editor: { default: null },
|
|
59
|
-
placement: { default: 'left' },
|
|
60
|
-
|
|
61
|
-
// Enabling `hoist` will cause the popover to have a small delay when
|
|
62
|
-
// scrolling the page.
|
|
63
|
-
hoist: { default: false },
|
|
64
|
-
|
|
65
|
-
flip: { default: false },
|
|
66
|
-
shift: { default: false },
|
|
67
|
-
hide: { default: true },
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface BlockHandlePopoverEvents extends OverlayPositionerEvents {
|
|
71
|
-
/**
|
|
72
|
-
* Fired when the hovered block changes.
|
|
73
|
-
*/
|
|
74
|
-
stateChange: CustomEvent<{ node: ProseMirrorNode; pos: number } | null>
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** @internal */
|
|
78
|
-
export const blockHandlePopoverEvents: EventDeclarations<BlockHandlePopoverEvents> = {
|
|
79
|
-
...overlayPositionerEvents,
|
|
80
|
-
stateChange: {},
|
|
81
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// This file is generated by packages/dev/src/gen-components.ts
|
|
2
|
-
|
|
3
|
-
export { BlockHandleAddElement } from './block-handle-add/element.gen.ts'
|
|
4
|
-
export { blockHandleAddEvents, blockHandleAddProps, type BlockHandleAddEvents, type BlockHandleAddProps } from './block-handle-add/types.ts'
|
|
5
|
-
export { useBlockHandleAdd } from './block-handle-add/setup.ts'
|
|
6
|
-
|
|
7
|
-
export { BlockHandleDraggableElement } from './block-handle-draggable/element.gen.ts'
|
|
8
|
-
export { blockHandleDraggableEvents, blockHandleDraggableProps, type BlockHandleDraggableEvents, type BlockHandleDraggableProps } from './block-handle-draggable/types.ts'
|
|
9
|
-
export { useBlockHandleDraggable } from './block-handle-draggable/setup.ts'
|
|
10
|
-
|
|
11
|
-
export { BlockHandlePopoverElement } from './block-handle-popover/element.gen.ts'
|
|
12
|
-
export { blockHandlePopoverEvents, blockHandlePopoverProps, type BlockHandlePopoverEvents, type BlockHandlePopoverProps } from './block-handle-popover/types.ts'
|
|
13
|
-
export { useBlockHandlePopover } from './block-handle-popover/setup.ts'
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from "@aria-ui/core"
|
|
2
|
-
|
|
3
|
-
import { useDropIndicator } from "./setup.ts"
|
|
4
|
-
import { dropIndicatorEvents, dropIndicatorProps, type DropIndicatorEvents, type DropIndicatorProps } from "./types.ts"
|
|
5
|
-
|
|
6
|
-
const DropIndicatorElementBase: BaseElementConstructor<DropIndicatorProps> = defineCustomElement<
|
|
7
|
-
DropIndicatorProps,
|
|
8
|
-
DropIndicatorEvents
|
|
9
|
-
>({
|
|
10
|
-
props: dropIndicatorProps,
|
|
11
|
-
events: dropIndicatorEvents,
|
|
12
|
-
setup: useDropIndicator,
|
|
13
|
-
})
|
|
14
|
-
class DropIndicatorElement extends DropIndicatorElementBase {}
|
|
15
|
-
|
|
16
|
-
registerCustomElement('prosekit-drop-indicator', DropIndicatorElement)
|
|
17
|
-
|
|
18
|
-
export { DropIndicatorElement }
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { createComputed, createSignal, useEffect, type ConnectableElement, type SetupOptions } from '@aria-ui/core'
|
|
2
|
-
import { usePresence } from '@aria-ui/presence'
|
|
3
|
-
import { defineDropIndicator, type ShowHandlerOptions } from '@prosekit/extensions/drop-indicator'
|
|
4
|
-
|
|
5
|
-
import { useEditorExtension } from '../../../hooks/use-editor-extension.ts'
|
|
6
|
-
import { useScrolling } from '../../../hooks/use-scrolling.ts'
|
|
7
|
-
import { assignStyles } from '../../../utils/assign-styles.ts'
|
|
8
|
-
|
|
9
|
-
import type { DropIndicatorEvents, DropIndicatorProps } from './types.ts'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export function useDropIndicator(
|
|
15
|
-
host: ConnectableElement,
|
|
16
|
-
{ state }: SetupOptions<DropIndicatorProps, DropIndicatorEvents>,
|
|
17
|
-
): void {
|
|
18
|
-
type DropIndicatorContext = ShowHandlerOptions | null
|
|
19
|
-
const context = createSignal<DropIndicatorContext>(null)
|
|
20
|
-
|
|
21
|
-
const extension = defineDropIndicator({
|
|
22
|
-
onShow: (options) => context.set(options),
|
|
23
|
-
onHide: () => context.set(null),
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
useEditorExtension(host, state.editor, extension)
|
|
27
|
-
|
|
28
|
-
const line = createComputed(() => context.get()?.line)
|
|
29
|
-
const scrolling = useScrolling(host)
|
|
30
|
-
const presence = createComputed(() => {
|
|
31
|
-
return !!context.get() && !scrolling.get()
|
|
32
|
-
})
|
|
33
|
-
usePresence(host, presence)
|
|
34
|
-
|
|
35
|
-
useEffect(
|
|
36
|
-
host,
|
|
37
|
-
() => {
|
|
38
|
-
const lineValue = line.get()
|
|
39
|
-
const lineWidth = state.width.get()
|
|
40
|
-
|
|
41
|
-
if (!lineValue) return
|
|
42
|
-
|
|
43
|
-
const { p1: { x: x1, y: y1 }, p2: { x: x2, y: y2 } } = lineValue
|
|
44
|
-
const horizontal = y1 === y2
|
|
45
|
-
|
|
46
|
-
let width: number
|
|
47
|
-
let height: number
|
|
48
|
-
let top: number = y1
|
|
49
|
-
let left: number = x1
|
|
50
|
-
|
|
51
|
-
if (horizontal) {
|
|
52
|
-
width = x2 - x1
|
|
53
|
-
height = lineWidth
|
|
54
|
-
top -= lineWidth / 2
|
|
55
|
-
} else {
|
|
56
|
-
width = lineWidth
|
|
57
|
-
height = y2 - y1
|
|
58
|
-
left -= lineWidth / 2
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
top = Math.round(top)
|
|
62
|
-
left = Math.round(left)
|
|
63
|
-
|
|
64
|
-
assignStyles(host, {
|
|
65
|
-
position: 'fixed',
|
|
66
|
-
pointerEvents: 'none',
|
|
67
|
-
width: `${width}px`,
|
|
68
|
-
height: `${height}px`,
|
|
69
|
-
transform: `translate(${left}px, ${top}px)`,
|
|
70
|
-
left: '0px',
|
|
71
|
-
top: '0px',
|
|
72
|
-
})
|
|
73
|
-
},
|
|
74
|
-
)
|
|
75
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { EventDeclarations, PropDeclarations } from '@aria-ui/core'
|
|
2
|
-
import type { Editor } from '@prosekit/core'
|
|
3
|
-
|
|
4
|
-
export interface DropIndicatorProps {
|
|
5
|
-
/**
|
|
6
|
-
* The ProseKit editor instance.
|
|
7
|
-
*
|
|
8
|
-
* @default null
|
|
9
|
-
* @hidden
|
|
10
|
-
*/
|
|
11
|
-
editor: Editor | null
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The line width in pixels.
|
|
15
|
-
*
|
|
16
|
-
* @default 2
|
|
17
|
-
*/
|
|
18
|
-
width: number
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** @internal */
|
|
22
|
-
export const dropIndicatorProps: PropDeclarations<DropIndicatorProps> = Object.freeze({
|
|
23
|
-
editor: { default: null },
|
|
24
|
-
width: { default: 2 },
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
export interface DropIndicatorEvents {
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** @internal */
|
|
31
|
-
export const dropIndicatorEvents: EventDeclarations<DropIndicatorEvents> = {}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// This file is generated by packages/dev/src/gen-components.ts
|
|
2
|
-
|
|
3
|
-
export { DropIndicatorElement } from './drop-indicator/element.gen.ts'
|
|
4
|
-
export { dropIndicatorEvents, dropIndicatorProps, type DropIndicatorEvents, type DropIndicatorProps } from './drop-indicator/types.ts'
|
|
5
|
-
export { useDropIndicator } from './drop-indicator/setup.ts'
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// This file is generated by packages/dev/src/gen-components.ts
|
|
2
|
-
|
|
3
|
-
export { InlinePopoverElement } from './inline-popover/element.gen.ts'
|
|
4
|
-
export { inlinePopoverEvents, inlinePopoverProps, type InlinePopoverEvents, type InlinePopoverProps } from './inline-popover/types.ts'
|
|
5
|
-
export { useInlinePopover } from './inline-popover/setup.ts'
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from "@aria-ui/core"
|
|
2
|
-
|
|
3
|
-
import { useInlinePopover } from "./setup.ts"
|
|
4
|
-
import { inlinePopoverEvents, inlinePopoverProps, type InlinePopoverEvents, type InlinePopoverProps } from "./types.ts"
|
|
5
|
-
|
|
6
|
-
const InlinePopoverElementBase: BaseElementConstructor<InlinePopoverProps> = defineCustomElement<
|
|
7
|
-
InlinePopoverProps,
|
|
8
|
-
InlinePopoverEvents
|
|
9
|
-
>({
|
|
10
|
-
props: inlinePopoverProps,
|
|
11
|
-
events: inlinePopoverEvents,
|
|
12
|
-
setup: useInlinePopover,
|
|
13
|
-
})
|
|
14
|
-
class InlinePopoverElement extends InlinePopoverElementBase {}
|
|
15
|
-
|
|
16
|
-
registerCustomElement('prosekit-inline-popover', InlinePopoverElement)
|
|
17
|
-
|
|
18
|
-
export { InlinePopoverElement }
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createComputed,
|
|
3
|
-
createSignal,
|
|
4
|
-
useAttribute,
|
|
5
|
-
useEffect,
|
|
6
|
-
type ConnectableElement,
|
|
7
|
-
type ReadonlySignal,
|
|
8
|
-
type SetupOptions,
|
|
9
|
-
} from '@aria-ui/core'
|
|
10
|
-
import { useOverlayPositionerState } from '@aria-ui/overlay/elements'
|
|
11
|
-
import { usePresence } from '@aria-ui/presence'
|
|
12
|
-
import type { ReferenceElement } from '@floating-ui/dom'
|
|
13
|
-
import type { Editor } from '@prosekit/core'
|
|
14
|
-
import type { Selection } from '@prosekit/pm/state'
|
|
15
|
-
|
|
16
|
-
import { useEditorFocusChangeEvent } from '../../../hooks/use-editor-focus-event.ts'
|
|
17
|
-
import { useEditorUpdateEvent } from '../../../hooks/use-editor-update-event.ts'
|
|
18
|
-
import { useKeymap } from '../../../hooks/use-keymap.ts'
|
|
19
|
-
|
|
20
|
-
import type { InlinePopoverEvents, InlinePopoverProps } from './types.ts'
|
|
21
|
-
import { getVirtualSelectionElement } from './virtual-selection-element.ts'
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
export function useInlinePopover(
|
|
27
|
-
host: ConnectableElement,
|
|
28
|
-
{ state, emit }: SetupOptions<InlinePopoverProps, InlinePopoverEvents>,
|
|
29
|
-
): void {
|
|
30
|
-
const { editor, defaultOpen, open, ...overlayState } = state
|
|
31
|
-
|
|
32
|
-
const reference = useInlinePopoverReference(host, editor)
|
|
33
|
-
const hasReference = createComputed(() => !!reference.get())
|
|
34
|
-
|
|
35
|
-
useEffect(host, () => {
|
|
36
|
-
const hasReferenceValue = hasReference.get()
|
|
37
|
-
const defaultOpenValue = defaultOpen.peek()
|
|
38
|
-
const openValue = open.peek()
|
|
39
|
-
|
|
40
|
-
if (defaultOpenValue || openValue) {
|
|
41
|
-
emit('openChange', hasReferenceValue)
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
useEffect(host, () => {
|
|
46
|
-
const hasReferenceValue = hasReference.get()
|
|
47
|
-
const defaultOpenValue = defaultOpen.peek()
|
|
48
|
-
|
|
49
|
-
if (hasReferenceValue && defaultOpenValue) {
|
|
50
|
-
open.set(true)
|
|
51
|
-
} else if (!hasReferenceValue) {
|
|
52
|
-
open.set(false)
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
useKeymap(host, editor, {
|
|
57
|
-
Escape: () => {
|
|
58
|
-
if (!state.dismissOnEscape.peek() || !open.peek()) {
|
|
59
|
-
return false
|
|
60
|
-
}
|
|
61
|
-
open.set(false)
|
|
62
|
-
emit('openChange', false)
|
|
63
|
-
return true
|
|
64
|
-
},
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
useOverlayPositionerState(host, overlayState, { reference })
|
|
68
|
-
|
|
69
|
-
useAttribute(host, 'data-state', () => (open.get() ? 'open' : 'closed'))
|
|
70
|
-
usePresence(host, open)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function useInlinePopoverReference(
|
|
74
|
-
host: ConnectableElement,
|
|
75
|
-
editor: ReadonlySignal<Editor | null>,
|
|
76
|
-
) {
|
|
77
|
-
const reference = createSignal<ReferenceElement | null>(null)
|
|
78
|
-
let editorFocused = false
|
|
79
|
-
|
|
80
|
-
useEditorFocusChangeEvent(host, editor, (focus) => {
|
|
81
|
-
editorFocused = focus
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
let prevSelection: Selection | undefined
|
|
85
|
-
|
|
86
|
-
useEditorUpdateEvent(host, editor, (view) => {
|
|
87
|
-
const isPopoverFocused = !editorFocused && host.contains(host.ownerDocument.activeElement)
|
|
88
|
-
|
|
89
|
-
if (isPopoverFocused) {
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const { selection } = view.state
|
|
94
|
-
const selectionUnchanged = prevSelection?.eq(selection)
|
|
95
|
-
prevSelection = selection
|
|
96
|
-
|
|
97
|
-
// Skip reference update if only the document content has changed, not the
|
|
98
|
-
// selection itself.
|
|
99
|
-
//
|
|
100
|
-
// Example: If the user selects text and then applies mark bold using the
|
|
101
|
-
// popover, the selection may widen, but we don't want to reposition the
|
|
102
|
-
// popover.
|
|
103
|
-
if (selectionUnchanged) {
|
|
104
|
-
return
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
reference.set(getVirtualSelectionElement(view) || null)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
return reference
|
|
111
|
-
}
|