@prosekit/solid 0.5.0 → 0.5.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-x4Duyu8z.js +2 -1
- package/dist/create-component-x4Duyu8z.js.map +1 -0
- package/dist/{create-props-B3k6ERfv.d.ts → create-props-BwXSSFVp.d.ts} +3 -2
- package/dist/create-props-BwXSSFVp.d.ts.map +1 -0
- package/dist/editor-context-DIj_hnDx.js +2 -1
- package/dist/editor-context-DIj_hnDx.js.map +1 -0
- package/dist/prosekit-solid-autocomplete.d.ts +12 -11
- package/dist/prosekit-solid-autocomplete.d.ts.map +1 -0
- package/dist/prosekit-solid-autocomplete.js +2 -1
- package/dist/prosekit-solid-autocomplete.js.map +1 -0
- package/dist/prosekit-solid-block-handle.d.ts +10 -9
- package/dist/prosekit-solid-block-handle.d.ts.map +1 -0
- package/dist/prosekit-solid-block-handle.js +2 -1
- package/dist/prosekit-solid-block-handle.js.map +1 -0
- package/dist/prosekit-solid-drop-indicator.d.ts +6 -5
- package/dist/prosekit-solid-drop-indicator.d.ts.map +1 -0
- package/dist/prosekit-solid-drop-indicator.js +2 -1
- package/dist/prosekit-solid-drop-indicator.js.map +1 -0
- package/dist/prosekit-solid-inline-popover.d.ts +6 -5
- package/dist/prosekit-solid-inline-popover.d.ts.map +1 -0
- package/dist/prosekit-solid-inline-popover.js +2 -1
- package/dist/prosekit-solid-inline-popover.js.map +1 -0
- package/dist/prosekit-solid-popover.d.ts +10 -9
- package/dist/prosekit-solid-popover.d.ts.map +1 -0
- package/dist/prosekit-solid-popover.js +2 -1
- package/dist/prosekit-solid-popover.js.map +1 -0
- package/dist/prosekit-solid-resizable.d.ts +8 -7
- package/dist/prosekit-solid-resizable.d.ts.map +1 -0
- package/dist/prosekit-solid-resizable.js +2 -1
- package/dist/prosekit-solid-resizable.js.map +1 -0
- package/dist/prosekit-solid-table-handle.d.ts +22 -21
- package/dist/prosekit-solid-table-handle.d.ts.map +1 -0
- package/dist/prosekit-solid-table-handle.js +2 -1
- package/dist/prosekit-solid-table-handle.js.map +1 -0
- package/dist/prosekit-solid-tooltip.d.ts +10 -9
- package/dist/prosekit-solid-tooltip.d.ts.map +1 -0
- package/dist/prosekit-solid-tooltip.js +2 -1
- package/dist/prosekit-solid-tooltip.js.map +1 -0
- package/dist/prosekit-solid.d.ts +65 -67
- package/dist/prosekit-solid.d.ts.map +1 -0
- package/dist/prosekit-solid.js +41 -5
- package/dist/prosekit-solid.js.map +1 -0
- package/dist/{types-DFZJMe9D.d.ts → types-CoG9Vl2B.d.ts} +10 -23
- package/dist/types-CoG9Vl2B.d.ts.map +1 -0
- package/package.json +18 -18
- package/src/components/autocomplete/autocomplete-empty.gen.ts +29 -0
- package/src/components/autocomplete/autocomplete-item.gen.ts +29 -0
- package/src/components/autocomplete/autocomplete-list.gen.ts +29 -0
- package/src/components/autocomplete/autocomplete-popover.gen.ts +29 -0
- package/src/components/autocomplete/index.gen.ts +7 -0
- package/src/components/block-handle/block-handle-add.gen.ts +29 -0
- package/src/components/block-handle/block-handle-draggable.gen.ts +29 -0
- package/src/components/block-handle/block-handle-popover.gen.ts +29 -0
- package/src/components/block-handle/index.gen.ts +5 -0
- package/src/components/create-component.ts +60 -0
- package/src/components/create-props.ts +13 -0
- package/src/components/drop-indicator/drop-indicator.gen.ts +29 -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 +29 -0
- package/src/components/popover/index.gen.ts +5 -0
- package/src/components/popover/popover-content.gen.ts +29 -0
- package/src/components/popover/popover-root.gen.ts +29 -0
- package/src/components/popover/popover-trigger.gen.ts +29 -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 +29 -0
- package/src/components/resizable/resizable-root.gen.ts +29 -0
- package/src/components/table-handle/index.gen.ts +17 -0
- package/src/components/table-handle/table-handle-column-root.gen.ts +29 -0
- package/src/components/table-handle/table-handle-column-trigger.gen.ts +29 -0
- package/src/components/table-handle/table-handle-drag-preview.gen.ts +29 -0
- package/src/components/table-handle/table-handle-drop-indicator.gen.ts +29 -0
- package/src/components/table-handle/table-handle-popover-content.gen.ts +29 -0
- package/src/components/table-handle/table-handle-popover-item.gen.ts +29 -0
- package/src/components/table-handle/table-handle-root.gen.ts +29 -0
- package/src/components/table-handle/table-handle-row-root.gen.ts +29 -0
- package/src/components/table-handle/table-handle-row-trigger.gen.ts +29 -0
- package/src/components/tooltip/index.gen.ts +5 -0
- package/src/components/tooltip/tooltip-content.gen.ts +29 -0
- package/src/components/tooltip/tooltip-root.gen.ts +29 -0
- package/src/components/tooltip/tooltip-trigger.gen.ts +29 -0
- package/src/contexts/editor-context.ts +23 -0
- package/src/extensions/solid-mark-view.ts +105 -0
- package/src/extensions/solid-node-view.ts +120 -0
- package/src/hooks/use-doc-change.ts +20 -0
- package/src/hooks/use-editor-extension.ts +36 -0
- package/src/hooks/use-editor.ts +59 -0
- package/src/hooks/use-extension.ts +41 -0
- package/src/hooks/use-keymap.ts +14 -0
- package/src/hooks/use-priority-extension.ts +18 -0
- package/src/hooks/use-state-update.ts +20 -0
- package/src/index.ts +30 -0
- package/src/types.ts +29 -0
- package/src/utils/to-value.ts +14 -0
|
@@ -0,0 +1,29 @@
|
|
|
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 { Component } from 'solid-js'
|
|
9
|
+
|
|
10
|
+
import type { PropsWithElement } from '../../types'
|
|
11
|
+
import { createComponent } from '../create-component'
|
|
12
|
+
import type { CreateProps } from '../create-props'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Props for the {@link TooltipRoot} component.
|
|
16
|
+
*/
|
|
17
|
+
export interface TooltipRootProps extends Partial<CreateProps<Props, Events>> {}
|
|
18
|
+
|
|
19
|
+
export const TooltipRoot: Component<PropsWithElement<
|
|
20
|
+
TooltipRootProps,
|
|
21
|
+
TooltipRootElement
|
|
22
|
+
>> = createComponent<
|
|
23
|
+
TooltipRootProps,
|
|
24
|
+
TooltipRootElement
|
|
25
|
+
>(
|
|
26
|
+
'prosekit-tooltip-root',
|
|
27
|
+
Object.keys(tooltipRootProps),
|
|
28
|
+
Object.keys(tooltipRootEvents),
|
|
29
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { Component } from 'solid-js'
|
|
9
|
+
|
|
10
|
+
import type { PropsWithElement } from '../../types'
|
|
11
|
+
import { createComponent } from '../create-component'
|
|
12
|
+
import type { CreateProps } from '../create-props'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Props for the {@link TooltipTrigger} component.
|
|
16
|
+
*/
|
|
17
|
+
export interface TooltipTriggerProps extends Partial<CreateProps<Props, Events>> {}
|
|
18
|
+
|
|
19
|
+
export const TooltipTrigger: Component<PropsWithElement<
|
|
20
|
+
TooltipTriggerProps,
|
|
21
|
+
TooltipTriggerElement
|
|
22
|
+
>> = createComponent<
|
|
23
|
+
TooltipTriggerProps,
|
|
24
|
+
TooltipTriggerElement
|
|
25
|
+
>(
|
|
26
|
+
'prosekit-tooltip-trigger',
|
|
27
|
+
Object.keys(tooltipTriggerProps),
|
|
28
|
+
Object.keys(tooltipTriggerEvents),
|
|
29
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Editor,
|
|
3
|
+
Extension,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
import {
|
|
6
|
+
createContext,
|
|
7
|
+
useContext,
|
|
8
|
+
type ContextProviderComponent,
|
|
9
|
+
} from 'solid-js'
|
|
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: ContextProviderComponent<Editor | null> = editorContext.Provider
|
|
@@ -0,0 +1,105 @@
|
|
|
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 MarkViewContextProps,
|
|
12
|
+
type SolidMarkViewUserOptions,
|
|
13
|
+
} from '@prosemirror-adapter/solid'
|
|
14
|
+
import {
|
|
15
|
+
createComponent,
|
|
16
|
+
createMemo,
|
|
17
|
+
type Accessor,
|
|
18
|
+
type Component,
|
|
19
|
+
} from 'solid-js'
|
|
20
|
+
|
|
21
|
+
import { useExtension } from '../hooks/use-extension'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export interface SolidMarkViewProps extends MarkViewContextProps {}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export type SolidMarkViewComponent = Component<SolidMarkViewProps>
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Options for {@link defineSolidMarkView}.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export interface SolidMarkViewOptions extends CoreMarkViewUserOptions<SolidMarkViewComponent> {
|
|
39
|
+
/**
|
|
40
|
+
* The name of the mark type.
|
|
41
|
+
*/
|
|
42
|
+
name: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function withMarkViewProps(
|
|
46
|
+
component: SolidMarkViewComponent,
|
|
47
|
+
): Component<SolidMarkViewProps> {
|
|
48
|
+
return function MarkViewPropsWrapper() {
|
|
49
|
+
const context: Accessor<SolidMarkViewProps> = useMarkViewContext()
|
|
50
|
+
const props: SolidMarkViewProps = {
|
|
51
|
+
get contentRef() {
|
|
52
|
+
return context().contentRef
|
|
53
|
+
},
|
|
54
|
+
get view() {
|
|
55
|
+
return context().view
|
|
56
|
+
},
|
|
57
|
+
get mark() {
|
|
58
|
+
return context().mark
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
return createComponent(component, props)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
export function consumeSolidMarkViews(): void {
|
|
69
|
+
const markViewFactory = useMarkViewFactory()
|
|
70
|
+
const extension = createMemo(
|
|
71
|
+
() => defineSolidMarkViewFactory(markViewFactory),
|
|
72
|
+
[markViewFactory],
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
useExtension(extension)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Defines a mark view using a Solid component.
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export function defineSolidMarkView(options: SolidMarkViewOptions): Extension {
|
|
84
|
+
const { name, component, ...userOptions } = options
|
|
85
|
+
|
|
86
|
+
const args: SolidMarkViewUserOptions = {
|
|
87
|
+
...userOptions,
|
|
88
|
+
component: withMarkViewProps(component),
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return defineMarkViewComponent<SolidMarkViewUserOptions>({
|
|
92
|
+
group: 'solid',
|
|
93
|
+
name,
|
|
94
|
+
args,
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function defineSolidMarkViewFactory(
|
|
99
|
+
factory: (options: SolidMarkViewOptions) => MarkViewConstructor,
|
|
100
|
+
) {
|
|
101
|
+
return defineMarkViewFactory<SolidMarkViewOptions>({
|
|
102
|
+
group: 'solid',
|
|
103
|
+
factory,
|
|
104
|
+
})
|
|
105
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
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 NodeViewContextProps,
|
|
12
|
+
type SolidNodeViewUserOptions,
|
|
13
|
+
} from '@prosemirror-adapter/solid'
|
|
14
|
+
import {
|
|
15
|
+
createComponent,
|
|
16
|
+
createMemo,
|
|
17
|
+
type Accessor,
|
|
18
|
+
type Component,
|
|
19
|
+
} from 'solid-js'
|
|
20
|
+
|
|
21
|
+
import { useExtension } from '../hooks/use-extension'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export interface SolidNodeViewProps extends NodeViewContextProps {}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export type SolidNodeViewComponent = Component<SolidNodeViewProps>
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Options for {@link defineSolidNodeView}.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export interface SolidNodeViewOptions extends CoreNodeViewUserOptions<SolidNodeViewComponent> {
|
|
39
|
+
/**
|
|
40
|
+
* The name of the node type.
|
|
41
|
+
*/
|
|
42
|
+
name: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function withNodeViewProps(
|
|
46
|
+
component: SolidNodeViewComponent,
|
|
47
|
+
): Component<SolidNodeViewProps> {
|
|
48
|
+
return function NodeViewPropsWrapper() {
|
|
49
|
+
const context: Accessor<SolidNodeViewProps> = useNodeViewContext()
|
|
50
|
+
const props: SolidNodeViewProps = {
|
|
51
|
+
get contentRef() {
|
|
52
|
+
return context().contentRef
|
|
53
|
+
},
|
|
54
|
+
get view() {
|
|
55
|
+
return context().view
|
|
56
|
+
},
|
|
57
|
+
get getPos() {
|
|
58
|
+
return context().getPos
|
|
59
|
+
},
|
|
60
|
+
get setAttrs() {
|
|
61
|
+
return context().setAttrs
|
|
62
|
+
},
|
|
63
|
+
get node() {
|
|
64
|
+
return context().node
|
|
65
|
+
},
|
|
66
|
+
get selected() {
|
|
67
|
+
return context().selected
|
|
68
|
+
},
|
|
69
|
+
get decorations() {
|
|
70
|
+
return context().decorations
|
|
71
|
+
},
|
|
72
|
+
get innerDecorations() {
|
|
73
|
+
return context().innerDecorations
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
return createComponent(component, props)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export function consumeSolidNodeViews(): void {
|
|
84
|
+
const nodeViewFactory = useNodeViewFactory()
|
|
85
|
+
const extension = createMemo(
|
|
86
|
+
() => defineSolidNodeViewFactory(nodeViewFactory),
|
|
87
|
+
[nodeViewFactory],
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
useExtension(extension)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Defines a node view using a Solid component.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export function defineSolidNodeView(options: SolidNodeViewOptions): Extension {
|
|
99
|
+
const { name, component, ...userOptions } = options
|
|
100
|
+
|
|
101
|
+
const args: SolidNodeViewUserOptions = {
|
|
102
|
+
...userOptions,
|
|
103
|
+
component: withNodeViewProps(component),
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return defineNodeViewComponent<SolidNodeViewUserOptions>({
|
|
107
|
+
group: 'solid',
|
|
108
|
+
name,
|
|
109
|
+
args,
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function defineSolidNodeViewFactory(
|
|
114
|
+
factory: (options: SolidNodeViewOptions) => NodeViewConstructor,
|
|
115
|
+
) {
|
|
116
|
+
return defineNodeViewFactory<SolidNodeViewOptions>({
|
|
117
|
+
group: 'solid',
|
|
118
|
+
factory,
|
|
119
|
+
})
|
|
120
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineDocChangeHandler } from '@prosekit/core'
|
|
2
|
+
import type { ProseMirrorNode } from '@prosekit/pm/model'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
useExtension,
|
|
6
|
+
type UseExtensionOptions,
|
|
7
|
+
} from './use-extension'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Calls the given handler whenever the editor document changes.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export function useDocChange(
|
|
15
|
+
handler: (doc: ProseMirrorNode) => void,
|
|
16
|
+
options?: UseExtensionOptions,
|
|
17
|
+
): void {
|
|
18
|
+
const extension = defineDocChangeHandler((view) => handler(view.state.doc))
|
|
19
|
+
useExtension(() => extension, options)
|
|
20
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EditorNotFoundError,
|
|
3
|
+
type Editor,
|
|
4
|
+
type Extension,
|
|
5
|
+
} from '@prosekit/core'
|
|
6
|
+
import {
|
|
7
|
+
createEffect,
|
|
8
|
+
onCleanup,
|
|
9
|
+
type Accessor,
|
|
10
|
+
} from 'solid-js'
|
|
11
|
+
|
|
12
|
+
import { useEditorContext } from '../contexts/editor-context'
|
|
13
|
+
import type { MaybeAccessor } from '../types'
|
|
14
|
+
import { toValue } from '../utils/to-value'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export function useEditorExtension(
|
|
20
|
+
editorAccessor: MaybeAccessor<Editor> | undefined | null,
|
|
21
|
+
extensionAccessor: Accessor<Extension | null>,
|
|
22
|
+
): void {
|
|
23
|
+
const editorContext = useEditorContext()
|
|
24
|
+
|
|
25
|
+
createEffect(() => {
|
|
26
|
+
const editor = toValue(editorAccessor) || toValue(editorContext)
|
|
27
|
+
const extension = extensionAccessor()
|
|
28
|
+
|
|
29
|
+
if (!editor) {
|
|
30
|
+
throw new EditorNotFoundError()
|
|
31
|
+
}
|
|
32
|
+
if (extension) {
|
|
33
|
+
onCleanup(editor.use(extension))
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineMountHandler,
|
|
3
|
+
defineUpdateHandler,
|
|
4
|
+
ProseKitError,
|
|
5
|
+
union,
|
|
6
|
+
type Editor,
|
|
7
|
+
type Extension,
|
|
8
|
+
} from '@prosekit/core'
|
|
9
|
+
import {
|
|
10
|
+
createEffect,
|
|
11
|
+
createSignal,
|
|
12
|
+
} from 'solid-js'
|
|
13
|
+
|
|
14
|
+
import { useEditorContext } from '../contexts/editor-context'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves the editor instance from the nearest ProseKit component.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export function useEditor<E extends Extension = any>(options?: {
|
|
22
|
+
/**
|
|
23
|
+
* Whether to update the component when the editor is mounted or editor state
|
|
24
|
+
* is updated.
|
|
25
|
+
*
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
update?: boolean
|
|
29
|
+
}): () => Editor<E> {
|
|
30
|
+
const update = options?.update ?? false
|
|
31
|
+
|
|
32
|
+
const editor = useEditorContext<E>()
|
|
33
|
+
if (!editor) {
|
|
34
|
+
throw new ProseKitError(
|
|
35
|
+
'useEditor must be used within the ProseKit component',
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const [depend, forceUpdate] = useForceUpdate()
|
|
40
|
+
|
|
41
|
+
createEffect(() => {
|
|
42
|
+
if (update) {
|
|
43
|
+
const extension = union(
|
|
44
|
+
defineMountHandler(forceUpdate),
|
|
45
|
+
defineUpdateHandler(forceUpdate),
|
|
46
|
+
)
|
|
47
|
+
return editor.use(extension)
|
|
48
|
+
}
|
|
49
|
+
}, [editor, update, forceUpdate])
|
|
50
|
+
|
|
51
|
+
return () => {
|
|
52
|
+
depend()
|
|
53
|
+
return editor
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function useForceUpdate() {
|
|
58
|
+
return createSignal(undefined, { equals: false })
|
|
59
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Editor,
|
|
3
|
+
Extension,
|
|
4
|
+
Priority,
|
|
5
|
+
} from '@prosekit/core'
|
|
6
|
+
import type { Accessor } from 'solid-js'
|
|
7
|
+
|
|
8
|
+
import type { MaybeAccessor } from '../types'
|
|
9
|
+
|
|
10
|
+
import { useEditorExtension } from './use-editor-extension'
|
|
11
|
+
import { usePriorityExtension } from './use-priority-extension'
|
|
12
|
+
|
|
13
|
+
export interface UseExtensionOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The editor to add the extension to. If not provided, it will use the
|
|
16
|
+
* editor from the nearest `ProseKit` component.
|
|
17
|
+
*/
|
|
18
|
+
editor?: MaybeAccessor<Editor>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Optional priority to add the extension with.
|
|
22
|
+
*/
|
|
23
|
+
priority?: Priority
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Add an extension to the editor.
|
|
28
|
+
*/
|
|
29
|
+
export function useExtension(
|
|
30
|
+
/**
|
|
31
|
+
* The accessor to an extension to add to the editor. If it changes, the previous
|
|
32
|
+
* extension will be removed and the new one (if not null) will be added.
|
|
33
|
+
*/
|
|
34
|
+
extension: Accessor<Extension | null>,
|
|
35
|
+
options?: UseExtensionOptions,
|
|
36
|
+
): void {
|
|
37
|
+
useEditorExtension(
|
|
38
|
+
options?.editor,
|
|
39
|
+
usePriorityExtension(extension, options?.priority),
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineKeymap,
|
|
3
|
+
type Keymap,
|
|
4
|
+
} from '@prosekit/core'
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
useExtension,
|
|
8
|
+
type UseExtensionOptions,
|
|
9
|
+
} from './use-extension'
|
|
10
|
+
|
|
11
|
+
export function useKeymap(keymap: () => Keymap, options?: UseExtensionOptions): void {
|
|
12
|
+
const extension = () => defineKeymap(keymap())
|
|
13
|
+
useExtension(extension, options)
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withPriority,
|
|
3
|
+
type Extension,
|
|
4
|
+
type Priority,
|
|
5
|
+
} from '@prosekit/core'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export function usePriorityExtension<T extends Extension = Extension>(
|
|
11
|
+
extension: () => T | null,
|
|
12
|
+
priority?: Priority | null,
|
|
13
|
+
): () => T | null {
|
|
14
|
+
return () => {
|
|
15
|
+
const ext = extension()
|
|
16
|
+
return ext && priority ? withPriority(ext, priority) : ext
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineUpdateHandler } from '@prosekit/core'
|
|
2
|
+
import type { EditorState } from '@prosekit/pm/state'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
useExtension,
|
|
6
|
+
type UseExtensionOptions,
|
|
7
|
+
} from './use-extension'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Calls the given handler whenever the editor state changes.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export function useStateUpdate(
|
|
15
|
+
handler: (state: EditorState) => void,
|
|
16
|
+
options?: UseExtensionOptions,
|
|
17
|
+
): void {
|
|
18
|
+
const extension = defineUpdateHandler((view) => handler(view.state))
|
|
19
|
+
useExtension(() => extension, options)
|
|
20
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ProseKit,
|
|
3
|
+
type ProseKitProps,
|
|
4
|
+
} from './components/prosekit'
|
|
5
|
+
export {
|
|
6
|
+
defineSolidMarkView,
|
|
7
|
+
type SolidMarkViewComponent,
|
|
8
|
+
type SolidMarkViewOptions,
|
|
9
|
+
type SolidMarkViewProps,
|
|
10
|
+
} from './extensions/solid-mark-view'
|
|
11
|
+
export {
|
|
12
|
+
defineSolidNodeView,
|
|
13
|
+
type SolidNodeViewComponent,
|
|
14
|
+
type SolidNodeViewOptions,
|
|
15
|
+
type SolidNodeViewProps,
|
|
16
|
+
} from './extensions/solid-node-view'
|
|
17
|
+
export { useDocChange } from './hooks/use-doc-change'
|
|
18
|
+
export { useEditor } from './hooks/use-editor'
|
|
19
|
+
export {
|
|
20
|
+
useExtension,
|
|
21
|
+
type UseExtensionOptions,
|
|
22
|
+
} from './hooks/use-extension'
|
|
23
|
+
export { useKeymap } from './hooks/use-keymap'
|
|
24
|
+
export { useStateUpdate } from './hooks/use-state-update'
|
|
25
|
+
export type {
|
|
26
|
+
MaybeAccessor,
|
|
27
|
+
PropsWithChildren,
|
|
28
|
+
PropsWithClass,
|
|
29
|
+
PropsWithElement,
|
|
30
|
+
} from './types'
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Accessor,
|
|
3
|
+
JSX,
|
|
4
|
+
JSXElement,
|
|
5
|
+
} from 'solid-js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export type PropsWithClass<P = unknown> = P & {
|
|
11
|
+
class?: string | undefined
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export type PropsWithChildren<P = unknown> = P & {
|
|
18
|
+
children?: JSXElement | undefined
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export type PropsWithElement<Props extends object, CustomElement extends HTMLElement> = Props & JSX.HTMLAttributes<CustomElement>
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* T or a reactive/non-reactive function returning T
|
|
28
|
+
*/
|
|
29
|
+
export type MaybeAccessor<T> = T | Accessor<T>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accesses the value of a MaybeAccessor
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* access("foo") // => "foo"
|
|
7
|
+
* access(() => "foo") // => "foo"
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export function toValue<T>(
|
|
11
|
+
v: (() => T) | T,
|
|
12
|
+
): T {
|
|
13
|
+
return (typeof v === 'function') ? (v as () => T)() : v
|
|
14
|
+
}
|