@prosekit/preact 0.5.0 → 0.6.0

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.
Files changed (94) hide show
  1. package/dist/create-component-D7yDR5ux.js +2 -1
  2. package/dist/create-component-D7yDR5ux.js.map +1 -0
  3. package/dist/{create-props-CkTwd_m_.d.ts → create-props-EGV61dJR.d.ts} +3 -2
  4. package/dist/create-props-EGV61dJR.d.ts.map +1 -0
  5. package/dist/editor-context-imq7MdJr.js +2 -1
  6. package/dist/editor-context-imq7MdJr.js.map +1 -0
  7. package/dist/prosekit-preact-autocomplete.d.ts +12 -11
  8. package/dist/prosekit-preact-autocomplete.d.ts.map +1 -0
  9. package/dist/prosekit-preact-autocomplete.js +2 -1
  10. package/dist/prosekit-preact-autocomplete.js.map +1 -0
  11. package/dist/prosekit-preact-block-handle.d.ts +9 -8
  12. package/dist/prosekit-preact-block-handle.d.ts.map +1 -0
  13. package/dist/prosekit-preact-block-handle.js +2 -1
  14. package/dist/prosekit-preact-block-handle.js.map +1 -0
  15. package/dist/prosekit-preact-drop-indicator.d.ts +5 -4
  16. package/dist/prosekit-preact-drop-indicator.d.ts.map +1 -0
  17. package/dist/prosekit-preact-drop-indicator.js +2 -1
  18. package/dist/prosekit-preact-drop-indicator.js.map +1 -0
  19. package/dist/prosekit-preact-inline-popover.d.ts +5 -4
  20. package/dist/prosekit-preact-inline-popover.d.ts.map +1 -0
  21. package/dist/prosekit-preact-inline-popover.js +2 -1
  22. package/dist/prosekit-preact-inline-popover.js.map +1 -0
  23. package/dist/prosekit-preact-popover.d.ts +9 -8
  24. package/dist/prosekit-preact-popover.d.ts.map +1 -0
  25. package/dist/prosekit-preact-popover.js +2 -1
  26. package/dist/prosekit-preact-popover.js.map +1 -0
  27. package/dist/prosekit-preact-resizable.d.ts +7 -6
  28. package/dist/prosekit-preact-resizable.d.ts.map +1 -0
  29. package/dist/prosekit-preact-resizable.js +2 -1
  30. package/dist/prosekit-preact-resizable.js.map +1 -0
  31. package/dist/prosekit-preact-table-handle.d.ts +21 -20
  32. package/dist/prosekit-preact-table-handle.d.ts.map +1 -0
  33. package/dist/prosekit-preact-table-handle.js +2 -1
  34. package/dist/prosekit-preact-table-handle.js.map +1 -0
  35. package/dist/prosekit-preact-tooltip.d.ts +9 -8
  36. package/dist/prosekit-preact-tooltip.d.ts.map +1 -0
  37. package/dist/prosekit-preact-tooltip.js +2 -1
  38. package/dist/prosekit-preact-tooltip.js.map +1 -0
  39. package/dist/prosekit-preact.d.ts +124 -34
  40. package/dist/prosekit-preact.d.ts.map +1 -0
  41. package/dist/prosekit-preact.js +137 -23
  42. package/dist/prosekit-preact.js.map +1 -0
  43. package/package.json +16 -14
  44. package/src/components/autocomplete/autocomplete-empty.gen.ts +34 -0
  45. package/src/components/autocomplete/autocomplete-item.gen.ts +34 -0
  46. package/src/components/autocomplete/autocomplete-list.gen.ts +34 -0
  47. package/src/components/autocomplete/autocomplete-popover.gen.ts +34 -0
  48. package/src/components/autocomplete/index.gen.ts +7 -0
  49. package/src/components/block-handle/block-handle-add.gen.ts +34 -0
  50. package/src/components/block-handle/block-handle-draggable.gen.ts +34 -0
  51. package/src/components/block-handle/block-handle-popover.gen.ts +34 -0
  52. package/src/components/block-handle/index.gen.ts +5 -0
  53. package/src/components/create-component.ts +135 -0
  54. package/src/components/create-props.ts +13 -0
  55. package/src/components/drop-indicator/drop-indicator.gen.ts +34 -0
  56. package/src/components/drop-indicator/index.gen.ts +1 -0
  57. package/src/components/inline-popover/index.gen.ts +1 -0
  58. package/src/components/inline-popover/inline-popover.gen.ts +34 -0
  59. package/src/components/merge-refs.ts +35 -0
  60. package/src/components/popover/index.gen.ts +5 -0
  61. package/src/components/popover/popover-content.gen.ts +34 -0
  62. package/src/components/popover/popover-root.gen.ts +34 -0
  63. package/src/components/popover/popover-trigger.gen.ts +34 -0
  64. package/src/components/prosekit.ts +37 -0
  65. package/src/components/resizable/index.gen.ts +3 -0
  66. package/src/components/resizable/resizable-handle.gen.ts +34 -0
  67. package/src/components/resizable/resizable-root.gen.ts +34 -0
  68. package/src/components/table-handle/index.gen.ts +17 -0
  69. package/src/components/table-handle/table-handle-column-root.gen.ts +34 -0
  70. package/src/components/table-handle/table-handle-column-trigger.gen.ts +34 -0
  71. package/src/components/table-handle/table-handle-drag-preview.gen.ts +34 -0
  72. package/src/components/table-handle/table-handle-drop-indicator.gen.ts +34 -0
  73. package/src/components/table-handle/table-handle-popover-content.gen.ts +34 -0
  74. package/src/components/table-handle/table-handle-popover-item.gen.ts +34 -0
  75. package/src/components/table-handle/table-handle-root.gen.ts +34 -0
  76. package/src/components/table-handle/table-handle-row-root.gen.ts +34 -0
  77. package/src/components/table-handle/table-handle-row-trigger.gen.ts +34 -0
  78. package/src/components/tooltip/index.gen.ts +5 -0
  79. package/src/components/tooltip/tooltip-content.gen.ts +34 -0
  80. package/src/components/tooltip/tooltip-root.gen.ts +34 -0
  81. package/src/components/tooltip/tooltip-trigger.gen.ts +34 -0
  82. package/src/contexts/editor-context.ts +23 -0
  83. package/src/extensions/preact-mark-view.ts +93 -0
  84. package/src/extensions/preact-node-view.ts +93 -0
  85. package/src/hooks/use-doc-change.ts +24 -0
  86. package/src/hooks/use-editor-derived-value.ts +81 -0
  87. package/src/hooks/use-editor-extension.ts +24 -0
  88. package/src/hooks/use-editor.ts +57 -0
  89. package/src/hooks/use-extension.ts +41 -0
  90. package/src/hooks/use-keymap.ts +15 -0
  91. package/src/hooks/use-priority-extension.ts +18 -0
  92. package/src/hooks/use-state-update.ts +24 -0
  93. package/src/index.ts +32 -0
  94. package/src/types.ts +16 -0
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TableHandleColumnRootElement,
3
+ type TableHandleColumnRootProps as Props,
4
+ type TableHandleColumnRootEvents as Events,
5
+ tableHandleColumnRootProps,
6
+ tableHandleColumnRootEvents,
7
+ } from '@prosekit/web/table-handle'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TableHandleColumnRoot} component.
19
+ */
20
+ export interface TableHandleColumnRootProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TableHandleColumnRoot: ForwardRefExoticComponent<
23
+ Partial<TableHandleColumnRootProps> &
24
+ RefAttributes<TableHandleColumnRootElement> &
25
+ HTMLAttributes<TableHandleColumnRootElement>
26
+ > = createComponent<
27
+ TableHandleColumnRootProps,
28
+ TableHandleColumnRootElement
29
+ >(
30
+ 'prosekit-table-handle-column-root',
31
+ 'TableHandleColumnRoot',
32
+ Object.keys(tableHandleColumnRootProps),
33
+ Object.keys(tableHandleColumnRootEvents),
34
+ )
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TableHandleColumnTriggerElement,
3
+ type TableHandleColumnTriggerProps as Props,
4
+ type TableHandleColumnTriggerEvents as Events,
5
+ tableHandleColumnTriggerProps,
6
+ tableHandleColumnTriggerEvents,
7
+ } from '@prosekit/web/table-handle'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TableHandleColumnTrigger} component.
19
+ */
20
+ export interface TableHandleColumnTriggerProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TableHandleColumnTrigger: ForwardRefExoticComponent<
23
+ Partial<TableHandleColumnTriggerProps> &
24
+ RefAttributes<TableHandleColumnTriggerElement> &
25
+ HTMLAttributes<TableHandleColumnTriggerElement>
26
+ > = createComponent<
27
+ TableHandleColumnTriggerProps,
28
+ TableHandleColumnTriggerElement
29
+ >(
30
+ 'prosekit-table-handle-column-trigger',
31
+ 'TableHandleColumnTrigger',
32
+ Object.keys(tableHandleColumnTriggerProps),
33
+ Object.keys(tableHandleColumnTriggerEvents),
34
+ )
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TableHandleDragPreviewElement,
3
+ type TableHandleDragPreviewProps as Props,
4
+ type TableHandleDragPreviewEvents as Events,
5
+ tableHandleDragPreviewProps,
6
+ tableHandleDragPreviewEvents,
7
+ } from '@prosekit/web/table-handle'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TableHandleDragPreview} component.
19
+ */
20
+ export interface TableHandleDragPreviewProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TableHandleDragPreview: ForwardRefExoticComponent<
23
+ Partial<TableHandleDragPreviewProps> &
24
+ RefAttributes<TableHandleDragPreviewElement> &
25
+ HTMLAttributes<TableHandleDragPreviewElement>
26
+ > = createComponent<
27
+ TableHandleDragPreviewProps,
28
+ TableHandleDragPreviewElement
29
+ >(
30
+ 'prosekit-table-handle-drag-preview',
31
+ 'TableHandleDragPreview',
32
+ Object.keys(tableHandleDragPreviewProps),
33
+ Object.keys(tableHandleDragPreviewEvents),
34
+ )
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TableHandleDropIndicatorElement,
3
+ type TableHandleDropIndicatorProps as Props,
4
+ type TableHandleDropIndicatorEvents as Events,
5
+ tableHandleDropIndicatorProps,
6
+ tableHandleDropIndicatorEvents,
7
+ } from '@prosekit/web/table-handle'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TableHandleDropIndicator} component.
19
+ */
20
+ export interface TableHandleDropIndicatorProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TableHandleDropIndicator: ForwardRefExoticComponent<
23
+ Partial<TableHandleDropIndicatorProps> &
24
+ RefAttributes<TableHandleDropIndicatorElement> &
25
+ HTMLAttributes<TableHandleDropIndicatorElement>
26
+ > = createComponent<
27
+ TableHandleDropIndicatorProps,
28
+ TableHandleDropIndicatorElement
29
+ >(
30
+ 'prosekit-table-handle-drop-indicator',
31
+ 'TableHandleDropIndicator',
32
+ Object.keys(tableHandleDropIndicatorProps),
33
+ Object.keys(tableHandleDropIndicatorEvents),
34
+ )
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TableHandlePopoverContentElement,
3
+ type TableHandlePopoverContentProps as Props,
4
+ type TableHandlePopoverContentEvents as Events,
5
+ tableHandlePopoverContentProps,
6
+ tableHandlePopoverContentEvents,
7
+ } from '@prosekit/web/table-handle'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TableHandlePopoverContent} component.
19
+ */
20
+ export interface TableHandlePopoverContentProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TableHandlePopoverContent: ForwardRefExoticComponent<
23
+ Partial<TableHandlePopoverContentProps> &
24
+ RefAttributes<TableHandlePopoverContentElement> &
25
+ HTMLAttributes<TableHandlePopoverContentElement>
26
+ > = createComponent<
27
+ TableHandlePopoverContentProps,
28
+ TableHandlePopoverContentElement
29
+ >(
30
+ 'prosekit-table-handle-popover-content',
31
+ 'TableHandlePopoverContent',
32
+ Object.keys(tableHandlePopoverContentProps),
33
+ Object.keys(tableHandlePopoverContentEvents),
34
+ )
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TableHandlePopoverItemElement,
3
+ type TableHandlePopoverItemProps as Props,
4
+ type TableHandlePopoverItemEvents as Events,
5
+ tableHandlePopoverItemProps,
6
+ tableHandlePopoverItemEvents,
7
+ } from '@prosekit/web/table-handle'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TableHandlePopoverItem} component.
19
+ */
20
+ export interface TableHandlePopoverItemProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TableHandlePopoverItem: ForwardRefExoticComponent<
23
+ Partial<TableHandlePopoverItemProps> &
24
+ RefAttributes<TableHandlePopoverItemElement> &
25
+ HTMLAttributes<TableHandlePopoverItemElement>
26
+ > = createComponent<
27
+ TableHandlePopoverItemProps,
28
+ TableHandlePopoverItemElement
29
+ >(
30
+ 'prosekit-table-handle-popover-item',
31
+ 'TableHandlePopoverItem',
32
+ Object.keys(tableHandlePopoverItemProps),
33
+ Object.keys(tableHandlePopoverItemEvents),
34
+ )
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TableHandleRootElement,
3
+ type TableHandleRootProps as Props,
4
+ type TableHandleRootEvents as Events,
5
+ tableHandleRootProps,
6
+ tableHandleRootEvents,
7
+ } from '@prosekit/web/table-handle'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TableHandleRoot} component.
19
+ */
20
+ export interface TableHandleRootProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TableHandleRoot: ForwardRefExoticComponent<
23
+ Partial<TableHandleRootProps> &
24
+ RefAttributes<TableHandleRootElement> &
25
+ HTMLAttributes<TableHandleRootElement>
26
+ > = createComponent<
27
+ TableHandleRootProps,
28
+ TableHandleRootElement
29
+ >(
30
+ 'prosekit-table-handle-root',
31
+ 'TableHandleRoot',
32
+ Object.keys(tableHandleRootProps),
33
+ Object.keys(tableHandleRootEvents),
34
+ )
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TableHandleRowRootElement,
3
+ type TableHandleRowRootProps as Props,
4
+ type TableHandleRowRootEvents as Events,
5
+ tableHandleRowRootProps,
6
+ tableHandleRowRootEvents,
7
+ } from '@prosekit/web/table-handle'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TableHandleRowRoot} component.
19
+ */
20
+ export interface TableHandleRowRootProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TableHandleRowRoot: ForwardRefExoticComponent<
23
+ Partial<TableHandleRowRootProps> &
24
+ RefAttributes<TableHandleRowRootElement> &
25
+ HTMLAttributes<TableHandleRowRootElement>
26
+ > = createComponent<
27
+ TableHandleRowRootProps,
28
+ TableHandleRowRootElement
29
+ >(
30
+ 'prosekit-table-handle-row-root',
31
+ 'TableHandleRowRoot',
32
+ Object.keys(tableHandleRowRootProps),
33
+ Object.keys(tableHandleRowRootEvents),
34
+ )
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TableHandleRowTriggerElement,
3
+ type TableHandleRowTriggerProps as Props,
4
+ type TableHandleRowTriggerEvents as Events,
5
+ tableHandleRowTriggerProps,
6
+ tableHandleRowTriggerEvents,
7
+ } from '@prosekit/web/table-handle'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TableHandleRowTrigger} component.
19
+ */
20
+ export interface TableHandleRowTriggerProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TableHandleRowTrigger: ForwardRefExoticComponent<
23
+ Partial<TableHandleRowTriggerProps> &
24
+ RefAttributes<TableHandleRowTriggerElement> &
25
+ HTMLAttributes<TableHandleRowTriggerElement>
26
+ > = createComponent<
27
+ TableHandleRowTriggerProps,
28
+ TableHandleRowTriggerElement
29
+ >(
30
+ 'prosekit-table-handle-row-trigger',
31
+ 'TableHandleRowTrigger',
32
+ Object.keys(tableHandleRowTriggerProps),
33
+ Object.keys(tableHandleRowTriggerEvents),
34
+ )
@@ -0,0 +1,5 @@
1
+ export { TooltipContent, type TooltipContentProps } from './tooltip-content.gen'
2
+
3
+ export { TooltipRoot, type TooltipRootProps } from './tooltip-root.gen'
4
+
5
+ export { TooltipTrigger, type TooltipTriggerProps } from './tooltip-trigger.gen'
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TooltipContentElement,
3
+ type TooltipContentProps as Props,
4
+ type TooltipContentEvents as Events,
5
+ tooltipContentProps,
6
+ tooltipContentEvents,
7
+ } from '@prosekit/web/tooltip'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TooltipContent} component.
19
+ */
20
+ export interface TooltipContentProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TooltipContent: ForwardRefExoticComponent<
23
+ Partial<TooltipContentProps> &
24
+ RefAttributes<TooltipContentElement> &
25
+ HTMLAttributes<TooltipContentElement>
26
+ > = createComponent<
27
+ TooltipContentProps,
28
+ TooltipContentElement
29
+ >(
30
+ 'prosekit-tooltip-content',
31
+ 'TooltipContent',
32
+ Object.keys(tooltipContentProps),
33
+ Object.keys(tooltipContentEvents),
34
+ )
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TooltipRootElement,
3
+ type TooltipRootProps as Props,
4
+ type TooltipRootEvents as Events,
5
+ tooltipRootProps,
6
+ tooltipRootEvents,
7
+ } from '@prosekit/web/tooltip'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TooltipRoot} component.
19
+ */
20
+ export interface TooltipRootProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TooltipRoot: ForwardRefExoticComponent<
23
+ Partial<TooltipRootProps> &
24
+ RefAttributes<TooltipRootElement> &
25
+ HTMLAttributes<TooltipRootElement>
26
+ > = createComponent<
27
+ TooltipRootProps,
28
+ TooltipRootElement
29
+ >(
30
+ 'prosekit-tooltip-root',
31
+ 'TooltipRoot',
32
+ Object.keys(tooltipRootProps),
33
+ Object.keys(tooltipRootEvents),
34
+ )
@@ -0,0 +1,34 @@
1
+ import {
2
+ type TooltipTriggerElement,
3
+ type TooltipTriggerProps as Props,
4
+ type TooltipTriggerEvents as Events,
5
+ tooltipTriggerProps,
6
+ tooltipTriggerEvents,
7
+ } from '@prosekit/web/tooltip'
8
+ import type {
9
+ ForwardRefExoticComponent,
10
+ HTMLAttributes,
11
+ RefAttributes,
12
+ } from 'preact/compat'
13
+
14
+ import { createComponent } from '../create-component'
15
+ import type { CreateProps } from '../create-props'
16
+
17
+ /**
18
+ * Props for the {@link TooltipTrigger} component.
19
+ */
20
+ export interface TooltipTriggerProps extends Partial<CreateProps<Props, Events>> {}
21
+
22
+ export const TooltipTrigger: ForwardRefExoticComponent<
23
+ Partial<TooltipTriggerProps> &
24
+ RefAttributes<TooltipTriggerElement> &
25
+ HTMLAttributes<TooltipTriggerElement>
26
+ > = createComponent<
27
+ TooltipTriggerProps,
28
+ TooltipTriggerElement
29
+ >(
30
+ 'prosekit-tooltip-trigger',
31
+ 'TooltipTrigger',
32
+ Object.keys(tooltipTriggerProps),
33
+ Object.keys(tooltipTriggerEvents),
34
+ )
@@ -0,0 +1,23 @@
1
+ import type {
2
+ Editor,
3
+ Extension,
4
+ } from '@prosekit/core'
5
+ import {
6
+ createContext,
7
+ type Provider,
8
+ } from 'preact'
9
+ import { useContext } from 'preact/hooks'
10
+
11
+ const editorContext = createContext<Editor | null>(null)
12
+
13
+ /**
14
+ * @internal
15
+ */
16
+ export function useEditorContext<E extends Extension>(): Editor<E> | null {
17
+ return useContext(editorContext)
18
+ }
19
+
20
+ /**
21
+ * @internal
22
+ */
23
+ export const EditorContextProvider: Provider<Editor | null> = editorContext.Provider
@@ -0,0 +1,93 @@
1
+ import {
2
+ defineMarkViewComponent,
3
+ defineMarkViewFactory,
4
+ type Extension,
5
+ } from '@prosekit/core'
6
+ import type { MarkViewConstructor } from '@prosekit/pm/view'
7
+ import type { CoreMarkViewUserOptions } from '@prosemirror-adapter/core'
8
+ import {
9
+ useMarkViewContext,
10
+ useMarkViewFactory,
11
+ type MarkViewContext,
12
+ type PreactMarkViewUserOptions,
13
+ } from '@prosemirror-adapter/preact'
14
+ import {
15
+ h,
16
+ type ComponentType,
17
+ type FunctionComponent,
18
+ } from 'preact'
19
+ import { useMemo } from 'preact/hooks'
20
+
21
+ import { useExtension } from '../hooks/use-extension'
22
+
23
+ /**
24
+ * @public
25
+ */
26
+ export interface PreactMarkViewProps extends MarkViewContext {}
27
+
28
+ /**
29
+ * @public
30
+ */
31
+ export type PreactMarkViewComponent = ComponentType<PreactMarkViewProps>
32
+
33
+ /**
34
+ * Options for {@link definePreactMarkView}.
35
+ *
36
+ * @public
37
+ */
38
+ export interface PreactMarkViewOptions extends CoreMarkViewUserOptions<PreactMarkViewComponent> {
39
+ /**
40
+ * The name of the mark type.
41
+ */
42
+ name: string
43
+ }
44
+
45
+ function withMarkViewProps(component: PreactMarkViewComponent) {
46
+ return function MarkViewPropsWrapper() {
47
+ const props: PreactMarkViewProps = useMarkViewContext()
48
+ return h(component, props)
49
+ }
50
+ }
51
+
52
+ /**
53
+ * @internal
54
+ */
55
+ export const PreactMarkViewConsumer: FunctionComponent = () => {
56
+ const markViewFactory = useMarkViewFactory()
57
+ const extension = useMemo(
58
+ () => definePreactMarkViewFactory(markViewFactory),
59
+ [markViewFactory],
60
+ )
61
+ useExtension(extension)
62
+
63
+ return null
64
+ }
65
+
66
+ /**
67
+ * Defines a mark view using a Preact component.
68
+ *
69
+ * @public
70
+ */
71
+ export function definePreactMarkView(options: PreactMarkViewOptions): Extension {
72
+ const { name, component, ...userOptions } = options
73
+
74
+ const args: PreactMarkViewUserOptions = {
75
+ ...userOptions,
76
+ component: withMarkViewProps(component),
77
+ }
78
+
79
+ return defineMarkViewComponent<PreactMarkViewUserOptions>({
80
+ group: 'preact',
81
+ name,
82
+ args,
83
+ })
84
+ }
85
+
86
+ function definePreactMarkViewFactory(
87
+ factory: (options: PreactMarkViewUserOptions) => MarkViewConstructor,
88
+ ) {
89
+ return defineMarkViewFactory<PreactMarkViewUserOptions>({
90
+ group: 'preact',
91
+ factory,
92
+ })
93
+ }
@@ -0,0 +1,93 @@
1
+ import {
2
+ defineNodeViewComponent,
3
+ defineNodeViewFactory,
4
+ type Extension,
5
+ } from '@prosekit/core'
6
+ import type { NodeViewConstructor } from '@prosekit/pm/view'
7
+ import type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core'
8
+ import {
9
+ useNodeViewContext,
10
+ useNodeViewFactory,
11
+ type NodeViewContext,
12
+ type PreactNodeViewUserOptions,
13
+ } from '@prosemirror-adapter/preact'
14
+ import {
15
+ h,
16
+ type ComponentType,
17
+ type FunctionComponent,
18
+ } from 'preact'
19
+ import { useMemo } from 'preact/hooks'
20
+
21
+ import { useExtension } from '../hooks/use-extension'
22
+
23
+ /**
24
+ * @public
25
+ */
26
+ export interface PreactNodeViewProps extends NodeViewContext {}
27
+
28
+ /**
29
+ * @public
30
+ */
31
+ export type PreactNodeViewComponent = ComponentType<PreactNodeViewProps>
32
+
33
+ /**
34
+ * Options for {@link definePreactNodeView}.
35
+ *
36
+ * @public
37
+ */
38
+ export interface PreactNodeViewOptions extends CoreNodeViewUserOptions<PreactNodeViewComponent> {
39
+ /**
40
+ * The name of the node type.
41
+ */
42
+ name: string
43
+ }
44
+
45
+ function withNodeViewProps(component: PreactNodeViewComponent) {
46
+ return function NodeViewPropsWrapper() {
47
+ const props: PreactNodeViewProps = useNodeViewContext()
48
+ return h(component, props)
49
+ }
50
+ }
51
+
52
+ /**
53
+ * @internal
54
+ */
55
+ export const PreactNodeViewConsumer: FunctionComponent = () => {
56
+ const nodeViewFactory = useNodeViewFactory()
57
+ const extension = useMemo(
58
+ () => definePreactNodeViewFactory(nodeViewFactory),
59
+ [nodeViewFactory],
60
+ )
61
+ useExtension(extension)
62
+
63
+ return null
64
+ }
65
+
66
+ /**
67
+ * Defines a node view using a Preact component.
68
+ *
69
+ * @public
70
+ */
71
+ export function definePreactNodeView(options: PreactNodeViewOptions): Extension {
72
+ const { name, component, ...userOptions } = options
73
+
74
+ const args: PreactNodeViewUserOptions = {
75
+ ...userOptions,
76
+ component: withNodeViewProps(component),
77
+ }
78
+
79
+ return defineNodeViewComponent<PreactNodeViewUserOptions>({
80
+ group: 'preact',
81
+ name,
82
+ args,
83
+ })
84
+ }
85
+
86
+ function definePreactNodeViewFactory(
87
+ factory: (options: PreactNodeViewUserOptions) => NodeViewConstructor,
88
+ ) {
89
+ return defineNodeViewFactory<PreactNodeViewUserOptions>({
90
+ group: 'preact',
91
+ factory,
92
+ })
93
+ }
@@ -0,0 +1,24 @@
1
+ import { defineDocChangeHandler } from '@prosekit/core'
2
+ import type { ProseMirrorNode } from '@prosekit/pm/model'
3
+ import { useMemo } from 'preact/hooks'
4
+
5
+ import {
6
+ useExtension,
7
+ type UseExtensionOptions,
8
+ } from './use-extension'
9
+
10
+ /**
11
+ * Calls the given handler whenever the editor document changes.
12
+ *
13
+ * @public
14
+ */
15
+ export function useDocChange(
16
+ handler: (doc: ProseMirrorNode) => void,
17
+ options?: UseExtensionOptions,
18
+ ): void {
19
+ const extension = useMemo(
20
+ () => defineDocChangeHandler((view) => handler(view.state.doc)),
21
+ [handler],
22
+ )
23
+ useExtension(extension, options)
24
+ }