@prosekit/web 0.7.3 → 0.7.5
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/{get-default-state-CIEy7xrl.js → get-default-state-BzBimBWi.js} +2 -1
- package/dist/get-default-state-BzBimBWi.js.map +1 -0
- package/dist/{get-safe-editor-view-DENm4avv.js → get-safe-editor-view-Dt9Amrcn.js} +2 -1
- package/dist/get-safe-editor-view-Dt9Amrcn.js.map +1 -0
- package/dist/{inject-style-D5jj7cme.js → inject-style-Dm6W58W3.js} +6 -9
- package/dist/inject-style-Dm6W58W3.js.map +1 -0
- package/dist/prosekit-web-autocomplete.d.ts +2 -1
- package/dist/prosekit-web-autocomplete.d.ts.map +1 -0
- package/dist/prosekit-web-autocomplete.js +9 -13
- package/dist/prosekit-web-autocomplete.js.map +1 -0
- package/dist/prosekit-web-block-handle.d.ts +2 -1
- package/dist/prosekit-web-block-handle.d.ts.map +1 -0
- package/dist/prosekit-web-block-handle.js +31 -31
- package/dist/prosekit-web-block-handle.js.map +1 -0
- package/dist/prosekit-web-drop-indicator.d.ts +2 -1
- package/dist/prosekit-web-drop-indicator.d.ts.map +1 -0
- package/dist/prosekit-web-drop-indicator.js +6 -6
- package/dist/prosekit-web-drop-indicator.js.map +1 -0
- package/dist/prosekit-web-inline-popover.d.ts +2 -1
- package/dist/prosekit-web-inline-popover.d.ts.map +1 -0
- package/dist/prosekit-web-inline-popover.js +8 -12
- package/dist/prosekit-web-inline-popover.js.map +1 -0
- package/dist/prosekit-web-popover.d.ts +2 -1
- package/dist/prosekit-web-popover.d.ts.map +1 -0
- package/dist/prosekit-web-popover.js +2 -1
- package/dist/prosekit-web-popover.js.map +1 -0
- package/dist/prosekit-web-resizable.d.ts +2 -1
- package/dist/prosekit-web-resizable.d.ts.map +1 -0
- package/dist/prosekit-web-resizable.js +5 -7
- package/dist/prosekit-web-resizable.js.map +1 -0
- package/dist/prosekit-web-table-handle.d.ts +2 -1
- package/dist/prosekit-web-table-handle.d.ts.map +1 -0
- package/dist/prosekit-web-table-handle.js +39 -72
- package/dist/prosekit-web-table-handle.js.map +1 -0
- package/dist/prosekit-web-tooltip.d.ts +2 -1
- package/dist/prosekit-web-tooltip.d.ts.map +1 -0
- package/dist/prosekit-web-tooltip.js +2 -1
- package/dist/prosekit-web-tooltip.js.map +1 -0
- package/dist/prosekit-web.js +1 -0
- package/dist/{use-editor-extension-Cc7ZG7uj.js → use-editor-extension-B2WuUfnd.js} +2 -1
- package/dist/use-editor-extension-B2WuUfnd.js.map +1 -0
- package/dist/{use-scrolling-BNfsQs3S.js → use-scrolling-BOvyjDvH.js} +2 -1
- package/dist/use-scrolling-BOvyjDvH.js.map +1 -0
- package/package.json +21 -21
- package/src/components/autocomplete/autocomplete-empty/element.gen.ts +18 -0
- package/src/components/autocomplete/autocomplete-empty/setup.ts +6 -0
- package/src/components/autocomplete/autocomplete-empty/types.ts +16 -0
- package/src/components/autocomplete/autocomplete-item/element.gen.ts +18 -0
- package/src/components/autocomplete/autocomplete-item/setup.ts +38 -0
- package/src/components/autocomplete/autocomplete-item/types.ts +31 -0
- package/src/components/autocomplete/autocomplete-list/element.gen.ts +18 -0
- package/src/components/autocomplete/autocomplete-list/setup.ts +140 -0
- package/src/components/autocomplete/autocomplete-list/types.ts +30 -0
- package/src/components/autocomplete/autocomplete-popover/element.gen.ts +18 -0
- package/src/components/autocomplete/autocomplete-popover/helpers.spec.ts +21 -0
- package/src/components/autocomplete/autocomplete-popover/helpers.ts +7 -0
- package/src/components/autocomplete/autocomplete-popover/setup.ts +185 -0
- package/src/components/autocomplete/autocomplete-popover/types.ts +103 -0
- package/src/components/autocomplete/context.ts +19 -0
- package/src/components/autocomplete/index.gen.ts +17 -0
- package/src/components/block-handle/block-handle-add/element.gen.ts +18 -0
- package/src/components/block-handle/block-handle-add/setup.ts +37 -0
- package/src/components/block-handle/block-handle-add/types.ts +26 -0
- package/src/components/block-handle/block-handle-draggable/element.gen.ts +18 -0
- package/src/components/block-handle/block-handle-draggable/set-drag-preview.ts +88 -0
- package/src/components/block-handle/block-handle-draggable/setup.ts +133 -0
- package/src/components/block-handle/block-handle-draggable/types.ts +26 -0
- package/src/components/block-handle/block-handle-popover/element.gen.ts +18 -0
- package/src/components/block-handle/block-handle-popover/pointer-move.ts +262 -0
- package/src/components/block-handle/block-handle-popover/setup.ts +88 -0
- package/src/components/block-handle/block-handle-popover/types.ts +84 -0
- package/src/components/block-handle/context.ts +34 -0
- package/src/components/block-handle/index.gen.ts +13 -0
- package/src/components/drop-indicator/drop-indicator/element.gen.ts +18 -0
- package/src/components/drop-indicator/drop-indicator/setup.ts +87 -0
- package/src/components/drop-indicator/drop-indicator/types.ts +34 -0
- package/src/components/drop-indicator/index.gen.ts +5 -0
- package/src/components/inline-popover/index.gen.ts +5 -0
- package/src/components/inline-popover/inline-popover/element.gen.ts +18 -0
- package/src/components/inline-popover/inline-popover/setup.ts +97 -0
- package/src/components/inline-popover/inline-popover/types.ts +115 -0
- package/src/components/inline-popover/inline-popover/virtual-selection-element.ts +75 -0
- package/src/components/popover/index.gen.ts +13 -0
- package/src/components/popover/popover-content/element.gen.ts +18 -0
- package/src/components/popover/popover-content/setup.ts +1 -0
- package/src/components/popover/popover-content/types.ts +12 -0
- package/src/components/popover/popover-root/element.gen.ts +18 -0
- package/src/components/popover/popover-root/setup.ts +1 -0
- package/src/components/popover/popover-root/types.ts +12 -0
- package/src/components/popover/popover-trigger/element.gen.ts +18 -0
- package/src/components/popover/popover-trigger/setup.ts +1 -0
- package/src/components/popover/popover-trigger/types.ts +12 -0
- package/src/components/resizable/context.ts +45 -0
- package/src/components/resizable/index.gen.ts +9 -0
- package/src/components/resizable/resizable-handle/calc-resize.spec.ts +280 -0
- package/src/components/resizable/resizable-handle/calc-resize.ts +121 -0
- package/src/components/resizable/resizable-handle/element.gen.ts +18 -0
- package/src/components/resizable/resizable-handle/setup.ts +112 -0
- package/src/components/resizable/resizable-handle/types.ts +32 -0
- package/src/components/resizable/resizable-root/element.gen.ts +18 -0
- package/src/components/resizable/resizable-root/setup.ts +93 -0
- package/src/components/resizable/resizable-root/types.ts +28 -0
- package/src/components/table-handle/context.ts +49 -0
- package/src/components/table-handle/dnd.ts +135 -0
- package/src/components/table-handle/hooks/use-drop.ts +94 -0
- package/src/components/table-handle/hooks/use-empty-image.ts +30 -0
- package/src/components/table-handle/index.gen.ts +37 -0
- package/src/components/table-handle/table-handle-column-root/element.gen.ts +18 -0
- package/src/components/table-handle/table-handle-column-root/setup.ts +71 -0
- package/src/components/table-handle/table-handle-column-root/types.ts +76 -0
- package/src/components/table-handle/table-handle-column-trigger/element.gen.ts +18 -0
- package/src/components/table-handle/table-handle-column-trigger/setup.ts +75 -0
- package/src/components/table-handle/table-handle-column-trigger/types.ts +23 -0
- package/src/components/table-handle/table-handle-drag-preview/element.gen.ts +18 -0
- package/src/components/table-handle/table-handle-drag-preview/render-preview.ts +80 -0
- package/src/components/table-handle/table-handle-drag-preview/setup.ts +67 -0
- package/src/components/table-handle/table-handle-drag-preview/types.ts +17 -0
- package/src/components/table-handle/table-handle-drag-preview/updater.ts +101 -0
- package/src/components/table-handle/table-handle-drop-indicator/calc-drag-over.ts +44 -0
- package/src/components/table-handle/table-handle-drop-indicator/element.gen.ts +18 -0
- package/src/components/table-handle/table-handle-drop-indicator/setup.ts +56 -0
- package/src/components/table-handle/table-handle-drop-indicator/types.ts +18 -0
- package/src/components/table-handle/table-handle-drop-indicator/updater.ts +110 -0
- package/src/components/table-handle/table-handle-popover-content/element.gen.ts +18 -0
- package/src/components/table-handle/table-handle-popover-content/setup.ts +90 -0
- package/src/components/table-handle/table-handle-popover-content/types.ts +40 -0
- package/src/components/table-handle/table-handle-popover-item/element.gen.ts +18 -0
- package/src/components/table-handle/table-handle-popover-item/setup.ts +23 -0
- package/src/components/table-handle/table-handle-popover-item/types.ts +24 -0
- package/src/components/table-handle/table-handle-root/element.gen.ts +18 -0
- package/src/components/table-handle/table-handle-root/setup.ts +93 -0
- package/src/components/table-handle/table-handle-root/types.ts +26 -0
- package/src/components/table-handle/table-handle-row-root/element.gen.ts +18 -0
- package/src/components/table-handle/table-handle-row-root/setup.ts +77 -0
- package/src/components/table-handle/table-handle-row-root/types.ts +75 -0
- package/src/components/table-handle/table-handle-row-trigger/element.gen.ts +18 -0
- package/src/components/table-handle/table-handle-row-trigger/setup.ts +74 -0
- package/src/components/table-handle/table-handle-row-trigger/types.ts +26 -0
- package/src/components/table-handle/utils.ts +107 -0
- package/src/components/tooltip/index.gen.ts +13 -0
- package/src/components/tooltip/tooltip-content/element.gen.ts +18 -0
- package/src/components/tooltip/tooltip-content/setup.ts +1 -0
- package/src/components/tooltip/tooltip-content/types.ts +12 -0
- package/src/components/tooltip/tooltip-root/element.gen.ts +18 -0
- package/src/components/tooltip/tooltip-root/setup.ts +1 -0
- package/src/components/tooltip/tooltip-root/types.ts +12 -0
- package/src/components/tooltip/tooltip-trigger/element.gen.ts +18 -0
- package/src/components/tooltip/tooltip-trigger/setup.ts +1 -0
- package/src/components/tooltip/tooltip-trigger/types.ts +12 -0
- package/src/hooks/use-editor-extension.ts +19 -0
- package/src/hooks/use-editor-focus-event.ts +23 -0
- package/src/hooks/use-editor-typing.ts +36 -0
- package/src/hooks/use-editor-update-event.ts +23 -0
- package/src/hooks/use-first-rendering.ts +20 -0
- package/src/hooks/use-keymap.ts +20 -0
- package/src/hooks/use-scrolling.ts +33 -0
- package/src/hooks/use-selecting.ts +63 -0
- package/src/index.ts +1 -0
- package/src/utils/assign-styles.ts +14 -0
- package/src/utils/clone-element.ts +110 -0
- package/src/utils/css-feature-detection.ts +9 -0
- package/src/utils/fade-color.ts +15 -0
- package/src/utils/get-box-element.ts +20 -0
- package/src/utils/get-client-rect.ts +35 -0
- package/src/utils/get-default-state.spec.ts +50 -0
- package/src/utils/get-default-state.ts +22 -0
- package/src/utils/get-effective-background-color.ts +21 -0
- package/src/utils/get-safe-editor-view.ts +10 -0
- package/src/utils/inject-style.ts +11 -0
- package/src/utils/is-finite-positive-number.ts +3 -0
- package/src/utils/max-z-index.ts +3 -0
- package/src/utils/throttle.ts +17 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ConnectableElement,
|
|
3
|
+
SetupOptions,
|
|
4
|
+
} from '@aria-ui/core'
|
|
5
|
+
import { useMenuItem } from '@aria-ui/menu/elements'
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
TableHandlePopoverItemEvents,
|
|
9
|
+
TableHandlePopoverItemProps,
|
|
10
|
+
} from './types'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export function useTableHandlePopoverItem(
|
|
16
|
+
element: ConnectableElement,
|
|
17
|
+
{
|
|
18
|
+
state,
|
|
19
|
+
emit,
|
|
20
|
+
}: SetupOptions<TableHandlePopoverItemProps, TableHandlePopoverItemEvents>,
|
|
21
|
+
): void {
|
|
22
|
+
useMenuItem(element, { state, emit })
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EventDeclarations,
|
|
3
|
+
PropDeclarations,
|
|
4
|
+
} from '@aria-ui/core'
|
|
5
|
+
import {
|
|
6
|
+
menuItemEvents,
|
|
7
|
+
menuItemProps,
|
|
8
|
+
type MenuItemEvents,
|
|
9
|
+
type MenuItemProps,
|
|
10
|
+
} from '@aria-ui/menu'
|
|
11
|
+
|
|
12
|
+
export interface TableHandlePopoverItemProps extends MenuItemProps {}
|
|
13
|
+
|
|
14
|
+
/** @internal */
|
|
15
|
+
export const tableHandlePopoverItemProps: PropDeclarations<TableHandlePopoverItemProps> = {
|
|
16
|
+
...menuItemProps,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface TableHandlePopoverItemEvents extends MenuItemEvents {}
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
export const tableHandlePopoverItemEvents: EventDeclarations<TableHandlePopoverItemEvents> = {
|
|
23
|
+
...menuItemEvents,
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from "@aria-ui/core"
|
|
2
|
+
|
|
3
|
+
import { useTableHandleRoot } from "./setup"
|
|
4
|
+
import { tableHandleRootEvents, tableHandleRootProps, type TableHandleRootEvents, type TableHandleRootProps } from "./types"
|
|
5
|
+
|
|
6
|
+
const TableHandleRootElementBase: BaseElementConstructor<TableHandleRootProps> = defineCustomElement<
|
|
7
|
+
TableHandleRootProps,
|
|
8
|
+
TableHandleRootEvents
|
|
9
|
+
>({
|
|
10
|
+
props: tableHandleRootProps,
|
|
11
|
+
events: tableHandleRootEvents,
|
|
12
|
+
setup: useTableHandleRoot,
|
|
13
|
+
})
|
|
14
|
+
class TableHandleRootElement extends TableHandleRootElementBase {}
|
|
15
|
+
|
|
16
|
+
registerCustomElement('prosekit-table-handle-root', TableHandleRootElement)
|
|
17
|
+
|
|
18
|
+
export { TableHandleRootElement }
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createComputed,
|
|
3
|
+
createSignal,
|
|
4
|
+
useEffect,
|
|
5
|
+
type ConnectableElement,
|
|
6
|
+
type ReadonlySignal,
|
|
7
|
+
type Signal,
|
|
8
|
+
type SignalState,
|
|
9
|
+
} from '@aria-ui/core'
|
|
10
|
+
import {
|
|
11
|
+
defineDOMEventHandler,
|
|
12
|
+
type Editor,
|
|
13
|
+
} from '@prosekit/core'
|
|
14
|
+
import type { EditorView } from '@prosekit/pm/view'
|
|
15
|
+
|
|
16
|
+
import { useEditorExtension } from '../../../hooks/use-editor-extension'
|
|
17
|
+
import { useEditorTyping } from '../../../hooks/use-editor-typing'
|
|
18
|
+
import { useScrolling } from '../../../hooks/use-scrolling'
|
|
19
|
+
import { useSelecting } from '../../../hooks/use-selecting'
|
|
20
|
+
import {
|
|
21
|
+
defaultTableHandleDndContext,
|
|
22
|
+
tableHandleDndContext,
|
|
23
|
+
tableHandleRootContext,
|
|
24
|
+
type TableHandleDndContext,
|
|
25
|
+
type TableHandleRootContext,
|
|
26
|
+
} from '../context'
|
|
27
|
+
import { useDrop } from '../hooks/use-drop'
|
|
28
|
+
import {
|
|
29
|
+
getHoveringCell,
|
|
30
|
+
isHoveringCellInfoEqual,
|
|
31
|
+
type HoveringCellInfo,
|
|
32
|
+
} from '../utils'
|
|
33
|
+
|
|
34
|
+
import type { TableHandleRootProps } from './types'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export function useTableHandleRoot(
|
|
40
|
+
host: ConnectableElement,
|
|
41
|
+
{ state }: { state: SignalState<TableHandleRootProps> },
|
|
42
|
+
): void {
|
|
43
|
+
const { editor } = state
|
|
44
|
+
|
|
45
|
+
const context = createSignal<TableHandleRootContext>(null)
|
|
46
|
+
const dndContext = createSignal<TableHandleDndContext>(defaultTableHandleDndContext)
|
|
47
|
+
|
|
48
|
+
const hoveringCell = useHoveringCell(host, editor)
|
|
49
|
+
const typing = useEditorTyping(host, editor)
|
|
50
|
+
const isInTable = createComputed(() => !!hoveringCell.get())
|
|
51
|
+
const selecting = useSelecting(host, editor, isInTable)
|
|
52
|
+
const scrolling = useScrolling(host)
|
|
53
|
+
const canShow = createComputed(() => {
|
|
54
|
+
return !typing.get() && !selecting.get() && !scrolling.get()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
useEffect(host, () => {
|
|
58
|
+
context.set(canShow.get() ? hoveringCell.get() : null)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
tableHandleRootContext.provide(host, context)
|
|
62
|
+
tableHandleDndContext.provide(host, dndContext)
|
|
63
|
+
|
|
64
|
+
useDrop(host, editor, dndContext)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function useHoveringCell(
|
|
68
|
+
host: ConnectableElement,
|
|
69
|
+
editor: ReadonlySignal<Editor | null>,
|
|
70
|
+
): Signal<HoveringCellInfo | null> {
|
|
71
|
+
const hoveringCell = createSignal<HoveringCellInfo | null>(null)
|
|
72
|
+
|
|
73
|
+
const extension = defineCellHoverHandler((curr: HoveringCellInfo | null) => {
|
|
74
|
+
const prev = hoveringCell.peek()
|
|
75
|
+
if (!isHoveringCellInfoEqual(prev, curr)) {
|
|
76
|
+
hoveringCell.set(curr)
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
useEditorExtension(host, editor, extension)
|
|
81
|
+
|
|
82
|
+
return hoveringCell
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function defineCellHoverHandler(
|
|
86
|
+
handler: (hoveringCell: HoveringCellInfo | null) => void,
|
|
87
|
+
) {
|
|
88
|
+
const pointerHandler = (view: EditorView, event: PointerEvent) => {
|
|
89
|
+
const hoveringCell = getHoveringCell(view, event)
|
|
90
|
+
return handler(hoveringCell ?? null)
|
|
91
|
+
}
|
|
92
|
+
return defineDOMEventHandler('pointerover', pointerHandler)
|
|
93
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EventDeclarations,
|
|
3
|
+
PropDeclarations,
|
|
4
|
+
} from '@aria-ui/core'
|
|
5
|
+
import type { Editor } from '@prosekit/core'
|
|
6
|
+
|
|
7
|
+
export interface TableHandleRootProps {
|
|
8
|
+
/**
|
|
9
|
+
* The ProseKit editor instance.
|
|
10
|
+
*
|
|
11
|
+
* @default null
|
|
12
|
+
* @hidden
|
|
13
|
+
*/
|
|
14
|
+
editor: Editor | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** @internal */
|
|
18
|
+
export const tableHandleRootProps: PropDeclarations<TableHandleRootProps> = {
|
|
19
|
+
editor: { default: null },
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @internal */
|
|
23
|
+
export interface TableHandleRootEvents {}
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export const tableHandleRootEvents: EventDeclarations<TableHandleRootEvents> = {}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from "@aria-ui/core"
|
|
2
|
+
|
|
3
|
+
import { useTableHandleRowRoot } from "./setup"
|
|
4
|
+
import { tableHandleRowRootEvents, tableHandleRowRootProps, type TableHandleRowRootEvents, type TableHandleRowRootProps } from "./types"
|
|
5
|
+
|
|
6
|
+
const TableHandleRowRootElementBase: BaseElementConstructor<TableHandleRowRootProps> = defineCustomElement<
|
|
7
|
+
TableHandleRowRootProps,
|
|
8
|
+
TableHandleRowRootEvents
|
|
9
|
+
>({
|
|
10
|
+
props: tableHandleRowRootProps,
|
|
11
|
+
events: tableHandleRowRootEvents,
|
|
12
|
+
setup: useTableHandleRowRoot,
|
|
13
|
+
})
|
|
14
|
+
class TableHandleRowRootElement extends TableHandleRowRootElementBase {}
|
|
15
|
+
|
|
16
|
+
registerCustomElement('prosekit-table-handle-row-root', TableHandleRowRootElement)
|
|
17
|
+
|
|
18
|
+
export { TableHandleRowRootElement }
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createComputed,
|
|
3
|
+
createSignal,
|
|
4
|
+
defineEmit,
|
|
5
|
+
useAttribute,
|
|
6
|
+
useEffect,
|
|
7
|
+
type ConnectableElement,
|
|
8
|
+
type SetupOptions,
|
|
9
|
+
} from '@aria-ui/core'
|
|
10
|
+
import {
|
|
11
|
+
menuRootEvents,
|
|
12
|
+
menuRootProps,
|
|
13
|
+
useMenuRoot,
|
|
14
|
+
} from '@aria-ui/menu/elements'
|
|
15
|
+
import { useOverlayPositionerState } from '@aria-ui/overlay/elements'
|
|
16
|
+
import { usePresence } from '@aria-ui/presence'
|
|
17
|
+
|
|
18
|
+
import { getStateWithDefaults } from '../../../utils/get-default-state'
|
|
19
|
+
import { getSafeEditorView } from '../../../utils/get-safe-editor-view'
|
|
20
|
+
import { tableHandleRootContext } from '../context'
|
|
21
|
+
|
|
22
|
+
import type {
|
|
23
|
+
TableHandleRowRootEvents,
|
|
24
|
+
TableHandleRowRootProps,
|
|
25
|
+
} from './types'
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export function useTableHandleRowRoot(
|
|
31
|
+
host: ConnectableElement,
|
|
32
|
+
{ state }: SetupOptions<TableHandleRowRootProps, TableHandleRowRootEvents>,
|
|
33
|
+
): void {
|
|
34
|
+
const { editor, ...overlayState } = state
|
|
35
|
+
|
|
36
|
+
const rootContext = tableHandleRootContext.consume(host)
|
|
37
|
+
|
|
38
|
+
const rowFirstCellPos = createComputed<number | undefined>(() => {
|
|
39
|
+
return rootContext.get()?.rowFirstCellPos
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const referenceCell = createComputed<HTMLElement | null>(() => {
|
|
43
|
+
const pos = rowFirstCellPos.get()
|
|
44
|
+
const view = getSafeEditorView(editor.get())
|
|
45
|
+
if (!pos || !view) return null
|
|
46
|
+
return view.nodeDOM(pos) as HTMLElement | null
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const contentOpen = createSignal(false)
|
|
50
|
+
|
|
51
|
+
// Close the menu when the hovering element is changed
|
|
52
|
+
// TODO: add a delay
|
|
53
|
+
useEffect(host, () => {
|
|
54
|
+
rowFirstCellPos.get()
|
|
55
|
+
contentOpen.set(false)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
useOverlayPositionerState(host, overlayState, {
|
|
59
|
+
reference: referenceCell,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const presence = createComputed(() => !!referenceCell.get())
|
|
63
|
+
useAttribute(host, 'data-state', () => (presence.get() ? 'open' : 'closed'))
|
|
64
|
+
usePresence(host, presence)
|
|
65
|
+
|
|
66
|
+
const menuRootState = getStateWithDefaults(
|
|
67
|
+
{
|
|
68
|
+
open: contentOpen,
|
|
69
|
+
},
|
|
70
|
+
menuRootProps,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
useMenuRoot(host, {
|
|
74
|
+
state: menuRootState,
|
|
75
|
+
emit: defineEmit(host, menuRootEvents),
|
|
76
|
+
})
|
|
77
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EventDeclarations,
|
|
3
|
+
PropDeclarations,
|
|
4
|
+
} from '@aria-ui/core'
|
|
5
|
+
import {
|
|
6
|
+
overlayPositionerProps,
|
|
7
|
+
type OverlayPositionerEvents,
|
|
8
|
+
type OverlayPositionerProps,
|
|
9
|
+
} from '@aria-ui/overlay'
|
|
10
|
+
import type { Placement } from '@floating-ui/dom'
|
|
11
|
+
import type { Editor } from '@prosekit/core'
|
|
12
|
+
|
|
13
|
+
export interface TableHandleRowRootProps extends Omit<OverlayPositionerProps, 'placement' | 'hoist' | 'flip' | 'shift' | 'hide'> {
|
|
14
|
+
/**
|
|
15
|
+
* The ProseKit editor instance.
|
|
16
|
+
*
|
|
17
|
+
* @default null
|
|
18
|
+
* @hidden
|
|
19
|
+
*/
|
|
20
|
+
editor: Editor | null
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The placement of the popover, relative to the hovered table cell.
|
|
24
|
+
*
|
|
25
|
+
* @default "left"
|
|
26
|
+
*/
|
|
27
|
+
placement: Placement
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether to use the browser [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API)
|
|
31
|
+
* to place the floating element on top of other page content.
|
|
32
|
+
*
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
hoist: boolean
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @default false
|
|
39
|
+
* @hidden
|
|
40
|
+
*/
|
|
41
|
+
flip: boolean
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @default false
|
|
45
|
+
* @hidden
|
|
46
|
+
*/
|
|
47
|
+
shift: boolean
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @default true
|
|
51
|
+
* @hidden
|
|
52
|
+
*/
|
|
53
|
+
hide: boolean
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @internal */
|
|
57
|
+
export const tableHandleRowRootProps: PropDeclarations<TableHandleRowRootProps> = {
|
|
58
|
+
...overlayPositionerProps,
|
|
59
|
+
editor: { default: null },
|
|
60
|
+
placement: { default: 'left' },
|
|
61
|
+
|
|
62
|
+
// Enabling `hoist` will cause the popover to have a small delay when
|
|
63
|
+
// scrolling the page.
|
|
64
|
+
hoist: { default: false },
|
|
65
|
+
|
|
66
|
+
flip: { default: false },
|
|
67
|
+
shift: { default: false },
|
|
68
|
+
hide: { default: true },
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @internal */
|
|
72
|
+
export interface TableHandleRowRootEvents extends OverlayPositionerEvents {}
|
|
73
|
+
|
|
74
|
+
/** @internal */
|
|
75
|
+
export const tableHandleRowRootEvents: EventDeclarations<TableHandleRowRootEvents> = {}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from "@aria-ui/core"
|
|
2
|
+
|
|
3
|
+
import { useTableHandleRowTrigger } from "./setup"
|
|
4
|
+
import { tableHandleRowTriggerEvents, tableHandleRowTriggerProps, type TableHandleRowTriggerEvents, type TableHandleRowTriggerProps } from "./types"
|
|
5
|
+
|
|
6
|
+
const TableHandleRowTriggerElementBase: BaseElementConstructor<TableHandleRowTriggerProps> = defineCustomElement<
|
|
7
|
+
TableHandleRowTriggerProps,
|
|
8
|
+
TableHandleRowTriggerEvents
|
|
9
|
+
>({
|
|
10
|
+
props: tableHandleRowTriggerProps,
|
|
11
|
+
events: tableHandleRowTriggerEvents,
|
|
12
|
+
setup: useTableHandleRowTrigger,
|
|
13
|
+
})
|
|
14
|
+
class TableHandleRowTriggerElement extends TableHandleRowTriggerElementBase {}
|
|
15
|
+
|
|
16
|
+
registerCustomElement('prosekit-table-handle-row-trigger', TableHandleRowTriggerElement)
|
|
17
|
+
|
|
18
|
+
export { TableHandleRowTriggerElement }
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useEffect,
|
|
3
|
+
useEventListener,
|
|
4
|
+
type ConnectableElement,
|
|
5
|
+
type SetupOptions,
|
|
6
|
+
} from '@aria-ui/core'
|
|
7
|
+
import { useMenuTrigger } from '@aria-ui/menu/elements'
|
|
8
|
+
import { selectTableRow } from '@prosekit/extensions/table'
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
tableHandleDndContext,
|
|
12
|
+
tableHandleRootContext,
|
|
13
|
+
} from '../context'
|
|
14
|
+
import { useEmptyImage } from '../hooks/use-empty-image'
|
|
15
|
+
|
|
16
|
+
import type {
|
|
17
|
+
TableHandleRowTriggerEvents,
|
|
18
|
+
TableHandleRowTriggerProps,
|
|
19
|
+
} from './types'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export function useTableHandleRowTrigger(
|
|
25
|
+
host: ConnectableElement,
|
|
26
|
+
{ state }: SetupOptions<TableHandleRowTriggerProps, TableHandleRowTriggerEvents>,
|
|
27
|
+
): void {
|
|
28
|
+
useMenuTrigger(host)
|
|
29
|
+
|
|
30
|
+
const context = tableHandleRootContext.consume(host)
|
|
31
|
+
|
|
32
|
+
const dndContext = tableHandleDndContext.consume(host)
|
|
33
|
+
|
|
34
|
+
useEventListener(host, 'pointerdown', () => {
|
|
35
|
+
const editor = state.editor.peek()
|
|
36
|
+
const cellPos = context.peek()?.cellPos
|
|
37
|
+
if (!editor || !cellPos) return
|
|
38
|
+
editor.exec(selectTableRow({ head: cellPos }))
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
useEffect(host, () => {
|
|
42
|
+
host.draggable = true
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const getEmptyImage = useEmptyImage(host)
|
|
46
|
+
|
|
47
|
+
useEventListener(host, 'dragstart', (event: DragEvent) => {
|
|
48
|
+
const dataTransfer = event.dataTransfer
|
|
49
|
+
if (dataTransfer) {
|
|
50
|
+
dataTransfer.effectAllowed = 'move'
|
|
51
|
+
const emptyImage = getEmptyImage()
|
|
52
|
+
if (emptyImage) {
|
|
53
|
+
dataTransfer.setDragImage(emptyImage, 0, 0)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const prev = dndContext.peek()
|
|
57
|
+
const index = context.peek()?.rowIndex
|
|
58
|
+
|
|
59
|
+
if (index == null || index < 0) {
|
|
60
|
+
console.warn('[prosekit] Invalid row index for drag operation:', index)
|
|
61
|
+
event.preventDefault()
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
dndContext.set({
|
|
66
|
+
...prev,
|
|
67
|
+
direction: 'row',
|
|
68
|
+
dragging: true,
|
|
69
|
+
draggingIndex: index,
|
|
70
|
+
startX: event.clientX,
|
|
71
|
+
startY: event.clientY,
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EventDeclarations,
|
|
3
|
+
PropDeclarations,
|
|
4
|
+
} from '@aria-ui/core'
|
|
5
|
+
import type { Editor } from '@prosekit/core'
|
|
6
|
+
import type { defineTableCommands } from '@prosekit/extensions/table'
|
|
7
|
+
|
|
8
|
+
type TableCommandsExtension = ReturnType<typeof defineTableCommands>
|
|
9
|
+
|
|
10
|
+
export interface TableHandleRowTriggerProps {
|
|
11
|
+
editor: Editor<TableCommandsExtension> | null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** @internal */
|
|
15
|
+
export const tableHandleRowTriggerProps: PropDeclarations<TableHandleRowTriggerProps> = {
|
|
16
|
+
editor: { default: null },
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface TableHandleRowTriggerEvents {
|
|
20
|
+
select: CustomEvent<void>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** @internal */
|
|
24
|
+
export const tableHandleRowTriggerEvents: EventDeclarations<TableHandleRowTriggerEvents> = {
|
|
25
|
+
select: {},
|
|
26
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { EditorView } from '@prosekit/pm/view'
|
|
2
|
+
import {
|
|
3
|
+
cellAround,
|
|
4
|
+
TableMap,
|
|
5
|
+
} from 'prosemirror-tables'
|
|
6
|
+
|
|
7
|
+
export interface HoveringCellInfo {
|
|
8
|
+
rowIndex: number
|
|
9
|
+
colIndex: number
|
|
10
|
+
cellPos: number
|
|
11
|
+
rowFirstCellPos: number
|
|
12
|
+
colFirstCellPos: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface DndInfo {
|
|
16
|
+
dragging: boolean
|
|
17
|
+
direction: 'row' | 'col'
|
|
18
|
+
draggingIndex: number
|
|
19
|
+
droppingIndex: number
|
|
20
|
+
x: number
|
|
21
|
+
y: number
|
|
22
|
+
startX: number
|
|
23
|
+
startY: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isHoveringCellInfoEqual(
|
|
27
|
+
a?: HoveringCellInfo | null,
|
|
28
|
+
b?: HoveringCellInfo | null,
|
|
29
|
+
): boolean {
|
|
30
|
+
if (!a && !b) return true
|
|
31
|
+
if (!a || !b) return false
|
|
32
|
+
return (
|
|
33
|
+
a.rowIndex === b.rowIndex
|
|
34
|
+
&& a.colIndex === b.colIndex
|
|
35
|
+
&& a.cellPos === b.cellPos
|
|
36
|
+
&& a.rowFirstCellPos === b.rowFirstCellPos
|
|
37
|
+
&& a.colFirstCellPos === b.colFirstCellPos
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Copied from https://github.com/ProseMirror/prosemirror-tables/blob/v1.5.0/src/columnresizing.ts#L256
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
function domCellAround(target: HTMLElement | null): HTMLElement | null {
|
|
47
|
+
while (target && target.nodeName != 'TD' && target.nodeName != 'TH') {
|
|
48
|
+
target = target.classList?.contains('ProseMirror')
|
|
49
|
+
? null
|
|
50
|
+
: (target.parentNode as HTMLElement | null)
|
|
51
|
+
}
|
|
52
|
+
return target
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function getHoveringCell(
|
|
56
|
+
view: EditorView,
|
|
57
|
+
event: MouseEvent,
|
|
58
|
+
): HoveringCellInfo | undefined {
|
|
59
|
+
const domCell = domCellAround(event.target as HTMLElement | null)
|
|
60
|
+
if (!domCell) return
|
|
61
|
+
|
|
62
|
+
const { left, top, width, height } = domCell.getBoundingClientRect()
|
|
63
|
+
const eventPos = view.posAtCoords({
|
|
64
|
+
// Use the center coordinates of the cell to ensure we're within the
|
|
65
|
+
// selected cell. This prevents potential issues when the mouse is on the
|
|
66
|
+
// border of two cells.
|
|
67
|
+
left: left + width / 2,
|
|
68
|
+
top: top + height / 2,
|
|
69
|
+
})
|
|
70
|
+
if (!eventPos) return
|
|
71
|
+
|
|
72
|
+
const $cellPos = cellAround(view.state.doc.resolve(eventPos.pos))
|
|
73
|
+
if (!$cellPos) return
|
|
74
|
+
|
|
75
|
+
const map = TableMap.get($cellPos.node(-1))
|
|
76
|
+
const tableStart = $cellPos.start(-1)
|
|
77
|
+
const cellRect = map.findCell($cellPos.pos - tableStart)
|
|
78
|
+
const rowIndex = cellRect.top
|
|
79
|
+
const colIndex = cellRect.left
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
rowIndex,
|
|
83
|
+
colIndex,
|
|
84
|
+
cellPos: $cellPos.pos,
|
|
85
|
+
rowFirstCellPos: getCellPos(map, tableStart, rowIndex, 0),
|
|
86
|
+
colFirstCellPos: getCellPos(map, tableStart, 0, colIndex),
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function getCellPos(
|
|
91
|
+
map: TableMap,
|
|
92
|
+
tableStart: number,
|
|
93
|
+
rowIndex: number,
|
|
94
|
+
colIndex: number,
|
|
95
|
+
) {
|
|
96
|
+
const cellIndex = getCellIndex(map, rowIndex, colIndex)
|
|
97
|
+
const posInTable = map.map[cellIndex]
|
|
98
|
+
return tableStart + posInTable
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getCellIndex(
|
|
102
|
+
map: TableMap,
|
|
103
|
+
rowIndex: number,
|
|
104
|
+
colIndex: number,
|
|
105
|
+
): number {
|
|
106
|
+
return map.width * rowIndex + colIndex
|
|
107
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This file is generated by packages/dev/src/gen-components.ts
|
|
2
|
+
|
|
3
|
+
export { TooltipContentElement } from './tooltip-content/element.gen'
|
|
4
|
+
export { tooltipContentEvents, tooltipContentProps, type TooltipContentEvents, type TooltipContentProps } from './tooltip-content/types'
|
|
5
|
+
export { useTooltipContent } from './tooltip-content/setup'
|
|
6
|
+
|
|
7
|
+
export { TooltipRootElement } from './tooltip-root/element.gen'
|
|
8
|
+
export { tooltipRootEvents, tooltipRootProps, type TooltipRootEvents, type TooltipRootProps } from './tooltip-root/types'
|
|
9
|
+
export { useTooltipRoot } from './tooltip-root/setup'
|
|
10
|
+
|
|
11
|
+
export { TooltipTriggerElement } from './tooltip-trigger/element.gen'
|
|
12
|
+
export { tooltipTriggerEvents, tooltipTriggerProps, type TooltipTriggerEvents, type TooltipTriggerProps } from './tooltip-trigger/types'
|
|
13
|
+
export { useTooltipTrigger } from './tooltip-trigger/setup'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from "@aria-ui/core"
|
|
2
|
+
|
|
3
|
+
import { useTooltipContent } from "./setup"
|
|
4
|
+
import { tooltipContentEvents, tooltipContentProps, type TooltipContentEvents, type TooltipContentProps } from "./types"
|
|
5
|
+
|
|
6
|
+
const TooltipContentElementBase: BaseElementConstructor<TooltipContentProps> = defineCustomElement<
|
|
7
|
+
TooltipContentProps,
|
|
8
|
+
TooltipContentEvents
|
|
9
|
+
>({
|
|
10
|
+
props: tooltipContentProps,
|
|
11
|
+
events: tooltipContentEvents,
|
|
12
|
+
setup: useTooltipContent,
|
|
13
|
+
})
|
|
14
|
+
class TooltipContentElement extends TooltipContentElementBase {}
|
|
15
|
+
|
|
16
|
+
registerCustomElement('prosekit-tooltip-content', TooltipContentElement)
|
|
17
|
+
|
|
18
|
+
export { TooltipContentElement }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTooltipContent } from '@aria-ui/tooltip/elements'
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TooltipContentEvents as Events,
|
|
3
|
+
TooltipContentProps as Props,
|
|
4
|
+
} from '@aria-ui/tooltip/elements'
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
tooltipContentEvents,
|
|
8
|
+
tooltipContentProps,
|
|
9
|
+
} from '@aria-ui/tooltip/elements'
|
|
10
|
+
|
|
11
|
+
export interface TooltipContentProps extends Props {}
|
|
12
|
+
export interface TooltipContentEvents extends Events {}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineCustomElement, registerCustomElement, type BaseElementConstructor } from "@aria-ui/core"
|
|
2
|
+
|
|
3
|
+
import { useTooltipRoot } from "./setup"
|
|
4
|
+
import { tooltipRootEvents, tooltipRootProps, type TooltipRootEvents, type TooltipRootProps } from "./types"
|
|
5
|
+
|
|
6
|
+
const TooltipRootElementBase: BaseElementConstructor<TooltipRootProps> = defineCustomElement<
|
|
7
|
+
TooltipRootProps,
|
|
8
|
+
TooltipRootEvents
|
|
9
|
+
>({
|
|
10
|
+
props: tooltipRootProps,
|
|
11
|
+
events: tooltipRootEvents,
|
|
12
|
+
setup: useTooltipRoot,
|
|
13
|
+
})
|
|
14
|
+
class TooltipRootElement extends TooltipRootElementBase {}
|
|
15
|
+
|
|
16
|
+
registerCustomElement('prosekit-tooltip-root', TooltipRootElement)
|
|
17
|
+
|
|
18
|
+
export { TooltipRootElement }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTooltipRoot } from '@aria-ui/tooltip/elements'
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TooltipRootEvents as Events,
|
|
3
|
+
TooltipRootProps as Props,
|
|
4
|
+
} from '@aria-ui/tooltip/elements'
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
tooltipRootEvents,
|
|
8
|
+
tooltipRootProps,
|
|
9
|
+
} from '@aria-ui/tooltip/elements'
|
|
10
|
+
|
|
11
|
+
export interface TooltipRootProps extends Props {}
|
|
12
|
+
export interface TooltipRootEvents extends Events {}
|