@prosekit/react 0.6.0 → 0.6.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/{create-component-CBvs05W1.js → create-component-DzdxL6Ne.js} +4 -2
- package/dist/create-component-DzdxL6Ne.js.map +1 -0
- package/dist/{create-props-CkTwd_m_.d.ts → create-props-DTgCRwCm.d.ts} +3 -2
- package/dist/create-props-DTgCRwCm.d.ts.map +1 -0
- package/dist/{editor-context-Cci4uqN_.js → editor-context-cG0zkv13.js} +2 -1
- package/dist/editor-context-cG0zkv13.js.map +1 -0
- package/dist/prosekit-react-autocomplete.d.ts +11 -10
- package/dist/prosekit-react-autocomplete.d.ts.map +1 -0
- package/dist/prosekit-react-autocomplete.js +4 -3
- package/dist/prosekit-react-autocomplete.js.map +1 -0
- package/dist/prosekit-react-block-handle.d.ts +9 -8
- package/dist/prosekit-react-block-handle.d.ts.map +1 -0
- package/dist/prosekit-react-block-handle.js +4 -3
- package/dist/prosekit-react-block-handle.js.map +1 -0
- package/dist/prosekit-react-drop-indicator.d.ts +5 -4
- package/dist/prosekit-react-drop-indicator.d.ts.map +1 -0
- package/dist/prosekit-react-drop-indicator.js +4 -3
- package/dist/prosekit-react-drop-indicator.js.map +1 -0
- package/dist/prosekit-react-inline-popover.d.ts +5 -4
- package/dist/prosekit-react-inline-popover.d.ts.map +1 -0
- package/dist/prosekit-react-inline-popover.js +4 -3
- package/dist/prosekit-react-inline-popover.js.map +1 -0
- package/dist/prosekit-react-popover.d.ts +9 -8
- package/dist/prosekit-react-popover.d.ts.map +1 -0
- package/dist/prosekit-react-popover.js +4 -3
- package/dist/prosekit-react-popover.js.map +1 -0
- package/dist/prosekit-react-resizable.d.ts +7 -6
- package/dist/prosekit-react-resizable.d.ts.map +1 -0
- package/dist/prosekit-react-resizable.js +4 -3
- package/dist/prosekit-react-resizable.js.map +1 -0
- package/dist/prosekit-react-table-handle.d.ts +21 -20
- package/dist/prosekit-react-table-handle.d.ts.map +1 -0
- package/dist/prosekit-react-table-handle.js +4 -3
- package/dist/prosekit-react-table-handle.js.map +1 -0
- package/dist/prosekit-react-tooltip.d.ts +9 -8
- package/dist/prosekit-react-tooltip.d.ts.map +1 -0
- package/dist/prosekit-react-tooltip.js +4 -3
- package/dist/prosekit-react-tooltip.js.map +1 -0
- package/dist/prosekit-react.d.ts +94 -85
- package/dist/prosekit-react.d.ts.map +1 -0
- package/dist/prosekit-react.js +23 -29
- package/dist/prosekit-react.js.map +1 -0
- package/package.json +21 -21
- package/src/components/autocomplete/autocomplete-empty.gen.ts +34 -0
- package/src/components/autocomplete/autocomplete-item.gen.ts +34 -0
- package/src/components/autocomplete/autocomplete-list.gen.ts +34 -0
- package/src/components/autocomplete/autocomplete-popover.gen.ts +34 -0
- package/src/components/autocomplete/index.gen.ts +7 -0
- package/src/components/block-handle/block-handle-add.gen.ts +34 -0
- package/src/components/block-handle/block-handle-draggable.gen.ts +34 -0
- package/src/components/block-handle/block-handle-popover.gen.ts +34 -0
- package/src/components/block-handle/index.gen.ts +5 -0
- package/src/components/create-component.ts +137 -0
- package/src/components/create-props.ts +13 -0
- package/src/components/drop-indicator/drop-indicator.gen.ts +34 -0
- package/src/components/drop-indicator/index.gen.ts +1 -0
- package/src/components/inline-popover/index.gen.ts +1 -0
- package/src/components/inline-popover/inline-popover.gen.ts +34 -0
- package/src/components/merge-refs.ts +35 -0
- package/src/components/popover/index.gen.ts +5 -0
- package/src/components/popover/popover-content.gen.ts +34 -0
- package/src/components/popover/popover-root.gen.ts +34 -0
- package/src/components/popover/popover-trigger.gen.ts +34 -0
- package/src/components/prosekit.ts +37 -0
- package/src/components/resizable/index.gen.ts +3 -0
- package/src/components/resizable/resizable-handle.gen.ts +34 -0
- package/src/components/resizable/resizable-root.gen.ts +34 -0
- package/src/components/table-handle/index.gen.ts +17 -0
- package/src/components/table-handle/table-handle-column-root.gen.ts +34 -0
- package/src/components/table-handle/table-handle-column-trigger.gen.ts +34 -0
- package/src/components/table-handle/table-handle-drag-preview.gen.ts +34 -0
- package/src/components/table-handle/table-handle-drop-indicator.gen.ts +34 -0
- package/src/components/table-handle/table-handle-popover-content.gen.ts +34 -0
- package/src/components/table-handle/table-handle-popover-item.gen.ts +34 -0
- package/src/components/table-handle/table-handle-root.gen.ts +34 -0
- package/src/components/table-handle/table-handle-row-root.gen.ts +34 -0
- package/src/components/table-handle/table-handle-row-trigger.gen.ts +34 -0
- package/src/components/tooltip/index.gen.ts +5 -0
- package/src/components/tooltip/tooltip-content.gen.ts +34 -0
- package/src/components/tooltip/tooltip-root.gen.ts +34 -0
- package/src/components/tooltip/tooltip-trigger.gen.ts +34 -0
- package/src/contexts/editor-context.ts +23 -0
- package/src/extensions/react-mark-view.ts +93 -0
- package/src/extensions/react-node-view.ts +93 -0
- package/src/hooks/use-doc-change.ts +24 -0
- package/src/hooks/use-editor-derived-value.ts +85 -0
- package/src/hooks/use-editor-extension.ts +24 -0
- package/src/hooks/use-editor.ts +62 -0
- package/src/hooks/use-extension.ts +41 -0
- package/src/hooks/use-keymap.ts +15 -0
- package/src/hooks/use-priority-extension.ts +18 -0
- package/src/hooks/use-state-update.ts +24 -0
- package/src/index.ts +29 -0
- package/src/types.ts +6 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AutocompleteEmptyElement,
|
|
3
|
+
type AutocompleteEmptyProps as Props,
|
|
4
|
+
type AutocompleteEmptyEvents as Events,
|
|
5
|
+
autocompleteEmptyProps,
|
|
6
|
+
autocompleteEmptyEvents,
|
|
7
|
+
} from '@prosekit/web/autocomplete'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link AutocompleteEmpty} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface AutocompleteEmptyProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const AutocompleteEmpty: ForwardRefExoticComponent<
|
|
23
|
+
AutocompleteEmptyProps &
|
|
24
|
+
RefAttributes<AutocompleteEmptyElement> &
|
|
25
|
+
HTMLAttributes<AutocompleteEmptyElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
AutocompleteEmptyProps,
|
|
28
|
+
AutocompleteEmptyElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-autocomplete-empty',
|
|
31
|
+
'AutocompleteEmpty',
|
|
32
|
+
Object.keys(autocompleteEmptyProps),
|
|
33
|
+
Object.keys(autocompleteEmptyEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AutocompleteItemElement,
|
|
3
|
+
type AutocompleteItemProps as Props,
|
|
4
|
+
type AutocompleteItemEvents as Events,
|
|
5
|
+
autocompleteItemProps,
|
|
6
|
+
autocompleteItemEvents,
|
|
7
|
+
} from '@prosekit/web/autocomplete'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link AutocompleteItem} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface AutocompleteItemProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const AutocompleteItem: ForwardRefExoticComponent<
|
|
23
|
+
AutocompleteItemProps &
|
|
24
|
+
RefAttributes<AutocompleteItemElement> &
|
|
25
|
+
HTMLAttributes<AutocompleteItemElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
AutocompleteItemProps,
|
|
28
|
+
AutocompleteItemElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-autocomplete-item',
|
|
31
|
+
'AutocompleteItem',
|
|
32
|
+
Object.keys(autocompleteItemProps),
|
|
33
|
+
Object.keys(autocompleteItemEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AutocompleteListElement,
|
|
3
|
+
type AutocompleteListProps as Props,
|
|
4
|
+
type AutocompleteListEvents as Events,
|
|
5
|
+
autocompleteListProps,
|
|
6
|
+
autocompleteListEvents,
|
|
7
|
+
} from '@prosekit/web/autocomplete'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link AutocompleteList} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface AutocompleteListProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const AutocompleteList: ForwardRefExoticComponent<
|
|
23
|
+
AutocompleteListProps &
|
|
24
|
+
RefAttributes<AutocompleteListElement> &
|
|
25
|
+
HTMLAttributes<AutocompleteListElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
AutocompleteListProps,
|
|
28
|
+
AutocompleteListElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-autocomplete-list',
|
|
31
|
+
'AutocompleteList',
|
|
32
|
+
Object.keys(autocompleteListProps),
|
|
33
|
+
Object.keys(autocompleteListEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AutocompletePopoverElement,
|
|
3
|
+
type AutocompletePopoverProps as Props,
|
|
4
|
+
type AutocompletePopoverEvents as Events,
|
|
5
|
+
autocompletePopoverProps,
|
|
6
|
+
autocompletePopoverEvents,
|
|
7
|
+
} from '@prosekit/web/autocomplete'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link AutocompletePopover} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface AutocompletePopoverProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const AutocompletePopover: ForwardRefExoticComponent<
|
|
23
|
+
AutocompletePopoverProps &
|
|
24
|
+
RefAttributes<AutocompletePopoverElement> &
|
|
25
|
+
HTMLAttributes<AutocompletePopoverElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
AutocompletePopoverProps,
|
|
28
|
+
AutocompletePopoverElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-autocomplete-popover',
|
|
31
|
+
'AutocompletePopover',
|
|
32
|
+
Object.keys(autocompletePopoverProps),
|
|
33
|
+
Object.keys(autocompletePopoverEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { AutocompleteEmpty, type AutocompleteEmptyProps } from './autocomplete-empty.gen'
|
|
2
|
+
|
|
3
|
+
export { AutocompleteItem, type AutocompleteItemProps } from './autocomplete-item.gen'
|
|
4
|
+
|
|
5
|
+
export { AutocompleteList, type AutocompleteListProps } from './autocomplete-list.gen'
|
|
6
|
+
|
|
7
|
+
export { AutocompletePopover, type AutocompletePopoverProps } from './autocomplete-popover.gen'
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BlockHandleAddElement,
|
|
3
|
+
type BlockHandleAddProps as Props,
|
|
4
|
+
type BlockHandleAddEvents as Events,
|
|
5
|
+
blockHandleAddProps,
|
|
6
|
+
blockHandleAddEvents,
|
|
7
|
+
} from '@prosekit/web/block-handle'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link BlockHandleAdd} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface BlockHandleAddProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const BlockHandleAdd: ForwardRefExoticComponent<
|
|
23
|
+
BlockHandleAddProps &
|
|
24
|
+
RefAttributes<BlockHandleAddElement> &
|
|
25
|
+
HTMLAttributes<BlockHandleAddElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
BlockHandleAddProps,
|
|
28
|
+
BlockHandleAddElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-block-handle-add',
|
|
31
|
+
'BlockHandleAdd',
|
|
32
|
+
Object.keys(blockHandleAddProps),
|
|
33
|
+
Object.keys(blockHandleAddEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BlockHandleDraggableElement,
|
|
3
|
+
type BlockHandleDraggableProps as Props,
|
|
4
|
+
type BlockHandleDraggableEvents as Events,
|
|
5
|
+
blockHandleDraggableProps,
|
|
6
|
+
blockHandleDraggableEvents,
|
|
7
|
+
} from '@prosekit/web/block-handle'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link BlockHandleDraggable} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface BlockHandleDraggableProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const BlockHandleDraggable: ForwardRefExoticComponent<
|
|
23
|
+
BlockHandleDraggableProps &
|
|
24
|
+
RefAttributes<BlockHandleDraggableElement> &
|
|
25
|
+
HTMLAttributes<BlockHandleDraggableElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
BlockHandleDraggableProps,
|
|
28
|
+
BlockHandleDraggableElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-block-handle-draggable',
|
|
31
|
+
'BlockHandleDraggable',
|
|
32
|
+
Object.keys(blockHandleDraggableProps),
|
|
33
|
+
Object.keys(blockHandleDraggableEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BlockHandlePopoverElement,
|
|
3
|
+
type BlockHandlePopoverProps as Props,
|
|
4
|
+
type BlockHandlePopoverEvents as Events,
|
|
5
|
+
blockHandlePopoverProps,
|
|
6
|
+
blockHandlePopoverEvents,
|
|
7
|
+
} from '@prosekit/web/block-handle'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link BlockHandlePopover} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface BlockHandlePopoverProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const BlockHandlePopover: ForwardRefExoticComponent<
|
|
23
|
+
BlockHandlePopoverProps &
|
|
24
|
+
RefAttributes<BlockHandlePopoverElement> &
|
|
25
|
+
HTMLAttributes<BlockHandlePopoverElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
BlockHandlePopoverProps,
|
|
28
|
+
BlockHandlePopoverElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-block-handle-popover',
|
|
31
|
+
'BlockHandlePopover',
|
|
32
|
+
Object.keys(blockHandlePopoverProps),
|
|
33
|
+
Object.keys(blockHandlePopoverEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { BlockHandleAdd, type BlockHandleAddProps } from './block-handle-add.gen'
|
|
2
|
+
|
|
3
|
+
export { BlockHandleDraggable, type BlockHandleDraggableProps } from './block-handle-draggable.gen'
|
|
4
|
+
|
|
5
|
+
export { BlockHandlePopover, type BlockHandlePopoverProps } from './block-handle-popover.gen'
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { AnyFunction } from '@prosekit/core'
|
|
2
|
+
import {
|
|
3
|
+
createElement,
|
|
4
|
+
forwardRef,
|
|
5
|
+
useEffect,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
type ForwardRefExoticComponent,
|
|
11
|
+
type HTMLAttributes,
|
|
12
|
+
type RefAttributes,
|
|
13
|
+
} from 'react'
|
|
14
|
+
|
|
15
|
+
import { useEditorContext } from '../contexts/editor-context'
|
|
16
|
+
|
|
17
|
+
import { mergeRefs } from './merge-refs'
|
|
18
|
+
|
|
19
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect
|
|
20
|
+
|
|
21
|
+
export function createComponent<
|
|
22
|
+
Props extends object,
|
|
23
|
+
CustomElement extends HTMLElement,
|
|
24
|
+
>(
|
|
25
|
+
tagName: string,
|
|
26
|
+
displayName: string,
|
|
27
|
+
propNames: string[],
|
|
28
|
+
eventNames: string[],
|
|
29
|
+
): ForwardRefExoticComponent<
|
|
30
|
+
Partial<Props> & RefAttributes<CustomElement> & HTMLAttributes<CustomElement>
|
|
31
|
+
> {
|
|
32
|
+
const hasEditor = propNames.includes('editor')
|
|
33
|
+
const lowerCaseEventNameMap = new Map(
|
|
34
|
+
eventNames.map((name) => [name.toLowerCase(), name]),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
const Component = forwardRef<any, any>((props: Props, ref) => {
|
|
38
|
+
const [el, setEl] = useState<HTMLElement | null>(null)
|
|
39
|
+
|
|
40
|
+
const properties: Record<string, unknown> = {}
|
|
41
|
+
const attributes: Record<string, unknown> = {}
|
|
42
|
+
const eventHandlersRef = useRef<Record<string, AnyFunction>>({})
|
|
43
|
+
const eventHandlers: Record<string, AnyFunction> = {}
|
|
44
|
+
|
|
45
|
+
for (const [name, value] of Object.entries(props)) {
|
|
46
|
+
if (value === undefined) {
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (propNames.includes(name)) {
|
|
51
|
+
properties[name] = value
|
|
52
|
+
continue
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (name.startsWith('on')) {
|
|
56
|
+
const lowerCaseEventName = name.slice(2).toLowerCase()
|
|
57
|
+
const eventName = lowerCaseEventNameMap.get(lowerCaseEventName)
|
|
58
|
+
if (eventName) {
|
|
59
|
+
const extractDetail = eventName.endsWith('Change')
|
|
60
|
+
eventHandlers[eventName] = (event: Event) => {
|
|
61
|
+
const handler = value as AnyFunction | null
|
|
62
|
+
if (typeof handler === 'function') {
|
|
63
|
+
handler(extractDetail ? (event as CustomEvent).detail : event)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
continue
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (name === 'className') {
|
|
71
|
+
attributes['class'] = value
|
|
72
|
+
} else {
|
|
73
|
+
attributes[name] = value
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const editor = useEditorContext()
|
|
78
|
+
|
|
79
|
+
if (hasEditor && editor && !properties['editor']) {
|
|
80
|
+
properties['editor'] = editor
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Set all properties.
|
|
84
|
+
useIsomorphicLayoutEffect(() => {
|
|
85
|
+
if (!el) return
|
|
86
|
+
for (const [name, value] of Object.entries(properties)) {
|
|
87
|
+
if (value !== undefined) {
|
|
88
|
+
// @ts-expect-error: we know that name is a valid property name
|
|
89
|
+
el[name] = value as unknown
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, [el, ...propNames.map((name) => properties[name])])
|
|
93
|
+
|
|
94
|
+
// Put all event listeners extracted from `props` into `eventHandlersRef`.
|
|
95
|
+
useIsomorphicLayoutEffect(() => {
|
|
96
|
+
eventHandlersRef.current = eventHandlers
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// Register the event listeners to the element.
|
|
100
|
+
useIsomorphicLayoutEffect(() => {
|
|
101
|
+
if (!el) {
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const fixedEventHandlers: Record<string, AnyFunction> = {}
|
|
106
|
+
|
|
107
|
+
for (const eventName of eventNames) {
|
|
108
|
+
fixedEventHandlers[eventName] = (event: Event) => {
|
|
109
|
+
eventHandlersRef.current[eventName]?.(event)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (const [name, handler] of Object.entries(fixedEventHandlers)) {
|
|
114
|
+
el.addEventListener(name, handler)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return () => {
|
|
118
|
+
for (const [name, handler] of Object.entries(fixedEventHandlers)) {
|
|
119
|
+
el.removeEventListener(name, handler)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}, [el])
|
|
123
|
+
|
|
124
|
+
const mergedRef = useMemo(() => mergeRefs([ref, setEl]), [ref])
|
|
125
|
+
|
|
126
|
+
return createElement(tagName, {
|
|
127
|
+
...attributes,
|
|
128
|
+
// Suppress hydration warnings for web components as the attributes are set after the component is mounted.
|
|
129
|
+
suppressHydrationWarning: true,
|
|
130
|
+
ref: mergedRef,
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
Component.displayName = displayName
|
|
135
|
+
|
|
136
|
+
return Component
|
|
137
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type CreateProps<
|
|
2
|
+
Props extends { [PropName in keyof Props]: unknown },
|
|
3
|
+
Events extends { [EventName in keyof Events]: CustomEvent },
|
|
4
|
+
> = Props & CreateEventProps<Events>
|
|
5
|
+
|
|
6
|
+
type CreateEventProps<
|
|
7
|
+
Events extends { [EventName in keyof Events]: CustomEvent },
|
|
8
|
+
> = {
|
|
9
|
+
[EventName in keyof Events as `on${Capitalize<string & EventName>}`]: (
|
|
10
|
+
event: EventName extends `${string}Change` ? Events[EventName]['detail']
|
|
11
|
+
: Events[EventName],
|
|
12
|
+
) => void
|
|
13
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type DropIndicatorElement,
|
|
3
|
+
type DropIndicatorProps as Props,
|
|
4
|
+
type DropIndicatorEvents as Events,
|
|
5
|
+
dropIndicatorProps,
|
|
6
|
+
dropIndicatorEvents,
|
|
7
|
+
} from '@prosekit/web/drop-indicator'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link DropIndicator} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface DropIndicatorProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const DropIndicator: ForwardRefExoticComponent<
|
|
23
|
+
DropIndicatorProps &
|
|
24
|
+
RefAttributes<DropIndicatorElement> &
|
|
25
|
+
HTMLAttributes<DropIndicatorElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
DropIndicatorProps,
|
|
28
|
+
DropIndicatorElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-drop-indicator',
|
|
31
|
+
'DropIndicator',
|
|
32
|
+
Object.keys(dropIndicatorProps),
|
|
33
|
+
Object.keys(dropIndicatorEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DropIndicator, type DropIndicatorProps } from './drop-indicator.gen'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InlinePopover, type InlinePopoverProps } from './inline-popover.gen'
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type InlinePopoverElement,
|
|
3
|
+
type InlinePopoverProps as Props,
|
|
4
|
+
type InlinePopoverEvents as Events,
|
|
5
|
+
inlinePopoverProps,
|
|
6
|
+
inlinePopoverEvents,
|
|
7
|
+
} from '@prosekit/web/inline-popover'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link InlinePopover} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface InlinePopoverProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const InlinePopover: ForwardRefExoticComponent<
|
|
23
|
+
InlinePopoverProps &
|
|
24
|
+
RefAttributes<InlinePopoverElement> &
|
|
25
|
+
HTMLAttributes<InlinePopoverElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
InlinePopoverProps,
|
|
28
|
+
InlinePopoverElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-inline-popover',
|
|
31
|
+
'InlinePopover',
|
|
32
|
+
Object.keys(inlinePopoverProps),
|
|
33
|
+
Object.keys(inlinePopoverEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Ref } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Assigns a value to a ref.
|
|
5
|
+
* @returns The ref cleanup callback, if any.
|
|
6
|
+
*/
|
|
7
|
+
function assignRef<T>(
|
|
8
|
+
ref: Ref<T> | undefined,
|
|
9
|
+
value: T | null,
|
|
10
|
+
): VoidFunction | undefined | void {
|
|
11
|
+
if (typeof ref === 'function') {
|
|
12
|
+
return ref(value)
|
|
13
|
+
} else if (ref) {
|
|
14
|
+
ref.current = value
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Merges multiple refs into a single one.
|
|
20
|
+
*/
|
|
21
|
+
export function mergeRefs<T>(refs: (Ref<T> | undefined)[]): Ref<T> {
|
|
22
|
+
return (value: T | null) => {
|
|
23
|
+
const cleanups: VoidFunction[] = []
|
|
24
|
+
|
|
25
|
+
for (const ref of refs) {
|
|
26
|
+
const cleanup = assignRef(ref, value)
|
|
27
|
+
const isCleanup = typeof cleanup === 'function'
|
|
28
|
+
cleanups.push(isCleanup ? cleanup : () => assignRef(ref, null))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
for (const cleanup of cleanups) cleanup()
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type PopoverContentElement,
|
|
3
|
+
type PopoverContentProps as Props,
|
|
4
|
+
type PopoverContentEvents as Events,
|
|
5
|
+
popoverContentProps,
|
|
6
|
+
popoverContentEvents,
|
|
7
|
+
} from '@prosekit/web/popover'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link PopoverContent} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface PopoverContentProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const PopoverContent: ForwardRefExoticComponent<
|
|
23
|
+
PopoverContentProps &
|
|
24
|
+
RefAttributes<PopoverContentElement> &
|
|
25
|
+
HTMLAttributes<PopoverContentElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
PopoverContentProps,
|
|
28
|
+
PopoverContentElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-popover-content',
|
|
31
|
+
'PopoverContent',
|
|
32
|
+
Object.keys(popoverContentProps),
|
|
33
|
+
Object.keys(popoverContentEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type PopoverRootElement,
|
|
3
|
+
type PopoverRootProps as Props,
|
|
4
|
+
type PopoverRootEvents as Events,
|
|
5
|
+
popoverRootProps,
|
|
6
|
+
popoverRootEvents,
|
|
7
|
+
} from '@prosekit/web/popover'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link PopoverRoot} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface PopoverRootProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const PopoverRoot: ForwardRefExoticComponent<
|
|
23
|
+
PopoverRootProps &
|
|
24
|
+
RefAttributes<PopoverRootElement> &
|
|
25
|
+
HTMLAttributes<PopoverRootElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
PopoverRootProps,
|
|
28
|
+
PopoverRootElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-popover-root',
|
|
31
|
+
'PopoverRoot',
|
|
32
|
+
Object.keys(popoverRootProps),
|
|
33
|
+
Object.keys(popoverRootEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type PopoverTriggerElement,
|
|
3
|
+
type PopoverTriggerProps as Props,
|
|
4
|
+
type PopoverTriggerEvents as Events,
|
|
5
|
+
popoverTriggerProps,
|
|
6
|
+
popoverTriggerEvents,
|
|
7
|
+
} from '@prosekit/web/popover'
|
|
8
|
+
import type {
|
|
9
|
+
ForwardRefExoticComponent,
|
|
10
|
+
HTMLAttributes,
|
|
11
|
+
RefAttributes,
|
|
12
|
+
} from 'react'
|
|
13
|
+
|
|
14
|
+
import { createComponent } from '../create-component'
|
|
15
|
+
import type { CreateProps } from '../create-props'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Props for the {@link PopoverTrigger} component.
|
|
19
|
+
*/
|
|
20
|
+
export interface PopoverTriggerProps extends Partial<CreateProps<Props, Events>> {}
|
|
21
|
+
|
|
22
|
+
export const PopoverTrigger: ForwardRefExoticComponent<
|
|
23
|
+
PopoverTriggerProps &
|
|
24
|
+
RefAttributes<PopoverTriggerElement> &
|
|
25
|
+
HTMLAttributes<PopoverTriggerElement>
|
|
26
|
+
> = createComponent<
|
|
27
|
+
PopoverTriggerProps,
|
|
28
|
+
PopoverTriggerElement
|
|
29
|
+
>(
|
|
30
|
+
'prosekit-popover-trigger',
|
|
31
|
+
'PopoverTrigger',
|
|
32
|
+
Object.keys(popoverTriggerProps),
|
|
33
|
+
Object.keys(popoverTriggerEvents),
|
|
34
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Editor } from '@prosekit/core'
|
|
2
|
+
import { ProsemirrorAdapterProvider } from '@prosemirror-adapter/react'
|
|
3
|
+
import {
|
|
4
|
+
createElement,
|
|
5
|
+
type ComponentType,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
} from 'react'
|
|
8
|
+
|
|
9
|
+
import { EditorContextProvider } from '../contexts/editor-context'
|
|
10
|
+
import { ReactMarkViewConsumer } from '../extensions/react-mark-view'
|
|
11
|
+
import { ReactNodeViewConsumer } from '../extensions/react-node-view'
|
|
12
|
+
|
|
13
|
+
export interface ProseKitProps {
|
|
14
|
+
editor: Editor
|
|
15
|
+
children?: ReactNode
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The root component for a ProseKit editor.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export const ProseKit: ComponentType<ProseKitProps> = (props) => {
|
|
24
|
+
const { editor, children } = props
|
|
25
|
+
|
|
26
|
+
return createElement(
|
|
27
|
+
ProsemirrorAdapterProvider,
|
|
28
|
+
null,
|
|
29
|
+
createElement(
|
|
30
|
+
EditorContextProvider,
|
|
31
|
+
{ value: editor },
|
|
32
|
+
createElement(ReactNodeViewConsumer),
|
|
33
|
+
createElement(ReactMarkViewConsumer),
|
|
34
|
+
children,
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
}
|