@prosekit/solid 0.5.0 → 0.5.1

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 (95) hide show
  1. package/dist/create-component-x4Duyu8z.js +2 -1
  2. package/dist/create-component-x4Duyu8z.js.map +1 -0
  3. package/dist/{create-props-B3k6ERfv.d.ts → create-props-BwXSSFVp.d.ts} +3 -2
  4. package/dist/create-props-BwXSSFVp.d.ts.map +1 -0
  5. package/dist/editor-context-DIj_hnDx.js +2 -1
  6. package/dist/editor-context-DIj_hnDx.js.map +1 -0
  7. package/dist/prosekit-solid-autocomplete.d.ts +12 -11
  8. package/dist/prosekit-solid-autocomplete.d.ts.map +1 -0
  9. package/dist/prosekit-solid-autocomplete.js +2 -1
  10. package/dist/prosekit-solid-autocomplete.js.map +1 -0
  11. package/dist/prosekit-solid-block-handle.d.ts +10 -9
  12. package/dist/prosekit-solid-block-handle.d.ts.map +1 -0
  13. package/dist/prosekit-solid-block-handle.js +2 -1
  14. package/dist/prosekit-solid-block-handle.js.map +1 -0
  15. package/dist/prosekit-solid-drop-indicator.d.ts +6 -5
  16. package/dist/prosekit-solid-drop-indicator.d.ts.map +1 -0
  17. package/dist/prosekit-solid-drop-indicator.js +2 -1
  18. package/dist/prosekit-solid-drop-indicator.js.map +1 -0
  19. package/dist/prosekit-solid-inline-popover.d.ts +6 -5
  20. package/dist/prosekit-solid-inline-popover.d.ts.map +1 -0
  21. package/dist/prosekit-solid-inline-popover.js +2 -1
  22. package/dist/prosekit-solid-inline-popover.js.map +1 -0
  23. package/dist/prosekit-solid-popover.d.ts +10 -9
  24. package/dist/prosekit-solid-popover.d.ts.map +1 -0
  25. package/dist/prosekit-solid-popover.js +2 -1
  26. package/dist/prosekit-solid-popover.js.map +1 -0
  27. package/dist/prosekit-solid-resizable.d.ts +8 -7
  28. package/dist/prosekit-solid-resizable.d.ts.map +1 -0
  29. package/dist/prosekit-solid-resizable.js +2 -1
  30. package/dist/prosekit-solid-resizable.js.map +1 -0
  31. package/dist/prosekit-solid-table-handle.d.ts +22 -21
  32. package/dist/prosekit-solid-table-handle.d.ts.map +1 -0
  33. package/dist/prosekit-solid-table-handle.js +2 -1
  34. package/dist/prosekit-solid-table-handle.js.map +1 -0
  35. package/dist/prosekit-solid-tooltip.d.ts +10 -9
  36. package/dist/prosekit-solid-tooltip.d.ts.map +1 -0
  37. package/dist/prosekit-solid-tooltip.js +2 -1
  38. package/dist/prosekit-solid-tooltip.js.map +1 -0
  39. package/dist/prosekit-solid.d.ts +69 -63
  40. package/dist/prosekit-solid.d.ts.map +1 -0
  41. package/dist/prosekit-solid.js +2 -1
  42. package/dist/prosekit-solid.js.map +1 -0
  43. package/dist/{types-DFZJMe9D.d.ts → types-CoG9Vl2B.d.ts} +10 -23
  44. package/dist/types-CoG9Vl2B.d.ts.map +1 -0
  45. package/package.json +18 -18
  46. package/src/components/autocomplete/autocomplete-empty.gen.ts +29 -0
  47. package/src/components/autocomplete/autocomplete-item.gen.ts +29 -0
  48. package/src/components/autocomplete/autocomplete-list.gen.ts +29 -0
  49. package/src/components/autocomplete/autocomplete-popover.gen.ts +29 -0
  50. package/src/components/autocomplete/index.gen.ts +7 -0
  51. package/src/components/block-handle/block-handle-add.gen.ts +29 -0
  52. package/src/components/block-handle/block-handle-draggable.gen.ts +29 -0
  53. package/src/components/block-handle/block-handle-popover.gen.ts +29 -0
  54. package/src/components/block-handle/index.gen.ts +5 -0
  55. package/src/components/create-component.ts +60 -0
  56. package/src/components/create-props.ts +13 -0
  57. package/src/components/drop-indicator/drop-indicator.gen.ts +29 -0
  58. package/src/components/drop-indicator/index.gen.ts +1 -0
  59. package/src/components/inline-popover/index.gen.ts +1 -0
  60. package/src/components/inline-popover/inline-popover.gen.ts +29 -0
  61. package/src/components/popover/index.gen.ts +5 -0
  62. package/src/components/popover/popover-content.gen.ts +29 -0
  63. package/src/components/popover/popover-root.gen.ts +29 -0
  64. package/src/components/popover/popover-trigger.gen.ts +29 -0
  65. package/src/components/prosekit.ts +37 -0
  66. package/src/components/resizable/index.gen.ts +3 -0
  67. package/src/components/resizable/resizable-handle.gen.ts +29 -0
  68. package/src/components/resizable/resizable-root.gen.ts +29 -0
  69. package/src/components/table-handle/index.gen.ts +17 -0
  70. package/src/components/table-handle/table-handle-column-root.gen.ts +29 -0
  71. package/src/components/table-handle/table-handle-column-trigger.gen.ts +29 -0
  72. package/src/components/table-handle/table-handle-drag-preview.gen.ts +29 -0
  73. package/src/components/table-handle/table-handle-drop-indicator.gen.ts +29 -0
  74. package/src/components/table-handle/table-handle-popover-content.gen.ts +29 -0
  75. package/src/components/table-handle/table-handle-popover-item.gen.ts +29 -0
  76. package/src/components/table-handle/table-handle-root.gen.ts +29 -0
  77. package/src/components/table-handle/table-handle-row-root.gen.ts +29 -0
  78. package/src/components/table-handle/table-handle-row-trigger.gen.ts +29 -0
  79. package/src/components/tooltip/index.gen.ts +5 -0
  80. package/src/components/tooltip/tooltip-content.gen.ts +29 -0
  81. package/src/components/tooltip/tooltip-root.gen.ts +29 -0
  82. package/src/components/tooltip/tooltip-trigger.gen.ts +29 -0
  83. package/src/contexts/editor-context.ts +23 -0
  84. package/src/extensions/solid-mark-view.ts +95 -0
  85. package/src/extensions/solid-node-view.ts +95 -0
  86. package/src/hooks/use-doc-change.ts +20 -0
  87. package/src/hooks/use-editor-extension.ts +36 -0
  88. package/src/hooks/use-editor.ts +59 -0
  89. package/src/hooks/use-extension.ts +41 -0
  90. package/src/hooks/use-keymap.ts +14 -0
  91. package/src/hooks/use-priority-extension.ts +18 -0
  92. package/src/hooks/use-state-update.ts +20 -0
  93. package/src/index.ts +30 -0
  94. package/src/types.ts +29 -0
  95. 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,95 @@
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 props: Accessor<SolidMarkViewProps> = useMarkViewContext()
50
+
51
+ return createComponent(component, props())
52
+ }
53
+ }
54
+
55
+ /**
56
+ * @internal
57
+ */
58
+ export function consumeSolidMarkViews(): void {
59
+ const markViewFactory = useMarkViewFactory()
60
+ const extension = createMemo(
61
+ () => defineSolidMarkViewFactory(markViewFactory),
62
+ [markViewFactory],
63
+ )
64
+
65
+ useExtension(extension)
66
+ }
67
+
68
+ /**
69
+ * Defines a mark view using a Solid component.
70
+ *
71
+ * @public
72
+ */
73
+ export function defineSolidMarkView(options: SolidMarkViewOptions): Extension {
74
+ const { name, component, ...userOptions } = options
75
+
76
+ const args: SolidMarkViewUserOptions = {
77
+ ...userOptions,
78
+ component: withMarkViewProps(component),
79
+ }
80
+
81
+ return defineMarkViewComponent<SolidMarkViewUserOptions>({
82
+ group: 'solid',
83
+ name,
84
+ args,
85
+ })
86
+ }
87
+
88
+ function defineSolidMarkViewFactory(
89
+ factory: (options: SolidMarkViewOptions) => MarkViewConstructor,
90
+ ) {
91
+ return defineMarkViewFactory<SolidMarkViewOptions>({
92
+ group: 'solid',
93
+ factory,
94
+ })
95
+ }
@@ -0,0 +1,95 @@
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 props: Accessor<SolidNodeViewProps> = useNodeViewContext()
50
+
51
+ return createComponent(component, props())
52
+ }
53
+ }
54
+
55
+ /**
56
+ * @internal
57
+ */
58
+ export function consumeSolidNodeViews(): void {
59
+ const nodeViewFactory = useNodeViewFactory()
60
+ const extension = createMemo(
61
+ () => defineSolidNodeViewFactory(nodeViewFactory),
62
+ [nodeViewFactory],
63
+ )
64
+
65
+ useExtension(extension)
66
+ }
67
+
68
+ /**
69
+ * Defines a node view using a Solid component.
70
+ *
71
+ * @public
72
+ */
73
+ export function defineSolidNodeView(options: SolidNodeViewOptions): Extension {
74
+ const { name, component, ...userOptions } = options
75
+
76
+ const args: SolidNodeViewUserOptions = {
77
+ ...userOptions,
78
+ component: withNodeViewProps(component),
79
+ }
80
+
81
+ return defineNodeViewComponent<SolidNodeViewUserOptions>({
82
+ group: 'solid',
83
+ name,
84
+ args,
85
+ })
86
+ }
87
+
88
+ function defineSolidNodeViewFactory(
89
+ factory: (options: SolidNodeViewOptions) => NodeViewConstructor,
90
+ ) {
91
+ return defineNodeViewFactory<SolidNodeViewOptions>({
92
+ group: 'solid',
93
+ factory,
94
+ })
95
+ }
@@ -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
+ }