@prosekit/solid 0.6.7 → 0.7.0-beta.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.
- package/dist/{create-component-B7NzEJxP.js → create-component.js} +3 -4
- package/dist/create-component.js.map +1 -0
- package/dist/{create-props-CFK4CtjG.d.ts → create-props.d.ts} +1 -1
- package/dist/create-props.d.ts.map +1 -0
- package/dist/{editor-context-CAdqwRwB.js → editor-context.js} +2 -3
- package/dist/editor-context.js.map +1 -0
- package/dist/prosekit-solid-autocomplete.d.ts +2 -2
- package/dist/prosekit-solid-autocomplete.js +2 -6
- package/dist/prosekit-solid-autocomplete.js.map +1 -1
- package/dist/prosekit-solid-block-handle.d.ts +2 -2
- package/dist/prosekit-solid-block-handle.js +2 -5
- package/dist/prosekit-solid-block-handle.js.map +1 -1
- package/dist/prosekit-solid-drop-indicator.d.ts +2 -2
- package/dist/prosekit-solid-drop-indicator.js +2 -3
- package/dist/prosekit-solid-drop-indicator.js.map +1 -1
- package/dist/prosekit-solid-inline-popover.d.ts +2 -2
- package/dist/prosekit-solid-inline-popover.js +2 -3
- package/dist/prosekit-solid-inline-popover.js.map +1 -1
- package/dist/prosekit-solid-popover.d.ts +2 -2
- package/dist/prosekit-solid-popover.js +2 -5
- package/dist/prosekit-solid-popover.js.map +1 -1
- package/dist/prosekit-solid-resizable.d.ts +2 -2
- package/dist/prosekit-solid-resizable.js +2 -4
- package/dist/prosekit-solid-resizable.js.map +1 -1
- package/dist/prosekit-solid-table-handle.d.ts +2 -2
- package/dist/prosekit-solid-table-handle.js +2 -11
- package/dist/prosekit-solid-table-handle.js.map +1 -1
- package/dist/prosekit-solid-tooltip.d.ts +2 -2
- package/dist/prosekit-solid-tooltip.js +2 -5
- package/dist/prosekit-solid-tooltip.js.map +1 -1
- package/dist/prosekit-solid.d.ts +2 -2
- package/dist/prosekit-solid.d.ts.map +1 -1
- package/dist/prosekit-solid.js +115 -140
- package/dist/prosekit-solid.js.map +1 -1
- package/dist/{types-Bx9mKDTJ.d.ts → types.d.ts} +1 -1
- package/dist/types.d.ts.map +1 -0
- package/package.json +7 -7
- package/src/components/prosekit.ts +6 -6
- package/src/components/view-renderer.ts +24 -0
- package/src/extensions/helpers.ts +4 -0
- package/src/extensions/solid-mark-view.ts +29 -49
- package/src/extensions/solid-node-view.ts +29 -64
- package/dist/create-component-B7NzEJxP.js.map +0 -1
- package/dist/create-props-CFK4CtjG.d.ts.map +0 -1
- package/dist/editor-context-CAdqwRwB.js.map +0 -1
- package/dist/types-Bx9mKDTJ.d.ts.map +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { defineNodeViewComponent, defineNodeViewFactory, type Extension } from '@prosekit/core'
|
|
2
|
-
import type { NodeViewConstructor } from '@prosekit/pm/view'
|
|
3
2
|
import type { CoreNodeViewUserOptions } from '@prosemirror-adapter/core'
|
|
4
3
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
AbstractSolidNodeView,
|
|
5
|
+
buildSolidNodeViewCreator,
|
|
7
6
|
type NodeViewContextProps,
|
|
8
|
-
type
|
|
7
|
+
type SolidRendererResult,
|
|
9
8
|
} from '@prosemirror-adapter/solid'
|
|
10
|
-
import { createComponent,
|
|
9
|
+
import { createComponent, type Component, type JSX } from 'solid-js'
|
|
10
|
+
import { Portal } from 'solid-js/web'
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { hidePortalDiv } from './helpers.ts'
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @public
|
|
@@ -33,52 +33,33 @@ export interface SolidNodeViewOptions extends CoreNodeViewUserOptions<SolidNodeV
|
|
|
33
33
|
name: string
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
get
|
|
43
|
-
|
|
36
|
+
class ProseKitSolidNodeView extends AbstractSolidNodeView<SolidNodeViewComponent> {
|
|
37
|
+
render = (): JSX.Element => {
|
|
38
|
+
const UserComponent = this.component
|
|
39
|
+
const getProps = this.context
|
|
40
|
+
return createComponent(Portal, {
|
|
41
|
+
mount: this.dom,
|
|
42
|
+
get children() {
|
|
43
|
+
const props: SolidNodeViewProps = getProps()
|
|
44
|
+
return createComponent(UserComponent, props)
|
|
44
45
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
get getPos() {
|
|
49
|
-
return context().getPos
|
|
50
|
-
},
|
|
51
|
-
get setAttrs() {
|
|
52
|
-
return context().setAttrs
|
|
53
|
-
},
|
|
54
|
-
get node() {
|
|
55
|
-
return context().node
|
|
56
|
-
},
|
|
57
|
-
get selected() {
|
|
58
|
-
return context().selected
|
|
59
|
-
},
|
|
60
|
-
get decorations() {
|
|
61
|
-
return context().decorations
|
|
62
|
-
},
|
|
63
|
-
get innerDecorations() {
|
|
64
|
-
return context().innerDecorations
|
|
65
|
-
},
|
|
66
|
-
}
|
|
67
|
-
return createComponent(component, props)
|
|
46
|
+
ref: hidePortalDiv,
|
|
47
|
+
})
|
|
68
48
|
}
|
|
69
49
|
}
|
|
70
50
|
|
|
71
51
|
/**
|
|
72
52
|
* @internal
|
|
73
53
|
*/
|
|
74
|
-
export function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
54
|
+
export function defineSolidNodeViewFactory(
|
|
55
|
+
renderSolidRenderer: SolidRendererResult['renderSolidRenderer'],
|
|
56
|
+
removeSolidRenderer: SolidRendererResult['removeSolidRenderer'],
|
|
57
|
+
): Extension {
|
|
58
|
+
const factory = buildSolidNodeViewCreator(renderSolidRenderer, removeSolidRenderer, ProseKitSolidNodeView)
|
|
59
|
+
return defineNodeViewFactory<SolidNodeViewOptions>({
|
|
60
|
+
group: 'solid',
|
|
61
|
+
factory,
|
|
62
|
+
})
|
|
82
63
|
}
|
|
83
64
|
|
|
84
65
|
/**
|
|
@@ -87,25 +68,9 @@ export function consumeSolidNodeViews(): void {
|
|
|
87
68
|
* @public
|
|
88
69
|
*/
|
|
89
70
|
export function defineSolidNodeView(options: SolidNodeViewOptions): Extension {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const args: SolidNodeViewUserOptions = {
|
|
93
|
-
...userOptions,
|
|
94
|
-
component: withNodeViewProps(component),
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return defineNodeViewComponent<SolidNodeViewUserOptions>({
|
|
98
|
-
group: 'solid',
|
|
99
|
-
name,
|
|
100
|
-
args,
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function defineSolidNodeViewFactory(
|
|
105
|
-
factory: (options: SolidNodeViewOptions) => NodeViewConstructor,
|
|
106
|
-
) {
|
|
107
|
-
return defineNodeViewFactory<SolidNodeViewOptions>({
|
|
71
|
+
return defineNodeViewComponent<SolidNodeViewOptions>({
|
|
108
72
|
group: 'solid',
|
|
109
|
-
|
|
73
|
+
name: options.name,
|
|
74
|
+
args: options,
|
|
110
75
|
})
|
|
111
76
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-component-B7NzEJxP.js","names":[],"sources":["../src/components/create-component.ts"],"sourcesContent":["import type { AnyFunction } from '@prosekit/core'\nimport type { Component } from 'solid-js'\nimport h from 'solid-js/h'\n\nimport { useEditorContext } from '../contexts/editor-context.ts'\nimport type { PropsWithElement } from '../types.ts'\n\nexport function createComponent<\n Props extends object,\n CustomElement extends HTMLElement,\n>(\n tagName: string,\n propNames: string[],\n eventNames: string[],\n): Component<PropsWithElement<Props, CustomElement>> {\n const hasEditor = propNames.includes('editor')\n const lowerCaseEventNameMap = new Map(\n eventNames.map((name) => [name.toLowerCase(), name]),\n )\n\n const Component = (props: Record<string, unknown>) => {\n const properties: Record<string, () => unknown> = {}\n const eventHandlers: Record<string, AnyFunction> = {}\n\n for (const name of Object.keys(props)) {\n if (propNames.includes(name)) {\n properties['prop:' + name] = () => props[name]\n continue\n }\n\n if (name.startsWith('on')) {\n const lowerCaseEventName = name.slice(2).toLowerCase()\n const eventName = lowerCaseEventNameMap.get(lowerCaseEventName)\n if (eventName) {\n const extractDetail = eventName.endsWith('Change')\n eventHandlers['on:' + eventName] = (event: Event) => {\n const handler = props[name] as AnyFunction | null\n if (typeof handler === 'function') {\n handler(extractDetail ? (event as CustomEvent).detail : event)\n }\n }\n continue\n }\n }\n\n properties[name] = () => props[name]\n }\n\n const editor = useEditorContext()\n\n if (hasEditor && editor) {\n properties['prop:editor'] = () => props['editor'] || editor\n }\n\n return () => h(tagName, { ...properties, ...eventHandlers })\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return Component as any\n}\n"],"mappings":";;;;AAOA,SAAgB,gBAId,SACA,WACA,YACmD;CACnD,MAAM,YAAY,UAAU,SAAS,SAAS;CAC9C,MAAM,wBAAwB,IAAI,IAChC,WAAW,KAAK,SAAS,CAAC,KAAK,aAAa,EAAE,KAAK,CAAC,CACrD;CAED,MAAM,aAAa,UAAmC;EACpD,MAAM,aAA4C,EAAE;EACpD,MAAM,gBAA6C,EAAE;AAErD,OAAK,MAAM,QAAQ,OAAO,KAAK,MAAM,EAAE;AACrC,OAAI,UAAU,SAAS,KAAK,EAAE;AAC5B,eAAW,UAAU,cAAc,MAAM;AACzC;;AAGF,OAAI,KAAK,WAAW,KAAK,EAAE;IACzB,MAAM,qBAAqB,KAAK,MAAM,EAAE,CAAC,aAAa;IACtD,MAAM,YAAY,sBAAsB,IAAI,mBAAmB;AAC/D,QAAI,WAAW;KACb,MAAM,gBAAgB,UAAU,SAAS,SAAS;AAClD,mBAAc,QAAQ,cAAc,UAAiB;MACnD,MAAM,UAAU,MAAM;AACtB,UAAI,OAAO,YAAY,WACrB,SAAQ,gBAAiB,MAAsB,SAAS,MAAM;;AAGlE;;;AAIJ,cAAW,cAAc,MAAM;;EAGjC,MAAM,SAAS,kBAAkB;AAEjC,MAAI,aAAa,OACf,YAAW,uBAAuB,MAAM,aAAa;AAGvD,eAAa,EAAE,SAAS;GAAE,GAAG;GAAY,GAAG;GAAe,CAAC;;AAI9D,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-props-CFK4CtjG.d.ts","names":[],"sources":["../src/components/create-props.ts"],"mappings":";KAAY,WAAA,oCACyB,KAAA,mDACE,MAAA,GAAS,WAAA,MAC5C,KAAA,GAAQ,gBAAA,CAAiB,MAAA;AAAA,KAExB,gBAAA,sCACkC,MAAA,GAAS,WAAA,4BAE1B,MAAA,SAAe,UAAA,UAAoB,SAAA,OACrD,KAAA,EAAO,SAAA,6BAAsC,MAAA,CAAO,SAAA,cAChD,MAAA,CAAO,SAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"editor-context-CAdqwRwB.js","names":[],"sources":["../src/contexts/editor-context.ts"],"sourcesContent":["import type { Editor, Extension } from '@prosekit/core'\nimport { createContext, useContext, type ContextProviderComponent } from 'solid-js'\n\nconst editorContext = createContext<Editor | null>(null)\n\n/**\n * @internal\n */\nexport function useEditorContext<E extends Extension>(): Editor<E> | null {\n return useContext(editorContext)\n}\n\n/**\n * @internal\n */\nexport const EditorContextProvider: ContextProviderComponent<Editor | null> = editorContext.Provider\n"],"mappings":";;;AAGA,MAAM,gBAAgB,cAA6B,KAAK;;;;AAKxD,SAAgB,mBAA0D;AACxE,QAAO,WAAW,cAAc;;;;;AAMlC,MAAa,wBAAiE,cAAc"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-Bx9mKDTJ.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;AAKA;KAAY,cAAA,gBAA8B,CAAA;EACxC,KAAA;AAAA;;;;KAMU,iBAAA,gBAAiC,CAAA;EAC3C,QAAA,GAAW,UAAA;AAAA;;;;KAMD,gBAAA,6CAA6D,WAAA,IAAe,KAAA,GAAQ,GAAA,CAAI,cAAA,CAAe,aAAA;;;;KAKvG,aAAA,MAAmB,CAAA,GAAI,QAAA,CAAS,CAAA"}
|